Search in sources :

Example 1 with RestfulYubiKeyAccountRegistry

use of org.apereo.cas.adaptors.yubikey.registry.RestfulYubiKeyAccountRegistry 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;
}
Also used : lombok.val(lombok.val) PermissiveYubiKeyAccountRegistry(org.apereo.cas.adaptors.yubikey.registry.PermissiveYubiKeyAccountRegistry) OpenYubiKeyAccountRegistry(org.apereo.cas.adaptors.yubikey.registry.OpenYubiKeyAccountRegistry) YubiKeyAccountRegistry(org.apereo.cas.adaptors.yubikey.YubiKeyAccountRegistry) RestfulYubiKeyAccountRegistry(org.apereo.cas.adaptors.yubikey.registry.RestfulYubiKeyAccountRegistry) OpenYubiKeyAccountRegistry(org.apereo.cas.adaptors.yubikey.registry.OpenYubiKeyAccountRegistry) PermissiveYubiKeyAccountRegistry(org.apereo.cas.adaptors.yubikey.registry.PermissiveYubiKeyAccountRegistry) JsonYubiKeyAccountRegistry(org.apereo.cas.adaptors.yubikey.registry.JsonYubiKeyAccountRegistry) RestfulYubiKeyAccountRegistry(org.apereo.cas.adaptors.yubikey.registry.RestfulYubiKeyAccountRegistry) YubiKeyAccount(org.apereo.cas.adaptors.yubikey.YubiKeyAccount) DefaultYubiKeyAccountValidator(org.apereo.cas.adaptors.yubikey.DefaultYubiKeyAccountValidator) JsonYubiKeyAccountRegistry(org.apereo.cas.adaptors.yubikey.registry.JsonYubiKeyAccountRegistry) Map(java.util.Map) 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)

Aggregations

Map (java.util.Map)1 lombok.val (lombok.val)1 DefaultYubiKeyAccountValidator (org.apereo.cas.adaptors.yubikey.DefaultYubiKeyAccountValidator)1 YubiKeyAccount (org.apereo.cas.adaptors.yubikey.YubiKeyAccount)1 YubiKeyAccountRegistry (org.apereo.cas.adaptors.yubikey.YubiKeyAccountRegistry)1 JsonYubiKeyAccountRegistry (org.apereo.cas.adaptors.yubikey.registry.JsonYubiKeyAccountRegistry)1 OpenYubiKeyAccountRegistry (org.apereo.cas.adaptors.yubikey.registry.OpenYubiKeyAccountRegistry)1 PermissiveYubiKeyAccountRegistry (org.apereo.cas.adaptors.yubikey.registry.PermissiveYubiKeyAccountRegistry)1 RestfulYubiKeyAccountRegistry (org.apereo.cas.adaptors.yubikey.registry.RestfulYubiKeyAccountRegistry)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