Search in sources :

Example 1 with CasConfigurationMetadataRepository

use of org.apereo.cas.metadata.CasConfigurationMetadataRepository 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 2 with CasConfigurationMetadataRepository

use of org.apereo.cas.metadata.CasConfigurationMetadataRepository in project cas by apereo.

the class FindPropertiesCommand method find.

/**
 * Find.
 *
 * @param strict          the strict
 * @param propertyPattern the property pattern
 * @return the map
 */
public Map<String, ConfigurationMetadataProperty> find(final boolean strict, final Pattern propertyPattern) {
    val results = new HashMap<String, ConfigurationMetadataProperty>();
    val repository = new CasConfigurationMetadataRepository();
    val props = repository.getRepository().getAllProperties();
    props.forEach((k, v) -> {
        val matched = StreamSupport.stream(RelaxedPropertyNames.forCamelCase(k).spliterator(), false).map(Object::toString).anyMatch(name -> strict ? RegexUtils.matches(propertyPattern, name) : RegexUtils.find(propertyPattern, name));
        if (matched) {
            results.put(k, v);
        }
    });
    return results;
}
Also used : lombok.val(lombok.val) HashMap(java.util.HashMap) CasConfigurationMetadataRepository(org.apereo.cas.metadata.CasConfigurationMetadataRepository)

Example 3 with CasConfigurationMetadataRepository

use of org.apereo.cas.metadata.CasConfigurationMetadataRepository in project cas by apereo.

the class CasConfigurationMetadataServerEndpointTests method verifyOperation.

@Test
public void verifyOperation() {
    val repository = new CasConfigurationMetadataRepository();
    val endpoint = new CasConfigurationMetadataServerEndpoint(casProperties, repository);
    val result = endpoint.properties();
    assertNotNull(result);
    assertFalse(result.isEmpty());
    val results = endpoint.search("server.port");
    assertNotNull(results);
    assertFalse(results.isEmpty());
}
Also used : lombok.val(lombok.val) CasConfigurationMetadataRepository(org.apereo.cas.metadata.CasConfigurationMetadataRepository) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with CasConfigurationMetadataRepository

use of org.apereo.cas.metadata.CasConfigurationMetadataRepository in project cas by apereo.

the class ConfigurationMetadataSearchResultTests method verifyAction.

@Test
public void verifyAction() {
    val repository = new CasConfigurationMetadataRepository();
    val properties = repository.getRepository().getAllProperties();
    val prop = properties.get("server.port");
    assertNotNull(prop);
    val r = new ConfigurationMetadataSearchResult(prop, repository);
    assertEquals(prop.getDefaultValue(), r.getDefaultValue());
    assertEquals(prop.getId(), r.getId());
    assertEquals(prop.getName(), r.getName());
    assertEquals(prop.getType(), r.getType());
    assertEquals(prop.getShortDescription(), r.getShortDescription());
    assertEquals(prop.getDescription(), r.getDescription());
    assertEquals(prop.getDefaultValue(), r.getDefaultValue());
    assertNotNull(r.getGroup());
}
Also used : lombok.val(lombok.val) CasConfigurationMetadataRepository(org.apereo.cas.metadata.CasConfigurationMetadataRepository) Test(org.junit.jupiter.api.Test)

Example 5 with CasConfigurationMetadataRepository

use of org.apereo.cas.metadata.CasConfigurationMetadataRepository in project cas by apereo.

the class FindPropertiesCommand method find.

/**
 * Find.
 *
 * @param strict          the strict
 * @param propertyPattern the property pattern
 * @return the map
 */
public Map<String, ConfigurationMetadataProperty> find(final boolean strict, final Pattern propertyPattern) {
    final Map<String, ConfigurationMetadataProperty> results = new LinkedHashMap<>();
    final CasConfigurationMetadataRepository repository = new CasConfigurationMetadataRepository();
    final Map<String, ConfigurationMetadataProperty> props = repository.getRepository().getAllProperties();
    props.forEach((k, v) -> {
        final boolean matched = StreamSupport.stream(RelaxedNames.forCamelCase(k).spliterator(), false).map(Object::toString).anyMatch(name -> strict ? RegexUtils.matches(propertyPattern, name) : RegexUtils.find(propertyPattern, name));
        if (matched) {
            results.put(k, v);
        }
    });
    return results;
}
Also used : ConfigurationMetadataProperty(org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty) CasConfigurationMetadataRepository(org.apereo.cas.metadata.CasConfigurationMetadataRepository) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

CasConfigurationMetadataRepository (org.apereo.cas.metadata.CasConfigurationMetadataRepository)6 lombok.val (lombok.val)3 Slf4j (lombok.extern.slf4j.Slf4j)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Test (org.junit.jupiter.api.Test)2 ConfigurationMetadataProperty (org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty)2 CommandMarker (org.springframework.shell.core.CommandMarker)2 CliCommand (org.springframework.shell.core.annotation.CliCommand)2 Service (org.springframework.stereotype.Service)2 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ClassUtils (org.apache.commons.lang3.ClassUtils)1 EncryptionJwtSigningJwtCryptographyProperties (org.apereo.cas.configuration.model.core.util.EncryptionJwtSigningJwtCryptographyProperties)1 EncryptionRandomizedSigningJwtCryptographyProperties (org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties)1 EncodingUtils (org.apereo.cas.util.EncodingUtils)1 Base64RandomStringGenerator (org.apereo.cas.util.gen.Base64RandomStringGenerator)1 Unchecked (org.jooq.lambda.Unchecked)1 ConfigurationMetadataGroup (org.springframework.boot.configurationmetadata.ConfigurationMetadataGroup)1