use of org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider in project cas by apereo.
the class UserAuthenticationResourceTests method verifyAuthWithMfaFails.
@Test
public void verifyAuthWithMfaFails() throws Exception {
val builder = new DefaultAuthenticationResultBuilder().collect(CoreAuthenticationTestUtils.getAuthentication());
when(authenticationSupport.handleInitialAuthenticationTransaction(any(), any())).thenReturn(builder);
when(requestedContextValidator.validateAuthenticationContext(any(), any(), any(), any(), any())).thenReturn(AuthenticationContextValidationResult.builder().success(false).build());
when(multifactorTriggerSelectionStrategy.resolve(any(), any(), any(), any(), any())).thenReturn(Optional.of(new TestMultifactorAuthenticationProvider("mfa-unknown")));
this.mockMvc.perform(post(TICKETS_RESOURCE_URL).param("username", "casuser").param("password", "Mellon")).andExpect(status().is4xxClientError());
}
use of org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider in project cas by apereo.
the class GlobalMultifactorAuthenticationTriggerTests method verifyOperationByValidProviders.
@Test
@Order(3)
public void verifyOperationByValidProviders() {
val props = new CasConfigurationProperties();
val otherProvider = new TestMultifactorAuthenticationProvider();
otherProvider.setId("mfa-other");
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, otherProvider);
props.getAuthn().getMfa().getTriggers().getGlobal().setGlobalProviderId(TestMultifactorAuthenticationProvider.ID + ',' + otherProvider.getId());
val trigger = new GlobalMultifactorAuthenticationTrigger(props, applicationContext, (providers, service, principal) -> providers.iterator().next());
val result = trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class));
assertTrue(result.isPresent());
assertEquals(TestMultifactorAuthenticationProvider.ID, result.get().getId());
}
use of org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider in project cas by apereo.
the class GroovyMultifactorAuthenticationProviderBypassEvaluatorTests method runGroovyBypassFor.
private static boolean runGroovyBypassFor(final Authentication authentication) {
val request = new MockHttpServletRequest();
val properties = new MultifactorAuthenticationProviderBypassProperties();
properties.getGroovy().setLocation(new ClassPathResource("GroovyBypass.groovy"));
val provider = new TestMultifactorAuthenticationProvider();
val groovy = new GroovyMultifactorAuthenticationProviderBypassEvaluator(properties, provider.getId());
val registeredService = mock(RegisteredService.class);
when(registeredService.getName()).thenReturn("Service");
when(registeredService.getServiceId()).thenReturn("http://app.org");
when(registeredService.getId()).thenReturn(1000L);
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
return groovy.shouldMultifactorAuthenticationProviderExecute(authentication, registeredService, provider, request);
}
use of org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider in project cas by apereo.
the class RestMultifactorAuthenticationProviderBypassEvaluatorTests method verifyOperationFailsWithNoProvider.
@Test
public void verifyOperationFailsWithNoProvider() {
try (val webServer = new MockWebServer(9316, new ByteArrayResource("Y".getBytes(StandardCharsets.UTF_8), "REST Output"), HttpStatus.ACCEPTED)) {
webServer.start();
val props = new MultifactorAuthenticationProviderBypassProperties();
props.getRest().setUrl("http://localhost:9316");
val provider = new TestMultifactorAuthenticationProvider();
val r = new RestMultifactorAuthenticationProviderBypassEvaluator(props, provider.getId());
val res = r.shouldMultifactorAuthenticationProviderExecute(MultifactorAuthenticationTestUtils.getAuthentication("casuser"), MultifactorAuthenticationTestUtils.getRegisteredService(), null, new MockHttpServletRequest());
assertTrue(res);
}
}
use of org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider in project cas by apereo.
the class DefaultMultifactorAuthenticationProviderResolverTests method verifyResolutionByPrincipalAttribute.
@Test
public void verifyResolutionByPrincipalAttribute() {
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 principal = CoreAuthenticationTestUtils.getPrincipal("casuser", CollectionUtils.wrap("authlevel", List.of(provider.getId())));
var results = resolver.resolveEventViaPrincipalAttribute(principal, 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());
results = resolver.resolveEventViaPrincipalAttribute(principal, List.of("authlevel"), CoreAuthenticationTestUtils.getRegisteredService(), Optional.of(context), List.of(), (input, mfaProvider) -> input.equalsIgnoreCase(provider.getId()));
assertNull(results);
results = resolver.resolveEventViaPrincipalAttribute(principal, List.of(), CoreAuthenticationTestUtils.getRegisteredService(), Optional.of(context), List.of(), (input, mfaProvider) -> input.equalsIgnoreCase(provider.getId()));
assertNull(results);
}
Aggregations