/** * 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(); } }
@Override public boolean supports(final Credential credential) { return credential != null && credential.getId() != null; }
@Override public boolean supports(final Credential credential) { return credential.getId() != null; }
/** * Creates a new instance from the given credential. * * @param credential Credential for which metadata should be created. */ public BasicCredentialMetaData(final Credential credential) { this.id = credential.getId(); this.credentialClass = credential.getClass(); }
@Override public boolean verify(final RequestContext requestContext, final Credential credential) { final String key = credential.getId(); synchronized (this.policyMap) { if (this.policyMap.containsKey(key)) { return this.policyMap.get(key); } } return false; }
@Override public Principal resolve(final Credential credential) { return this.principalFactory.createPrincipal(credential.getId()); }
@Override public boolean equals(final Object other) { if (other == null) { return false; } if (!(other instanceof Credential)) { return false; } if (other == this) { return true; } final EqualsBuilder builder = new EqualsBuilder(); builder.append(getId(), ((Credential) other).getId()); return builder.isEquals(); }
@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); }
@Override public HandlerResult authenticate(final Credential credential) throws GeneralSecurityException { logger.debug("Trusting credential for: {}", credential); return new DefaultHandlerResult( this, (PrincipalBearingCredential) credential, this.principalFactory.createPrincipal(credential.getId())); }
/** * Gets credential from the context. * * @param context the context * @return the credential, or null if it cant be found in the context or if it has no id. */ public static Credential getCredential(@NotNull final RequestContext context) { final Credential cFromRequest = (Credential) context.getRequestScope().get("credential"); final Credential cFromFlow = (Credential) context.getFlowScope().get("credential"); final Credential credential = cFromRequest != null ? cFromRequest : cFromFlow; if (credential != null && StringUtils.isBlank(credential.getId())) { return null; } return credential; }
@Override protected final Event doExecute(final RequestContext ctx) throws Exception { final Credential credentials = WebUtils.getCredential(ctx); final MessageContext messageContext = ctx.getMessageContext(); if (credentials != null) { final String id = credentials.getId(); return submit(ctx, credentials, messageContext, id); } logger.warn("Credentials could not be determined, or no username was associated with the request."); return getErrorEvent(ctx); }
@Override protected Event doExecute(final RequestContext context) { final FlowSession session = context.getFlowExecutionContext().getActiveSession(); LOGGER.debug("Authentication has entered the flow [{}] executing state [{}", context.getActiveFlow().getId(), session.getState().getId()); final Credential creds = WebUtils.getCredential(context); final String id = creds != null ? creds.getId() : null; final Credential mfaCreds = createCredentials(context, creds, id); final AttributeMap map = new LocalAttributeMap(ATTRIBUTE_ID_MFA_CREDENTIALS, mfaCreds); return new Event(this, EVENT_ID_SUCCESS, map); } }