/** * Creates a new builder. * * @return New builder instance */ public static AuthenticationBuilder newInstance() { return new DefaultAuthenticationBuilder(); } }
/** * @return The credential identifier. */ @Override public String toString() { return getId(); }
/** * Extracts the id of the user from the provided credential. This method should be overridden by subclasses to * achieve more sophisticated strategies for producing a principal ID from a credential. * * @param credential the credential provided by the user. * @return the username, or null if it could not be resolved. */ protected String extractPrincipalId(final Credential credential) { return credential.getId(); } }
/** * Creates a new builder initialized with data from the given authentication source. * * @param source Authentication source. * * @return New builder instance initialized with all fields in the given authentication source. */ public static AuthenticationBuilder newInstance(final Authentication source) { final DefaultAuthenticationBuilder builder = new DefaultAuthenticationBuilder(source.getPrincipal()); builder.setAuthenticationDate(source.getAuthenticationDate()); builder.setCredentials(source.getCredentials()); builder.setSuccesses(source.getSuccesses()); builder.setFailures(source.getFailures()); builder.setAttributes(source.getAttributes()); return builder; }
@Override public void populateAttributes(final AuthenticationBuilder builder, final Credential credential) { final UsernamePasswordCredential c = (UsernamePasswordCredential) credential; final Authentication authentication = builder.build(); this.credentialCache.put(authentication.getPrincipal().getId(), c.getPassword()); }
@Override public void populateAttributes(final AuthenticationBuilder builder, final Credential credential) { logger.debug("Processing request to capture the credential for [{}]", credential.getId()); final UsernamePasswordCredential c = (UsernamePasswordCredential) credential; builder.addAttribute(UsernamePasswordCredential.AUTHENTICATION_ATTRIBUTE_PASSWORD, c.getPassword()); logger.debug("Encrypted credential is added as the authentication attribute [{}] to the authentication", UsernamePasswordCredential.AUTHENTICATION_ATTRIBUTE_PASSWORD); }
/** * Helper method to construct a handler result * on successful authentication events. * * @param credential the credential on which the authentication was successfully performed. * Note that this credential instance may be different from what was originally provided * as transformation of the username may have occurred, if one is in fact defined. * @param principal the resolved principal * @param warnings the warnings * @return the constructed handler result */ protected final HandlerResult createHandlerResult(final Credential credential, final Principal principal, final List<MessageDescriptor> warnings) { return new DefaultHandlerResult(this, new BasicCredentialMetaData(credential), principal, warnings); } }
/** * Add authentication method attribute. * * @param builder the builder * @param authentication the authentication */ private void addAuthenticationMethodAttribute(final AuthenticationBuilder builder, final Authentication authentication) { for (final HandlerResult result : authentication.getSuccesses().values()) { builder.addAttribute(AUTHENTICATION_METHOD_ATTRIBUTE, result.getHandlerName()); } }
@Override public void populateAttributes(final AuthenticationBuilder builder, final Credential credential) { final RememberMeCredential r = (RememberMeCredential) credential; if (r.isRememberMe()) { LOGGER.debug("Credential is configured to be remembered. Captured this as {} attribute", RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME); builder.addAttribute(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME, Boolean.TRUE); } }
@Override public AuthenticationTransactionManager handle(final AuthenticationTransaction authenticationTransaction, final AuthenticationContextBuilder authenticationContext) throws AuthenticationException { if (!authenticationTransaction.getCredentials().isEmpty()) { final Authentication authentication = this.authenticationManager.authenticate(authenticationTransaction); LOGGER.debug("Successful authentication; Collecting authentication result [{}]", authentication); authenticationContext.collect(authentication); } LOGGER.debug("Transaction ignored since there are no credentials to authenticate"); return this; }
/** * Creates a new instance from an authentication event that was successful prior to principal resolution. * * @param authentication Authentication event. */ public UnresolvedPrincipalException(final Authentication authentication) { super(UNRESOLVED_PRINCIPAL, authentication.getFailures(), authentication.getSuccesses()); }
/** * Wrap credentials into an authentication transaction, as a factory method, * and return the final result. * * @param credentials the credentials * @return the authentication transaction */ public static AuthenticationTransaction wrap(final Credential... credentials) { return new AuthenticationTransaction(sanitizeCredentials(credentials)); }
/** * @return Returns the code. If there is a chained exception it recursively * calls {@code getCode()} on the cause of the chained exception rather than the returning * the code itself. */ public final String getCode() { final Throwable cause = this.getCause(); if (cause instanceof RootCasException) { return ((RootCasException) cause).getCode(); } return this.code; }
/** * Instantiates a new trusted proxy authentication trust store ssl socket factory. * @param trustStoreFile the trust store file * @param trustStorePassword the trust store password * @param trustStoreType the trust store type */ public FileTrustStoreSslSocketFactory(final File trustStoreFile, final String trustStorePassword, final String trustStoreType) { super(getTrustedSslContext(trustStoreFile, trustStorePassword, trustStoreType)); }
@Override public Map<String, Class<? extends Exception>> getFailures() { return wrap(this.failures); }
@Override public String toString() { return this.getCode(); } }
@Override public AuthenticationContext build() { return build(null); }
@Override public boolean supports(final Credential credential) { return credential != null && credential.getId() != null; }
/** * Creates a new instance from what would otherwise have been a successful authentication event and the two * disparate principals resolved. * * @param authentication Authentication event. * @param a First resolved principal. * @param b Second resolved principal. */ public MixedPrincipalException(final Authentication authentication, final Principal a, final Principal b) { super(a + " != " + b, authentication.getFailures(), authentication.getSuccesses()); this.first = a; this.second = b; }
@Override public boolean supports(final Credential credential) { return credential.getId() != null; }