Search in sources :

Example 1 with EncryptionRandomizedSigningJwtCryptographyProperties

use of org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties in project cas by apereo.

the class DynamoDbTicketRegistryConfiguration method ticketRegistry.

@Autowired
@RefreshScope
@Bean
public TicketRegistry ticketRegistry(@Qualifier("ticketCatalog") final TicketCatalog ticketCatalog) {
    final DynamoDbTicketRegistryProperties db = casProperties.getTicket().getRegistry().getDynamoDb();
    final EncryptionRandomizedSigningJwtCryptographyProperties crypto = db.getCrypto();
    return new DynamoDbTicketRegistry(CoreTicketUtils.newTicketRegistryCipherExecutor(crypto, "dynamoDb"), dynamoDbTicketRegistryFacilitator(ticketCatalog));
}
Also used : DynamoDbTicketRegistryProperties(org.apereo.cas.configuration.model.support.dynamodb.DynamoDbTicketRegistryProperties) DynamoDbTicketRegistry(org.apereo.cas.ticket.registry.DynamoDbTicketRegistry) EncryptionRandomizedSigningJwtCryptographyProperties(org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Autowired(org.springframework.beans.factory.annotation.Autowired) Bean(org.springframework.context.annotation.Bean)

Example 2 with EncryptionRandomizedSigningJwtCryptographyProperties

use of org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties in project cas by apereo.

the class CasCoreWebflowConfiguration method webflowCipherExecutor.

@Bean
@RefreshScope
public CipherExecutor webflowCipherExecutor() {
    final WebflowProperties webflow = casProperties.getWebflow();
    final EncryptionRandomizedSigningJwtCryptographyProperties crypto = webflow.getCrypto();
    boolean enabled = crypto.isEnabled();
    if (!enabled && (StringUtils.isNotBlank(crypto.getEncryption().getKey())) && StringUtils.isNotBlank(crypto.getSigning().getKey())) {
        LOGGER.warn("Webflow encryption/signing is not enabled explicitly in the configuration, yet signing/encryption keys " + "are defined for operations. CAS will proceed to enable the webflow encryption/signing functionality.");
        enabled = true;
    }
    if (enabled) {
        return new WebflowConversationStateCipherExecutor(crypto.getEncryption().getKey(), crypto.getSigning().getKey(), crypto.getAlg(), crypto.getSigning().getKeySize(), crypto.getEncryption().getKeySize());
    }
    LOGGER.warn("Webflow encryption/signing is turned off. This " + "MAY NOT be safe in a production environment. Consider using other choices to handle encryption, " + "signing and verification of webflow state.");
    return CipherExecutor.noOp();
}
Also used : WebflowConversationStateCipherExecutor(org.apereo.cas.util.cipher.WebflowConversationStateCipherExecutor) WebflowProperties(org.apereo.cas.configuration.model.webapp.WebflowProperties) EncryptionRandomizedSigningJwtCryptographyProperties(org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with EncryptionRandomizedSigningJwtCryptographyProperties

use of org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties in project cas by apereo.

the class AbstractTicketRegistryTests method setUpEncryption.

private void setUpEncryption() {
    final AbstractTicketRegistry registry = AopTestUtils.getTargetObject(this.ticketRegistry);
    if (this.useEncryption) {
        final CipherExecutor cipher = CoreTicketUtils.newTicketRegistryCipherExecutor(new EncryptionRandomizedSigningJwtCryptographyProperties(), "[tests]");
        registry.setCipherExecutor(cipher);
    } else {
        registry.setCipherExecutor(CipherExecutor.noOp());
    }
}
Also used : CipherExecutor(org.apereo.cas.CipherExecutor) EncryptionRandomizedSigningJwtCryptographyProperties(org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties)

Example 4 with EncryptionRandomizedSigningJwtCryptographyProperties

use of org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties in project cas by apereo.

the class GenerateCryptoKeysCommand method generateKey.

/**
 * Generate key.
 *
 * @param name the name
 */
@CliCommand(value = "generate-key", help = "Generate signing/encryption crypto keys for CAS settings")
public void generateKey(@CliOption(key = { "group" }, help = "Property group that holds the key (i.e. cas.webflow). The group must have a child category of 'crypto'.", mandatory = true, specifiedDefaultValue = "", unspecifiedDefaultValue = "", optionContext = "Property name for that holds the key") final String name) {
    /*
        Because the command is used both from the shell and CLI,
        we need to validate parameters again.
         */
    if (StringUtils.isBlank(name)) {
        LOGGER.warn("No property/setting name is specified for signing/encryption key generation.");
        return;
    }
    final CasConfigurationMetadataRepository repository = new CasConfigurationMetadataRepository();
    final String cryptoGroup = name.concat(".crypto");
    repository.getRepository().getAllGroups().entrySet().stream().filter(e -> e.getKey().startsWith(cryptoGroup)).forEach(e -> {
        final ConfigurationMetadataGroup grp = e.getValue();
        grp.getSources().forEach(Unchecked.biConsumer((k, v) -> {
            final Object obj = ClassUtils.getClass(k, true).getDeclaredConstructor().newInstance();
            if (obj instanceof EncryptionJwtSigningJwtCryptographyProperties) {
                final EncryptionJwtSigningJwtCryptographyProperties crypto = (EncryptionJwtSigningJwtCryptographyProperties) obj;
                LOGGER.info(cryptoGroup.concat(".encryption.key=" + EncodingUtils.generateJsonWebKey(crypto.getEncryption().getKeySize())));
                LOGGER.info(cryptoGroup.concat(".signing.key=" + EncodingUtils.generateJsonWebKey(crypto.getSigning().getKeySize())));
            } else if (obj instanceof EncryptionRandomizedSigningJwtCryptographyProperties) {
                final EncryptionRandomizedSigningJwtCryptographyProperties crypto = (EncryptionRandomizedSigningJwtCryptographyProperties) obj;
                final String encKey = new Base64RandomStringGenerator(crypto.getEncryption().getKeySize()).getNewString();
                LOGGER.info(cryptoGroup.concat(".encryption.key=" + encKey));
                LOGGER.info(cryptoGroup.concat(".signing.key=" + EncodingUtils.generateJsonWebKey(crypto.getSigning().getKeySize())));
            }
        }));
    });
}
Also used : CliCommand(org.springframework.shell.core.annotation.CliCommand) Unchecked(org.jooq.lambda.Unchecked) StringUtils(org.apache.commons.lang3.StringUtils) CliOption(org.springframework.shell.core.annotation.CliOption) ClassUtils(org.apache.commons.lang3.ClassUtils) CasConfigurationMetadataRepository(org.apereo.cas.metadata.CasConfigurationMetadataRepository) Slf4j(lombok.extern.slf4j.Slf4j) EncryptionJwtSigningJwtCryptographyProperties(org.apereo.cas.configuration.model.core.util.EncryptionJwtSigningJwtCryptographyProperties) Service(org.springframework.stereotype.Service) Base64RandomStringGenerator(org.apereo.cas.util.gen.Base64RandomStringGenerator) EncodingUtils(org.apereo.cas.util.EncodingUtils) ConfigurationMetadataGroup(org.springframework.boot.configurationmetadata.ConfigurationMetadataGroup) EncryptionRandomizedSigningJwtCryptographyProperties(org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties) CommandMarker(org.springframework.shell.core.CommandMarker) CasConfigurationMetadataRepository(org.apereo.cas.metadata.CasConfigurationMetadataRepository) Base64RandomStringGenerator(org.apereo.cas.util.gen.Base64RandomStringGenerator) ConfigurationMetadataGroup(org.springframework.boot.configurationmetadata.ConfigurationMetadataGroup) EncryptionJwtSigningJwtCryptographyProperties(org.apereo.cas.configuration.model.core.util.EncryptionJwtSigningJwtCryptographyProperties) EncryptionRandomizedSigningJwtCryptographyProperties(org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 5 with EncryptionRandomizedSigningJwtCryptographyProperties

use of org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties in project cas by apereo.

the class BaseTicketRegistryTests method setUpEncryption.

private void setUpEncryption() {
    var registry = (AbstractTicketRegistry) AopTestUtils.getTargetObject(ticketRegistry);
    if (this.useEncryption) {
        val cipher = CoreTicketUtils.newTicketRegistryCipherExecutor(new EncryptionRandomizedSigningJwtCryptographyProperties(), "[tests]");
        registry.setCipherExecutor(cipher);
    } else {
        registry.setCipherExecutor(CipherExecutor.noOp());
    }
}
Also used : lombok.val(lombok.val) EncryptionRandomizedSigningJwtCryptographyProperties(org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties)

Aggregations

EncryptionRandomizedSigningJwtCryptographyProperties (org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties)6 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)3 Bean (org.springframework.context.annotation.Bean)3 Autowired (org.springframework.beans.factory.annotation.Autowired)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 Slf4j (lombok.extern.slf4j.Slf4j)1 lombok.val (lombok.val)1 Ehcache (net.sf.ehcache.Ehcache)1 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)1 ClassUtils (org.apache.commons.lang3.ClassUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 CipherExecutor (org.apereo.cas.CipherExecutor)1 EncryptionJwtSigningJwtCryptographyProperties (org.apereo.cas.configuration.model.core.util.EncryptionJwtSigningJwtCryptographyProperties)1 DynamoDbTicketRegistryProperties (org.apereo.cas.configuration.model.support.dynamodb.DynamoDbTicketRegistryProperties)1 WebflowProperties (org.apereo.cas.configuration.model.webapp.WebflowProperties)1 CasConfigurationMetadataRepository (org.apereo.cas.metadata.CasConfigurationMetadataRepository)1 TicketDefinition (org.apereo.cas.ticket.TicketDefinition)1 DynamoDbTicketRegistry (org.apereo.cas.ticket.registry.DynamoDbTicketRegistry)1 EhCacheTicketRegistry (org.apereo.cas.ticket.registry.EhCacheTicketRegistry)1 EncodingUtils (org.apereo.cas.util.EncodingUtils)1