Search in sources :

Example 1 with MultifactorAuthenticationTrustRecord

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

the class MultifactorAuthnTrustConfiguration method mfaTrustEngine.

@ConditionalOnMissingBean(name = "mfaTrustEngine")
@Bean
@RefreshScope
public MultifactorAuthenticationTrustStorage mfaTrustEngine() {
    final LoadingCache<String, MultifactorAuthenticationTrustRecord> storage = CacheBuilder.newBuilder().initialCapacity(INITIAL_CACHE_SIZE).maximumSize(MAX_CACHE_SIZE).recordStats().expireAfterWrite(casProperties.getAuthn().getMfa().getTrusted().getExpiration(), casProperties.getAuthn().getMfa().getTrusted().getTimeUnit()).build(new CacheLoader<String, MultifactorAuthenticationTrustRecord>() {

        @Override
        public MultifactorAuthenticationTrustRecord load(final String s) throws Exception {
            LOGGER.error("Load operation of the cache is not supported.");
            return null;
        }
    });
    final InMemoryMultifactorAuthenticationTrustStorage m = new InMemoryMultifactorAuthenticationTrustStorage(storage);
    m.setCipherExecutor(mfaTrustCipherExecutor());
    return m;
}
Also used : InMemoryMultifactorAuthenticationTrustStorage(org.apereo.cas.trusted.authentication.storage.InMemoryMultifactorAuthenticationTrustStorage) MultifactorAuthenticationTrustRecord(org.apereo.cas.trusted.authentication.api.MultifactorAuthenticationTrustRecord) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with MultifactorAuthenticationTrustRecord

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

the class MongoDbMultifactorAuthenticationTrustStorage method get.

@Override
public Set<MultifactorAuthenticationTrustRecord> get(final String principal) {
    final Query query = new Query();
    query.addCriteria(Criteria.where("principal").is(principal));
    final List<MultifactorAuthenticationTrustRecord> results = this.mongoTemplate.find(query, MultifactorAuthenticationTrustRecord.class, this.collectionName);
    return new HashSet<>(results);
}
Also used : MultifactorAuthenticationTrustRecord(org.apereo.cas.trusted.authentication.api.MultifactorAuthenticationTrustRecord) Query(org.springframework.data.mongodb.core.query.Query) HashSet(java.util.HashSet)

Example 3 with MultifactorAuthenticationTrustRecord

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

the class MongoDbMultifactorAuthenticationTrustStorage method get.

@Override
public Set<MultifactorAuthenticationTrustRecord> get(final LocalDate onOrAfterDate) {
    final Query query = new Query();
    query.addCriteria(Criteria.where("date").gte(onOrAfterDate));
    final List<MultifactorAuthenticationTrustRecord> results = this.mongoTemplate.find(query, MultifactorAuthenticationTrustRecord.class, this.collectionName);
    return new HashSet<>(results);
}
Also used : MultifactorAuthenticationTrustRecord(org.apereo.cas.trusted.authentication.api.MultifactorAuthenticationTrustRecord) Query(org.springframework.data.mongodb.core.query.Query) HashSet(java.util.HashSet)

Example 4 with MultifactorAuthenticationTrustRecord

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

the class RestMultifactorAuthenticationTrustStorage method getResults.

private static Set<MultifactorAuthenticationTrustRecord> getResults(final String url) {
    final RestTemplate restTemplate = new RestTemplate();
    final ResponseEntity<MultifactorAuthenticationTrustRecord[]> responseEntity = restTemplate.getForEntity(url, MultifactorAuthenticationTrustRecord[].class);
    if (responseEntity.getStatusCode() == HttpStatus.OK) {
        final MultifactorAuthenticationTrustRecord[] results = responseEntity.getBody();
        return Stream.of(results).collect(Collectors.toSet());
    }
    return Collections.emptySet();
}
Also used : MultifactorAuthenticationTrustRecord(org.apereo.cas.trusted.authentication.api.MultifactorAuthenticationTrustRecord) RestTemplate(org.springframework.web.client.RestTemplate)

Example 5 with MultifactorAuthenticationTrustRecord

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

the class MultifactorAuthenticationSetTrustAction method doExecute.

@Override
public Event doExecute(final RequestContext requestContext) throws Exception {
    final Authentication c = WebUtils.getAuthentication(requestContext);
    if (c == null) {
        LOGGER.error("Could not determine authentication from the request context");
        return error();
    }
    AuthenticationCredentialsLocalBinder.bindCurrent(c);
    final String principal = c.getPrincipal().getId();
    if (!MultifactorAuthenticationTrustUtils.isMultifactorAuthenticationTrustedInScope(requestContext)) {
        LOGGER.debug("Attempt to store trusted authentication record for [{}]", principal);
        final MultifactorAuthenticationTrustRecord record = MultifactorAuthenticationTrustRecord.newInstance(principal, MultifactorAuthenticationTrustUtils.generateGeography());
        if (requestContext.getRequestParameters().contains(PARAM_NAME_DEVICE_NAME)) {
            final String deviceName = requestContext.getRequestParameters().get(PARAM_NAME_DEVICE_NAME);
            if (StringUtils.isNotBlank(deviceName)) {
                record.setName(deviceName);
            }
        }
        storage.set(record);
        LOGGER.debug("Saved trusted authentication record for [{}] under [{}]", principal, record.getName());
    }
    LOGGER.debug("Trusted authentication session exists for [{}]", principal);
    MultifactorAuthenticationTrustUtils.trackTrustedMultifactorAuthenticationAttribute(c, trustedProperties.getAuthenticationContextAttribute());
    return success();
}
Also used : MultifactorAuthenticationTrustRecord(org.apereo.cas.trusted.authentication.api.MultifactorAuthenticationTrustRecord) Authentication(org.apereo.cas.authentication.Authentication)

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