Search in sources :

Example 1 with Client

use of com.duosecurity.Client in project cas by apereo.

the class DuoSecurityUniversalPromptPrepareLoginAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
    val authentication = WebUtils.getInProgressAuthentication();
    val duoSecurityIdentifier = WebUtils.getMultifactorAuthenticationProviderById(requestContext);
    val provider = duoProviderBean.getProvider(duoSecurityIdentifier);
    val client = provider.getDuoAuthenticationService().getDuoClient().map(c -> (Client) c).orElseThrow(() -> new RuntimeException("Unable to locate Duo Security client"));
    val state = client.generateState();
    val factory = (TransientSessionTicketFactory) ticketFactory.get(TransientSessionTicket.class);
    val properties = new LinkedHashMap<String, Object>();
    properties.put("duoProviderId", duoSecurityIdentifier);
    properties.put(Authentication.class.getSimpleName(), authentication);
    properties.put(AuthenticationResultBuilder.class.getSimpleName(), WebUtils.getAuthenticationResultBuilder(requestContext));
    properties.put(AuthenticationResult.class.getSimpleName(), WebUtils.getAuthenticationResult(requestContext));
    properties.put(Credential.class.getSimpleName(), WebUtils.getMultifactorAuthenticationParentCredential(requestContext));
    val flowScope = requestContext.getFlowScope().asMap();
    properties.put(MutableAttributeMap.class.getSimpleName(), flowScope);
    Optional.ofNullable(WebUtils.getRegisteredService(requestContext)).ifPresent(registeredService -> properties.put(RegisteredService.class.getSimpleName(), registeredService));
    val service = WebUtils.getService(requestContext);
    val ticket = factory.create(state, service, properties);
    ticketRegistry.addTicket(ticket);
    LOGGER.debug("Stored Duo Security session via [{}]", ticket);
    val principal = resolvePrincipal(authentication.getPrincipal());
    val authUrl = client.createAuthUrl(principal.getId(), ticket.getId());
    requestContext.getFlowScope().put("duoUniversalPromptLoginUrl", authUrl);
    LOGGER.debug("Redirecting to Duo Security url at [{}]", authUrl);
    return success(ticket);
}
Also used : lombok.val(lombok.val) TransientSessionTicket(org.apereo.cas.ticket.TransientSessionTicket) DuoSecurityMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) MultifactorAuthenticationProviderBean(org.apereo.cas.authentication.MultifactorAuthenticationProviderBean) MutableAttributeMap(org.springframework.webflow.core.collection.MutableAttributeMap) RequestContext(org.springframework.webflow.execution.RequestContext) DuoSecurityMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider) RegisteredService(org.apereo.cas.services.RegisteredService) Client(com.duosecurity.Client) LinkedHashMap(java.util.LinkedHashMap) Slf4j(lombok.extern.slf4j.Slf4j) TicketRegistry(org.apereo.cas.ticket.registry.TicketRegistry) AbstractMultifactorAuthenticationAction(org.apereo.cas.web.flow.actions.AbstractMultifactorAuthenticationAction) TransientSessionTicketFactory(org.apereo.cas.ticket.TransientSessionTicketFactory) Authentication(org.apereo.cas.authentication.Authentication) AuthenticationResultBuilder(org.apereo.cas.authentication.AuthenticationResultBuilder) Optional(java.util.Optional) TicketFactory(org.apereo.cas.ticket.TicketFactory) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Credential(org.apereo.cas.authentication.Credential) WebUtils(org.apereo.cas.web.support.WebUtils) Event(org.springframework.webflow.execution.Event) TransientSessionTicket(org.apereo.cas.ticket.TransientSessionTicket) Credential(org.apereo.cas.authentication.Credential) Authentication(org.apereo.cas.authentication.Authentication) MutableAttributeMap(org.springframework.webflow.core.collection.MutableAttributeMap) TransientSessionTicketFactory(org.apereo.cas.ticket.TransientSessionTicketFactory) Client(com.duosecurity.Client) AuthenticationResultBuilder(org.apereo.cas.authentication.AuthenticationResultBuilder) LinkedHashMap(java.util.LinkedHashMap) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult)

Aggregations

Client (com.duosecurity.Client)1 LinkedHashMap (java.util.LinkedHashMap)1 Optional (java.util.Optional)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1 lombok.val (lombok.val)1 DuoSecurityMultifactorAuthenticationProvider (org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider)1 Authentication (org.apereo.cas.authentication.Authentication)1 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)1 AuthenticationResultBuilder (org.apereo.cas.authentication.AuthenticationResultBuilder)1 Credential (org.apereo.cas.authentication.Credential)1 MultifactorAuthenticationProviderBean (org.apereo.cas.authentication.MultifactorAuthenticationProviderBean)1 DuoSecurityMultifactorAuthenticationProperties (org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties)1 RegisteredService (org.apereo.cas.services.RegisteredService)1 TicketFactory (org.apereo.cas.ticket.TicketFactory)1 TransientSessionTicket (org.apereo.cas.ticket.TransientSessionTicket)1 TransientSessionTicketFactory (org.apereo.cas.ticket.TransientSessionTicketFactory)1 TicketRegistry (org.apereo.cas.ticket.registry.TicketRegistry)1 AbstractMultifactorAuthenticationAction (org.apereo.cas.web.flow.actions.AbstractMultifactorAuthenticationAction)1 WebUtils (org.apereo.cas.web.support.WebUtils)1