use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.
the class DefaultAdaptiveAuthenticationPolicyTests method verifyActionUserAgentRejected.
@Test
public void verifyActionUserAgentRejected() {
val request = new MockHttpServletRequest();
request.setRemoteAddr("185.86.151.11");
request.setLocalAddr("185.88.151.11");
request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, USER_AGENT);
ClientInfoHolder.setClientInfo(new ClientInfo(request));
val props = new AdaptiveAuthenticationProperties();
props.getPolicy().setRejectBrowsers("Mozilla/5.0.+");
val service = mock(GeoLocationService.class);
val p = new DefaultAdaptiveAuthenticationPolicy(service, IPAddressIntelligenceService.allowed(), props);
assertFalse(p.apply(new MockRequestContext(), USER_AGENT, new GeoLocationRequest(51.5, -0.118)));
}
use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.
the class RestfulIPAddressIntelligenceServiceTests method verifyAllowedOperation.
@Test
public void verifyAllowedOperation() {
try (val webServer = new MockWebServer(9300, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val props = new AdaptiveAuthenticationProperties();
props.getIpIntel().getRest().setUrl("http://localhost:9300");
val service = new RestfulIPAddressIntelligenceService(props);
val result = service.examine(new MockRequestContext(), "1.2.3.4");
assertNotNull(result);
assertTrue(result.isAllowed());
}
}
use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.
the class BlackDotIPAddressIntelligenceServiceTests method verifySuccessStatusRanked.
@Test
public void verifySuccessStatusRanked() throws Exception {
val data = MAPPER.writeValueAsString(CollectionUtils.wrap("status", "success", "result", 0.4351));
try (val webServer = new MockWebServer(9359, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val props = new AdaptiveAuthenticationProperties();
props.getIpIntel().getBlackDot().setUrl("http://localhost:9359?ip=%s");
props.getIpIntel().getBlackDot().setEmailAddress("cas@apereo.org");
val service = new BlackDotIPAddressIntelligenceService(props);
val response = service.examine(new MockRequestContext(), "37.58.59.181");
assertFalse(response.isBanned());
assertEquals(0.4351, response.getScore());
}
}
use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.
the class BlackDotIPAddressIntelligenceServiceTests method verifyBannedOperation.
@Test
public void verifyBannedOperation() {
try (val webServer = new MockWebServer(9355, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.TOO_MANY_REQUESTS)) {
webServer.start();
val props = new AdaptiveAuthenticationProperties();
props.getIpIntel().getBlackDot().setUrl("http://localhost:9355?ip=%s");
props.getIpIntel().getBlackDot().setEmailAddress("cas@apereo.org");
val service = new BlackDotIPAddressIntelligenceService(props);
val response = service.examine(new MockRequestContext(), "37.58.59.181");
assertTrue(response.isBanned());
}
}
use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.
the class BlackDotIPAddressIntelligenceServiceTests method verifySuccessStatusAndBannedWithRank.
@Test
public void verifySuccessStatusAndBannedWithRank() throws Exception {
val data = MAPPER.writeValueAsString(CollectionUtils.wrap("status", "success", "result", 1));
try (val webServer = new MockWebServer(9357, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val props = new AdaptiveAuthenticationProperties();
props.getIpIntel().getBlackDot().setUrl("http://localhost:9357?ip=%s");
props.getIpIntel().getBlackDot().setEmailAddress("cas@apereo.org");
val service = new BlackDotIPAddressIntelligenceService(props);
val response = service.examine(new MockRequestContext(), "37.58.59.181");
assertTrue(response.isBanned());
}
}
Aggregations