use of org.springframework.context.support.StaticApplicationContext 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);
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class RestResourceUtilsTests method verifyCreateResponseEntityForAuthnFailure.
@Test
public void verifyCreateResponseEntityForAuthnFailure() {
val request = new MockHttpServletRequest();
val map = CollectionUtils.<String, Throwable>wrap(UnauthorizedAuthenticationException.class.getSimpleName(), new UnauthorizedAuthenticationException("test"));
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
val response = RestResourceUtils.createResponseEntityForAuthnFailure(new AuthenticationException("test", map, new HashMap<>(0)), request, applicationContext);
assertTrue(response.getStatusCode().isError());
assertNotNull(response.getBody());
assertFalse(response.getBody().contains(UnauthorizedAuthenticationException.class.getSimpleName()));
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class ChainingSingleLogoutServiceLogoutUrlBuilderTests method beforeEach.
@BeforeEach
public void beforeEach() {
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val context = ServicesManagerConfigurationContext.builder().serviceRegistry(new InMemoryServiceRegistry(appCtx)).applicationContext(appCtx).environments(new HashSet<>(0)).servicesCache(Caffeine.newBuilder().build()).registeredServiceLocators(List.of(new DefaultServicesManagerRegisteredServiceLocator())).build();
this.servicesManager = new DefaultServicesManager(context);
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class DefaultCentralAuthenticationServiceMockitoTests method prepareNewCAS.
@BeforeEach
public void prepareNewCAS() {
this.authentication = mock(Authentication.class);
when(this.authentication.getAuthenticationDate()).thenReturn(ZonedDateTime.now(ZoneOffset.UTC));
val metadata = new BasicCredentialMetaData(RegisteredServiceTestUtils.getCredentialsWithSameUsernameAndPassword("principal"));
val successes = new HashMap<String, AuthenticationHandlerExecutionResult>();
successes.put("handler1", new DefaultAuthenticationHandlerExecutionResult(mock(AuthenticationHandler.class), metadata));
when(this.authentication.getCredentials()).thenReturn(List.of(metadata));
when(this.authentication.getSuccesses()).thenReturn(successes);
when(this.authentication.getPrincipal()).thenReturn(PrincipalFactoryUtils.newPrincipalFactory().createPrincipal(PRINCIPAL));
val tgtRootMock = createRootTicketGrantingTicket();
val service1 = getService(SVC1_ID);
val stMock = createMockServiceTicket(ST_ID, service1);
val tgtMock = createMockTicketGrantingTicket(TGT_ID, stMock, false, tgtRootMock, new ArrayList<>());
when(tgtMock.getProxiedBy()).thenReturn(getService("proxiedBy"));
stMock.setTicketGrantingTicket(tgtMock);
val authnListMock = mock(List.class);
/*
* Size is required to be 2, so that
* we can simulate proxying capabilities
*/
when(authnListMock.size()).thenReturn(2);
when(authnListMock.toArray()).thenReturn(new Object[] { this.authentication, this.authentication });
when(authnListMock.get(anyInt())).thenReturn(this.authentication);
when(tgtMock.getChainedAuthentications()).thenReturn(authnListMock);
val service2 = getService(SVC2_ID);
val stMock2 = createMockServiceTicket(ST2_ID, service2);
val tgtMock2 = createMockTicketGrantingTicket(TGT2_ID, stMock2, false, tgtRootMock, authnListMock);
stMock2.setTicketGrantingTicket(tgtMock2);
mockTicketRegistry(stMock, tgtMock, stMock2, tgtMock2);
val smMock = getServicesManager(service1, service2);
val factory = getTicketFactory();
val authenticationRequestServiceSelectionStrategies = new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy());
val enforcer = mock(AuditableExecution.class);
when(enforcer.execute(any())).thenReturn(new AuditableExecutionResult());
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
val context = CentralAuthenticationServiceContext.builder().applicationContext(applicationContext).ticketRegistry(ticketRegMock).servicesManager(smMock).ticketFactory(factory).lockRepository(LockRepository.asDefault()).authenticationServiceSelectionPlan(authenticationRequestServiceSelectionStrategies).authenticationPolicyFactory(new AcceptAnyAuthenticationPolicyFactory()).principalFactory(PrincipalFactoryUtils.newPrincipalFactory()).cipherExecutor(CipherExecutor.noOpOfStringToString()).registeredServiceAccessStrategyEnforcer(enforcer).serviceMatchingStrategy(new DefaultServiceMatchingStrategy(smMock)).build();
this.cas = new DefaultCentralAuthenticationService(context);
}
use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class LdapUtilsTests method verifyScriptedFilter.
@Test
public void verifyScriptedFilter() {
val appCtx = new StaticApplicationContext();
appCtx.refresh();
ApplicationContextProvider.holdApplicationContext(appCtx);
assertThrows(RuntimeException.class, () -> LdapUtils.newLdaptiveSearchFilter("classpath:LdapFilterQuery.groovy", List.of("p1", "p2"), List.of("v1", "v2")));
val cacheMgr = new GroovyScriptResourceCacheManager();
ApplicationContextProvider.registerBeanIntoApplicationContext(appCtx, cacheMgr, ScriptResourceCacheManager.BEAN_NAME);
var filter = LdapUtils.newLdaptiveSearchFilter("classpath:LdapFilterQuery.groovy", List.of("p1", "p2"), List.of("v1", "v2"));
assertNotNull(filter);
assertNotNull(filter.getFilter());
filter = LdapUtils.newLdaptiveSearchFilter("classpath:LdapFilterQuery.groovy", List.of("p1", "p2"), List.of("v1", "v2"));
assertNotNull(filter);
assertNotNull(filter.getFilter());
filter = LdapUtils.newLdaptiveSearchFilter("classpath:UnknownLdapFilterQuery.groovy", List.of("p1", "p2"), List.of("v1", "v2"));
assertNotNull(filter);
}
Aggregations