use of org.apereo.cas.adaptors.yubikey.YubiKeyAccount in project cas by apereo.
the class YubiKeyAuthenticationEventExecutionPlanConfiguration method yubiKeyAccountRegistry.
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnMissingBean(name = "yubiKeyAccountRegistry")
public YubiKeyAccountRegistry yubiKeyAccountRegistry(final CasConfigurationProperties casProperties, @Qualifier("yubiKeyAccountValidator") final YubiKeyAccountValidator yubiKeyAccountValidator, @Qualifier("yubicoClient") final YubicoClient yubicoClient, @Qualifier("yubikeyAccountCipherExecutor") final CipherExecutor yubikeyAccountCipherExecutor) {
val yubi = casProperties.getAuthn().getMfa().getYubikey();
if (yubi.getJsonFile() != null) {
LOGGER.debug("Using JSON resource [{}] as the YubiKey account registry", yubi.getJsonFile());
val registry = new JsonYubiKeyAccountRegistry(yubi.getJsonFile(), yubiKeyAccountValidator);
registry.setCipherExecutor(yubikeyAccountCipherExecutor);
return registry;
}
if (StringUtils.isNotBlank(yubi.getRest().getUrl())) {
LOGGER.debug("Using REST API resource [{}] as the YubiKey account registry", yubi.getRest().getUrl());
val registry = new RestfulYubiKeyAccountRegistry(yubi.getRest(), yubiKeyAccountValidator);
registry.setCipherExecutor(yubikeyAccountCipherExecutor);
return registry;
}
if (yubi.getAllowedDevices() != null && !yubi.getAllowedDevices().isEmpty()) {
LOGGER.debug("Using statically-defined devices for [{}] as the YubiKey account registry", yubi.getAllowedDevices().keySet());
val map = (Map<String, YubiKeyAccount>) yubi.getAllowedDevices().entrySet().stream().map(entry -> YubiKeyAccount.builder().id(System.currentTimeMillis()).username(entry.getKey()).devices(List.of(YubiKeyRegisteredDevice.builder().publicId(entry.getValue()).name(UUID.randomUUID().toString()).registrationDate(ZonedDateTime.now(Clock.systemUTC())).build())).build()).collect(Collectors.toMap(YubiKeyAccount::getUsername, acct -> acct));
val registry = new PermissiveYubiKeyAccountRegistry(map, yubiKeyAccountValidator);
registry.setCipherExecutor(CipherExecutor.noOpOfSerializableToString());
return registry;
}
LOGGER.warn("All credentials are considered eligible for YubiKey authentication. " + "Consider providing an account registry implementation via [{}]", YubiKeyAccountRegistry.class.getName());
val registry = new OpenYubiKeyAccountRegistry(new DefaultYubiKeyAccountValidator(yubicoClient));
registry.setCipherExecutor(yubikeyAccountCipherExecutor);
return registry;
}
Aggregations