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