use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.
the class BlackDotIPAddressIntelligenceServiceTests method verifyErrorStatusOperation.
@Test
public void verifyErrorStatusOperation() throws Exception {
val data = MAPPER.writeValueAsString(Collections.singletonMap("status", "error"));
try (val webServer = new MockWebServer(9356, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val props = new AdaptiveAuthenticationProperties();
props.getIpIntel().getBlackDot().setUrl("http://localhost:9356?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 verifySuccessStatus.
@Test
public void verifySuccessStatus() throws Exception {
val data = MAPPER.writeValueAsString(CollectionUtils.wrap("status", "success", "result", 0));
try (val webServer = new MockWebServer(9358, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val props = new AdaptiveAuthenticationProperties();
props.getIpIntel().getBlackDot().setUrl("http://localhost:9358?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());
}
}
use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.
the class CoreAuthenticationUtilsTests method verifyIpIntelligenceService.
@Test
public void verifyIpIntelligenceService() {
var properties = new AdaptiveAuthenticationProperties();
assertNotNull(CoreAuthenticationUtils.newIpAddressIntelligenceService(properties));
properties = new AdaptiveAuthenticationProperties();
properties.getIpIntel().getRest().setUrl("http://localhost:1234");
assertNotNull(CoreAuthenticationUtils.newIpAddressIntelligenceService(properties));
properties = new AdaptiveAuthenticationProperties();
properties.getIpIntel().getGroovy().setLocation(new ClassPathResource("GroovyIPService.groovy"));
assertNotNull(CoreAuthenticationUtils.newIpAddressIntelligenceService(properties));
properties = new AdaptiveAuthenticationProperties();
properties.getIpIntel().getBlackDot().setEmailAddress("cas@example.org");
assertNotNull(CoreAuthenticationUtils.newIpAddressIntelligenceService(properties));
}
use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.
the class DefaultAdaptiveAuthenticationPolicyTests method verifyActionClientIpRejected.
@Test
public void verifyActionClientIpRejected() {
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().setRejectIpAddresses("185\\.86.+");
val service = mock(GeoLocationService.class);
var policy = new DefaultAdaptiveAuthenticationPolicy(service, IPAddressIntelligenceService.banned(), props);
val location = new GeoLocationRequest(51.5, -0.118);
assertFalse(policy.apply(new MockRequestContext(), USER_AGENT, location));
policy = new DefaultAdaptiveAuthenticationPolicy(service, (context, clientIpAddress) -> IPAddressIntelligenceResponse.builder().status(IPAddressIntelligenceResponse.IPAddressIntelligenceStatus.RANKED).score(12.15).build(), props);
assertFalse(policy.apply(new MockRequestContext(), USER_AGENT, location));
}
use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.
the class DefaultAdaptiveAuthenticationPolicyTests method verifyActionGeoLocationPass.
@Test
public void verifyActionGeoLocationPass() {
val request = new MockHttpServletRequest();
ClientInfoHolder.setClientInfo(new ClientInfo(request));
val geoRequest = new GeoLocationRequest(51.5, -0.118);
val props = new AdaptiveAuthenticationProperties();
val service = mock(GeoLocationService.class);
val response = new GeoLocationResponse();
response.setLatitude(Double.parseDouble(geoRequest.getLatitude()));
response.setLongitude(Double.parseDouble(geoRequest.getLongitude()));
when(service.locate(anyString(), any())).thenReturn(response);
val p = new DefaultAdaptiveAuthenticationPolicy(service, IPAddressIntelligenceService.allowed(), props);
assertTrue(p.apply(new MockRequestContext(), USER_AGENT, geoRequest));
}
Aggregations