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());
}
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);
}
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);
}
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();
}
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();
}
}
Aggregations