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();
}
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);
}
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());
}
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());
}
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());
}
Aggregations