Search in sources :

Example 1 with AuthenticationRiskScore

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();
        }
    });
}
Also used : lombok.val(lombok.val) AuthenticationRiskScore(org.apereo.cas.api.AuthenticationRiskScore) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 2 with AuthenticationRiskScore

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()));
}
Also used : lombok.val(lombok.val) AuthenticationRiskScore(org.apereo.cas.api.AuthenticationRiskScore) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Test(org.junit.jupiter.api.Test)

Example 3 with AuthenticationRiskScore

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);
}
Also used : lombok.val(lombok.val) AuthenticationRiskScore(org.apereo.cas.api.AuthenticationRiskScore) BigDecimal(java.math.BigDecimal) Audit(org.apereo.inspektr.audit.annotation.Audit)

Example 4 with AuthenticationRiskScore

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();
        }
    });
}
Also used : lombok.val(lombok.val) AuthenticationRiskScore(org.apereo.cas.api.AuthenticationRiskScore) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 5 with AuthenticationRiskScore

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()));
}
Also used : lombok.val(lombok.val) TestMultifactorAuthenticationProvider(org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider) AuthenticationRiskScore(org.apereo.cas.api.AuthenticationRiskScore) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)7 AuthenticationRiskScore (org.apereo.cas.api.AuthenticationRiskScore)7 Test (org.junit.jupiter.api.Test)5 Executable (org.junit.jupiter.api.function.Executable)3 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)2 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 BigDecimal (java.math.BigDecimal)1 Supplier (java.util.function.Supplier)1 TestMultifactorAuthenticationProvider (org.apereo.cas.authentication.mfa.TestMultifactorAuthenticationProvider)1 Audit (org.apereo.inspektr.audit.annotation.Audit)1