Search in sources :

Example 6 with AdaptiveAuthenticationProperties

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());
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) AdaptiveAuthenticationProperties(org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties) ByteArrayResource(org.springframework.core.io.ByteArrayResource) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.jupiter.api.Test)

Example 7 with AdaptiveAuthenticationProperties

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());
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) AdaptiveAuthenticationProperties(org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties) ByteArrayResource(org.springframework.core.io.ByteArrayResource) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.jupiter.api.Test)

Example 8 with AdaptiveAuthenticationProperties

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));
}
Also used : AdaptiveAuthenticationProperties(org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 9 with AdaptiveAuthenticationProperties

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));
}
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 10 with AdaptiveAuthenticationProperties

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));
}
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)

Aggregations

AdaptiveAuthenticationProperties (org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties)17 Test (org.junit.jupiter.api.Test)17 lombok.val (lombok.val)16 MockRequestContext (org.springframework.webflow.test.MockRequestContext)16 MockWebServer (org.apereo.cas.util.MockWebServer)9 ByteArrayResource (org.springframework.core.io.ByteArrayResource)9 GeoLocationRequest (org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)4 GeoLocationResponse (org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse)3 ClassPathResource (org.springframework.core.io.ClassPathResource)2 GeoLocationService (org.apereo.cas.authentication.adaptive.geo.GeoLocationService)1 IPAddressIntelligenceResponse (org.apereo.cas.authentication.adaptive.intel.IPAddressIntelligenceResponse)1 IPAddressIntelligenceService (org.apereo.cas.authentication.adaptive.intel.IPAddressIntelligenceService)1 HttpRequestUtils (org.apereo.cas.util.HttpRequestUtils)1 ClientInfoHolder (org.apereo.inspektr.common.web.ClientInfoHolder)1 Assertions (org.junit.jupiter.api.Assertions)1 Tag (org.junit.jupiter.api.Tag)1 Mockito (org.mockito.Mockito)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1