List of usage examples for org.apache.http.auth AuthenticationException AuthenticationException
public AuthenticationException(final String message, final Throwable cause)
From source file:org.apache.http.impl.auth.win.WindowsNegotiateScheme.java
@Override public Header authenticate(final Credentials credentials, final HttpRequest request, final HttpContext context) throws AuthenticationException { final String response; if (clientCred == null) { // ?? We don't use the credentials, should we allow anything? if (!(credentials instanceof CurrentWindowsCredentials)) { throw new InvalidCredentialsException("Credentials cannot be used for " + getSchemeName() + " authentication: " + credentials.getClass().getName()); }// w w w. j a va2 s.c o m // client credentials handle try { final String username = CurrentWindowsCredentials.getCurrentUsername(); final TimeStamp lifetime = new TimeStamp(); clientCred = new CredHandle(); final int rc = Secur32.INSTANCE.AcquireCredentialsHandle(username, scheme, Sspi.SECPKG_CRED_OUTBOUND, null, null, null, null, clientCred, lifetime); if (WinError.SEC_E_OK != rc) { throw new Win32Exception(rc); } response = getToken(null, null, username); } catch (Throwable t) { dispose(); throw new AuthenticationException("Authentication Failed", t); } } else if (this.challenge == null || this.challenge.length() == 0) { dispose(); throw new AuthenticationException("Authentication Failed"); } else { try { final byte[] continueTokenBytes = Base64.decodeBase64(this.challenge); final SecBufferDesc continueTokenBuffer = new SecBufferDesc(Sspi.SECBUFFER_TOKEN, continueTokenBytes); response = getToken(this.sppicontext, continueTokenBuffer, "localhost"); } catch (Throwable t) { dispose(); throw new AuthenticationException("Authentication Failed", t); } } final CharArrayBuffer buffer = new CharArrayBuffer(scheme.length() + 30); if (isProxy()) { buffer.append(AUTH.PROXY_AUTH_RESP); } else { buffer.append(AUTH.WWW_AUTH_RESP); } buffer.append(": "); buffer.append(scheme); // NTLM or Negotiate buffer.append(" "); buffer.append(response); return new BufferedHeader(buffer); }