/** * Returns the authentication realm. * * @return the name of the authentication realm */ public String getRealm() { if (this.authScheme != null) { return this.authScheme.getRealm(); } else { return null; } }
/** * Returns proxy authentication realm, if it has been used during authentication process. * Otherwise returns <tt>null</tt>. * * @return proxy authentication realm * * @deprecated use #getProxyAuthState() */ public String getProxyAuthenticationRealm() { return this.proxyAuthState.getRealm(); }
/** * Returns authentication realm. The realm may not be null. * * @return the authentication realm */ public String getRealm() { return getParameter("realm"); }
/** * Creates a copy of the given credentials scope. * * @since 3.0 */ public AuthScope(final AuthScope authscope) { super(); if (authscope == null) { throw new IllegalArgumentException("Scope may not be null"); } this.host = authscope.getHost(); this.port = authscope.getPort(); this.realm = authscope.getRealm(); this.scheme = authscope.getScheme(); }
/** * Processes the given challenge token. Some authentication schemes * may involve multiple challenge-response exchanges. Such schemes must be able * to maintain the state information when dealing with sequential challenges * * @param challenge the challenge string * * @throws MalformedChallengeException is thrown if the authentication challenge * is malformed * * @since 3.0 */ public void processChallenge(final String challenge) throws MalformedChallengeException { String s = AuthChallengeParser.extractScheme(challenge); if (!s.equalsIgnoreCase(getSchemeName())) { throw new MalformedChallengeException( "Invalid " + getSchemeName() + " challenge: " + challenge); } this.params = AuthChallengeParser.extractParams(challenge); }
/** * Processes the NTLM challenge. * * @param challenge the challenge string * * @throws MalformedChallengeException is thrown if the authentication challenge * is malformed * * @since 3.0 */ public void processChallenge(final String challenge) throws MalformedChallengeException { String s = AuthChallengeParser.extractScheme(challenge); if (!s.equalsIgnoreCase(getSchemeName())) { throw new MalformedChallengeException("Invalid NTLM challenge: " + challenge); } int i = challenge.indexOf(' '); if (i != -1) { s = challenge.substring(i, challenge.length()); this.ntlmchallenge = s.trim(); this.state = TYPE2_MSG_RECEIVED; } else { this.ntlmchallenge = ""; if (this.state == UNINITIATED) { this.state = INITIATED; } else { this.state = FAILED; } } }
public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("Auth state: auth requested ["); buffer.append(this.authRequested); buffer.append("]; auth attempted ["); buffer.append(this.authAttempted); if (this.authScheme != null) { buffer.append("]; auth scheme ["); buffer.append(this.authScheme.getSchemeName()); buffer.append("]; realm ["); buffer.append(this.authScheme.getRealm()); } buffer.append("] preemptive ["); buffer.append(this.preemptive); buffer.append("]"); return buffer.toString(); } }
/** * Encrypt the data. * @param key The key. * @param bytes The data * @return byte[] The encrypted data * @throws HttpException If {@link Cipher.doFinal(byte[])} fails */ private byte[] encrypt(byte[] key, byte[] bytes) throws AuthenticationException { Cipher ecipher = getCipher(key); try { byte[] enc = ecipher.doFinal(bytes); return enc; } catch (IllegalBlockSizeException e) { throw new AuthenticationException("Invalid block size for DES encryption.", e); } catch (BadPaddingException e) { throw new AuthenticationException("Data not padded correctly for DES encryption.", e); } }
/** * Return the cipher for the specified key. * @param key The key. * @return Cipher The cipher. * @throws AuthenticationException If the cipher cannot be retrieved. */ private Cipher getCipher(byte[] key) throws AuthenticationException { try { final Cipher ecipher = Cipher.getInstance("DES/ECB/NoPadding"); key = setupKey(key); ecipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "DES")); return ecipher; } catch (NoSuchAlgorithmException e) { throw new AuthenticationException("DES encryption is not available.", e); } catch (InvalidKeyException e) { throw new AuthenticationException("Invalid key for DES encryption.", e); } catch (NoSuchPaddingException e) { throw new AuthenticationException( "NoPadding option for DES is not available.", e); } }
/** * Gets an ID based upon the realm and the nonce value. This ensures that requests * to the same realm with different nonce values will succeed. This differentiation * allows servers to request re-authentication using a fresh nonce value. * * @deprecated no longer used */ public String getID() { String id = getRealm(); String nonce = getParameter("nonce"); if (nonce != null) { id += "-" + nonce; } return id; }
/** * Default constructor for RFC2617 compliant authetication schemes. * * @param challenge authentication challenge * * @throws MalformedChallengeException is thrown if the authentication challenge * is malformed * * @deprecated Use parameterless constructor and {@link AuthScheme#processChallenge(String)} * method */ public RFC2617Scheme(final String challenge) throws MalformedChallengeException { super(); processChallenge(challenge); }
/** * @deprecated Use {@link #authenticate(UsernamePasswordCredentials, String)} * * Returns a basic <tt>Authorization</tt> header value for the given * {@link UsernamePasswordCredentials}. * * @param credentials The credentials to encode. * * @return a basic authorization string */ public static String authenticate(UsernamePasswordCredentials credentials) { return authenticate(credentials, "ISO-8859-1"); }
public HttpMethodDirector( final HttpConnectionManager connectionManager, final HostConfiguration hostConfiguration, final HttpClientParams params, final HttpState state ) { super(); this.connectionManager = connectionManager; this.hostConfiguration = hostConfiguration; this.params = params; this.state = state; this.authProcessor = new AuthChallengeProcessor(this.params); }
/** * Constructor for the NTLM authentication scheme. * * @param challenge The authentication challenge * * @throws MalformedChallengeException is thrown if the authentication challenge * is malformed */ public NTLMScheme(final String challenge) throws MalformedChallengeException { super(); processChallenge(challenge); }
/** * Constructor for the digest authetication scheme. * * @param challenge authentication challenge * * @throws MalformedChallengeException is thrown if the authentication challenge * is malformed * * @deprecated Use parameterless constructor and {@link AuthScheme#processChallenge(String)} * method */ public DigestScheme(final String challenge) throws MalformedChallengeException { this(); processChallenge(challenge); }
/** * Returns a String identifying the authentication challenge. This is * used, in combination with the host and port to determine if * authorization has already been attempted or not. Schemes which * require multiple requests to complete the authentication should * return a different value for each stage in the request. * * <p>Additionally, the ID should take into account any changes to the * authentication challenge and return a different value when appropriate. * For example when the realm changes in basic authentication it should be * considered a different authentication attempt and a different value should * be returned.</p> * * <p>This method simply returns the realm for the challenge.</p> * * @return String a String identifying the authentication challenge. The * returned value may be null. * * @deprecated no longer used */ public String getID() { return getRealm(); } }
/** * Preemptively assigns Basic authentication scheme. */ public void setPreemptive() { if (!this.preemptive) { if (this.authScheme != null) { throw new IllegalStateException("Authentication state already initialized"); } this.authScheme = AuthPolicy.getAuthScheme(PREEMPTIVE_AUTH_SCHEME); this.preemptive = true; } }
/** * Tests if the Digest authentication process has been completed. * * @return <tt>true</tt> if Digest authorization has been processed, * <tt>false</tt> otherwise. * * @since 3.0 */ public boolean isComplete() { String s = getParameter("stale"); if ("true".equalsIgnoreCase(s)) { return false; } else { return this.complete; } }
/** * Returns authentication realm, if it has been used during authentication process. * Otherwise returns <tt>null</tt>. * * @return authentication realm * * @deprecated use #getHostAuthState() */ public String getAuthenticationRealm() { return this.hostAuthState.getRealm(); }
/** * Processes the Basic challenge. * * @param challenge the challenge string * * @throws MalformedChallengeException is thrown if the authentication challenge * is malformed * * @since 3.0 */ public void processChallenge(String challenge) throws MalformedChallengeException { super.processChallenge(challenge); this.complete = true; }