Search in sources :

Example 11 with AuthenticationRiskScore

use of org.apereo.cas.api.AuthenticationRiskScore in project cas by apereo.

the class DefaultAuthenticationRiskEvaluator method eval.

@Audit(action = "EVALUATE_RISKY_AUTHENTICATION", actionResolverName = "ADAPTIVE_RISKY_AUTHENTICATION_ACTION_RESOLVER", resourceResolverName = "ADAPTIVE_RISKY_AUTHENTICATION_RESOURCE_RESOLVER")
@Override
public AuthenticationRiskScore eval(final Authentication authentication, final RegisteredService service, final HttpServletRequest request) {
    if (this.calculators.isEmpty()) {
        return new AuthenticationRiskScore(AuthenticationRequestRiskCalculator.HIGHEST_RISK_SCORE);
    }
    final List<AuthenticationRiskScore> scores = new ArrayList<>();
    this.calculators.stream().forEach(r -> scores.add(r.calculate(authentication, service, request)));
    final BigDecimal sum = scores.stream().map(AuthenticationRiskScore::getScore).reduce(BigDecimal.ZERO, BigDecimal::add);
    final BigDecimal score = sum.divide(BigDecimal.valueOf(this.calculators.size()), 2, BigDecimal.ROUND_UP);
    return new AuthenticationRiskScore(score);
}
Also used : AuthenticationRiskScore(org.apereo.cas.api.AuthenticationRiskScore) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Audit(org.apereo.inspektr.audit.annotation.Audit)

Aggregations

AuthenticationRiskScore (org.apereo.cas.api.AuthenticationRiskScore)11 Authentication (org.apereo.cas.authentication.Authentication)8 RegisteredService (org.apereo.cas.services.RegisteredService)8 Test (org.junit.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)3 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 AuthenticationRiskContingencyResponse (org.apereo.cas.api.AuthenticationRiskContingencyResponse)1 Principal (org.apereo.cas.authentication.principal.Principal)1 CasRiskBasedAuthenticationEvaluationStartedEvent (org.apereo.cas.support.events.authentication.adaptive.CasRiskBasedAuthenticationEvaluationStartedEvent)1 CasRiskBasedAuthenticationMitigationStartedEvent (org.apereo.cas.support.events.authentication.adaptive.CasRiskBasedAuthenticationMitigationStartedEvent)1 CasRiskyAuthenticationDetectedEvent (org.apereo.cas.support.events.authentication.adaptive.CasRiskyAuthenticationDetectedEvent)1 CasRiskyAuthenticationMitigatedEvent (org.apereo.cas.support.events.authentication.adaptive.CasRiskyAuthenticationMitigatedEvent)1 CasEvent (org.apereo.cas.support.events.dao.CasEvent)1 Audit (org.apereo.inspektr.audit.annotation.Audit)1