SEC-1352: Added support for placeholders in <user-service>

The username, password and authorities attributes can now be placeholders.
This commit is contained in:
Luke Taylor
2010-01-05 22:34:10 +00:00
parent f5d36aef65
commit dc5417f1d5
2 changed files with 50 additions and 21 deletions

View File

@@ -13,7 +13,6 @@ import org.junit.After;
/**
* @author Luke Taylor
* @version $Id$
*/
public class UserServiceBeanDefinitionParserTests {
private AbstractXmlApplicationContext appContext;
@@ -45,6 +44,22 @@ public class UserServiceBeanDefinitionParserTests {
userService.loadUserByUsername("joe");
}
@Test
public void namePasswordAndAuthoritiesSupportPlaceholders() {
System.setProperty("principal.name", "joe");
System.setProperty("principal.pass", "joespassword");
System.setProperty("principal.authorities", "ROLE_A,ROLE_B");
setContext(
"<b:bean class='org.springframework.beans.factory.config.PropertyPlaceholderConfigurer'/>" +
"<user-service id='service'>" +
" <user name='${principal.name}' password='${principal.pass}' authorities='${principal.authorities}'/>" +
"</user-service>");
UserDetailsService userService = (UserDetailsService) appContext.getBean("service");
UserDetails joe = userService.loadUserByUsername("joe");
assertEquals("joespassword", joe.getPassword());
assertEquals(2, joe.getAuthorities().size());
}
@Test
public void embeddedUsersWithNoPasswordIsGivenGeneratedValue() {
setContext(