Search in sources :

Example 56 with ApplicationContext

use of org.springframework.context.ApplicationContext in project cas by apereo.

the class ShibbolethAttributeResolverConfiguration method attributeRepository.

@Bean
public IPersonAttributeDao attributeRepository() {
    try {
        final PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
        final Map<String, Object> result = new HashMap<>();
        environment.getPropertySources().forEach(s -> {
            if (s instanceof EnumerablePropertySource<?>) {
                final EnumerablePropertySource<?> ps = (EnumerablePropertySource<?>) s;
                Arrays.asList(ps.getPropertyNames()).forEach(key -> result.put(key, ps.getProperty(key)));
            }
        });
        final Properties p = new Properties();
        p.putAll(result);
        cfg.setProperties(p);
        registerBeanIntoApplicationContext(cfg, "shibboleth.PropertySourcesPlaceholderConfigurer");
        final ApplicationContext tempApplicationContext = SpringSupport.newContext(getClass().getName(), casProperties.getShibAttributeResolver().getResources(), Collections.singletonList(cfg), Collections.emptyList(), Collections.emptyList(), this.applicationContext);
        final Collection<DataConnector> values = BeanFactoryUtils.beansOfTypeIncludingAncestors(tempApplicationContext, DataConnector.class).values();
        final Collection<DataConnector> connectors = new HashSet<>(values);
        final AttributeResolverImpl impl = new AttributeResolverImpl();
        impl.setId(getClass().getSimpleName());
        impl.setApplicationContext(tempApplicationContext);
        impl.setAttributeDefinitions(BeanFactoryUtils.beansOfTypeIncludingAncestors(tempApplicationContext, AttributeDefinition.class).values());
        impl.setDataConnectors(connectors);
        if (!impl.isInitialized()) {
            impl.initialize();
        }
        return new ShibbolethPersonAttributeDao(impl);
    } catch (final Exception e) {
        LOGGER.warn(e.getMessage(), e);
    }
    return Beans.newStubAttributeRepository(casProperties.getAuthn().getAttributeRepository());
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) HashMap(java.util.HashMap) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Properties(java.util.Properties) ApplicationContext(org.springframework.context.ApplicationContext) ShibbolethPersonAttributeDao(org.apereo.cas.persondir.support.ShibbolethPersonAttributeDao) AttributeResolverImpl(net.shibboleth.idp.attribute.resolver.impl.AttributeResolverImpl) DataConnector(net.shibboleth.idp.attribute.resolver.DataConnector) HashSet(java.util.HashSet) Bean(org.springframework.context.annotation.Bean)

Example 57 with ApplicationContext

use of org.springframework.context.ApplicationContext in project spring-security by spring-projects.

the class CorsConfigurer method configure.

@Override
public void configure(H http) throws Exception {
    ApplicationContext context = http.getSharedObject(ApplicationContext.class);
    CorsFilter corsFilter = getCorsFilter(context);
    if (corsFilter == null) {
        throw new IllegalStateException("Please configure either a " + CORS_FILTER_BEAN_NAME + " bean or a " + CORS_CONFIGURATION_SOURCE_BEAN_NAME + "bean.");
    }
    http.addFilter(corsFilter);
}
Also used : CorsFilter(org.springframework.web.filter.CorsFilter) ApplicationContext(org.springframework.context.ApplicationContext)

Example 58 with ApplicationContext

use of org.springframework.context.ApplicationContext in project spring-security by spring-projects.

the class SessionManagementConfigurer method registerDelegateApplicationListener.

private void registerDelegateApplicationListener(H http, ApplicationListener<?> delegate) {
    ApplicationContext context = http.getSharedObject(ApplicationContext.class);
    if (context == null) {
        return;
    }
    if (context.getBeansOfType(DelegatingApplicationListener.class).isEmpty()) {
        return;
    }
    DelegatingApplicationListener delegating = context.getBean(DelegatingApplicationListener.class);
    SmartApplicationListener smartListener = new GenericApplicationListenerAdapter(delegate);
    delegating.addListener(smartListener);
}
Also used : SmartApplicationListener(org.springframework.context.event.SmartApplicationListener) GenericApplicationListenerAdapter(org.springframework.context.event.GenericApplicationListenerAdapter) ApplicationContext(org.springframework.context.ApplicationContext) DelegatingApplicationListener(org.springframework.security.context.DelegatingApplicationListener)

Example 59 with ApplicationContext

use of org.springframework.context.ApplicationContext in project spring-boot by spring-projects.

the class RemoteUrlPropertyExtractorTests method validUrl.

@Test
public void validUrl() throws Exception {
    ApplicationContext context = doTest("http://localhost:8080");
    assertThat(context.getEnvironment().getProperty("remoteUrl")).isEqualTo("http://localhost:8080");
    assertThat(context.getEnvironment().getProperty("spring.thymeleaf.cache")).isNull();
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) Test(org.junit.Test)

Example 60 with ApplicationContext

use of org.springframework.context.ApplicationContext in project spring-boot by spring-projects.

the class MockRestServiceServerResetTestExecutionListener method afterTestMethod.

@Override
public void afterTestMethod(TestContext testContext) throws Exception {
    ApplicationContext applicationContext = testContext.getApplicationContext();
    String[] names = applicationContext.getBeanNamesForType(MockRestServiceServer.class, false, false);
    for (String name : names) {
        applicationContext.getBean(name, MockRestServiceServer.class).reset();
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) MockRestServiceServer(org.springframework.test.web.client.MockRestServiceServer)

Aggregations

ApplicationContext (org.springframework.context.ApplicationContext)578 Test (org.junit.Test)262 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)179 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)44 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)37 ConfigurableMessenger (org.springframework.scripting.ConfigurableMessenger)28 File (java.io.File)25 DataSource (javax.sql.DataSource)24 Messenger (org.springframework.scripting.Messenger)24 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)21 Refreshable (org.springframework.aop.target.dynamic.Refreshable)20 StubCloudConnectorTest (org.springframework.cloud.StubCloudConnectorTest)17 HashMap (java.util.HashMap)16 SchedulerException (org.quartz.SchedulerException)16 ArrayList (java.util.ArrayList)14 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)14 WebApplicationContext (org.springframework.web.context.WebApplicationContext)14 MovieMapper (com.mapper.MovieMapper)13 Map (java.util.Map)13 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)13