Search in sources :

Example 16 with InMemoryServiceRegistry

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);
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) DefaultServicesManager(org.apereo.cas.services.DefaultServicesManager) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 17 with InMemoryServiceRegistry

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);
}
Also used : lombok.val(lombok.val) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) CasRegisteredServiceDeletedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with InMemoryServiceRegistry

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);
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with InMemoryServiceRegistry

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());
}
Also used : lombok.val(lombok.val) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) CasRegisteredServiceDeletedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with InMemoryServiceRegistry

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);
}
Also used : lombok.val(lombok.val) DefaultServicesManagerRegisteredServiceLocator(org.apereo.cas.services.DefaultServicesManagerRegisteredServiceLocator) SamlServiceFactory(org.apereo.cas.support.saml.authentication.principal.SamlServiceFactory) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ArrayList(java.util.ArrayList) SamlResponseBuilder(org.apereo.cas.support.saml.authentication.SamlResponseBuilder) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) DefaultAuthenticationAttributeReleasePolicy(org.apereo.cas.authentication.DefaultAuthenticationAttributeReleasePolicy) DefaultArgumentExtractor(org.apereo.cas.web.support.DefaultArgumentExtractor) NoOpProtocolAttributeEncoder(org.apereo.cas.authentication.support.NoOpProtocolAttributeEncoder) DefaultCasProtocolAttributeEncoder(org.apereo.cas.authentication.support.DefaultCasProtocolAttributeEncoder) DefaultServicesManager(org.apereo.cas.services.DefaultServicesManager) Saml10ObjectBuilder(org.apereo.cas.support.saml.util.Saml10ObjectBuilder) HashSet(java.util.HashSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

InMemoryServiceRegistry (org.apereo.cas.services.InMemoryServiceRegistry)22 lombok.val (lombok.val)16 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)16 DefaultServicesManager (org.apereo.cas.services.DefaultServicesManager)14 HashSet (java.util.HashSet)9 DefaultServicesManagerRegisteredServiceLocator (org.apereo.cas.services.DefaultServicesManagerRegisteredServiceLocator)8 Test (org.junit.jupiter.api.Test)8 PublisherIdentifier (org.apereo.cas.util.PublisherIdentifier)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 RegisteredService (org.apereo.cas.services.RegisteredService)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)4 WebApplicationServiceFactory (org.apereo.cas.authentication.principal.WebApplicationServiceFactory)4 Before (org.junit.Before)4 ArrayList (java.util.ArrayList)3 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)3 DefaultArgumentExtractor (org.apereo.cas.web.support.DefaultArgumentExtractor)3 List (java.util.List)2 DefaultAuthenticationAttributeReleasePolicy (org.apereo.cas.authentication.DefaultAuthenticationAttributeReleasePolicy)2 DefaultAuthenticationEventExecutionPlan (org.apereo.cas.authentication.DefaultAuthenticationEventExecutionPlan)2