use of org.apereo.cas.services.InMemoryServiceRegistry in project cas by apereo.
the class SamlRegisteredServiceTests method checkPattern.
@Test
public void checkPattern() {
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val registeredService = new SamlRegisteredService();
registeredService.setName(SAML_SERVICE);
registeredService.setServiceId("^http://.+");
registeredService.setMetadataLocation(METADATA_LOCATION);
val dao = new InMemoryServiceRegistry(appCtx, List.of(registeredService), new ArrayList<>());
val context = ServicesManagerConfigurationContext.builder().serviceRegistry(dao).applicationContext(appCtx).environments(new HashSet<>(0)).servicesCache(Caffeine.newBuilder().build()).registeredServiceLocators(List.of(samlIdPServicesManagerRegisteredServiceLocator)).build();
val impl = new DefaultServicesManager(context);
impl.load();
val service = new WebApplicationServiceFactory().createService("http://mmoayyed.unicon.net:8081/sp/saml/SSO");
service.getAttributes().put(SamlProtocolConstants.PARAMETER_ENTITY_ID, List.of(registeredService.getServiceId()));
val foundService = impl.findServiceBy(service);
assertNotNull(foundService);
}
use of org.apereo.cas.services.InMemoryServiceRegistry in project cas by apereo.
the class DefaultRegisteredServiceReplicationStrategyTests method verifyGetInCacheAndRemove.
@Test
public void verifyGetInCacheAndRemove() {
val id = new PublisherIdentifier();
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val serviceRegistry = new InMemoryServiceRegistry(appCtx);
val stream = casProperties.getServiceRegistry().getStream();
val mgr = mock(DistributedCacheManager.class);
val strategy = new DefaultRegisteredServiceReplicationStrategy(mgr, stream, id);
val service = newService("Test");
val object = DistributedCacheObject.<RegisteredService>builder().value(service).publisherIdentifier(id).properties(Map.of("event", CasRegisteredServiceDeletedEvent.class.getSimpleName())).build();
when(mgr.find(any())).thenReturn(Optional.of(object));
val svc = strategy.getRegisteredServiceFromCacheIfAny(service, 1000, serviceRegistry);
assertNotNull(svc);
assertEquals(serviceRegistry.size(), 0);
}
use of org.apereo.cas.services.InMemoryServiceRegistry in project cas by apereo.
the class DefaultRegisteredServiceReplicationStrategyTests method verifyGetInCacheAndSave.
@Test
public void verifyGetInCacheAndSave() {
val id = new PublisherIdentifier();
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val serviceRegistry = new InMemoryServiceRegistry(appCtx);
val stream = casProperties.getServiceRegistry().getStream();
val mgr = mock(DistributedCacheManager.class);
val strategy = new DefaultRegisteredServiceReplicationStrategy(mgr, stream, id);
val service = newService("Test");
val object = DistributedCacheObject.<RegisteredService>builder().value(service).publisherIdentifier(id).build();
when(mgr.find(any())).thenReturn(Optional.of(object));
val svc = strategy.getRegisteredServiceFromCacheIfAny(null, 1000, serviceRegistry);
assertNotNull(svc);
assertEquals(serviceRegistry.size(), 1);
}
use of org.apereo.cas.services.InMemoryServiceRegistry in project cas by apereo.
the class DefaultRegisteredServiceReplicationStrategyTests method verifyUpdateWithMatch.
@Test
public void verifyUpdateWithMatch() {
val id = new PublisherIdentifier();
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val serviceRegistry = new InMemoryServiceRegistry(appCtx);
val stream = casProperties.getServiceRegistry().getStream();
val mgr = mock(DistributedCacheManager.class);
val service = newService("Test1");
val service2 = newService("Test2");
val obj1 = DistributedCacheObject.<RegisteredService>builder().value(service).publisherIdentifier(id).build();
val object = DistributedCacheObject.<RegisteredService>builder().value(service).publisherIdentifier(id).properties(Map.of("event", CasRegisteredServiceDeletedEvent.class.getSimpleName())).build();
when(mgr.getAll()).thenReturn(CollectionUtils.wrapList(obj1, object));
val strategy = new DefaultRegisteredServiceReplicationStrategy(mgr, stream, id);
val results = strategy.updateLoadedRegisteredServicesFromCache(CollectionUtils.wrapList(service, service2), serviceRegistry);
assertFalse(results.isEmpty());
}
use of org.apereo.cas.services.InMemoryServiceRegistry in project cas by apereo.
the class Saml10SuccessResponseViewTests method initialize.
@BeforeEach
public void initialize() {
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val list = new ArrayList<RegisteredService>();
list.add(RegisteredServiceTestUtils.getRegisteredService("https://.+"));
val dao = new InMemoryServiceRegistry(appCtx, list, new ArrayList<>());
val context = ServicesManagerConfigurationContext.builder().serviceRegistry(dao).applicationContext(appCtx).environments(new HashSet<>(0)).servicesCache(Caffeine.newBuilder().build()).registeredServiceLocators(List.of(new DefaultServicesManagerRegisteredServiceLocator())).build();
val mgmr = new DefaultServicesManager(context);
mgmr.load();
val protocolAttributeEncoder = new DefaultCasProtocolAttributeEncoder(mgmr, CipherExecutor.noOpOfStringToString());
val builder = new Saml10ObjectBuilder(configBean);
val samlResponseBuilder = new SamlResponseBuilder(builder, "testIssuer", "whatever", 1000, "PT30S", new NoOpProtocolAttributeEncoder(), mgmr);
this.response = new Saml10SuccessResponseView(protocolAttributeEncoder, mgmr, new DefaultArgumentExtractor(new SamlServiceFactory()), StandardCharsets.UTF_8.name(), new DefaultAuthenticationAttributeReleasePolicy("attribute"), new DefaultAuthenticationServiceSelectionPlan(), NoOpProtocolAttributesRenderer.INSTANCE, samlResponseBuilder);
}
Aggregations