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;
});
}
Aggregations