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;
}
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);
}
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);
}
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();
}
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();
}
Aggregations