use of org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider in project cas by apereo.
the class DefaultMultifactorAuthenticationProviderResolverTests method verifyResolutionByAuthenticationAttribute.
@Test
public void verifyResolutionByAuthenticationAttribute() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val provider = registerProviderInApplicationContext(applicationContext, context, new TestMultifactorAuthenticationProvider());
val resolver = new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical());
val authentication = CoreAuthenticationTestUtils.getAuthentication("casuser", CollectionUtils.wrap("authlevel", List.of(provider.getId())));
val results = resolver.resolveEventViaAuthenticationAttribute(authentication, List.of("authlevel"), CoreAuthenticationTestUtils.getRegisteredService(), Optional.of(context), List.of(provider), (input, mfaProvider) -> input.equalsIgnoreCase(provider.getId()));
assertNotNull(results);
assertEquals(provider.getId(), results.iterator().next().getId());
}
use of org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider in project cas by apereo.
the class DefaultMultifactorAuthenticationProviderResolverTests method registerProviderInApplicationContext.
private static TestMultifactorAuthenticationProvider registerProviderInApplicationContext(final ConfigurableApplicationContext applicationContext, final MockRequestContext context, final TestMultifactorAuthenticationProvider candidateProvider) {
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, candidateProvider);
val targetResolver = new DefaultTargetStateResolver(provider.getId());
val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(provider.getId())), targetResolver);
context.getRootFlow().getGlobalTransitionSet().add(transition);
return (TestMultifactorAuthenticationProvider) provider;
}
use of org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider in project cas by apereo.
the class AuthenticationAttributeMultifactorAuthenticationTriggerTests method verifyMultipleProvider.
@Test
@Order(2)
public void verifyMultipleProvider() {
val otherProvider = new TestMultifactorAuthenticationProvider();
otherProvider.setId("mfa-other");
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, otherProvider);
val props = new CasConfigurationProperties();
val mfa = props.getAuthn().getMfa().getTriggers().getAuthentication();
mfa.setGlobalAuthenticationAttributeNameTriggers("mfa-mode");
mfa.setGlobalAuthenticationAttributeValueRegex(otherProvider.getId());
val trigger = new AuthenticationAttributeMultifactorAuthenticationTrigger(props, new DefaultMultifactorAuthenticationProviderResolver(MultifactorAuthenticationPrincipalResolver.identical()), applicationContext);
val result = trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class));
assertTrue(result.isPresent());
}
use of org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider in project cas by apereo.
the class PrepareMultifactorProviderSelectionActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val flowSession = new MockFlowSession(new Flow(CasWebflowConfigurer.FLOW_ID_LOGIN));
flowSession.setState(new ViewState(flowSession.getDefinitionInternal(), "viewState", mock(ViewFactory.class)));
val exec = new MockFlowExecutionContext(flowSession);
val context = new MockRequestContext(exec);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
val chain = new DefaultChainingMultifactorAuthenticationProvider(new DefaultMultifactorAuthenticationFailureModeEvaluator(casProperties));
val provider = new TestMultifactorAuthenticationProvider();
provider.setBypassEvaluator(new DefaultChainingMultifactorAuthenticationBypassProvider());
chain.addMultifactorAuthenticationProvider(provider);
val attributes = new LocalAttributeMap(RegisteredService.class.getName(), RegisteredServiceTestUtils.getRegisteredService());
attributes.put(MultifactorAuthenticationProvider.class.getName(), chain);
val event = new EventFactorySupport().event(this, ChainingMultifactorAuthenticationProvider.DEFAULT_IDENTIFIER, attributes);
context.setCurrentEvent(event);
assertNull(action.execute(context));
assertNotNull(WebUtils.getSelectableMultifactorAuthenticationProviders(context));
}
use of org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider in project cas by apereo.
the class DuoSecurityUniversalPromptPrepareLoginActionTests 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));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
val identifier = casProperties.getAuthn().getMfa().getDuo().get(0).getId();
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, new TestMultifactorAuthenticationProvider(identifier));
configurableApplicationContext.getBeansOfType(MultifactorAuthenticationPrincipalResolver.class).forEach((key, value) -> ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, value, key));
WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
WebUtils.putRegisteredService(context, RegisteredServiceTestUtils.getRegisteredService());
WebUtils.putMultifactorAuthenticationProviderIdIntoFlowScope(context, provider);
val result = duoUniversalPromptPrepareLoginAction.execute(context);
assertNotNull(result);
assertNotNull(result.getAttributes().get("result"));
assertTrue(context.getFlowScope().contains("duoUniversalPromptLoginUrl"));
}
Aggregations