Search in sources :

Example 26 with RegisteredServiceJsonSerializer

use of org.apereo.cas.services.util.RegisteredServiceJsonSerializer in project cas by apereo.

the class OidcCustomScopeAttributeReleasePolicyTests method verifySerialization.

@Test
public void verifySerialization() {
    val policy = new OidcCustomScopeAttributeReleasePolicy("groups", CollectionUtils.wrap("groups"));
    val chain = new ChainingAttributeReleasePolicy();
    chain.addPolicy(policy);
    val service = getOidcRegisteredService();
    service.setAttributeReleasePolicy(chain);
    val serializer = new RegisteredServiceJsonSerializer();
    var json = serializer.toString(service);
    assertNotNull(json);
    assertNotNull(serializer.from(json));
}
Also used : lombok.val(lombok.val) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) ChainingAttributeReleasePolicy(org.apereo.cas.services.ChainingAttributeReleasePolicy) Test(org.junit.jupiter.api.Test)

Example 27 with RegisteredServiceJsonSerializer

use of org.apereo.cas.services.util.RegisteredServiceJsonSerializer in project cas by apereo.

the class OidcOpenIdScopeAttributeReleasePolicyTests method verifySerialization.

@Test
public void verifySerialization() {
    val policy = new OidcOpenIdScopeAttributeReleasePolicy();
    val chain = new ChainingAttributeReleasePolicy();
    chain.addPolicy(policy);
    val service = getOidcRegisteredService();
    service.setAttributeReleasePolicy(chain);
    val serializer = new RegisteredServiceJsonSerializer();
    val json = serializer.toString(service);
    assertNotNull(json);
    assertNotNull(serializer.from(json));
}
Also used : lombok.val(lombok.val) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) ChainingAttributeReleasePolicy(org.apereo.cas.services.ChainingAttributeReleasePolicy) Test(org.junit.jupiter.api.Test)

Example 28 with RegisteredServiceJsonSerializer

use of org.apereo.cas.services.util.RegisteredServiceJsonSerializer in project cas by apereo.

the class OidcAddressScopeAttributeReleasePolicyTests method verifySerialization.

@Test
public void verifySerialization() {
    val policy = new OidcAddressScopeAttributeReleasePolicy();
    val chain = new ChainingAttributeReleasePolicy();
    chain.addPolicy(policy);
    val service = getOidcRegisteredService();
    service.setAttributeReleasePolicy(chain);
    val serializer = new RegisteredServiceJsonSerializer();
    val json = serializer.toString(service);
    assertNotNull(json);
    assertNotNull(serializer.from(json));
}
Also used : lombok.val(lombok.val) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) ChainingAttributeReleasePolicy(org.apereo.cas.services.ChainingAttributeReleasePolicy) Test(org.junit.jupiter.api.Test)

Example 29 with RegisteredServiceJsonSerializer

use of org.apereo.cas.services.util.RegisteredServiceJsonSerializer in project cas by apereo.

the class GenerateYamlRegisteredServiceCommand method generate.

private static void generate(final File filePath, final File result) {
    try {
        val validator = new RegisteredServiceJsonSerializer();
        if (filePath.isFile() && filePath.exists() && filePath.canRead() && filePath.length() > 0) {
            val svc = validator.from(filePath);
            LOGGER.info("Service [{}] is valid at [{}].", svc.getName(), filePath.getCanonicalPath());
            val yaml = new RegisteredServiceYamlSerializer();
            try (val writer = new StringWriter()) {
                yaml.to(writer, svc);
                LOGGER.info(writer.toString());
                if (result != null) {
                    yaml.to(result, svc);
                    LOGGER.info("YAML service definition is saved at [{}].", result.getCanonicalPath());
                }
            }
        } else {
            LOGGER.warn("File [{}] is does not exist, is not readable or is empty", filePath.getCanonicalPath());
        }
    } catch (final Exception e) {
        LOGGER.error("Could not understand and validate [{}]: [{}]", filePath.getPath(), e.getMessage());
    } finally {
        LOGGER.info("-".repeat(SEP_LINE_LENGTH));
    }
}
Also used : lombok.val(lombok.val) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) StringWriter(java.io.StringWriter) RegisteredServiceYamlSerializer(org.apereo.cas.services.util.RegisteredServiceYamlSerializer)

Example 30 with RegisteredServiceJsonSerializer

use of org.apereo.cas.services.util.RegisteredServiceJsonSerializer in project cas by apereo.

the class ValidateRegisteredServiceCommand method validate.

private static void validate(final File filePath) {
    try {
        var validator = (RegisteredServiceJsonSerializer) null;
        if (filePath.isFile() && filePath.exists() && filePath.canRead() && filePath.length() > 0) {
            switch(FilenameUtils.getExtension(filePath.getPath()).toLowerCase()) {
                case "json":
                    validator = new RegisteredServiceJsonSerializer();
                    break;
                case "yml":
                case "yaml":
                    validator = new RegisteredServiceYamlSerializer();
                    break;
                default:
                    LOGGER.debug("Unknown file [{}]", filePath.getCanonicalPath());
                    break;
            }
            if (validator != null) {
                val svc = Objects.requireNonNull(validator).from(filePath);
                LOGGER.info("Service [{}] is valid at [{}].", svc.getName(), filePath.getCanonicalPath());
            }
        } else {
            LOGGER.warn("File [{}] is does not exist, is not readable or is empty", filePath.getCanonicalPath());
        }
    } catch (final Exception e) {
        LOGGER.error("Could not understand and validate [{}]: [{}]", filePath.getPath(), e.getMessage());
    } finally {
        LOGGER.info("-".repeat(SEP_LINE_LENGTH));
    }
}
Also used : lombok.val(lombok.val) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) RegisteredServiceYamlSerializer(org.apereo.cas.services.util.RegisteredServiceYamlSerializer)

Aggregations

lombok.val (lombok.val)31 RegisteredServiceJsonSerializer (org.apereo.cas.services.util.RegisteredServiceJsonSerializer)31 Test (org.junit.jupiter.api.Test)23 ClassPathResource (org.springframework.core.io.ClassPathResource)8 File (java.io.File)6 ChainingAttributeReleasePolicy (org.apereo.cas.services.ChainingAttributeReleasePolicy)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 RegisteredServiceYamlSerializer (org.apereo.cas.services.util.RegisteredServiceYamlSerializer)4 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 KafkaObjectFactory (org.apereo.cas.kafka.KafkaObjectFactory)2 RegisteredService (org.apereo.cas.services.RegisteredService)2 CasRegisteredServiceDeletedEvent (org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent)2 CasRegisteredServiceSavedEvent (org.apereo.cas.support.events.service.CasRegisteredServiceSavedEvent)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)2 Bean (org.springframework.context.annotation.Bean)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1