Search in sources :

Example 6 with MultifactorAuthenticationTrustRecord

use of org.apereo.cas.trusted.authentication.api.MultifactorAuthenticationTrustRecord in project cas by apereo.

the class MultifactorAuthenticationVerifyTrustAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
    final Authentication c = WebUtils.getAuthentication(requestContext);
    if (c == null) {
        LOGGER.warn("Could not determine authentication from the request context");
        return no();
    }
    final String principal = c.getPrincipal().getId();
    final LocalDate onOrAfter = LocalDate.now().minus(trustedProperties.getExpiration(), DateTimeUtils.toChronoUnit(trustedProperties.getTimeUnit()));
    LOGGER.warn("Retrieving trusted authentication records for [{}] that are on/after [{}]", principal, onOrAfter);
    final Set<MultifactorAuthenticationTrustRecord> results = storage.get(principal, onOrAfter);
    if (results.isEmpty()) {
        LOGGER.debug("No valid trusted authentication records could be found for [{}]", principal);
        return no();
    }
    final String geography = MultifactorAuthenticationTrustUtils.generateGeography();
    LOGGER.debug("Retrieving authentication records for [{}] that match [{}]", principal, geography);
    if (results.stream().noneMatch(entry -> entry.getGeography().equals(geography))) {
        LOGGER.debug("No trusted authentication records could be found for [{}] to match the current geography", principal);
        return no();
    }
    LOGGER.debug("Trusted authentication records found for [{}] that matches the current geography", principal);
    MultifactorAuthenticationTrustUtils.setMultifactorAuthenticationTrustedInScope(requestContext);
    MultifactorAuthenticationTrustUtils.trackTrustedMultifactorAuthenticationAttribute(c, trustedProperties.getAuthenticationContextAttribute());
    return yes();
}
Also used : MultifactorAuthenticationTrustRecord(org.apereo.cas.trusted.authentication.api.MultifactorAuthenticationTrustRecord) Authentication(org.apereo.cas.authentication.Authentication) LocalDate(java.time.LocalDate)

Aggregations

MultifactorAuthenticationTrustRecord (org.apereo.cas.trusted.authentication.api.MultifactorAuthenticationTrustRecord)6 HashSet (java.util.HashSet)2 Authentication (org.apereo.cas.authentication.Authentication)2 Query (org.springframework.data.mongodb.core.query.Query)2 LocalDate (java.time.LocalDate)1 InMemoryMultifactorAuthenticationTrustStorage (org.apereo.cas.trusted.authentication.storage.InMemoryMultifactorAuthenticationTrustStorage)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 Bean (org.springframework.context.annotation.Bean)1 RestTemplate (org.springframework.web.client.RestTemplate)1