|
1
|
|
|
package org.apereo.cas.adaptors.duo.web.flow.action; |
|
2
|
|
|
|
|
3
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
4
|
|
|
import org.apereo.cas.adaptors.duo.DuoUserAccount; |
|
5
|
|
|
import org.apereo.cas.adaptors.duo.DuoUserAccountAuthStatus; |
|
6
|
|
|
import org.apereo.cas.adaptors.duo.authn.DuoMultifactorAuthenticationProvider; |
|
7
|
|
|
import org.apereo.cas.adaptors.duo.authn.DuoSecurityAuthenticationService; |
|
8
|
|
|
import org.apereo.cas.authentication.Authentication; |
|
9
|
|
|
import org.apereo.cas.authentication.principal.Principal; |
|
10
|
|
|
import org.apereo.cas.services.MultifactorAuthenticationProvider; |
|
11
|
|
|
import org.apereo.cas.services.VariegatedMultifactorAuthenticationProvider; |
|
12
|
|
|
import org.apereo.cas.web.flow.CasWebflowConstants; |
|
13
|
|
|
import org.apereo.cas.web.support.WebUtils; |
|
14
|
|
|
import org.springframework.webflow.action.AbstractAction; |
|
15
|
|
|
import org.springframework.webflow.action.EventFactorySupport; |
|
16
|
|
|
import org.springframework.webflow.execution.Event; |
|
17
|
|
|
import org.springframework.webflow.execution.RequestContext; |
|
18
|
|
|
|
|
19
|
|
|
import java.util.Collection; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* This is {@link DetermineDuoUserAccountAction}. |
|
23
|
|
|
* |
|
24
|
|
|
* @author Misagh Moayyed |
|
25
|
|
|
* @since 5.2.0 |
|
26
|
|
|
*/ |
|
27
|
|
|
public class DetermineDuoUserAccountAction extends AbstractAction { |
|
28
|
|
|
private final VariegatedMultifactorAuthenticationProvider provider; |
|
29
|
|
|
|
|
30
|
|
|
public DetermineDuoUserAccountAction(final VariegatedMultifactorAuthenticationProvider provider) { |
|
31
|
|
|
this.provider = provider; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
@Override |
|
35
|
|
|
protected Event doExecute(final RequestContext requestContext) { |
|
36
|
|
|
final Authentication authentication = WebUtils.getAuthentication(requestContext); |
|
37
|
|
|
final Principal p = authentication.getPrincipal(); |
|
38
|
|
|
|
|
39
|
|
|
final Collection<MultifactorAuthenticationProvider> providers = WebUtils.getResolvedMultifactorAuthenticationProviders(requestContext); |
|
40
|
|
|
for (final MultifactorAuthenticationProvider pr : providers) { |
|
41
|
|
|
final DuoMultifactorAuthenticationProvider duoProvider = this.provider.findProvider(pr.getId(), DuoMultifactorAuthenticationProvider.class); |
|
42
|
|
|
final DuoSecurityAuthenticationService duoAuthenticationService = duoProvider.getDuoAuthenticationService(); |
|
43
|
|
|
|
|
44
|
|
|
final DuoUserAccount account = duoAuthenticationService.getDuoUserAccount(p.getId()); |
|
45
|
|
|
if (account.getStatus() == DuoUserAccountAuthStatus.ENROLL && StringUtils.isNotBlank(duoProvider.getRegistrationUrl())) { |
|
46
|
|
|
requestContext.getFlowScope().put("duoRegistrationUrl", duoProvider.getRegistrationUrl()); |
|
47
|
|
|
return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_ENROLL); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
return success(); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|