HTTPCLIENT-1394: made WindowsCredentialsProvider a decorator for an arbitrary CredentialsProvider

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1602398 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2014-06-13 12:02:02 +00:00
parent 8b01566bf7
commit 101850f4fc
1 changed files with 19 additions and 3 deletions

View File

@ -29,8 +29,9 @@ package org.apache.http.impl.auth.win;
import org.apache.http.annotation.ThreadSafe; import org.apache.http.annotation.ThreadSafe;
import org.apache.http.auth.AuthScope; import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials; import org.apache.http.auth.Credentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.AuthSchemes; import org.apache.http.client.config.AuthSchemes;
import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.util.Args;
/** /**
* {@link org.apache.http.client.CredentialsProvider} implementation that always returns * {@link org.apache.http.client.CredentialsProvider} implementation that always returns
@ -42,7 +43,13 @@ import org.apache.http.impl.client.BasicCredentialsProvider;
* @since 4.4 * @since 4.4
*/ */
@ThreadSafe @ThreadSafe
public class WindowsCredentialsProvider extends BasicCredentialsProvider { public class WindowsCredentialsProvider implements CredentialsProvider {
private final CredentialsProvider provider;
public WindowsCredentialsProvider(final CredentialsProvider provider) {
this.provider = Args.notNull(provider, "Credentials provider");
}
@Override @Override
public Credentials getCredentials(final AuthScope authscope) { public Credentials getCredentials(final AuthScope authscope) {
@ -50,10 +57,19 @@ public class WindowsCredentialsProvider extends BasicCredentialsProvider {
if (AuthSchemes.NTLM.equalsIgnoreCase(scheme) || AuthSchemes.SPNEGO.equalsIgnoreCase(scheme)) { if (AuthSchemes.NTLM.equalsIgnoreCase(scheme) || AuthSchemes.SPNEGO.equalsIgnoreCase(scheme)) {
return CurrentWindowsCredentials.INSTANCE; return CurrentWindowsCredentials.INSTANCE;
} else { } else {
return super.getCredentials(authscope); return provider.getCredentials(authscope);
} }
} }
@Override
public void setCredentials(final AuthScope authscope, final Credentials credentials) {
provider.setCredentials(authscope, credentials);
}
@Override
public void clear() {
provider.clear();
}
} }