use of org.springframework.webflow.engine.support.DefaultTargetStateResolver in project cas by apereo.
the class TimedMultifactorAuthenticationPolicyEventResolverTests method initialize.
@BeforeEach
public void initialize() {
this.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 targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
context.getRootFlow().getGlobalTransitionSet().add(transition);
WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
}
use of org.springframework.webflow.engine.support.DefaultTargetStateResolver in project cas by apereo.
the class AuthenticationAttributeMultifactorAuthenticationPolicyEventResolverTests method verifyOperation.
@Test
public void verifyOperation() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val registeredService = RegisteredServiceTestUtils.getRegisteredService();
servicesManager.save(registeredService);
WebUtils.putRegisteredService(context, registeredService);
WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
var results = authenticationAttributeMultifactorAuthenticationPolicyEventResolver.resolve(context);
assertNull(results);
val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
context.getRootFlow().getGlobalTransitionSet().add(transition);
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val authn = RegisteredServiceTestUtils.getAuthentication();
authn.getAttributes().put("authn-method-dummy", List.of("mfa-dummy"));
WebUtils.putAuthentication(authn, context);
results = authenticationAttributeMultifactorAuthenticationPolicyEventResolver.resolve(context);
assertNotNull(results);
assertEquals(1, results.size());
assertEquals(TestMultifactorAuthenticationProvider.ID, results.iterator().next().getId());
}
use of org.springframework.webflow.engine.support.DefaultTargetStateResolver in project cas by apereo.
the class RequestHeaderMultifactorAuthenticationPolicyEventResolverTests method verifyOperation.
@Test
public void verifyOperation() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val service = RegisteredServiceTestUtils.getRegisteredService();
servicesManager.save(service);
WebUtils.putRegisteredService(context, service);
WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
var results = requestHeaderAuthenticationPolicyWebflowEventResolver.resolve(context);
assertNull(results);
val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
context.getRootFlow().getGlobalTransitionSet().add(transition);
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
request.addHeader(casProperties.getAuthn().getMfa().getTriggers().getHttp().getRequestHeader(), TestMultifactorAuthenticationProvider.ID);
results = requestHeaderAuthenticationPolicyWebflowEventResolver.resolve(context);
assertNotNull(results);
assertEquals(1, results.size());
assertEquals(TestMultifactorAuthenticationProvider.ID, results.iterator().next().getId());
}
use of org.springframework.webflow.engine.support.DefaultTargetStateResolver in project cas by apereo.
the class AbstractCasMultifactorWebflowConfigurer method registerMultifactorProviderAuthenticationWebflow.
@Override
public void registerMultifactorProviderAuthenticationWebflow(final Flow flow, final String subflowId, final String providerId) {
multifactorAuthenticationFlowDefinitionRegistries.forEach(registry -> {
if (!registry.containsFlowDefinition(subflowId)) {
LOGGER.error("Could not locate flow id [{}]", subflowId);
return;
}
if (flow == null) {
LOGGER.error("Unable to locate parent flow definition to register provider [{}]", providerId);
return;
}
val mfaFlow = (Flow) registry.getFlowDefinition(subflowId);
mfaFlow.getStartActionList().add(requestContext -> {
WebUtils.createCredential(requestContext);
return null;
});
mfaFlow.getStartActionList().add(createSetAction("flowScope.".concat(CasWebflowConstants.VAR_ID_MFA_PROVIDER_ID), StringUtils.quote(providerId)));
val initStartState = (TransitionableState) mfaFlow.getStartState();
val transition = (Transition) initStartState.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS);
val targetStateId = transition.getTargetStateId();
transition.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_MFA_CHECK_BYPASS));
registerMultifactorProviderBypassAction(mfaFlow);
registerMultifactorProviderAvailableAction(mfaFlow, targetStateId);
registerMultifactorProviderFailureAction(flow, mfaFlow);
val subflowState = createSubflowState(flow, subflowId, subflowId);
val subflowMappings = Stream.of(CasWebflowConstants.ATTRIBUTE_SERVICE, CasWebflowConstants.ATTRIBUTE_REGISTERED_SERVICE).map(attr -> new DefaultMapping(createExpression("flowScope." + attr), createExpression(attr))).collect(Collectors.toList());
subflowMappings.add(new DefaultMapping(createExpression("flowScope." + CasWebflowConstants.VAR_ID_CREDENTIAL), createExpression("parent" + StringUtils.capitalize(CasWebflowConstants.VAR_ID_CREDENTIAL))));
multifactorAuthenticationFlowCustomizers.forEach(c -> c.getMultifactorWebflowAttributeMappings().forEach(key -> subflowMappings.add(new DefaultMapping(createExpression("flowScope." + key), createExpression(key)))));
val inputMapper = createMapperToSubflowState(subflowMappings);
val subflowMapper = createSubflowAttributeMapper(inputMapper, null);
subflowState.setAttributeMapper(subflowMapper);
val flowMappings = Stream.of(CasWebflowConstants.ATTRIBUTE_SERVICE, CasWebflowConstants.ATTRIBUTE_REGISTERED_SERVICE).map(attr -> new DefaultMapping(createExpression(attr), createExpression("flowScope." + attr))).collect(Collectors.toList());
flowMappings.add(new DefaultMapping(createExpression("parent" + StringUtils.capitalize(CasWebflowConstants.VAR_ID_CREDENTIAL)), createExpression("flowScope.parent" + StringUtils.capitalize(CasWebflowConstants.VAR_ID_CREDENTIAL))));
multifactorAuthenticationFlowCustomizers.forEach(c -> c.getMultifactorWebflowAttributeMappings().forEach(key -> flowMappings.add(new DefaultMapping(createExpression(key), createExpression("flowScope." + key)))));
val flowInputMapper = createMapperToSubflowState(flowMappings);
mfaFlow.setInputMapper(flowInputMapper);
val states = getCandidateStatesForMultifactorAuthentication();
registerMultifactorAuthenticationSubflowWithStates(flow, subflowState, states);
registerMultifactorFlowDefinitionIntoLoginFlowRegistry();
augmentMultifactorProviderFlowRegistry();
LOGGER.trace("Registering the [{}] flow into the flow [{}]", subflowId, flow.getId());
val startState = flow.getTransitionableState(flow.getStartState().getId());
createTransitionForState(startState, subflowId, subflowId, true);
val initState = getState(flow, CasWebflowConstants.STATE_ID_INITIAL_AUTHN_REQUEST_VALIDATION_CHECK);
createTransitionForState(initState, subflowId, subflowId, true);
});
}
Aggregations