Search in sources :

Example 1 with CasSimpleMultifactorAuthenticationTicket

use of org.apereo.cas.mfa.simple.ticket.CasSimpleMultifactorAuthenticationTicket in project cas by apereo.

the class CasSimpleMultifactorSendTokenAction method getOrCreateToken.

/**
 * Get or create a token.
 *
 * @param requestContext the request context
 * @param principal      the principal
 * @return the token
 */
protected CasSimpleMultifactorAuthenticationTicket getOrCreateToken(final RequestContext requestContext, final Principal principal) {
    val currentToken = WebUtils.getSimpleMultifactorAuthenticationToken(requestContext, CasSimpleMultifactorAuthenticationTicket.class);
    return Optional.ofNullable(currentToken).filter(token -> !token.isExpired()).orElseGet(() -> {
        WebUtils.removeSimpleMultifactorAuthenticationToken(requestContext);
        val service = WebUtils.getService(requestContext);
        val mfaFactory = (CasSimpleMultifactorAuthenticationTicketFactory) ticketFactory.get(CasSimpleMultifactorAuthenticationTicket.class);
        val token = mfaFactory.create(service, CollectionUtils.wrap(CasSimpleMultifactorAuthenticationConstants.PROPERTY_PRINCIPAL, principal));
        LOGGER.debug("Created multifactor authentication token [{}] for service [{}]", token.getId(), service);
        return token;
    });
}
Also used : lombok.val(lombok.val) BucketConsumer(org.apereo.cas.bucket4j.consumer.BucketConsumer) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) LocalAttributeMap(org.springframework.webflow.core.collection.LocalAttributeMap) StringUtils(org.apache.commons.lang3.StringUtils) RequestContext(org.springframework.webflow.execution.RequestContext) CasSimpleMultifactorAuthenticationTicketFactory(org.apereo.cas.mfa.simple.ticket.CasSimpleMultifactorAuthenticationTicketFactory) CommunicationsManager(org.apereo.cas.notifications.CommunicationsManager) CasSimpleMultifactorAuthenticationConstants(org.apereo.cas.mfa.simple.CasSimpleMultifactorAuthenticationConstants) FunctionUtils(org.apereo.cas.util.function.FunctionUtils) AbstractMultifactorAuthenticationAction(org.apereo.cas.web.flow.actions.AbstractMultifactorAuthenticationAction) CasWebflowConstants(org.apereo.cas.web.flow.CasWebflowConstants) CasSimpleMultifactorAuthenticationTicket(org.apereo.cas.mfa.simple.ticket.CasSimpleMultifactorAuthenticationTicket) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) TicketFactory(org.apereo.cas.ticket.TicketFactory) CasSimpleMultifactorTokenCommunicationStrategy(org.apereo.cas.mfa.simple.CasSimpleMultifactorTokenCommunicationStrategy) lombok.val(lombok.val) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Slf4j(lombok.extern.slf4j.Slf4j) CasSimpleMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.simple.CasSimpleMultifactorAuthenticationProperties) CasSimpleMultifactorAuthenticationProvider(org.apereo.cas.mfa.simple.CasSimpleMultifactorAuthenticationProvider) EmailMessageBodyBuilder(org.apereo.cas.notifications.mail.EmailMessageBodyBuilder) Optional(java.util.Optional) Principal(org.apereo.cas.authentication.principal.Principal) WebUtils(org.apereo.cas.web.support.WebUtils) Event(org.springframework.webflow.execution.Event) Ticket(org.apereo.cas.ticket.Ticket) CasSimpleMultifactorAuthenticationTicket(org.apereo.cas.mfa.simple.ticket.CasSimpleMultifactorAuthenticationTicket) CasSimpleMultifactorAuthenticationTicketFactory(org.apereo.cas.mfa.simple.ticket.CasSimpleMultifactorAuthenticationTicketFactory)

Aggregations

Map (java.util.Map)1 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 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)1 Principal (org.apereo.cas.authentication.principal.Principal)1 BucketConsumer (org.apereo.cas.bucket4j.consumer.BucketConsumer)1 CasSimpleMultifactorAuthenticationProperties (org.apereo.cas.configuration.model.support.mfa.simple.CasSimpleMultifactorAuthenticationProperties)1 CasSimpleMultifactorAuthenticationConstants (org.apereo.cas.mfa.simple.CasSimpleMultifactorAuthenticationConstants)1 CasSimpleMultifactorAuthenticationProvider (org.apereo.cas.mfa.simple.CasSimpleMultifactorAuthenticationProvider)1 CasSimpleMultifactorTokenCommunicationStrategy (org.apereo.cas.mfa.simple.CasSimpleMultifactorTokenCommunicationStrategy)1 CasSimpleMultifactorAuthenticationTicket (org.apereo.cas.mfa.simple.ticket.CasSimpleMultifactorAuthenticationTicket)1 CasSimpleMultifactorAuthenticationTicketFactory (org.apereo.cas.mfa.simple.ticket.CasSimpleMultifactorAuthenticationTicketFactory)1 CommunicationsManager (org.apereo.cas.notifications.CommunicationsManager)1 EmailMessageBodyBuilder (org.apereo.cas.notifications.mail.EmailMessageBodyBuilder)1 Ticket (org.apereo.cas.ticket.Ticket)1 TicketFactory (org.apereo.cas.ticket.TicketFactory)1 CollectionUtils (org.apereo.cas.util.CollectionUtils)1