use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class DefaultRequestedAuthenticationContextValidatorTests method buildApplicationContext.
private static ConfigurableApplicationContext buildApplicationContext() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
return applicationContext;
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class DefaultChainingMultifactorAuthenticationBypassProviderTests method verifyEmptyChainOperation.
@Test
public void verifyEmptyChainOperation() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
val p = new DefaultChainingMultifactorAuthenticationBypassProvider();
val res = p.filterMultifactorAuthenticationProviderBypassEvaluatorsBy("unknown");
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val principal = MultifactorAuthenticationTestUtils.getPrincipal("casuser");
val authentication = MultifactorAuthenticationTestUtils.getAuthentication(principal);
val service = MultifactorAuthenticationTestUtils.getRegisteredService();
assertTrue(res.shouldMultifactorAuthenticationProviderExecute(authentication, service, provider, new MockHttpServletRequest()));
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class DefaultChainingMultifactorAuthenticationBypassProviderTests method verifyOperation.
@Test
public void verifyOperation() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
val request = new MockHttpServletRequest();
request.addHeader("headerbypass", "true");
val props = new MultifactorAuthenticationProviderBypassProperties();
props.setHttpRequestHeaders("headerbypass");
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val principal = MultifactorAuthenticationTestUtils.getPrincipal("casuser");
val authentication = MultifactorAuthenticationTestUtils.getAuthentication(principal);
val p = new DefaultChainingMultifactorAuthenticationBypassProvider();
p.addMultifactorAuthenticationProviderBypassEvaluator(new HttpRequestMultifactorAuthenticationProviderBypassEvaluator(props, provider.getId()));
assertFalse(p.isEmpty());
assertNotNull(p.getId());
assertNotNull(p.getProviderId());
assertEquals(1, p.size());
assertFalse(p.isMultifactorAuthenticationBypassed(authentication, provider.getId()));
p.rememberBypass(authentication, provider);
mockRememberBypass(provider, authentication);
assertTrue(p.isMultifactorAuthenticationBypassed(authentication, provider.getId()));
when(authentication.getAttributes()).thenReturn(new HashMap<>());
p.forgetBypass(authentication);
assertFalse(p.isMultifactorAuthenticationBypassed(authentication, provider.getId()));
val service = MultifactorAuthenticationTestUtils.getRegisteredService();
assertFalse(p.shouldMultifactorAuthenticationProviderExecute(authentication, service, provider, request));
assertTrue(p.belongsToMultifactorAuthenticationProvider(provider.getId()).isPresent());
assertFalse(p.filterMultifactorAuthenticationProviderBypassEvaluatorsBy(provider.getId()).isEmpty());
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class BaseMultifactorAuthenticationTriggerTests method setup.
@BeforeEach
public void setup(final TestInfo info) {
this.applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
if (!info.getTags().contains("DisableProviderRegistration")) {
this.multifactorAuthenticationProvider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
}
this.authentication = mock(Authentication.class);
val principal = mock(Principal.class);
when(principal.getId()).thenReturn("casuser");
when(principal.getAttributes()).thenReturn(Map.of("email", List.of("casuser@example.org")));
when(authentication.getAttributes()).thenReturn(Map.of("category", List.of("user-object"), "mfa-mode", List.of("mfa-other")));
when(authentication.getPrincipal()).thenReturn(principal);
this.registeredService = mock(RegisteredService.class);
when(registeredService.getName()).thenReturn("Service");
when(registeredService.getServiceId()).thenReturn("http://app.org");
when(registeredService.getId()).thenReturn(1000L);
this.geoLocationService = mock(GeoLocationService.class);
this.httpRequest = new MockHttpServletRequest();
this.httpRequest.setRemoteAddr("185.86.151.11");
this.httpRequest.setLocalAddr("185.88.151.12");
this.httpRequest.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "Mozilla/5.0 (Windows NT 10.0; WOW64)");
var clientInfo = new ClientInfo(this.httpRequest);
ClientInfoHolder.setClientInfo(clientInfo);
this.httpResponse = new MockHttpServletResponse();
}
use of org.springframework.context.support.StaticApplicationContext 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);
}
Aggregations