mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-08 11:32:47 +00:00
SEC-1463: Change namespace user-service parser to store username in lower-case when building map for in-memory UserDetailsService. Lookups are supposed to be case-insensitive with this class.
This commit is contained in:
parent
e6e168f127
commit
8c605516b3
@ -24,6 +24,7 @@ import org.w3c.dom.Element;
|
|||||||
* @author Luke Taylor
|
* @author Luke Taylor
|
||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class UserServiceBeanDefinitionParser extends AbstractUserDetailsServiceBeanDefinitionParser {
|
public class UserServiceBeanDefinitionParser extends AbstractUserDetailsServiceBeanDefinitionParser {
|
||||||
|
|
||||||
static final String ATT_PASSWORD = "password";
|
static final String ATT_PASSWORD = "password";
|
||||||
@ -90,7 +91,7 @@ public class UserServiceBeanDefinitionParser extends AbstractUserDetailsServiceB
|
|||||||
user.addConstructorArgValue(!locked);
|
user.addConstructorArgValue(!locked);
|
||||||
user.addConstructorArgValue(authorities.getBeanDefinition());
|
user.addConstructorArgValue(authorities.getBeanDefinition());
|
||||||
|
|
||||||
users.put(userName, user.getBeanDefinition());
|
users.put(userName.toLowerCase(), user.getBeanDefinition());
|
||||||
}
|
}
|
||||||
|
|
||||||
userMap.getPropertyValues().addPropertyValue("users", users);
|
userMap.getPropertyValues().addPropertyValue("users", users);
|
||||||
|
@ -77,12 +77,12 @@ public class UserServiceBeanDefinitionParserTests {
|
|||||||
setContext(
|
setContext(
|
||||||
"<user-service id='service'>" +
|
"<user-service id='service'>" +
|
||||||
" <user name='joe' password='joespassword' authorities='ROLE_A' locked='true'/>" +
|
" <user name='joe' password='joespassword' authorities='ROLE_A' locked='true'/>" +
|
||||||
" <user name='bob' password='bobspassword' authorities='ROLE_A' disabled='true'/>" +
|
" <user name='Bob' password='bobspassword' authorities='ROLE_A' disabled='true'/>" +
|
||||||
"</user-service>");
|
"</user-service>");
|
||||||
UserDetailsService userService = (UserDetailsService) appContext.getBean("service");
|
UserDetailsService userService = (UserDetailsService) appContext.getBean("service");
|
||||||
UserDetails joe = userService.loadUserByUsername("joe");
|
UserDetails joe = userService.loadUserByUsername("joe");
|
||||||
assertFalse(joe.isAccountNonLocked());
|
assertFalse(joe.isAccountNonLocked());
|
||||||
UserDetails bob = userService.loadUserByUsername("bob");
|
UserDetails bob = userService.loadUserByUsername("bOb");
|
||||||
assertFalse(bob.isEnabled());
|
assertFalse(bob.isEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,10 +29,14 @@ import java.util.Properties;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves user details from an in-memory list created by the bean context.
|
* Retrieves user details from an in-memory list created in the application context.
|
||||||
|
* <p>
|
||||||
|
* Username lookups are case-insensitive.
|
||||||
*
|
*
|
||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
|
* @author Luke Taylor
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class InMemoryDaoImpl implements UserDetailsService, InitializingBean {
|
public class InMemoryDaoImpl implements UserDetailsService, InitializingBean {
|
||||||
//~ Instance fields ================================================================================================
|
//~ Instance fields ================================================================================================
|
||||||
|
|
||||||
|
@ -29,7 +29,9 @@ import org.springframework.util.Assert;
|
|||||||
* Used by {@link InMemoryDaoImpl} to store a list of users and their corresponding granted authorities.
|
* Used by {@link InMemoryDaoImpl} to store a list of users and their corresponding granted authorities.
|
||||||
*
|
*
|
||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
|
* @deprecated Use a plain map instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class UserMap {
|
public class UserMap {
|
||||||
//~ Static fields/initializers =====================================================================================
|
//~ Static fields/initializers =====================================================================================
|
||||||
|
|
||||||
|
@ -30,26 +30,14 @@ import java.util.Properties;
|
|||||||
*
|
*
|
||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class InMemoryDaoTests extends TestCase {
|
public class InMemoryDaoTests extends TestCase {
|
||||||
//~ Constructors ===================================================================================================
|
|
||||||
|
|
||||||
public InMemoryDaoTests() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public InMemoryDaoTests(String arg0) {
|
|
||||||
super(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
junit.textui.TestRunner.run(InMemoryDaoTests.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private UserMap makeUserMap() {
|
private UserMap makeUserMap() {
|
||||||
UserMapEditor editor = new UserMapEditor();
|
UserMapEditor editor = new UserMapEditor();
|
||||||
editor.setAsText("rod=koala,ROLE_ONE,ROLE_TWO,enabled\r\nscott=wombat,ROLE_ONE,ROLE_TWO,enabled");
|
editor.setAsText("rod=koala,ROLE_ONE,ROLE_TWO,enabled\nScott=wombat,ROLE_ONE,ROLE_TWO,enabled");
|
||||||
|
|
||||||
return (UserMap) editor.getValue();
|
return (UserMap) editor.getValue();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user