use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class MultifactorAuthenticationProviderBypassAuditResourceResolverTests method verifyJsonOperation.
@Test
public void verifyJsonOperation() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
val resolver = new MultifactorAuthenticationProviderBypassAuditResourceResolver();
resolver.setAuditFormat(AuditTrailManager.AuditFormats.JSON);
val jp = mock(JoinPoint.class);
val args = new Object[] { MultifactorAuthenticationTestUtils.getAuthentication("casuser"), MultifactorAuthenticationTestUtils.getRegisteredService(), TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext) };
when(jp.getArgs()).thenReturn(args);
when(jp.getTarget()).thenReturn("TargetObject");
val outcome = resolver.resolveFrom(jp, new Object());
assertTrue(outcome.length > 0);
assertNotNull(resolver.resolveFrom(jp, new RuntimeException("failed")));
when(jp.getArgs()).thenReturn(null);
assertEquals(0, resolver.resolveFrom(jp, new Object()).length);
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class AuthenticationMultifactorAuthenticationProviderBypassEvaluatorTests method verifyOperation.
@Test
public void verifyOperation() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val eval = new DefaultChainingMultifactorAuthenticationBypassProvider();
val bypassProps = new MultifactorAuthenticationProviderBypassProperties();
bypassProps.setAuthenticationAttributeName("cn");
bypassProps.setAuthenticationAttributeValue("ex.+");
eval.addMultifactorAuthenticationProviderBypassEvaluator(new AuthenticationMultifactorAuthenticationProviderBypassEvaluator(bypassProps, TestMultifactorAuthenticationProvider.ID));
val authentication = CoreAuthenticationTestUtils.getAuthentication("casuser", Map.of("cn", List.of("example")));
val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
val policy = new DefaultRegisteredServiceMultifactorPolicy();
when(registeredService.getMultifactorPolicy()).thenReturn(policy);
assertFalse(eval.shouldMultifactorAuthenticationProviderExecute(authentication, registeredService, provider, new MockHttpServletRequest()));
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class ScriptedRegisteredServiceMultifactorAuthenticationTriggerTests method verifyEmptyProviders.
@Test
public void verifyEmptyProviders() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
val policy = mock(RegisteredServiceMultifactorPolicy.class);
when(policy.getScript()).thenReturn("groovy { return '" + multifactorAuthenticationProvider.getId() + "' }");
when(this.registeredService.getMultifactorPolicy()).thenReturn(policy);
val props = new CasConfigurationProperties();
val trigger = new ScriptedRegisteredServiceMultifactorAuthenticationTrigger(props, applicationContext);
assertThrows(AuthenticationException.class, () -> trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class)));
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class HttpRequestMultifactorAuthenticationProviderBypassEvaluatorTests method verifyShouldProceed.
@Test
public void verifyShouldProceed() {
val properties = new MultifactorAuthenticationProviderBypassProperties();
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val eval = new HttpRequestMultifactorAuthenticationProviderBypassEvaluator(properties, provider.getId());
val principal = CoreAuthenticationTestUtils.getPrincipal(Map.of("cn", List.of("example")));
val authentication = CoreAuthenticationTestUtils.getAuthentication(principal);
val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
val request = new MockHttpServletRequest();
assertTrue(eval.shouldMultifactorAuthenticationProviderExecute(authentication, registeredService, provider, request));
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class RegisteredServicePrincipalAttributeMultifactorAuthenticationProviderBypassEvaluatorTests method verifyOperation.
@Test
public void verifyOperation() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val eval = new DefaultChainingMultifactorAuthenticationBypassProvider();
eval.addMultifactorAuthenticationProviderBypassEvaluator(new RegisteredServicePrincipalAttributeMultifactorAuthenticationProviderBypassEvaluator(TestMultifactorAuthenticationProvider.ID));
val principal = CoreAuthenticationTestUtils.getPrincipal(Map.of("cn", List.of("example")));
val authentication = CoreAuthenticationTestUtils.getAuthentication(principal);
val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
val policy = new DefaultRegisteredServiceMultifactorPolicy();
policy.setBypassEnabled(true);
policy.setBypassPrincipalAttributeName("cn");
policy.setBypassPrincipalAttributeValue("^e[x]am.*");
when(registeredService.getMultifactorPolicy()).thenReturn(policy);
assertFalse(eval.shouldMultifactorAuthenticationProviderExecute(authentication, registeredService, provider, new MockHttpServletRequest()));
}
Aggregations