refined basic auth

This commit is contained in:
Adrian Cole 2010-06-22 15:23:07 -07:00
parent 0b9772e910
commit d6e06d5272
1 changed files with 5 additions and 4 deletions

View File

@ -21,8 +21,7 @@ package org.jclouds.http.filters;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.Collections; import java.util.Set;
import java.util.List;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
@ -32,6 +31,8 @@ import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpRequestFilter;
import com.google.common.collect.ImmutableSet;
/** /**
* Uses Basic Authentication to sign the request. * Uses Basic Authentication to sign the request.
* *
@ -42,11 +43,11 @@ import org.jclouds.http.HttpRequestFilter;
@Singleton @Singleton
public class BasicAuthentication implements HttpRequestFilter { public class BasicAuthentication implements HttpRequestFilter {
private final List<String> credentialList; private final Set<String> credentialList;
public BasicAuthentication(String user, String password, EncryptionService encryptionService) public BasicAuthentication(String user, String password, EncryptionService encryptionService)
throws UnsupportedEncodingException { throws UnsupportedEncodingException {
this.credentialList = Collections.singletonList("Basic " this.credentialList = ImmutableSet.of("Basic "
+ encryptionService.toBase64String(String.format("%s:%s", + encryptionService.toBase64String(String.format("%s:%s",
checkNotNull(user, "user"), checkNotNull(password, "password")).getBytes( checkNotNull(user, "user"), checkNotNull(password, "password")).getBytes(
"UTF-8"))); "UTF-8")));