use of com.yubico.data.CredentialRegistration in project cas by apereo.
the class MongoDbWebAuthnCredentialRepository method getRegistrationsByUsername.
@Override
public Collection<CredentialRegistration> getRegistrationsByUsername(final String username) {
val query = new Query().addCriteria(Criteria.where(MongoDbWebAuthnCredentialRegistration.FIELD_USERNAME).is(username)).collation(Collation.of(Locale.ENGLISH).strength(Collation.ComparisonLevel.primary()));
val records = mongoTemplate.find(query, MongoDbWebAuthnCredentialRegistration.class, getProperties().getAuthn().getMfa().getWebAuthn().getMongo().getCollection());
return records.stream().map(record -> getCipherExecutor().decode(record.getRecords())).map(Unchecked.function(record -> WebAuthnUtils.getObjectMapper().readValue(record, new TypeReference<Set<CredentialRegistration>>() {
}))).flatMap(Collection::stream).collect(Collectors.toList());
}
use of com.yubico.data.CredentialRegistration in project cas by apereo.
the class JpaWebAuthnCredentialRepository method update.
@Override
@SneakyThrows
public void update(final String username, final Collection<CredentialRegistration> givenRecords) {
val records = givenRecords.stream().map(record -> {
if (record.getRegistrationTime() == null) {
return record.withRegistrationTime(Instant.now(Clock.systemUTC()));
}
return record;
}).collect(Collectors.toList());
val jsonRecords = getCipherExecutor().encode(WebAuthnUtils.getObjectMapper().writeValueAsString(records));
new TransactionTemplate(transactionManager).execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(final TransactionStatus status) {
val count = entityManager.createQuery(UPDATE_QUERY.concat("SET r.records=:records WHERE r.username = :username")).setParameter("username", username.trim().toLowerCase()).setParameter("records", jsonRecords).executeUpdate();
if (count == 0) {
val record = JpaWebAuthnCredentialRegistration.builder().username(username.trim().toLowerCase()).records(jsonRecords).build();
entityManager.merge(record);
}
}
});
}
use of com.yubico.data.CredentialRegistration in project cas by apereo.
the class RedisWebAuthnCredentialRepository method update.
@Override
@SneakyThrows
protected void update(final String username, final Collection<CredentialRegistration> givenRecords) {
val redisKey = buildRedisKeyForRecord(username);
if (givenRecords.isEmpty()) {
redisTemplate.delete(redisKey);
} else {
val records = givenRecords.stream().map(record -> {
if (record.getRegistrationTime() == null) {
return record.withRegistrationTime(Instant.now(Clock.systemUTC()));
}
return record;
}).collect(Collectors.toList());
val jsonRecords = getCipherExecutor().encode(WebAuthnUtils.getObjectMapper().writeValueAsString(records));
val entry = RedisWebAuthnCredentialRegistration.builder().records(jsonRecords).username(username.trim().toLowerCase()).build();
redisTemplate.boundValueOps(redisKey).set(entry);
}
}
Aggregations