Search in sources :

Example 16 with RegisteredServiceJsonSerializer

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

the class DeleteResourceBasedRegisteredServiceWatcherTests method verifyTempFilesIgnored.

@Test
public void verifyTempFilesIgnored() throws Exception {
    val result = new AtomicBoolean(false);
    val mockAppContext = mock(ConfigurableApplicationContext.class);
    doAnswer(args -> {
        val clazz = args.getArgument(0).getClass();
        result.set(clazz.equals(CasRegisteredServiceDeletedEvent.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 DeleteResourceBasedRegisteredServiceWatcher(registry);
    watcher.accept(new File(".Sample-1.json"));
    assertFalse(result.get());
    watcher.accept(new File("Sample-1.json.swp"));
    assertFalse(result.get());
    assertEquals(1, registry.size());
}
Also used : lombok.val(lombok.val) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) CasRegisteredServiceDeletedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 17 with RegisteredServiceJsonSerializer

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

the class DeleteResourceBasedRegisteredServiceWatcherTests method verifyOperationNotFound.

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

        @Override
        protected String[] getExtensions() {
            return new String[] { "json" };
        }
    });
    watcher.accept(new File("removed.json"));
    assertTrue(result.get());
}
Also used : lombok.val(lombok.val) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) ArrayList(java.util.ArrayList) CasRegisteredServicesLoadedEvent(org.apereo.cas.support.events.service.CasRegisteredServicesLoadedEvent) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 18 with RegisteredServiceJsonSerializer

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

the class JsonServiceRegistryTests method verifyExistingDefinitionForCompatibility2.

@Test
public void verifyExistingDefinitionForCompatibility2() throws Exception {
    val resource = new ClassPathResource("returnMappedAttributeReleasePolicyTest2.json");
    val serializer = new RegisteredServiceJsonSerializer();
    val service = serializer.from(resource.getInputStream());
    assertNotNull(service);
    assertNotNull(service.getAttributeReleasePolicy());
    val policy = (ReturnMappedAttributeReleasePolicy) service.getAttributeReleasePolicy();
    assertNotNull(policy);
    assertEquals(2, policy.getAllowedAttributes().size());
}
Also used : lombok.val(lombok.val) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with RegisteredServiceJsonSerializer

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

the class JsonServiceRegistryTests method verifyExistingDefinitionForCompatibility1.

@Test
public void verifyExistingDefinitionForCompatibility1() throws Exception {
    val resource = new ClassPathResource("returnMappedAttributeReleasePolicyTest1.json");
    val serializer = new RegisteredServiceJsonSerializer();
    val service = serializer.from(resource.getInputStream());
    assertNotNull(service);
    assertNotNull(service.getAttributeReleasePolicy());
    val policy = (ReturnMappedAttributeReleasePolicy) service.getAttributeReleasePolicy();
    assertNotNull(policy);
    assertEquals(2, policy.getAllowedAttributes().size());
}
Also used : lombok.val(lombok.val) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with RegisteredServiceJsonSerializer

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

the class CasServicesStreamingKafkaConfiguration method registeredServiceKafkaListenerContainerFactory.

@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnMissingBean(name = "registeredServiceKafkaListenerContainerFactory")
public ConcurrentKafkaListenerContainerFactory<String, DistributedCacheObject> registeredServiceKafkaListenerContainerFactory(final CasConfigurationProperties casProperties) {
    val kafka = casProperties.getServiceRegistry().getStream().getKafka();
    val factory = new KafkaObjectFactory<String, DistributedCacheObject>(kafka.getBootstrapAddress());
    factory.setConsumerGroupId("registeredServices");
    val mapper = new RegisteredServiceJsonSerializer().getObjectMapper();
    return factory.getKafkaListenerContainerFactory(new StringDeserializer(), new JsonDeserializer<>(DistributedCacheObject.class, mapper));
}
Also used : lombok.val(lombok.val) KafkaObjectFactory(org.apereo.cas.kafka.KafkaObjectFactory) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) DistributedCacheObject(org.apereo.cas.util.cache.DistributedCacheObject) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) 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

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