Search in sources :

Example 16 with GeoLocationRequest

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)));
}
Also used : lombok.val(lombok.val) GeoLocationResponse(org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest) Test(org.junit.jupiter.api.Test)

Example 17 with GeoLocationRequest

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;
}
Also used : lombok.val(lombok.val) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest) Date(java.util.Date)

Example 18 with GeoLocationRequest

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));
}
Also used : lombok.val(lombok.val) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest) lombok.val(lombok.val) GeoLocationService(org.apereo.cas.authentication.adaptive.geo.GeoLocationService) MockRequestContext(org.springframework.webflow.test.MockRequestContext) IPAddressIntelligenceResponse(org.apereo.cas.authentication.adaptive.intel.IPAddressIntelligenceResponse) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AdaptiveAuthenticationProperties(org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties) HttpRequestUtils(org.apereo.cas.util.HttpRequestUtils) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) GeoLocationResponse(org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse) IPAddressIntelligenceService(org.apereo.cas.authentication.adaptive.intel.IPAddressIntelligenceService) ClientInfoHolder(org.apereo.inspektr.common.web.ClientInfoHolder) Assertions(org.junit.jupiter.api.Assertions) Tag(org.junit.jupiter.api.Tag) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AdaptiveAuthenticationProperties(org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockRequestContext(org.springframework.webflow.test.MockRequestContext) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest) Test(org.junit.jupiter.api.Test)

Example 19 with GeoLocationRequest

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));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) GeoLocationResponse(org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse) AdaptiveAuthenticationProperties(org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockRequestContext(org.springframework.webflow.test.MockRequestContext) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest) Test(org.junit.jupiter.api.Test)

Example 20 with GeoLocationRequest

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)));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AdaptiveAuthenticationProperties(org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockRequestContext(org.springframework.webflow.test.MockRequestContext) GeoLocationRequest(org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest) Test(org.junit.jupiter.api.Test)

Aggregations

GeoLocationRequest (org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)20 lombok.val (lombok.val)13 GeoLocationResponse (org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse)7 Test (org.junit.jupiter.api.Test)7 AdaptiveAuthenticationProperties (org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties)5 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)5 MockRequestContext (org.springframework.webflow.test.MockRequestContext)5 CasEvent (org.apereo.cas.support.events.dao.CasEvent)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 GeoLocationService (org.apereo.cas.authentication.adaptive.geo.GeoLocationService)3 ClientInfoHolder (org.apereo.inspektr.common.web.ClientInfoHolder)3 BigDecimal (java.math.BigDecimal)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Authentication (org.apereo.cas.authentication.Authentication)2 RegisteredService (org.apereo.cas.services.RegisteredService)2 CasEventRepository (org.apereo.cas.support.events.CasEventRepository)2 WebUtils (org.apereo.cas.web.support.WebUtils)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 Collection (java.util.Collection)1