Search in sources :

Example 61 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class SamlRegisteredServiceTests method verifySavingInCommonSamlService.

@Test
public void verifySavingInCommonSamlService() throws Exception {
    val appCtx = new StaticApplicationContext();
    appCtx.refresh();
    val service = new SamlRegisteredService();
    service.setName(SAML_SERVICE);
    service.setServiceId("http://mmoayyed.unicon.net");
    service.setMetadataLocation(METADATA_LOCATION);
    val policy = new InCommonRSAttributeReleasePolicy();
    val chain = new ChainingAttributeReleasePolicy();
    chain.setPolicies(Arrays.asList(policy, new DenyAllAttributeReleasePolicy()));
    service.setAttributeReleasePolicy(chain);
    val dao = new JsonServiceRegistry(new FileSystemResource(FileUtils.getTempDirectoryPath() + File.separator + "json-service-registry"), WatcherService.noOp(), appCtx, new NoOpRegisteredServiceReplicationStrategy(), new DefaultRegisteredServiceResourceNamingStrategy(), new ArrayList<>());
    dao.save(service);
    dao.load();
}
Also used : lombok.val(lombok.val) DenyAllAttributeReleasePolicy(org.apereo.cas.services.DenyAllAttributeReleasePolicy) DefaultRegisteredServiceResourceNamingStrategy(org.apereo.cas.services.resource.DefaultRegisteredServiceResourceNamingStrategy) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ChainingAttributeReleasePolicy(org.apereo.cas.services.ChainingAttributeReleasePolicy) FileSystemResource(org.springframework.core.io.FileSystemResource) JsonServiceRegistry(org.apereo.cas.services.JsonServiceRegistry) NoOpRegisteredServiceReplicationStrategy(org.apereo.cas.services.replication.NoOpRegisteredServiceReplicationStrategy) Test(org.junit.jupiter.api.Test)

Example 62 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class SamlRegisteredServiceAttributeReleasePolicyTests method verifyBadServiceProvider.

@Test
public void verifyBadServiceProvider() {
    val resolver = mock(SamlRegisteredServiceCachingMetadataResolver.class);
    when(resolver.resolve(any(), any())).thenReturn(mock(MetadataResolver.class));
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, new CasConfigurationProperties(), "CasConfigurationProperties");
    ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, resolver, SamlRegisteredServiceCachingMetadataResolver.DEFAULT_BEAN_NAME);
    ApplicationContextProvider.holdApplicationContext(applicationContext);
    val registeredService = SamlIdPTestUtils.getSamlRegisteredService();
    registeredService.setServiceId("https://sp.cas.org");
    val policy = new EduPersonTargetedIdAttributeReleasePolicy();
    val releasePolicyContext = RegisteredServiceAttributeReleasePolicyContext.builder().registeredService(registeredService).service(CoreAuthenticationTestUtils.getService("https://sp.cas.org")).principal(CoreAuthenticationTestUtils.getPrincipal("casuser")).build();
    val attributes = policy.getAttributes(releasePolicyContext);
    assertTrue(attributes.isEmpty());
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) SamlRegisteredServiceCachingMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) Test(org.junit.jupiter.api.Test)

Example 63 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class YubiKeyAccountSaveRegistrationActionTests method setup.

@BeforeEach
public void setup() {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    ApplicationContextProvider.holdApplicationContext(applicationContext);
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, new YubiKeyMultifactorAuthenticationProvider());
    ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
}
Also used : lombok.val(lombok.val) YubiKeyMultifactorAuthenticationProvider(org.apereo.cas.adaptors.yubikey.YubiKeyMultifactorAuthenticationProvider) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 64 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class ApplicationContextProviderTests method verifyOperation.

@Test
public void verifyOperation() {
    val appCtx = new StaticApplicationContext();
    appCtx.refresh();
    val container = BeanContainer.of("Hello", "World");
    appCtx.registerBean("beanContainer", BeanContainer.class);
    appCtx.getBeanFactory().initializeBean(container, "beanContainer");
    appCtx.getBeanFactory().autowireBean(container);
    appCtx.getBeanFactory().registerSingleton("beanContainer", container);
    ApplicationContextProvider.holdApplicationContext(appCtx);
    assertDoesNotThrow(new Executable() {

        @Override
        public void execute() {
            val holding = new HoldingBeanContainer();
            ApplicationContextProvider.processBeanInjections(holding);
            assertNotNull(holding.getContainer());
            assertEquals(2, holding.getContainer().size());
        }
    });
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 65 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class DelegatingControllerTests method verifyFails.

@Test
public void verifyFails() throws Exception {
    val request = new MockHttpServletRequest();
    request.setMethod("POST");
    val response = new MockHttpServletResponse();
    val ctrl = new DelegatingController();
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    ctrl.setApplicationContext(applicationContext);
    val mv = ctrl.handleRequest(request, response);
    assertNotNull(mv);
    assertEquals(ctrl.getFailureView(), mv.getViewName());
}
Also used : lombok.val(lombok.val) DelegatingController(org.apereo.cas.web.DelegatingController) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)322 Test (org.junit.jupiter.api.Test)218 lombok.val (lombok.val)159 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)59 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)39 BeforeEach (org.junit.jupiter.api.BeforeEach)36 Test (org.junit.Test)34 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)31 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)25 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)20 HashSet (java.util.HashSet)19 MockRequestContext (org.springframework.webflow.test.MockRequestContext)19 InMemoryServiceRegistry (org.apereo.cas.services.InMemoryServiceRegistry)16 MockServletContext (org.springframework.mock.web.MockServletContext)16 MultifactorAuthenticationProviderBypassProperties (org.apereo.cas.configuration.model.support.mfa.MultifactorAuthenticationProviderBypassProperties)15 BeanDefinitionReader (org.springframework.beans.factory.support.BeanDefinitionReader)13 ApplicationContext (org.springframework.context.ApplicationContext)12 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 QueueChannel (org.springframework.integration.channel.QueueChannel)11