use of org.springframework.beans.factory.support.ManagedList in project spring-security by spring-projects.
the class FilterChainBeanDefinitionParser method parse.
public BeanDefinition parse(Element elt, ParserContext pc) {
MatcherType matcherType = MatcherType.fromElement(elt);
String path = elt.getAttribute(HttpSecurityBeanDefinitionParser.ATT_PATH_PATTERN);
String requestMatcher = elt.getAttribute(ATT_REQUEST_MATCHER_REF);
String filters = elt.getAttribute(HttpSecurityBeanDefinitionParser.ATT_FILTERS);
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(DefaultSecurityFilterChain.class);
if (StringUtils.hasText(path)) {
Assert.isTrue(!StringUtils.hasText(requestMatcher), "");
builder.addConstructorArgValue(matcherType.createMatcher(pc, path, null));
} else {
Assert.isTrue(StringUtils.hasText(requestMatcher), "");
builder.addConstructorArgReference(requestMatcher);
}
if (filters.equals(HttpSecurityBeanDefinitionParser.OPT_FILTERS_NONE)) {
builder.addConstructorArgValue(Collections.EMPTY_LIST);
} else {
String[] filterBeanNames = StringUtils.tokenizeToStringArray(filters, ",");
ManagedList<RuntimeBeanReference> filterChain = new ManagedList<RuntimeBeanReference>(filterBeanNames.length);
for (String name : filterBeanNames) {
filterChain.add(new RuntimeBeanReference(name));
}
builder.addConstructorArgValue(filterChain);
}
return builder.getBeanDefinition();
}
use of org.springframework.beans.factory.support.ManagedList in project spring-security by spring-projects.
the class FilterChainMapBeanDefinitionDecorator method decorate.
@SuppressWarnings("unchecked")
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder holder, ParserContext parserContext) {
BeanDefinition filterChainProxy = holder.getBeanDefinition();
ManagedList<BeanMetadataElement> securityFilterChains = new ManagedList<BeanMetadataElement>();
Element elt = (Element) node;
MatcherType matcherType = MatcherType.fromElement(elt);
List<Element> filterChainElts = DomUtils.getChildElementsByTagName(elt, Elements.FILTER_CHAIN);
for (Element chain : filterChainElts) {
String path = chain.getAttribute(HttpSecurityBeanDefinitionParser.ATT_PATH_PATTERN);
String filters = chain.getAttribute(HttpSecurityBeanDefinitionParser.ATT_FILTERS);
if (!StringUtils.hasText(path)) {
parserContext.getReaderContext().error("The attribute '" + HttpSecurityBeanDefinitionParser.ATT_PATH_PATTERN + "' must not be empty", elt);
}
if (!StringUtils.hasText(filters)) {
parserContext.getReaderContext().error("The attribute '" + HttpSecurityBeanDefinitionParser.ATT_FILTERS + "'must not be empty", elt);
}
BeanDefinition matcher = matcherType.createMatcher(parserContext, path, null);
if (filters.equals(HttpSecurityBeanDefinitionParser.OPT_FILTERS_NONE)) {
securityFilterChains.add(createSecurityFilterChain(matcher, new ManagedList(0)));
} else {
String[] filterBeanNames = StringUtils.tokenizeToStringArray(filters, ",");
ManagedList filterChain = new ManagedList(filterBeanNames.length);
for (String name : filterBeanNames) {
filterChain.add(new RuntimeBeanReference(name));
}
securityFilterChains.add(createSecurityFilterChain(matcher, filterChain));
}
}
filterChainProxy.getConstructorArgumentValues().addGenericArgumentValue(securityFilterChains);
return holder;
}
use of org.springframework.beans.factory.support.ManagedList in project spring-security by spring-projects.
the class AuthenticationConfigBuilder method getLogoutHandlers.
@SuppressWarnings({ "rawtypes", "unchecked" })
ManagedList getLogoutHandlers() {
if (logoutHandlers == null && rememberMeProviderRef != null) {
logoutHandlers = new ManagedList();
if (csrfLogoutHandler != null) {
logoutHandlers.add(csrfLogoutHandler);
}
logoutHandlers.add(new RuntimeBeanReference(rememberMeServicesId));
logoutHandlers.add(new RootBeanDefinition(SecurityContextLogoutHandler.class));
}
return logoutHandlers;
}
use of org.springframework.beans.factory.support.ManagedList in project spring-security by spring-projects.
the class UserServiceBeanDefinitionParser method doParse.
@SuppressWarnings("unchecked")
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
String userProperties = element.getAttribute(ATT_PROPERTIES);
List<Element> userElts = DomUtils.getChildElementsByTagName(element, ELT_USER);
if (StringUtils.hasText(userProperties)) {
if (!CollectionUtils.isEmpty(userElts)) {
throw new BeanDefinitionStoreException("Use of a properties file and user elements are mutually exclusive");
}
BeanDefinition bd = new RootBeanDefinition(PropertiesFactoryBean.class);
bd.getPropertyValues().addPropertyValue("location", userProperties);
builder.addConstructorArgValue(bd);
return;
}
if (CollectionUtils.isEmpty(userElts)) {
throw new BeanDefinitionStoreException("You must supply user definitions, either with <" + ELT_USER + "> child elements or a " + "properties file (using the '" + ATT_PROPERTIES + "' attribute)");
}
ManagedList<BeanDefinition> users = new ManagedList<BeanDefinition>();
for (Object elt : userElts) {
Element userElt = (Element) elt;
String userName = userElt.getAttribute(ATT_NAME);
String password = userElt.getAttribute(ATT_PASSWORD);
if (!StringUtils.hasLength(password)) {
password = generateRandomPassword();
}
boolean locked = "true".equals(userElt.getAttribute(ATT_LOCKED));
boolean disabled = "true".equals(userElt.getAttribute(ATT_DISABLED));
BeanDefinitionBuilder authorities = BeanDefinitionBuilder.rootBeanDefinition(AuthorityUtils.class);
authorities.addConstructorArgValue(userElt.getAttribute(ATT_AUTHORITIES));
authorities.setFactoryMethod("commaSeparatedStringToAuthorityList");
BeanDefinitionBuilder user = BeanDefinitionBuilder.rootBeanDefinition(User.class);
user.addConstructorArgValue(userName);
user.addConstructorArgValue(password);
user.addConstructorArgValue(!disabled);
user.addConstructorArgValue(true);
user.addConstructorArgValue(true);
user.addConstructorArgValue(!locked);
user.addConstructorArgValue(authorities.getBeanDefinition());
users.add(user.getBeanDefinition());
}
builder.addConstructorArgValue(users);
}
use of org.springframework.beans.factory.support.ManagedList in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testPrototypeWithArrayConversionForConstructor.
@Test
public void testPrototypeWithArrayConversionForConstructor() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
List<String> list = new ManagedList<>();
list.add("myName");
list.add("myBeanName");
RootBeanDefinition bd = new RootBeanDefinition(DerivedTestBean.class);
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
bd.getConstructorArgumentValues().addGenericArgumentValue(list);
lbf.registerBeanDefinition("test", bd);
DerivedTestBean tb = (DerivedTestBean) lbf.getBean("test");
assertEquals("myName", tb.getName());
assertEquals("myBeanName", tb.getBeanName());
DerivedTestBean tb2 = (DerivedTestBean) lbf.getBean("test");
assertTrue(tb != tb2);
assertEquals("myName", tb2.getName());
assertEquals("myBeanName", tb2.getBeanName());
}
Aggregations