use of org.apereo.cas.authentication.credential.BasicIdentifiableCredential in project cas by apereo.
the class OAuth20DefaultCasAuthenticationBuilder method build.
@Override
public Authentication build(final UserProfile profile, final OAuthRegisteredService registeredService, final WebContext context, final Service service) {
val attrs = new HashMap<>(profile.getAttributes());
val profileAttributes = CoreAuthenticationUtils.convertAttributeValuesToMultiValuedObjects(attrs);
val newPrincipal = principalFactory.createPrincipal(profile.getId(), profileAttributes);
LOGGER.debug("Created final principal [{}] after filtering attributes based on [{}]", newPrincipal, registeredService);
val authenticator = profile.getClass().getCanonicalName();
val metadata = new BasicCredentialMetaData(new BasicIdentifiableCredential(profile.getId()));
val handlerResult = new DefaultAuthenticationHandlerExecutionResult(authenticator, metadata, newPrincipal, new ArrayList<>(0));
val scopes = OAuth20Utils.getRequestedScopes(context);
val state = context.getRequestParameter(OAuth20Constants.STATE).map(String::valueOf).or(() -> OAuth20Utils.getRequestParameter(context, OAuth20Constants.STATE)).orElse(StringUtils.EMPTY);
val nonce = context.getRequestParameter(OAuth20Constants.NONCE).map(String::valueOf).or(() -> OAuth20Utils.getRequestParameter(context, OAuth20Constants.NONCE)).orElse(StringUtils.EMPTY);
LOGGER.debug("OAuth [{}] is [{}], and [{}] is [{}]", OAuth20Constants.STATE, state, OAuth20Constants.NONCE, nonce);
val builder = DefaultAuthenticationBuilder.newInstance();
if (profile instanceof BasicUserProfile) {
val authenticationAttributes = ((BasicUserProfile) profile).getAuthenticationAttributes();
builder.addAttributes(authenticationAttributes);
}
builder.addAttribute("permissions", new LinkedHashSet<>(profile.getPermissions())).addAttribute("roles", new LinkedHashSet<>(profile.getRoles())).addAttribute("scopes", scopes).addAttribute(OAuth20Constants.STATE, state).addAttribute(OAuth20Constants.NONCE, nonce).addAttribute(OAuth20Constants.CLIENT_ID, registeredService.getClientId()).addCredential(metadata).setPrincipal(newPrincipal).setAuthenticationDate(ZonedDateTime.now(ZoneOffset.UTC)).addSuccess(profile.getClass().getCanonicalName(), handlerResult);
context.getRequestParameter(OAuth20Constants.ACR_VALUES).ifPresent(value -> builder.addAttribute(OAuth20Constants.ACR_VALUES, value));
return builder.build();
}
use of org.apereo.cas.authentication.credential.BasicIdentifiableCredential in project cas by apereo.
the class CasResolveAttributesReportEndpoint method resolvePrincipalAttributes.
/**
* Resolve principal attributes map.
*
* @param uid the uid
* @return the map
*/
@ReadOperation
@Operation(summary = "Resolve principal attributes for user", parameters = { @Parameter(name = "uid", required = true) })
public Map<String, Object> resolvePrincipalAttributes(@Selector final String uid) {
val p = defaultPrincipalResolver.getObject().resolve(new BasicIdentifiableCredential(uid));
val map = new HashMap<String, Object>();
map.put("uid", p.getId());
map.put("attributes", p.getAttributes());
return map;
}
use of org.apereo.cas.authentication.credential.BasicIdentifiableCredential in project cas by apereo.
the class SendPasswordResetInstructionsAction method sendPasswordResetEmailToAccount.
/**
* Send password reset email to account.
*
* @param username the username
* @param to the to
* @param url the url
* @param requestContext the request context
* @return true /false
*/
protected boolean sendPasswordResetEmailToAccount(final String username, final String to, final String url, final RequestContext requestContext) {
if (StringUtils.isNotBlank(to)) {
val reset = casProperties.getAuthn().getPm().getReset().getMail();
val parameters = CollectionUtils.<String, Object>wrap("url", url);
val credential = new BasicIdentifiableCredential();
credential.setId(username);
val person = principalResolver.resolve(credential);
FunctionUtils.doIfNotNull(person, principal -> parameters.put("principal", principal));
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val text = EmailMessageBodyBuilder.builder().properties(reset).parameters(parameters).locale(Optional.ofNullable(request.getLocale())).build().produce();
LOGGER.debug("Sending password reset URL [{}] via email to [{}] for username [{}]", url, to, username);
return this.communicationsManager.email(reset, to, text);
}
return false;
}
use of org.apereo.cas.authentication.credential.BasicIdentifiableCredential in project cas by apereo.
the class SendForgotUsernameInstructionsAction method sendForgotUsernameEmailToAccount.
/**
* Send forgot username email to account.
*
* @param query the query
* @param requestContext the request context
* @return the boolean
*/
protected boolean sendForgotUsernameEmailToAccount(final PasswordManagementQuery query, final RequestContext requestContext) {
val parameters = CollectionUtils.<String, Object>wrap("email", query.getEmail());
val credential = new BasicIdentifiableCredential();
credential.setId(query.getUsername());
val person = principalResolver.resolve(credential);
FunctionUtils.doIf(person != null && !person.getClass().equals(NullPrincipal.class), principal -> {
parameters.put("principal", principal);
requestContext.getFlashScope().put(Principal.class.getName(), person);
}).accept(person);
val reset = casProperties.getAuthn().getPm().getForgotUsername().getMail();
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val body = EmailMessageBodyBuilder.builder().properties(reset).locale(Optional.ofNullable(request.getLocale())).parameters(parameters).build().produce();
return this.communicationsManager.email(reset, query.getEmail(), body);
}
use of org.apereo.cas.authentication.credential.BasicIdentifiableCredential in project cas by apereo.
the class OAuth20UserProfileEndpointControllerTests method getAuthentication.
protected static Authentication getAuthentication(final Principal principal) {
val metadata = new BasicCredentialMetaData(new BasicIdentifiableCredential(principal.getId()));
val handlerResult = new DefaultAuthenticationHandlerExecutionResult(principal.getClass().getCanonicalName(), metadata, principal, new ArrayList<>());
return DefaultAuthenticationBuilder.newInstance().setPrincipal(principal).addCredential(metadata).setAuthenticationDate(ZonedDateTime.now(ZoneId.systemDefault())).addSuccess(principal.getClass().getCanonicalName(), handlerResult).build();
}
Aggregations