Search in sources :

Example 11 with RegisteredServiceJsonSerializer

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

the class CasServicesStreamingKafkaConfiguration method registeredServiceDistributedKafkaTemplate.

@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public KafkaOperations<String, DistributedCacheObject<RegisteredService>> registeredServiceDistributedKafkaTemplate(final ConfigurableApplicationContext applicationContext, final CasConfigurationProperties casProperties) {
    return BeanSupplier.of(KafkaOperations.class).when(CONDITION.given(applicationContext.getEnvironment())).supply(() -> {
        val kafka = casProperties.getServiceRegistry().getStream().getKafka();
        val mapper = new RegisteredServiceJsonSerializer().getObjectMapper();
        val factory = new KafkaObjectFactory<String, DistributedCacheObject<RegisteredService>>(kafka.getBootstrapAddress());
        return factory.getKafkaTemplate(new StringSerializer(), new JsonSerializer<>(mapper));
    }).otherwiseProxy().get();
}
Also used : lombok.val(lombok.val) KafkaObjectFactory(org.apereo.cas.kafka.KafkaObjectFactory) RegisteredService(org.apereo.cas.services.RegisteredService) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 12 with RegisteredServiceJsonSerializer

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

the class CasServicesStreamingKafkaConfigurationTests method verifySerialization.

@Test
public void verifySerialization() throws Exception {
    val o = DistributedCacheObject.<RegisteredService>builder().value(RegisteredServiceTestUtils.getRegisteredService()).publisherIdentifier(new PublisherIdentifier()).build();
    val file = new File(FileUtils.getTempDirectoryPath(), UUID.randomUUID().toString() + ".json");
    val mapper = new RegisteredServiceJsonSerializer().getObjectMapper();
    mapper.writeValue(file, o);
    val readPolicy = mapper.readValue(file, DistributedCacheObject.class);
    assertEquals(o, readPolicy);
}
Also used : lombok.val(lombok.val) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) File(java.io.File) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with RegisteredServiceJsonSerializer

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

the class SamlRegisteredServiceTests method verifySignAssertionTrueWithDeserialization.

@Test
public void verifySignAssertionTrueWithDeserialization() {
    val json = "{\n" + "  \"@class\" : \"org.apereo.cas.support.saml.services.SamlRegisteredService\",\n" + "  \"serviceId\" : \"the-entity\",\n" + "  \"name\" : \"SAMLService\",\n" + "  \"id\" : 10000003,\n" + "  \"evaluationOrder\" : 10,\n" + "  \"signAssertions\" : true,\n" + "  \"metadataLocation\" : \"https://url/to/metadata.xml\"\n" + '}';
    val serializer = new RegisteredServiceJsonSerializer();
    val service = (SamlRegisteredService) serializer.from(json);
    assertNotNull(service);
    assertTrue(service.getSignAssertions().isTrue());
}
Also used : lombok.val(lombok.val) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) Test(org.junit.jupiter.api.Test)

Example 14 with RegisteredServiceJsonSerializer

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

the class CreateResourceBasedRegisteredServiceWatcherTests method verifyOperationFoundCreated.

@Test
public void verifyOperationFoundCreated() throws Exception {
    val result = new AtomicBoolean(false);
    val mockAppContext = mock(ConfigurableApplicationContext.class);
    doAnswer(args -> {
        val clazz = args.getArgument(0).getClass();
        result.set(clazz.equals(CasRegisteredServiceSavedEvent.class));
        return null;
    }).when(mockAppContext).publishEvent(any());
    val registry = new AbstractResourceBasedServiceRegistry(new ClassPathResource("services"), List.of(new RegisteredServiceJsonSerializer()), mockAppContext, new ArrayList<>()) {

        @Override
        protected String[] getExtensions() {
            return new String[] { "json" };
        }
    };
    var results = registry.load();
    assertFalse(results.isEmpty());
    val watcher = new CreateResourceBasedRegisteredServiceWatcher(registry);
    watcher.accept(new File(registry.getServiceRegistryDirectory().toFile(), "Sample-1.json"));
    assertTrue(result.get());
    assertEquals(1, registry.size());
}
Also used : lombok.val(lombok.val) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CasRegisteredServiceSavedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceSavedEvent) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 15 with RegisteredServiceJsonSerializer

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

the class ModifyResourceBasedRegisteredServiceWatcherTests method verifyOperationFoundModified.

@Test
public void verifyOperationFoundModified() throws Exception {
    val result = new AtomicBoolean(false);
    val mockAppContext = mock(ConfigurableApplicationContext.class);
    doAnswer(args -> {
        val clazz = args.getArgument(0).getClass();
        result.set(clazz.equals(CasRegisteredServiceSavedEvent.class));
        return null;
    }).when(mockAppContext).publishEvent(any());
    val registry = new AbstractResourceBasedServiceRegistry(new ClassPathResource("services"), List.of(new RegisteredServiceJsonSerializer()), mockAppContext, new ArrayList<>()) {

        @Override
        protected String[] getExtensions() {
            return new String[] { "json" };
        }
    };
    var results = registry.load();
    assertFalse(results.isEmpty());
    val service = registry.findServiceById(1);
    service.setEvaluationOrder(666);
    registry.load();
    val temp = new FileSystemResource(File.createTempFile("Sample-1", ".json"));
    new RegisteredServiceJsonSerializer().to(temp.getFile(), service);
    val watcher = new ModifyResourceBasedRegisteredServiceWatcher(registry);
    watcher.accept(temp.getFile());
    assertTrue(result.get());
    assertEquals(1, registry.size());
    registry.removeRegisteredService(service);
    assertEquals(0, registry.size());
}
Also used : lombok.val(lombok.val) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CasRegisteredServiceSavedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceSavedEvent) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) FileSystemResource(org.springframework.core.io.FileSystemResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

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