use of org.springframework.beans.factory.BeanDefinitionStoreException 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.BeanDefinitionStoreException in project grails-core by grails.
the class GrailsPlaceholderConfigurer method doProcessProperties.
@Override
protected void doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess, StringValueResolver valueResolver) {
BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver) {
@Override
protected void visitMap(Map<?, ?> mapVal) {
if (mapVal instanceof Config)
return;
super.visitMap(mapVal);
}
};
String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
for (String curName : beanNames) {
// to avoid failing on unresolvable placeholders in properties file locations.
if (!(curName.equals(this.beanName) && beanFactoryToProcess.equals(this.beanFactory))) {
BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(curName);
try {
visitor.visitBeanDefinition(bd);
} catch (Exception ex) {
throw new BeanDefinitionStoreException(bd.getResourceDescription(), curName, ex.getMessage(), ex);
}
}
}
// New in Spring 2.5: resolve placeholders in alias target names and aliases as well.
beanFactoryToProcess.resolveAliases(valueResolver);
// New in Spring 3.0: resolve placeholders in embedded values such as annotation attributes.
beanFactoryToProcess.addEmbeddedValueResolver(valueResolver);
}
use of org.springframework.beans.factory.BeanDefinitionStoreException in project spring-framework by spring-projects.
the class ContextLoaderTests method testFrameworkServletWithDefaultLocation.
@Test
public void testFrameworkServletWithDefaultLocation() throws Exception {
DispatcherServlet servlet = new DispatcherServlet();
servlet.setContextClass(XmlWebApplicationContext.class);
try {
servlet.init(new MockServletConfig(new MockServletContext(""), "test"));
fail("Should have thrown BeanDefinitionStoreException");
} catch (BeanDefinitionStoreException ex) {
// expected
assertTrue(ex.getCause() instanceof IOException);
assertTrue(ex.getCause().getMessage().contains("/WEB-INF/test-servlet.xml"));
}
}
use of org.springframework.beans.factory.BeanDefinitionStoreException in project spring-framework by spring-projects.
the class ViewResolverTests method testXmlViewResolverWithoutCache.
@Test
public void testXmlViewResolverWithoutCache() throws Exception {
StaticWebApplicationContext wac = new StaticWebApplicationContext() {
@Override
protected Resource getResourceByPath(String path) {
assertTrue("Correct default location", XmlViewResolver.DEFAULT_LOCATION.equals(path));
return super.getResourceByPath(path);
}
};
wac.setServletContext(new MockServletContext());
wac.refresh();
XmlViewResolver vr = new XmlViewResolver();
vr.setCache(false);
try {
vr.setApplicationContext(wac);
} catch (ApplicationContextException ex) {
fail("Should not have thrown ApplicationContextException: " + ex.getMessage());
}
try {
vr.resolveViewName("example1", Locale.getDefault());
fail("Should have thrown BeanDefinitionStoreException");
} catch (BeanDefinitionStoreException ex) {
// expected
}
}
use of org.springframework.beans.factory.BeanDefinitionStoreException in project spring-framework by spring-projects.
the class ViewResolverTests method testXmlViewResolverDefaultLocation.
@Test
public void testXmlViewResolverDefaultLocation() {
StaticWebApplicationContext wac = new StaticWebApplicationContext() {
@Override
protected Resource getResourceByPath(String path) {
assertTrue("Correct default location", XmlViewResolver.DEFAULT_LOCATION.equals(path));
return super.getResourceByPath(path);
}
};
wac.setServletContext(new MockServletContext());
wac.refresh();
XmlViewResolver vr = new XmlViewResolver();
try {
vr.setApplicationContext(wac);
vr.afterPropertiesSet();
fail("Should have thrown BeanDefinitionStoreException");
} catch (BeanDefinitionStoreException ex) {
// expected
}
}
Aggregations