Search in sources :

Example 1 with PasswordManagementQuery

use of org.apereo.cas.pm.PasswordManagementQuery 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);
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) AuditPrincipalResolvers(org.apereo.cas.audit.AuditPrincipalResolvers) RequiredArgsConstructor(lombok.RequiredArgsConstructor) EmailValidator(org.apache.commons.validator.routines.EmailValidator) StringUtils(org.apache.commons.lang3.StringUtils) RequestContext(org.springframework.webflow.execution.RequestContext) AuditActionResolvers(org.apereo.cas.audit.AuditActionResolvers) CommunicationsManager(org.apereo.cas.notifications.CommunicationsManager) BasicIdentifiableCredential(org.apereo.cas.authentication.credential.BasicIdentifiableCredential) FunctionUtils(org.apereo.cas.util.function.FunctionUtils) CasWebflowConstants(org.apereo.cas.web.flow.CasWebflowConstants) CollectionUtils(org.apereo.cas.util.CollectionUtils) NullPrincipal(org.apereo.cas.authentication.principal.NullPrincipal) Audit(org.apereo.inspektr.audit.annotation.Audit) PrincipalResolver(org.apereo.cas.authentication.principal.PrincipalResolver) lombok.val(lombok.val) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Slf4j(lombok.extern.slf4j.Slf4j) PasswordManagementService(org.apereo.cas.pm.PasswordManagementService) EmailMessageBodyBuilder(org.apereo.cas.notifications.mail.EmailMessageBodyBuilder) AuditResourceResolvers(org.apereo.cas.audit.AuditResourceResolvers) AuditableActions(org.apereo.cas.audit.AuditableActions) Optional(java.util.Optional) PasswordManagementQuery(org.apereo.cas.pm.PasswordManagementQuery) Principal(org.apereo.cas.authentication.principal.Principal) WebUtils(org.apereo.cas.web.support.WebUtils) BaseCasWebflowAction(org.apereo.cas.web.flow.actions.BaseCasWebflowAction) Event(org.springframework.webflow.execution.Event) BasicIdentifiableCredential(org.apereo.cas.authentication.credential.BasicIdentifiableCredential)

Aggregations

Optional (java.util.Optional)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1 lombok.val (lombok.val)1 StringUtils (org.apache.commons.lang3.StringUtils)1 EmailValidator (org.apache.commons.validator.routines.EmailValidator)1 AuditActionResolvers (org.apereo.cas.audit.AuditActionResolvers)1 AuditPrincipalResolvers (org.apereo.cas.audit.AuditPrincipalResolvers)1 AuditResourceResolvers (org.apereo.cas.audit.AuditResourceResolvers)1 AuditableActions (org.apereo.cas.audit.AuditableActions)1 BasicIdentifiableCredential (org.apereo.cas.authentication.credential.BasicIdentifiableCredential)1 NullPrincipal (org.apereo.cas.authentication.principal.NullPrincipal)1 Principal (org.apereo.cas.authentication.principal.Principal)1 PrincipalResolver (org.apereo.cas.authentication.principal.PrincipalResolver)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1 CommunicationsManager (org.apereo.cas.notifications.CommunicationsManager)1 EmailMessageBodyBuilder (org.apereo.cas.notifications.mail.EmailMessageBodyBuilder)1 PasswordManagementQuery (org.apereo.cas.pm.PasswordManagementQuery)1 PasswordManagementService (org.apereo.cas.pm.PasswordManagementService)1 CollectionUtils (org.apereo.cas.util.CollectionUtils)1