SEC-1464: Deprecate UserMap, InMemoryDaoImpl and other related classes in favour of the simpler (non-property editor based) InMemoryUserDetailsManager.
This commit is contained in:
parent
f5859fabcf
commit
024e6904ff
|
@ -30,7 +30,9 @@ 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 by the bean context.
|
||||||
*
|
*
|
||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
|
* @deprecated Use InMemoryUserDetailsManager instead (or write your own implementation)
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class InMemoryDaoImpl implements UserDetailsService, InitializingBean {
|
public class InMemoryDaoImpl implements UserDetailsService, InitializingBean {
|
||||||
//~ Instance fields ================================================================================================
|
//~ Instance fields ================================================================================================
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,9 @@ import org.springframework.util.Assert;
|
||||||
* should not be used if usernames need to be case-sensitive.
|
* should not be used if usernames need to be case-sensitive.
|
||||||
*
|
*
|
||||||
* @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 =====================================================================================
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ import java.util.Properties;
|
||||||
*
|
*
|
||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class UserMapEditor extends PropertyEditorSupport {
|
public class UserMapEditor extends PropertyEditorSupport {
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,8 @@ public class InMemoryUserDetailsManager implements UserDetailsManager {
|
||||||
throw new UsernameNotFoundException(username);
|
throw new UsernameNotFoundException(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return new User(user.getUsername(), user.getPassword(), user.isEnabled(), true, true, true,
|
||||||
|
user.getAuthorities());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,27 +27,11 @@ import org.springframework.security.core.userdetails.memory.UserMapEditor;
|
||||||
*
|
*
|
||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class UserMapEditorTests extends TestCase {
|
public class UserMapEditorTests extends TestCase {
|
||||||
//~ Constructors ===================================================================================================
|
|
||||||
|
|
||||||
public UserMapEditorTests() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserMapEditorTests(String arg0) {
|
|
||||||
super(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
junit.textui.TestRunner.run(UserMapEditorTests.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testConvertedIntoUserSuccessfullyWhenDisabled() {
|
public void testConvertedIntoUserSuccessfullyWhenDisabled() {
|
||||||
UserMapEditor editor = new UserMapEditor();
|
UserMapEditor editor = new UserMapEditor();
|
||||||
editor.setAsText("rod=koala,ROLE_ONE,ROLE_TWO,disabled");
|
editor.setAsText("rod=koala,ROLE_ONE,ROLE_TWO,disabled");
|
||||||
|
|
|
@ -29,8 +29,8 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
*
|
*
|
||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class UserMapTests {
|
public class UserMapTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddAndRetrieveUser() {
|
public void testAddAndRetrieveUser() {
|
||||||
UserDetails rod = new User("rod", "koala", true, true, true, true,
|
UserDetails rod = new User("rod", "koala", true, true, true, true,
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
package org.springframework.security.web.authentication.www;
|
package org.springframework.security.web.authentication.www;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -37,11 +38,11 @@ import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
import org.springframework.security.core.authority.AuthorityUtils;
|
import org.springframework.security.core.authority.AuthorityUtils;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.security.core.userdetails.User;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.security.core.userdetails.cache.NullUserCache;
|
import org.springframework.security.core.userdetails.cache.NullUserCache;
|
||||||
import org.springframework.security.core.userdetails.memory.InMemoryDaoImpl;
|
|
||||||
import org.springframework.security.core.userdetails.memory.UserMap;
|
|
||||||
import org.springframework.security.core.userdetails.memory.UserMapEditor;
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
|
||||||
|
@ -109,26 +110,27 @@ public class DigestAuthenticationFilterTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void clearContext() throws Exception {
|
public void clearContext() {
|
||||||
SecurityContextHolder.clearContext();
|
SecurityContextHolder.clearContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() {
|
||||||
SecurityContextHolder.clearContext();
|
SecurityContextHolder.clearContext();
|
||||||
|
|
||||||
// Create User Details Service
|
// Create User Details Service
|
||||||
InMemoryDaoImpl dao = new InMemoryDaoImpl();
|
UserDetailsService uds = new UserDetailsService() {
|
||||||
UserMapEditor editor = new UserMapEditor();
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
editor.setAsText("rod,ok=koala,ROLE_ONE,ROLE_TWO,enabled\r\n");
|
return new User("rod,ok", "koala", AuthorityUtils.createAuthorityList("ROLE_ONE","ROLE_TWO"));
|
||||||
dao.setUserMap((UserMap) editor.getValue());
|
}
|
||||||
|
};
|
||||||
|
|
||||||
DigestAuthenticationEntryPoint ep = new DigestAuthenticationEntryPoint();
|
DigestAuthenticationEntryPoint ep = new DigestAuthenticationEntryPoint();
|
||||||
ep.setRealmName(REALM);
|
ep.setRealmName(REALM);
|
||||||
ep.setKey(KEY);
|
ep.setKey(KEY);
|
||||||
|
|
||||||
filter = new DigestAuthenticationFilter();
|
filter = new DigestAuthenticationFilter();
|
||||||
filter.setUserDetailsService(dao);
|
filter.setUserDetailsService(uds);
|
||||||
filter.setAuthenticationEntryPoint(ep);
|
filter.setAuthenticationEntryPoint(ep);
|
||||||
|
|
||||||
request = new MockHttpServletRequest("GET", REQUEST_URI);
|
request = new MockHttpServletRequest("GET", REQUEST_URI);
|
||||||
|
@ -169,7 +171,7 @@ public class DigestAuthenticationFilterTests {
|
||||||
@Test
|
@Test
|
||||||
public void testGettersSetters() {
|
public void testGettersSetters() {
|
||||||
DigestAuthenticationFilter filter = new DigestAuthenticationFilter();
|
DigestAuthenticationFilter filter = new DigestAuthenticationFilter();
|
||||||
filter.setUserDetailsService(new InMemoryDaoImpl());
|
filter.setUserDetailsService(mock(UserDetailsService.class));
|
||||||
assertTrue(filter.getUserDetailsService() != null);
|
assertTrue(filter.getUserDetailsService() != null);
|
||||||
|
|
||||||
filter.setAuthenticationEntryPoint(new DigestAuthenticationEntryPoint());
|
filter.setAuthenticationEntryPoint(new DigestAuthenticationEntryPoint());
|
||||||
|
@ -329,7 +331,7 @@ public class DigestAuthenticationFilterTests {
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void startupDetectsMissingAuthenticationEntryPoint() throws Exception {
|
public void startupDetectsMissingAuthenticationEntryPoint() throws Exception {
|
||||||
DigestAuthenticationFilter filter = new DigestAuthenticationFilter();
|
DigestAuthenticationFilter filter = new DigestAuthenticationFilter();
|
||||||
filter.setUserDetailsService(new InMemoryDaoImpl());
|
filter.setUserDetailsService(mock(UserDetailsService.class));
|
||||||
filter.afterPropertiesSet();
|
filter.afterPropertiesSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue