use of org.apereo.cas.services.RegisteredService in project cas by apereo.
the class DateTimeAuthenticationRequestRiskCalculator method calculateScore.
@Override
protected BigDecimal calculateScore(final HttpServletRequest request, final Authentication authentication, final RegisteredService service, final Collection<CasEvent> events) {
final ZonedDateTime timestamp = ZonedDateTime.now();
LOGGER.debug("Filtering authentication events for timestamp [{}]", timestamp);
final long count = events.stream().filter(e -> e.getCreationTime().getHour() == timestamp.getHour() || e.getCreationTime().plusHours(windowInHours).getHour() == timestamp.getHour() || e.getCreationTime().minusHours(windowInHours).getHour() == timestamp.getHour()).count();
LOGGER.debug("Total authentication events found for [{}]: [{}]", timestamp, count);
if (count == events.size()) {
LOGGER.debug("Principal [{}] has always authenticated from [{}]", authentication.getPrincipal(), timestamp);
return LOWEST_RISK_SCORE;
}
return getFinalAveragedScore(count, events.size());
}
use of org.apereo.cas.services.RegisteredService in project cas by apereo.
the class DateTimeAuthenticationRequestRiskCalculatorTests method verifyTestWhenAuthnEventsFoundForUser.
@Test
public void verifyTestWhenAuthnEventsFoundForUser() {
final Authentication authentication = CoreAuthenticationTestUtils.getAuthentication("casuser");
final RegisteredService service = RegisteredServiceTestUtils.getRegisteredService("test");
final MockHttpServletRequest request = new MockHttpServletRequest();
final AuthenticationRiskScore score = authenticationRiskEvaluator.eval(authentication, service, request);
assertTrue(score.isLowestRisk());
}
use of org.apereo.cas.services.RegisteredService in project cas by apereo.
the class DateTimeAuthenticationRequestRiskCalculatorTests method verifyTestWhenNoAuthnEventsFoundForUser.
@Test
public void verifyTestWhenNoAuthnEventsFoundForUser() {
final Authentication authentication = CoreAuthenticationTestUtils.getAuthentication("datetimeperson");
final RegisteredService service = RegisteredServiceTestUtils.getRegisteredService("test");
final MockHttpServletRequest request = new MockHttpServletRequest();
final AuthenticationRiskScore score = authenticationRiskEvaluator.eval(authentication, service, request);
assertTrue(score.isHighestRisk());
}
use of org.apereo.cas.services.RegisteredService in project cas by apereo.
the class GeoLocationAuthenticationRequestRiskCalculatorTests method verifyTestWhenAuthnEventsFoundForUser.
@Test
public void verifyTestWhenAuthnEventsFoundForUser() {
final Authentication authentication = CoreAuthenticationTestUtils.getAuthentication("casuser");
final RegisteredService service = RegisteredServiceTestUtils.getRegisteredService("test");
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr("107.181.69.221");
request.setLocalAddr("127.0.0.1");
ClientInfoHolder.setClientInfo(new ClientInfo(request));
final AuthenticationRiskScore score = authenticationRiskEvaluator.eval(authentication, service, request);
assertTrue(score.isHighestRisk());
}
use of org.apereo.cas.services.RegisteredService in project cas by apereo.
the class IpAddressAuthenticationRequestRiskCalculatorTests method verifyTestWhenNoAuthnEventsFoundForUser.
@Test
public void verifyTestWhenNoAuthnEventsFoundForUser() {
final Authentication authentication = CoreAuthenticationTestUtils.getAuthentication("nobody");
final RegisteredService service = RegisteredServiceTestUtils.getRegisteredService("test");
final MockHttpServletRequest request = new MockHttpServletRequest();
final AuthenticationRiskScore score = authenticationRiskEvaluator.eval(authentication, service, request);
assertTrue(score.isHighestRisk());
}
Aggregations