Search in sources :

Example 36 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class ClientInfoAuthenticationMetaDataPopulatorTests method verifyOperation.

@Test
public void verifyOperation() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("223.456.789.000");
    request.setLocalAddr("123.456.789.000");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "test");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val populator = new ClientInfoAuthenticationMetaDataPopulator();
    val c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    val builder = DefaultAuthenticationBuilder.newInstance(CoreAuthenticationTestUtils.getAuthentication());
    assertTrue(populator.supports(c));
    populator.populateAttributes(builder, new DefaultAuthenticationTransactionFactory().newTransaction(c));
    val authn = builder.build();
    val attributes = authn.getAttributes();
    assertTrue(attributes.containsKey(ClientInfoAuthenticationMetaDataPopulator.ATTRIBUTE_CLIENT_IP_ADDRESS));
    assertTrue(attributes.containsKey(ClientInfoAuthenticationMetaDataPopulator.ATTRIBUTE_SERVER_IP_ADDRESS));
    assertTrue(attributes.containsKey(ClientInfoAuthenticationMetaDataPopulator.ATTRIBUTE_USER_AGENT));
    assertTrue(attributes.containsKey(ClientInfoAuthenticationMetaDataPopulator.ATTRIBUTE_GEO_LOCATION));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) ClientInfoAuthenticationMetaDataPopulator(org.apereo.cas.authentication.metadata.ClientInfoAuthenticationMetaDataPopulator) Test(org.junit.jupiter.api.Test)

Example 37 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class GeoLocationAuthenticationRequestRiskCalculatorTests method verifyTestWhenAuthnEventsFoundForUser.

@Test
public void verifyTestWhenAuthnEventsFoundForUser() {
    HttpsURLConnection.setDefaultHostnameVerifier(CasSSLContext.disabled().getHostnameVerifier());
    HttpsURLConnection.setDefaultSSLSocketFactory(CasSSLContext.disabled().getSslContext().getSocketFactory());
    val authentication = CoreAuthenticationTestUtils.getAuthentication("casuser");
    val service = RegisteredServiceTestUtils.getRegisteredService("test");
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("172.217.11.174");
    request.setLocalAddr("127.0.0.1");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val score = authenticationRiskEvaluator.eval(authentication, service, request);
    assertTrue(score.isHighestRisk());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) Test(org.junit.jupiter.api.Test)

Example 38 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class UserAgentAuthenticationRequestRiskCalculatorTests method verifyTestWhenAuthnEventsFoundForUser.

@Test
public void verifyTestWhenAuthnEventsFoundForUser() {
    val authentication = CoreAuthenticationTestUtils.getAuthentication("casuser");
    val service = RegisteredServiceTestUtils.getRegisteredService("test");
    val request = new MockHttpServletRequest();
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)");
    request.setRemoteAddr("107.181.69.221");
    request.setLocalAddr("127.0.0.1");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val score = authenticationRiskEvaluator.eval(authentication, service, request);
    assertTrue(score.isRiskGreaterThan(casProperties.getAuthn().getAdaptive().getRisk().getThreshold()));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) Test(org.junit.jupiter.api.Test)

Example 39 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class IpAddressAuthenticationRequestRiskCalculatorTests method verifyTestWhenAuthnEventsFoundForUser.

@Test
public void verifyTestWhenAuthnEventsFoundForUser() {
    val authentication = CoreAuthenticationTestUtils.getAuthentication("casuser");
    val service = RegisteredServiceTestUtils.getRegisteredService("test");
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("107.181.69.221");
    request.setLocalAddr("127.0.0.1");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val score = authenticationRiskEvaluator.eval(authentication, service, request);
    assertTrue(score.isRiskGreaterThan(casProperties.getAuthn().getAdaptive().getRisk().getThreshold()));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) Test(org.junit.jupiter.api.Test)

Example 40 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class MultifactorAuthenticationVerifyTrustActionTests method verifyDeviceTrusted.

@Test
@Order(2)
public void verifyDeviceTrusted() throws Exception {
    val context = new MockRequestContext();
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
    WebUtils.putRegisteredService(context, RegisteredServiceTestUtils.getRegisteredService("sample-service", Collections.EMPTY_MAP));
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("123.456.789.000");
    request.setLocalAddr("123.456.789.000");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "test");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val record = getMultifactorAuthenticationTrustRecord();
    record.setRecordDate(ZonedDateTime.now(ZoneOffset.UTC).minusSeconds(5));
    val deviceFingerprint = deviceFingerprintStrategy.determineFingerprintComponent(record.getPrincipal(), request, response);
    record.setDeviceFingerprint(deviceFingerprint);
    mfaTrustEngine.save(record);
    assertNotNull(response.getCookies());
    assertEquals(response.getCookies().length, 1);
    request.setCookies(response.getCookies());
    val authn = RegisteredServiceTestUtils.getAuthentication(record.getPrincipal());
    WebUtils.putAuthentication(authn, context);
    assertEquals("yes", mfaVerifyTrustAction.execute(context).getId());
    assertTrue(MultifactorAuthenticationTrustUtils.isMultifactorAuthenticationTrustedInScope(context));
    assertTrue(authn.getAttributes().containsKey(casProperties.getAuthn().getMfa().getTrusted().getCore().getAuthenticationContextAttribute()));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ClientInfo (org.apereo.inspektr.common.web.ClientInfo)82 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)69 lombok.val (lombok.val)65 Test (org.junit.jupiter.api.Test)42 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)36 MockRequestContext (org.springframework.webflow.test.MockRequestContext)35 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)31 MockServletContext (org.springframework.mock.web.MockServletContext)29 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)14 MockWebServer (org.apereo.cas.util.MockWebServer)13 ByteArrayResource (org.springframework.core.io.ByteArrayResource)13 BeforeEach (org.junit.jupiter.api.BeforeEach)12 BeforeAll (org.junit.jupiter.api.BeforeAll)6 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)5 GeoLocationRequest (org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)4 Cookie (javax.servlet.http.Cookie)4 GeoLocationResponse (org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse)4 AdaptiveAuthenticationProperties (org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties)4