use of org.springframework.beans.factory.config.BeanReference in project spring-framework by spring-projects.
the class AopNamespaceHandlerEventTests method testAspectEvent.
@Test
public void testAspectEvent() throws Exception {
this.reader.loadBeanDefinitions(CONTEXT);
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
assertEquals("Incorrect number of events fired", 5, componentDefinitions.length);
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
assertEquals("aop:config", compositeDef.getName());
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length);
AspectComponentDefinition acd = null;
for (int i = 0; i < nestedComponentDefs.length; i++) {
ComponentDefinition componentDefinition = nestedComponentDefs[i];
if (componentDefinition instanceof AspectComponentDefinition) {
acd = (AspectComponentDefinition) componentDefinition;
break;
}
}
assertNotNull("AspectComponentDefinition not found", acd);
BeanDefinition[] beanDefinitions = acd.getBeanDefinitions();
assertEquals(5, beanDefinitions.length);
BeanReference[] beanReferences = acd.getBeanReferences();
assertEquals(6, beanReferences.length);
Set<String> expectedReferences = new HashSet<>();
expectedReferences.add("pc");
expectedReferences.add("countingAdvice");
for (int i = 0; i < beanReferences.length; i++) {
BeanReference beanReference = beanReferences[i];
expectedReferences.remove(beanReference.getBeanName());
}
assertEquals("Incorrect references found", 0, expectedReferences.size());
for (int i = 1; i < componentDefinitions.length; i++) {
assertTrue(componentDefinitions[i] instanceof BeanComponentDefinition);
}
ComponentDefinition[] nestedComponentDefs2 = acd.getNestedComponents();
assertEquals("Inner PointcutComponentDefinition not found", 1, nestedComponentDefs2.length);
assertTrue(nestedComponentDefs2[0] instanceof PointcutComponentDefinition);
PointcutComponentDefinition pcd = (PointcutComponentDefinition) nestedComponentDefs2[0];
assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length);
}
use of org.springframework.beans.factory.config.BeanReference in project spring-framework by spring-projects.
the class AnnotationDrivenBeanDefinitionParser method extractBeanRefSubElements.
private ManagedList<BeanReference> extractBeanRefSubElements(Element parentElement, ParserContext parserContext) {
ManagedList<BeanReference> list = new ManagedList<>();
list.setSource(parserContext.extractSource(parentElement));
for (Element refElement : DomUtils.getChildElementsByTagName(parentElement, "ref")) {
BeanReference reference;
if (StringUtils.hasText("bean")) {
reference = new RuntimeBeanReference(refElement.getAttribute("bean"), false);
list.add(reference);
} else if (StringUtils.hasText("parent")) {
reference = new RuntimeBeanReference(refElement.getAttribute("parent"), true);
list.add(reference);
} else {
parserContext.getReaderContext().error("'bean' or 'parent' attribute is required for <ref> element", parserContext.extractSource(parentElement));
}
}
return list;
}
use of org.springframework.beans.factory.config.BeanReference in project spring-security-oauth by spring-projects.
the class ConfigUtils method findDefaultFilterChainBeanId.
@SuppressWarnings({ "unchecked" })
protected static String findDefaultFilterChainBeanId(ParserContext parserContext) {
BeanDefinition filterChainList = parserContext.getRegistry().getBeanDefinition(BeanIds.FILTER_CHAINS);
// Get the list of SecurityFilterChain beans
List<BeanReference> filterChains = (List<BeanReference>) filterChainList.getPropertyValues().getPropertyValue("sourceList").getValue();
return filterChains.get(filterChains.size() - 1).getBeanName();
}
use of org.springframework.beans.factory.config.BeanReference in project spring-security by spring-projects.
the class ClearCredentialsMethodInvokingFactoryBean method parse.
/**
* The aim of this method is to build the list of filters which have been defined by
* the namespace elements and attributes within the <http> configuration, along
* with any custom-filter's linked to user-defined filter beans.
* <p>
* By the end of this method, the default <tt>FilterChainProxy</tt> bean should have
* been registered and will have the map of filter chains defined, with the
* "universal" match pattern mapped to the list of beans which have been parsed here.
*/
@SuppressWarnings({ "unchecked" })
public BeanDefinition parse(Element element, ParserContext pc) {
CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), pc.extractSource(element));
pc.pushContainingComponent(compositeDef);
registerFilterChainProxyIfNecessary(pc, pc.extractSource(element));
// Obtain the filter chains and add the new chain to it
BeanDefinition listFactoryBean = pc.getRegistry().getBeanDefinition(BeanIds.FILTER_CHAINS);
List<BeanReference> filterChains = (List<BeanReference>) listFactoryBean.getPropertyValues().getPropertyValue("sourceList").getValue();
filterChains.add(createFilterChain(element, pc));
pc.popAndRegisterContainingComponent();
return null;
}
use of org.springframework.beans.factory.config.BeanReference in project spring-security by spring-projects.
the class ClearCredentialsMethodInvokingFactoryBean method createFilterChain.
/**
* Creates the {@code SecurityFilterChain} bean from an <http> element.
*/
private BeanReference createFilterChain(Element element, ParserContext pc) {
boolean secured = !OPT_SECURITY_NONE.equals(element.getAttribute(ATT_SECURED));
if (!secured) {
if (!StringUtils.hasText(element.getAttribute(ATT_PATH_PATTERN)) && !StringUtils.hasText(ATT_REQUEST_MATCHER_REF)) {
pc.getReaderContext().error("The '" + ATT_SECURED + "' attribute must be used in combination with" + " the '" + ATT_PATH_PATTERN + "' or '" + ATT_REQUEST_MATCHER_REF + "' attributes.", pc.extractSource(element));
}
for (int n = 0; n < element.getChildNodes().getLength(); n++) {
if (element.getChildNodes().item(n) instanceof Element) {
pc.getReaderContext().error("If you are using <http> to define an unsecured pattern, " + "it cannot contain child elements.", pc.extractSource(element));
}
}
return createSecurityFilterChainBean(element, pc, Collections.emptyList());
}
final BeanReference portMapper = createPortMapper(element, pc);
final BeanReference portResolver = createPortResolver(portMapper, pc);
ManagedList<BeanReference> authenticationProviders = new ManagedList<BeanReference>();
BeanReference authenticationManager = createAuthenticationManager(element, pc, authenticationProviders);
boolean forceAutoConfig = isDefaultHttpConfig(element);
HttpConfigurationBuilder httpBldr = new HttpConfigurationBuilder(element, forceAutoConfig, pc, portMapper, portResolver, authenticationManager);
AuthenticationConfigBuilder authBldr = new AuthenticationConfigBuilder(element, forceAutoConfig, pc, httpBldr.getSessionCreationPolicy(), httpBldr.getRequestCache(), authenticationManager, httpBldr.getSessionStrategy(), portMapper, portResolver, httpBldr.getCsrfLogoutHandler());
httpBldr.setLogoutHandlers(authBldr.getLogoutHandlers());
httpBldr.setEntryPoint(authBldr.getEntryPointBean());
httpBldr.setAccessDeniedHandler(authBldr.getAccessDeniedHandlerBean());
authenticationProviders.addAll(authBldr.getProviders());
List<OrderDecorator> unorderedFilterChain = new ArrayList<OrderDecorator>();
unorderedFilterChain.addAll(httpBldr.getFilters());
unorderedFilterChain.addAll(authBldr.getFilters());
unorderedFilterChain.addAll(buildCustomFilterList(element, pc));
Collections.sort(unorderedFilterChain, new OrderComparator());
checkFilterChainOrder(unorderedFilterChain, pc, pc.extractSource(element));
// The list of filter beans
List<BeanMetadataElement> filterChain = new ManagedList<BeanMetadataElement>();
for (OrderDecorator od : unorderedFilterChain) {
filterChain.add(od.bean);
}
return createSecurityFilterChainBean(element, pc, filterChain);
}
Aggregations