use of org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest in project cas by apereo.
the class GeoLocationServiceTests method verifyLocateFails.
@Test
public void verifyLocateFails() {
val svc = mock(AbstractGeoLocationService.class);
when(svc.locate(anyString())).thenReturn(null);
when(svc.locate(anyString(), any(GeoLocationRequest.class))).thenCallRealMethod();
when(svc.locate(anyDouble(), anyDouble())).thenReturn(new GeoLocationResponse());
assertNotNull(svc.locate("1.2.3.4", new GeoLocationRequest(1, 1)));
}
use of org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest in project cas by apereo.
the class MockTicketGrantingTicketCreatedEventProducer method getMockGeoLocation.
private static GeoLocationRequest getMockGeoLocation() {
val index = ThreadLocalRandom.current().nextInt(ALL_GEOLOCS.size());
val location = new GeoLocationRequest();
val pair = ALL_GEOLOCS.get(index);
location.setLatitude(pair.getKey());
location.setLongitude(pair.getValue());
location.setAccuracy("50");
location.setTimestamp(String.valueOf(new Date().getTime()));
return location;
}
use of org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest 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.authentication.adaptive.geo.GeoLocationRequest 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));
}
use of org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest 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)));
}
Aggregations