Search in sources :

Example 11 with AdaptiveAuthenticationProperties

use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties 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)

Example 12 with AdaptiveAuthenticationProperties

use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.

the class RestfulIPAddressIntelligenceServiceTests method verifyAllowedOperation.

@Test
public void verifyAllowedOperation() {
    try (val webServer = new MockWebServer(9300, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        val props = new AdaptiveAuthenticationProperties();
        props.getIpIntel().getRest().setUrl("http://localhost:9300");
        val service = new RestfulIPAddressIntelligenceService(props);
        val result = service.examine(new MockRequestContext(), "1.2.3.4");
        assertNotNull(result);
        assertTrue(result.isAllowed());
    }
}
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 13 with AdaptiveAuthenticationProperties

use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.

the class BlackDotIPAddressIntelligenceServiceTests method verifySuccessStatusRanked.

@Test
public void verifySuccessStatusRanked() throws Exception {
    val data = MAPPER.writeValueAsString(CollectionUtils.wrap("status", "success", "result", 0.4351));
    try (val webServer = new MockWebServer(9359, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        val props = new AdaptiveAuthenticationProperties();
        props.getIpIntel().getBlackDot().setUrl("http://localhost:9359?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());
        assertEquals(0.4351, response.getScore());
    }
}
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 14 with AdaptiveAuthenticationProperties

use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.

the class BlackDotIPAddressIntelligenceServiceTests method verifyBannedOperation.

@Test
public void verifyBannedOperation() {
    try (val webServer = new MockWebServer(9355, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.TOO_MANY_REQUESTS)) {
        webServer.start();
        val props = new AdaptiveAuthenticationProperties();
        props.getIpIntel().getBlackDot().setUrl("http://localhost:9355?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 15 with AdaptiveAuthenticationProperties

use of org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties in project cas by apereo.

the class BlackDotIPAddressIntelligenceServiceTests method verifySuccessStatusAndBannedWithRank.

@Test
public void verifySuccessStatusAndBannedWithRank() throws Exception {
    val data = MAPPER.writeValueAsString(CollectionUtils.wrap("status", "success", "result", 1));
    try (val webServer = new MockWebServer(9357, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
        webServer.start();
        val props = new AdaptiveAuthenticationProperties();
        props.getIpIntel().getBlackDot().setUrl("http://localhost:9357?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)

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