use of org.apereo.cas.api.AuthenticationRiskScore in project cas by apereo.
the class AuthenticationRiskEmailNotifierTests method verifyNoMailAttr.
@Test
public void verifyNoMailAttr() {
authenticationRiskEmailNotifier.setRegisteredService(CoreAuthenticationTestUtils.getRegisteredService());
val principal = CoreAuthenticationTestUtils.getPrincipal(CollectionUtils.wrap("nothing", List.of("cas@example.org")));
val authentication = CoreAuthenticationTestUtils.getAuthentication(principal);
authenticationRiskEmailNotifier.setAuthentication(authentication);
authenticationRiskEmailNotifier.setAuthenticationRiskScore(new AuthenticationRiskScore(BigDecimal.ONE));
assertDoesNotThrow(new Executable() {
@Override
public void execute() throws Throwable {
authenticationRiskEmailNotifier.publish();
}
});
}
use of org.apereo.cas.api.AuthenticationRiskScore in project cas by apereo.
the class MultifactorAuthenticationContingencyPlanTests method verifyNoProvider.
@Test
public void verifyNoProvider() {
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val props = new CasConfigurationProperties();
val plan = new MultifactorAuthenticationContingencyPlan(props, appCtx);
val principal = CoreAuthenticationTestUtils.getPrincipal(CollectionUtils.wrap("mail", List.of("cas@example.org")));
val authentication = CoreAuthenticationTestUtils.getAuthentication(principal);
val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
assertThrows(AuthenticationException.class, () -> plan.execute(authentication, registeredService, new AuthenticationRiskScore(BigDecimal.ONE), new MockHttpServletRequest()));
}
use of org.apereo.cas.api.AuthenticationRiskScore in project cas by apereo.
the class DefaultAuthenticationRiskEvaluator method eval.
@Audit(action = AuditableActions.EVALUATE_RISKY_AUTHENTICATION, actionResolverName = AuditActionResolvers.ADAPTIVE_RISKY_AUTHENTICATION_ACTION_RESOLVER, resourceResolverName = AuditResourceResolvers.ADAPTIVE_RISKY_AUTHENTICATION_RESOURCE_RESOLVER)
@Override
public AuthenticationRiskScore eval(final Authentication authentication, final RegisteredService service, final HttpServletRequest request) {
val activeCalculators = this.calculators.stream().filter(BeanSupplier::isNotProxy).collect(Collectors.toList());
if (activeCalculators.isEmpty()) {
return new AuthenticationRiskScore(AuthenticationRequestRiskCalculator.HIGHEST_RISK_SCORE);
}
val scores = activeCalculators.stream().map(r -> r.calculate(authentication, service, request)).filter(Objects::nonNull).collect(Collectors.toList());
val sum = scores.stream().map(AuthenticationRiskScore::getScore).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
val score = sum.divide(BigDecimal.valueOf(activeCalculators.size()), 2, RoundingMode.UP);
return new AuthenticationRiskScore(score);
}
use of org.apereo.cas.api.AuthenticationRiskScore in project cas by apereo.
the class AuthenticationRiskEmailNotifierTests method verifyOperation.
@Test
public void verifyOperation() {
authenticationRiskEmailNotifier.setRegisteredService(CoreAuthenticationTestUtils.getRegisteredService());
val principal = CoreAuthenticationTestUtils.getPrincipal(CollectionUtils.wrap("mail", List.of("cas@example.org")));
val authentication = CoreAuthenticationTestUtils.getAuthentication(principal);
authenticationRiskEmailNotifier.setAuthentication(authentication);
authenticationRiskEmailNotifier.setAuthenticationRiskScore(new AuthenticationRiskScore(BigDecimal.ONE));
assertDoesNotThrow(new Executable() {
@Override
public void execute() throws Throwable {
authenticationRiskEmailNotifier.publish();
}
});
}
use of org.apereo.cas.api.AuthenticationRiskScore in project cas by apereo.
the class MultifactorAuthenticationContingencyPlanTests method verifyManyProviders.
@Test
public void verifyManyProviders() {
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val props = new CasConfigurationProperties();
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(appCtx, new TestMultifactorAuthenticationProvider());
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(appCtx, new TestMultifactorAuthenticationProvider("mfa-two"));
val plan = new MultifactorAuthenticationContingencyPlan(props, appCtx);
val principal = CoreAuthenticationTestUtils.getPrincipal(CollectionUtils.wrap("mail", List.of("cas@example.org")));
val authentication = CoreAuthenticationTestUtils.getAuthentication(principal);
val registeredService = CoreAuthenticationTestUtils.getRegisteredService();
assertThrows(AuthenticationException.class, () -> plan.execute(authentication, registeredService, new AuthenticationRiskScore(BigDecimal.ONE), new MockHttpServletRequest()));
}
Aggregations