use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-integration by spring-projects.
the class SecurityIntegrationConfigurationInitializer method initialize.
@Override
@SuppressWarnings("unchecked")
public void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException {
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
Map<String, ManagedSet<String>> securityInterceptors = new ManagedMap<String, ManagedSet<String>>();
Map<String, Map<Pattern, ChannelAccessPolicy>> policies = new HashMap<String, Map<Pattern, ChannelAccessPolicy>>();
for (String beanName : registry.getBeanDefinitionNames()) {
BeanDefinition beanDefinition = registry.getBeanDefinition(beanName);
if (ChannelSecurityInterceptor.class.getName().equals(beanDefinition.getBeanClassName())) {
BeanDefinition metadataSource = (BeanDefinition) beanDefinition.getConstructorArgumentValues().getIndexedArgumentValue(0, BeanDefinition.class).getValue();
Map<String, ?> value = (Map<String, ?>) metadataSource.getConstructorArgumentValues().getIndexedArgumentValue(0, Map.class).getValue();
ManagedSet<String> patterns = new ManagedSet<String>();
if (!securityInterceptors.containsKey(beanName)) {
securityInterceptors.put(beanName, patterns);
} else {
patterns = securityInterceptors.get(beanName);
}
patterns.addAll(value.keySet());
} else if (beanDefinition instanceof AnnotatedBeanDefinition) {
if (beanDefinition.getSource() instanceof MethodMetadata) {
MethodMetadata beanMethod = (MethodMetadata) beanDefinition.getSource();
String annotationType = SecuredChannel.class.getName();
if (beanMethod.isAnnotated(annotationType)) {
Map<String, Object> securedAttributes = beanMethod.getAnnotationAttributes(annotationType);
String[] interceptors = (String[]) securedAttributes.get("interceptor");
String[] sendAccess = (String[]) securedAttributes.get("sendAccess");
String[] receiveAccess = (String[]) securedAttributes.get("receiveAccess");
ChannelAccessPolicy accessPolicy = new DefaultChannelAccessPolicy(sendAccess, receiveAccess);
for (String interceptor : interceptors) {
ManagedSet<String> patterns = new ManagedSet<String>();
if (!securityInterceptors.containsKey(interceptor)) {
securityInterceptors.put(interceptor, patterns);
} else {
patterns = securityInterceptors.get(interceptor);
}
patterns.add(beanName);
Map<Pattern, ChannelAccessPolicy> mapping = new HashMap<Pattern, ChannelAccessPolicy>();
if (!policies.containsKey(interceptor)) {
policies.put(interceptor, mapping);
} else {
mapping = policies.get(interceptor);
}
mapping.put(Pattern.compile(beanName), accessPolicy);
}
}
}
}
}
if (!securityInterceptors.isEmpty()) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(ChannelSecurityInterceptorBeanPostProcessor.class).addConstructorArgValue(securityInterceptors);
if (!policies.isEmpty()) {
builder.addConstructorArgValue(policies);
}
registry.registerBeanDefinition(CHANNEL_SECURITY_INTERCEPTOR_BPP_BEAN_NAME, builder.getBeanDefinition());
}
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project camunda-bpm-platform by camunda.
the class StateHandlerAnnotationBeanFactoryPostProcessor method postProcessBeanFactory.
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
if (beanFactory instanceof BeanDefinitionRegistry) {
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
configureDefaultActivitiRegistry(ActivitiContextUtils.ACTIVITI_REGISTRY_BEAN_NAME, registry);
} else {
log.info("BeanFactory is not a BeanDefinitionRegistry. The default '" + ActivitiContextUtils.ACTIVITI_REGISTRY_BEAN_NAME + "' cannot be configured.");
}
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project camunda-bpm-platform by camunda.
the class ProcessScope method postProcessBeanFactory.
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
beanFactory.registerScope(ProcessScope.PROCESS_SCOPE_NAME, this);
Assert.isInstanceOf(BeanDefinitionRegistry.class, beanFactory, "BeanFactory was not a BeanDefinitionRegistry, so ProcessScope cannot be used.");
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
for (String beanName : beanFactory.getBeanDefinitionNames()) {
BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
// Replace this or any of its inner beans with scoped proxy if it has this scope
boolean scoped = PROCESS_SCOPE_NAME.equals(definition.getScope());
Scopifier scopifier = new Scopifier(registry, PROCESS_SCOPE_NAME, proxyTargetClass, scoped);
scopifier.visitBeanDefinition(definition);
if (scoped) {
Scopifier.createScopedProxy(beanName, definition, registry, proxyTargetClass);
}
}
beanFactory.registerSingleton(ProcessScope.PROCESS_SCOPE_PROCESS_VARIABLES_SINGLETON, this.processVariablesMap);
beanFactory.registerResolvableDependency(ProcessInstance.class, createSharedProcessInstance());
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project cuba by cuba-platform.
the class RemoteProxyBeanCreator method processSubstitutions.
protected void processSubstitutions(ConfigurableListableBeanFactory beanFactory) {
if (substitutions != null) {
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
for (Map.Entry<String, String> entry : substitutions.entrySet()) {
// replace bean with substitution bean
if (beanFactory.containsBean(entry.getKey())) {
String beanName = entry.getKey();
String beanClass = entry.getValue();
BeanDefinition definition = new RootBeanDefinition(beanClass);
MutablePropertyValues propertyValues = definition.getPropertyValues();
propertyValues.add("substitutedBean", beanFactory.getBean(beanName));
registry.registerBeanDefinition(beanName, definition);
}
}
}
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spock by spockframework.
the class SpringMockTestExecutionListener method beforeTestMethod.
@Override
public void beforeTestMethod(SpringTestContext testContext) throws Exception {
Object testInstance = testContext.getTestInstance();
if (!(testInstance instanceof Specification))
return;
Specification specification = (Specification) testInstance;
ScanScopedBeans scanScopedBeans = ReflectionUtil.getAnnotationRecursive(specification.getClass(), ScanScopedBeans.class);
Set<String> scopes = scanScopedBeans == null ? Collections.<String>emptySet() : new HashSet<>(Arrays.asList(scanScopedBeans.value()));
ApplicationContext applicationContext = testContext.getApplicationContext();
String[] mockBeanNames = applicationContext.getBeanDefinitionNames();
List<Object> mockedBeans = new ArrayList<>();
for (String beanName : mockBeanNames) {
BeanDefinition beanDefinition = ((BeanDefinitionRegistry) applicationContext).getBeanDefinition(beanName);
if (beanDefinition.isAbstract() || beanDefinition.isLazyInit()) {
continue;
}
if (beanDefinition.isSingleton() || scanScopedBean(scanScopedBeans, scopes, beanDefinition)) {
Object bean = applicationContext.getBean(beanName);
if (mockUtil.isMock(bean)) {
mockUtil.attachMock(bean, specification);
mockedBeans.add(bean);
}
}
}
testContext.setAttribute(MOCKED_BEANS_LIST, mockedBeans);
}
Aggregations