@Override protected HandlerResult postAuthenticate(final Credential credential, final HandlerResult result) { final TokenCredential tokenCredential = (TokenCredential) credential; tokenCredential.setId(result.getPrincipal().getId()); return super.postAuthenticate(credential, result); }
/** * 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()); } }
/** * {@InheritDoc} */ @Override protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException { final ClientCredential clientCredentials = (ClientCredential) credential; final OpenIdCredentials openIdCredentials = clientCredentials.getOpenIdCredentials(); logger.debug("Client credentials : '{}'", clientCredentials); final String clientName = openIdCredentials.getClientName(); logger.debug("Client name : '{}'", clientName); // Web context final ServletExternalContext servletExternalContext = (ServletExternalContext) ExternalContextHolder.getExternalContext(); final HttpServletRequest request = (HttpServletRequest) servletExternalContext.getNativeRequest(); final HttpServletResponse response = (HttpServletResponse) servletExternalContext.getNativeResponse(); final WebContext webContext = new J2EContext(request, response); // Get user profile final UserProfile userProfile = this.client.getUserProfile(openIdCredentials, webContext); logger.debug("userProfile : {}", userProfile); if (userProfile != null) { final String id = userProfile.getId(); if (StringHelper.isNotEmpty(id)) { openIdCredentials.setUserProfile(userProfile); return new HandlerResult(this, clientCredentials, new SimplePrincipal(id, userProfile.getAttributes())); } } throw new FailedLoginException("Provider did not produce profile for " + clientCredentials); }
logger.info("{} successfully authenticated {}", handler.getName(), credential); if (resolver == null) { principal = result.getPrincipal(); logger.debug( "No resolver configured for {}. Falling back to handler principal {}", + "This is likely due to misconfiguration or missing attributes; CAS will attempt to use the principal " + "produced by the authentication handler, if any.", resolver.getClass().getSimpleName()); principal = result.getPrincipal();