Index: src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java =================================================================== --- src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java (revision 1583188) +++ src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java (working copy) @@ -85,13 +85,15 @@ private CtxtHandle sppicontext; private boolean continueNeeded; private String challenge; + private String servicePrincipalName; - public WindowsNegotiateScheme(final String scheme) { + public WindowsNegotiateScheme(final String scheme, final String servicePrincipalName) { super(); this.scheme = (scheme == null) ? AuthSchemes.SPNEGO : scheme; this.challenge = null; this.continueNeeded = true; + this.servicePrincipalName = servicePrincipalName; } public void dispose() { @@ -187,7 +189,7 @@ throw new Win32Exception(rc); } - response = getToken(null, null, username); + response = getToken(null, null); } catch (Throwable t) { dispose(); throw new AuthenticationException("Authentication Failed", t); @@ -200,7 +202,7 @@ final byte[] continueTokenBytes = Base64.decodeBase64(this.challenge); final SecBufferDesc continueTokenBuffer = new SecBufferDesc( Sspi.SECBUFFER_TOKEN, continueTokenBytes); - response = getToken(this.sppicontext, continueTokenBuffer, "localhost"); + response = getToken(this.sppicontext, continueTokenBuffer); } catch (Throwable t) { dispose(); throw new AuthenticationException("Authentication Failed", t); @@ -225,15 +227,14 @@ */ private String getToken( final CtxtHandle continueCtx, - final SecBufferDesc continueToken, - final String targetName) { + final SecBufferDesc continueToken) { final IntByReference attr = new IntByReference(); final SecBufferDesc token = new SecBufferDesc( Sspi.SECBUFFER_TOKEN, Sspi.MAX_TOKEN_SIZE); sppicontext = new CtxtHandle(); final int rc = Secur32.INSTANCE.InitializeSecurityContext(clientCred, - continueCtx, targetName, Sspi.ISC_REQ_CONNECTION, 0, + continueCtx, servicePrincipalName, Sspi.ISC_REQ_CONNECTION, 0, Sspi.SECURITY_NATIVE_DREP, continueToken, 0, sppicontext, token, attr, null); switch (rc) { Index: src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateSchemeFactory.java =================================================================== --- src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateSchemeFactory.java (revision 1583192) +++ src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateSchemeFactory.java (working copy) @@ -44,9 +44,16 @@ @Immutable public class WindowsNegotiateSchemeFactory implements AuthSchemeProvider { + private String servicePrincipalName; + + public WindowsNegotiateSchemeFactory(final String servicePrincipalName) { + super(); + this.servicePrincipalName = servicePrincipalName; + } + @Override public AuthScheme create(final HttpContext context) { - return new WindowsNegotiateScheme(AuthSchemes.SPNEGO); + return new WindowsNegotiateScheme(AuthSchemes.SPNEGO, servicePrincipalName); } } Index: src/main/java/org/apache/http/impl/auth/win/WindowsNTLMSchemeFactory.java =================================================================== --- src/main/java/org/apache/http/impl/auth/win/WindowsNTLMSchemeFactory.java (revision 1583188) +++ src/main/java/org/apache/http/impl/auth/win/WindowsNTLMSchemeFactory.java (working copy) @@ -44,9 +44,16 @@ @Immutable public class WindowsNTLMSchemeFactory implements AuthSchemeProvider { + private String servicePrincipalName; + + public WindowsNTLMSchemeFactory(final String servicePrincipalName) { + super(); + this.servicePrincipalName = servicePrincipalName; + } + @Override public AuthScheme create(final HttpContext context) { - return new WindowsNegotiateScheme(AuthSchemes.NTLM); + return new WindowsNegotiateScheme(AuthSchemes.NTLM, servicePrincipalName); } }