Search in sources :

Example 1 with InMemoryServiceRegistry

use of org.apereo.cas.services.InMemoryServiceRegistry in project cas by apereo.

the class Saml10SuccessResponseViewTests method setUp.

@Before
public void setUp() {
    final List<RegisteredService> list = new ArrayList<>();
    list.add(RegisteredServiceTestUtils.getRegisteredService("https://.+"));
    final InMemoryServiceRegistry dao = new InMemoryServiceRegistry();
    dao.setRegisteredServices(list);
    final ServicesManager mgmr = new DefaultServicesManager(dao, mock(ApplicationEventPublisher.class));
    mgmr.load();
    this.response = new Saml10SuccessResponseView(new DefaultCasProtocolAttributeEncoder(mgmr, CipherExecutor.noOpOfStringToString()), mgmr, "attribute", new Saml10ObjectBuilder(configBean), new DefaultArgumentExtractor(new SamlServiceFactory()), StandardCharsets.UTF_8.name(), 1000, 30, "testIssuer", "whatever", new DefaultAuthenticationAttributeReleasePolicy());
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) SamlServiceFactory(org.apereo.cas.support.saml.authentication.principal.SamlServiceFactory) ArrayList(java.util.ArrayList) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) DefaultAuthenticationAttributeReleasePolicy(org.apereo.cas.authentication.DefaultAuthenticationAttributeReleasePolicy) ServicesManager(org.apereo.cas.services.ServicesManager) DefaultServicesManager(org.apereo.cas.services.DefaultServicesManager) DefaultArgumentExtractor(org.apereo.cas.web.support.DefaultArgumentExtractor) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) DefaultCasProtocolAttributeEncoder(org.apereo.cas.authentication.support.DefaultCasProtocolAttributeEncoder) DefaultServicesManager(org.apereo.cas.services.DefaultServicesManager) Saml10ObjectBuilder(org.apereo.cas.support.saml.util.Saml10ObjectBuilder) Before(org.junit.Before)

Example 2 with InMemoryServiceRegistry

use of org.apereo.cas.services.InMemoryServiceRegistry in project cas by apereo.

the class DefaultRegisteredServiceReplicationStrategyTests method verifyUpdateWithNoMatch.

@Test
public void verifyUpdateWithNoMatch() {
    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");
    service.setId(500);
    val cachedService = newService("Test2");
    val object = DistributedCacheObject.<RegisteredService>builder().value(cachedService).publisherIdentifier(id).build();
    when(mgr.getAll()).thenReturn(CollectionUtils.wrapList(object));
    val strategy = new DefaultRegisteredServiceReplicationStrategy(mgr, stream, id);
    val results = strategy.updateLoadedRegisteredServicesFromCache(CollectionUtils.wrapList(service), serviceRegistry);
    assertFalse(results.isEmpty());
    assertEquals(2, results.size());
}
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 3 with InMemoryServiceRegistry

use of org.apereo.cas.services.InMemoryServiceRegistry in project cas by apereo.

the class DefaultRegisteredServiceReplicationStrategyTests method verifyGetInCacheAndUpdate.

@Test
public void verifyGetInCacheAndUpdate() {
    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 service2 = newService("Test1");
    val object = DistributedCacheObject.<RegisteredService>builder().value(service2).publisherIdentifier(id).build();
    when(mgr.find(any())).thenReturn(Optional.of(object));
    var svc = strategy.getRegisteredServiceFromCacheIfAny(service, 1000, serviceRegistry);
    assertNotNull(svc);
    assertEquals(serviceRegistry.size(), 1);
    svc = serviceRegistry.findServiceById(1000);
    assertEquals("Test1", svc.getName());
}
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 4 with InMemoryServiceRegistry

use of org.apereo.cas.services.InMemoryServiceRegistry in project cas by apereo.

the class DefaultRegisteredServiceReplicationStrategyTests method verifySetInCache.

@Test
public void verifySetInCache() {
    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);
    when(mgr.find(any())).thenReturn(Optional.empty());
    var svc = strategy.getRegisteredServiceFromCacheIfAny(newService("Test"), 1000, serviceRegistry);
    assertNotNull(svc);
    svc = strategy.getRegisteredServiceFromCacheIfAny(newService("Test"), "https://example.org", serviceRegistry);
    assertNotNull(svc);
    strategy.destroy();
}
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 5 with InMemoryServiceRegistry

use of org.apereo.cas.services.InMemoryServiceRegistry in project cas by apereo.

the class DefaultRegisteredServiceReplicationStrategyTests method verifyGetInCacheAndMatch.

@Test
public void verifyGetInCacheAndMatch() {
    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 service2 = newService("Test");
    val object = DistributedCacheObject.<RegisteredService>builder().value(service2).publisherIdentifier(id).build();
    when(mgr.find(any())).thenReturn(Optional.of(object));
    var svc = strategy.getRegisteredServiceFromCacheIfAny(service, 1000, serviceRegistry);
    assertNotNull(svc);
    assertEquals(serviceRegistry.size(), 0);
}
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)

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