use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.
the class DefaultAdaptiveAuthenticationPolicyTests method verifyActionGeoLocationRejected.
@Test
public void verifyActionGeoLocationRejected() {
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 geoRequest = new GeoLocationRequest(51.5, -0.118);
val props = new AdaptiveAuthenticationProperties();
props.getPolicy().setRejectCountries("UK");
val service = mock(GeoLocationService.class);
val response = new GeoLocationResponse();
response.addAddress("UK");
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);
assertFalse(p.apply(new MockRequestContext(), USER_AGENT, geoRequest));
}
use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.
the class DefaultAdaptiveAuthenticationPolicyTests method verifyActionWithNoClientInfo.
@Test
public void verifyActionWithNoClientInfo() {
val props = new AdaptiveAuthenticationProperties();
val service = mock(GeoLocationService.class);
val p = new DefaultAdaptiveAuthenticationPolicy(service, IPAddressIntelligenceService.allowed(), props);
assertTrue(p.apply(new MockRequestContext(), "something", new GeoLocationRequest()));
}
use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.
the class DefaultIPAddressIntelligenceServiceTests method verifyOperation.
@Test
public void verifyOperation() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
val input = new DefaultIPAddressIntelligenceService(new AdaptiveAuthenticationProperties());
assertTrue(input.examine(context, "1.2.3.4").isAllowed());
}
use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.
the class RestfulIPAddressIntelligenceServiceTests method verifyBannedOperation.
@Test
public void verifyBannedOperation() {
try (val webServer = new MockWebServer(9304, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.FORBIDDEN)) {
webServer.start();
val props = new AdaptiveAuthenticationProperties();
props.getIpIntel().getRest().setUrl("http://localhost:9304");
val service = new RestfulIPAddressIntelligenceService(props);
val result = service.examine(new MockRequestContext(), "1.2.3.4");
assertNotNull(result);
assertTrue(result.isBanned());
}
}
use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.
the class RestfulIPAddressIntelligenceServiceTests method verifyRankedOperation.
@Test
public void verifyRankedOperation() {
try (val webServer = new MockWebServer(9306, new ByteArrayResource("12.435".getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.PRECONDITION_REQUIRED)) {
webServer.start();
val props = new AdaptiveAuthenticationProperties();
props.getIpIntel().getRest().setUrl("http://localhost:9306");
var service = new RestfulIPAddressIntelligenceService(props);
var result = service.examine(new MockRequestContext(), "1.2.3.4");
assertNotNull(result);
assertTrue(result.isRanked());
props.getPolicy().setRejectIpAddresses("123\\..*");
service = new RestfulIPAddressIntelligenceService(props);
result = service.examine(new MockRequestContext(), "123.1.2.3");
assertNotNull(result);
assertTrue(result.isBanned());
}
}
Aggregations