use of org.springframework.webflow.engine.support.DefaultTargetStateResolver in project cas by apereo.
the class AbstractMultifactorTrustedDeviceWebflowConfigurer method registerMultifactorTrustedAuthentication.
/**
* Register multifactor trusted authentication.
*
* @param registry the registry
*/
protected void registerMultifactorTrustedAuthentication(final FlowDefinitionRegistry registry) {
validateFlowDefinitionConfiguration();
LOGGER.trace("Flow definitions found in the registry are [{}]", (Object[]) registry.getFlowDefinitionIds());
val flowId = Arrays.stream(registry.getFlowDefinitionIds()).findFirst().orElseThrow();
LOGGER.trace("Processing flow definition [{}]", flowId);
val flow = (Flow) registry.getFlowDefinition(flowId);
Assert.notNull(flow, String.format("%s flow cannot be null or undefined", flowId));
val state = getState(flow, CasWebflowConstants.STATE_ID_INIT_LOGIN_FORM, ActionState.class);
Assert.notNull(state, String.format("%s state cannot be null or undefined", CasWebflowConstants.STATE_ID_INIT_LOGIN_FORM));
val transition = (Transition) state.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS);
Assert.notNull(state, String.format("%s transition cannot be null or undefined", CasWebflowConstants.TRANSITION_ID_SUCCESS));
val targetStateId = transition.getTargetStateId();
transition.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_VERIFY_TRUSTED_DEVICE));
val verifyAction = createActionState(flow, CasWebflowConstants.STATE_ID_VERIFY_TRUSTED_DEVICE, CasWebflowConstants.ACTION_ID_MFA_VERIFY_TRUST_ACTION);
val enableDeviceRegistration = casProperties.getAuthn().getMfa().getTrusted().getCore().isDeviceRegistrationEnabled();
if (enableDeviceRegistration) {
LOGGER.trace("Device registration is turned on for multifactor flow [{}]", flowId);
createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_YES, CasWebflowConstants.STATE_ID_FINISH_MFA_TRUSTED_AUTH);
} else {
createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_YES, CasWebflowConstants.STATE_ID_REAL_SUBMIT);
}
createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_NO, targetStateId);
createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_SKIP, targetStateId);
val submit = getState(flow, CasWebflowConstants.STATE_ID_REAL_SUBMIT, ActionState.class);
val success = (Transition) submit.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS);
Assert.notNull(state, String.format("%s transition cannot be null or undefined", CasWebflowConstants.TRANSITION_ID_SUCCESS));
if (enableDeviceRegistration) {
success.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_PREPARE_REGISTER_TRUSTED_DEVICE));
} else {
success.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE));
}
createRegisterDeviceView(flow);
val registerAction = createActionState(flow, CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE, CasWebflowConstants.ACTION_ID_MFA_SET_TRUST_ACTION);
createStateDefaultTransition(registerAction, CasWebflowConstants.STATE_ID_SUCCESS);
Assert.isTrue(submit.getActionList().size() > 0, "There are no actions defined for " + flowId);
val act = submit.getActionList().iterator().next();
val finishMfaTrustedAuth = createActionState(flow, CasWebflowConstants.STATE_ID_FINISH_MFA_TRUSTED_AUTH, act);
val finishedTransition = createTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS, CasWebflowConstants.STATE_ID_SUCCESS);
finishMfaTrustedAuth.getTransitionSet().add(finishedTransition);
createStateDefaultTransition(finishMfaTrustedAuth, CasWebflowConstants.STATE_ID_SUCCESS);
}
use of org.springframework.webflow.engine.support.DefaultTargetStateResolver in project cas by apereo.
the class RadiusConfigurationTests method verifyAccessChallengedWebflowEventResolver.
@Test
public void verifyAccessChallengedWebflowEventResolver() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
var result = radiusAccessChallengedAuthenticationWebflowEventResolver.getObject().resolve(context);
assertNull(result);
val principal = CoreAuthenticationTestUtils.getPrincipal("casuser", CollectionUtils.wrap(Attr_ReplyMessage.NAME, "Reply-Back", Attr_State.NAME, "State".getBytes(StandardCharsets.UTF_8)));
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(principal), context);
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
context.getRootFlow().getGlobalTransitionSet().add(transition);
result = radiusAccessChallengedAuthenticationWebflowEventResolver.getObject().resolve(context);
assertEquals(1, result.size());
assertEquals(TestMultifactorAuthenticationProvider.ID, result.iterator().next().getId());
}
use of org.springframework.webflow.engine.support.DefaultTargetStateResolver in project cas by apereo.
the class BaseDuoSecurityTests method getMockRequestContext.
public static RequestContext getMockRequestContext(final ConfigurableApplicationContext applicationContext) {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
request.setRemoteAddr("185.86.151.11");
request.setLocalAddr("195.88.151.11");
request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "MSIE");
ClientInfoHolder.setClientInfo(new ClientInfo(request));
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val provider = getDuoSecurityMultifactorAuthenticationProvider();
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, provider);
val targetResolver = new DefaultTargetStateResolver(provider.getId());
val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(provider.getId())), targetResolver);
context.getRootFlow().getGlobalTransitionSet().add(transition);
WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
val authentication = CoreAuthenticationTestUtils.getAuthentication();
WebUtils.putAuthentication(authentication, context);
val builder = mock(AuthenticationResultBuilder.class);
when(builder.getInitialAuthentication()).thenReturn(Optional.of(authentication));
when(builder.collect(any(Authentication.class))).thenReturn(builder);
WebUtils.putAuthenticationResultBuilder(builder, context);
return context;
}
use of org.springframework.webflow.engine.support.DefaultTargetStateResolver in project cas by apereo.
the class DefaultMultifactorAuthenticationProviderWebflowEventResolverTests method verifyEventResolverWithMfa.
@Test
public void verifyEventResolverWithMfa() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
context.getRootFlow().getGlobalTransitionSet().add(transition);
val tgt = new MockTicketGrantingTicket("casuser");
WebUtils.putTicketGrantingTicketInScopes(context, tgt);
WebUtils.putAuthentication(tgt.getAuthentication(), context);
val service = RegisteredServiceTestUtils.getService(UUID.randomUUID().toString());
WebUtils.putServiceIntoFlowScope(context, service);
val registeredService = RegisteredServiceTestUtils.getRegisteredService(Map.of());
registeredService.setServiceId(service.getId());
servicesManager.save(registeredService);
WebUtils.putRegisteredService(context, registeredService);
val builder = mock(AuthenticationResultBuilder.class);
when(builder.getInitialAuthentication()).thenReturn(Optional.of(tgt.getAuthentication()));
when(builder.collect(any(Authentication.class))).thenReturn(builder);
WebUtils.putAuthenticationResultBuilder(builder, context);
assertEquals(TestMultifactorAuthenticationProvider.ID, globalAuthenticationPolicyWebflowEventResolver.resolve(context).iterator().next().getId());
}
use of org.springframework.webflow.engine.support.DefaultTargetStateResolver in project cas by apereo.
the class RankedMultifactorAuthenticationProviderWebflowEventResolverWithCompositeTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val tgt = new MockTicketGrantingTicket("casuser");
WebUtils.putTicketGrantingTicketInScopes(context, tgt);
cas.addTicket(tgt);
val registeredService = RegisteredServiceTestUtils.getRegisteredService(Map.of());
val multifactorPolicy = new DefaultRegisteredServiceMultifactorPolicy();
registeredService.setMultifactorPolicy(multifactorPolicy);
servicesManager.save(registeredService);
WebUtils.putRegisteredService(context, registeredService);
val targetResolver = new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_MFA_COMPOSITE);
val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(CasWebflowConstants.STATE_ID_MFA_COMPOSITE)), targetResolver);
context.getRootFlow().getGlobalTransitionSet().add(transition);
assertEquals(CasWebflowConstants.STATE_ID_MFA_COMPOSITE, resolver.resolveSingle(context).getId());
}
Aggregations