use of org.apereo.cas.authentication.bypass.HttpRequestMultifactorAuthenticationProviderBypassEvaluator in project cas by apereo.
the class MultifactorAuthenticationProviderBypassTests method verifyMultifactorAuthenticationBypassByHttpRequestRemoteAddress.
@Test
public void verifyMultifactorAuthenticationBypassByHttpRequestRemoteAddress() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
val request = new MockHttpServletRequest();
request.setRemoteAddr("123.456.789.000");
val props = new MultifactorAuthenticationProviderBypassProperties();
props.setHttpRequestRemoteAddress("123.+");
val principal = MultifactorAuthenticationTestUtils.getPrincipal("casuser");
val authentication = MultifactorAuthenticationTestUtils.getAuthentication(principal);
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val bypass = new HttpRequestMultifactorAuthenticationProviderBypassEvaluator(props, provider.getId());
val service = MultifactorAuthenticationTestUtils.getRegisteredService();
assertFalse(bypass.shouldMultifactorAuthenticationProviderExecute(authentication, service, provider, request));
}
use of org.apereo.cas.authentication.bypass.HttpRequestMultifactorAuthenticationProviderBypassEvaluator in project cas by apereo.
the class MultifactorAuthenticationProviderBypassTests method verifyMultifactorAuthenticationBypassByHttpRequestRemoteHost.
@Test
public void verifyMultifactorAuthenticationBypassByHttpRequestRemoteHost() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
val request = new MockHttpServletRequest();
request.setRemoteHost("somewhere.example.org");
val props = new MultifactorAuthenticationProviderBypassProperties();
props.setHttpRequestRemoteAddress(".+example\\.org");
val principal = MultifactorAuthenticationTestUtils.getPrincipal("casuser");
val authentication = MultifactorAuthenticationTestUtils.getAuthentication(principal);
val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val bypass = new HttpRequestMultifactorAuthenticationProviderBypassEvaluator(props, provider.getId());
val service = MultifactorAuthenticationTestUtils.getRegisteredService();
assertFalse(bypass.shouldMultifactorAuthenticationProviderExecute(authentication, service, provider, request));
}
use of org.apereo.cas.authentication.bypass.HttpRequestMultifactorAuthenticationProviderBypassEvaluator 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.apereo.cas.authentication.bypass.HttpRequestMultifactorAuthenticationProviderBypassEvaluator in project cas by apereo.
the class AuthyAuthenticationMultifactorProviderBypassConfiguration method authyHttpRequestMultifactorAuthenticationProviderBypass.
@ConditionalOnMissingBean(name = "authyHttpRequestMultifactorAuthenticationProviderBypass")
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public MultifactorAuthenticationProviderBypassEvaluator authyHttpRequestMultifactorAuthenticationProviderBypass(final CasConfigurationProperties casProperties) {
val authy = casProperties.getAuthn().getMfa().getAuthy();
val props = authy.getBypass();
return new HttpRequestMultifactorAuthenticationProviderBypassEvaluator(props, authy.getId());
}
use of org.apereo.cas.authentication.bypass.HttpRequestMultifactorAuthenticationProviderBypassEvaluator in project cas by apereo.
the class DuoSecurityMultifactorProviderBypassConfiguration method duoSecurityHttpRequestMultifactorAuthenticationProviderBypass.
@ConditionalOnMissingBean(name = "duoSecurityHttpRequestMultifactorAuthenticationProviderBypass")
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public MultifactorAuthenticationProviderBypassEvaluator duoSecurityHttpRequestMultifactorAuthenticationProviderBypass(final ConfigurableApplicationContext applicationContext, final CasConfigurationProperties casProperties) {
return BeanSupplier.of(MultifactorAuthenticationProviderBypassEvaluator.class).when(DuoSecurityAuthenticationService.CONDITION.given(applicationContext.getEnvironment())).supply(() -> {
val duoProps = casProperties.getAuthn().getMfa().getDuo();
val bypass = new DefaultChainingMultifactorAuthenticationBypassProvider();
duoProps.stream().filter(duo -> {
val props = duo.getBypass();
return StringUtils.isNotBlank(props.getHttpRequestHeaders()) || StringUtils.isNotBlank(props.getHttpRequestRemoteAddress());
}).forEach(duo -> bypass.addMultifactorAuthenticationProviderBypassEvaluator(new HttpRequestMultifactorAuthenticationProviderBypassEvaluator(duo.getBypass(), duo.getId())));
if (bypass.isEmpty()) {
return NeverAllowMultifactorAuthenticationProviderBypassEvaluator.getInstance();
}
return bypass;
}).otherwiseProxy().get();
}
Aggregations