SEC-1012: Converted Groupsmanager to use List<String>
This commit is contained in:
parent
1f78974073
commit
2dfd006665
|
@ -22,7 +22,7 @@ public interface GroupManager {
|
|||
/**
|
||||
* Returns the names of all groups that this group manager controls.
|
||||
*/
|
||||
String[] findAllGroups();
|
||||
List<String> findAllGroups();
|
||||
|
||||
/**
|
||||
* Locates the users who are members of a group
|
||||
|
@ -30,7 +30,7 @@ public interface GroupManager {
|
|||
* @param groupName the group whose members are required
|
||||
* @return the usernames of the group members
|
||||
*/
|
||||
String[] findUsersInGroup(String groupName);
|
||||
List<String> findUsersInGroup(String groupName);
|
||||
|
||||
/**
|
||||
* Creates a new group with the specified list of authorities.
|
||||
|
|
|
@ -229,13 +229,13 @@ public class JdbcUserDetailsManager extends JdbcDaoImpl implements UserDetailsMa
|
|||
|
||||
//~ GroupManager implementation ====================================================================================
|
||||
|
||||
public String[] findAllGroups() {
|
||||
return (String[]) getJdbcTemplate().queryForList(findAllGroupsSql, String.class).toArray(new String[0]);
|
||||
public List<String> findAllGroups() {
|
||||
return getJdbcTemplate().queryForList(findAllGroupsSql, String.class);
|
||||
}
|
||||
|
||||
public String[] findUsersInGroup(String groupName) {
|
||||
public List<String> findUsersInGroup(String groupName) {
|
||||
Assert.hasText(groupName);
|
||||
return (String[]) getJdbcTemplate().queryForList(findUsersInGroupSql, new String[] {groupName}, String.class).toArray(new String[0]);
|
||||
return getJdbcTemplate().queryForList(findUsersInGroupSql, new String[] {groupName}, String.class);
|
||||
}
|
||||
|
||||
public void createGroup(final String groupName, final List<GrantedAuthority> authorities) {
|
||||
|
|
|
@ -1,12 +1,28 @@
|
|||
package org.springframework.security.userdetails.jdbc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.BadCredentialsException;
|
||||
import org.springframework.security.MockAuthenticationManager;
|
||||
import org.springframework.security.PopulatedDatabase;
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
import org.springframework.security.GrantedAuthorityImpl;
|
||||
import org.springframework.security.MockAuthenticationManager;
|
||||
import org.springframework.security.PopulatedDatabase;
|
||||
import org.springframework.security.TestDataSource;
|
||||
import org.springframework.security.context.SecurityContextHolder;
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
|
@ -14,21 +30,6 @@ import org.springframework.security.providers.dao.UserCache;
|
|||
import org.springframework.security.userdetails.User;
|
||||
import org.springframework.security.userdetails.UserDetails;
|
||||
import org.springframework.security.util.AuthorityUtils;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Tests for {@link JdbcUserDetailsManager}
|
||||
|
@ -192,7 +193,7 @@ public class JdbcUserDetailsManagerTests {
|
|||
|
||||
@Test
|
||||
public void findAllGroupsReturnsExpectedGroupNames() {
|
||||
List<String> groups = new ArrayList<String>(Arrays.asList(manager.findAllGroups()));
|
||||
List<String> groups = manager.findAllGroups();
|
||||
assertEquals(4, groups.size());
|
||||
|
||||
Collections.sort(groups);
|
||||
|
@ -204,11 +205,11 @@ public class JdbcUserDetailsManagerTests {
|
|||
|
||||
@Test
|
||||
public void findGroupMembersReturnsCorrectData() {
|
||||
String[] groupMembers = manager.findUsersInGroup("GROUP_0");
|
||||
assertEquals(1, groupMembers.length);
|
||||
assertEquals("jerry", groupMembers[0]);
|
||||
List<String> groupMembers = manager.findUsersInGroup("GROUP_0");
|
||||
assertEquals(1, groupMembers.size());
|
||||
assertEquals("jerry", groupMembers.get(0));
|
||||
groupMembers = manager.findUsersInGroup("GROUP_1");
|
||||
assertEquals(2, groupMembers.length);
|
||||
assertEquals(2, groupMembers.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -310,7 +311,7 @@ public class JdbcUserDetailsManagerTests {
|
|||
cache.remove(username);
|
||||
}
|
||||
|
||||
Map getUserMap() {
|
||||
Map<String,UserDetails> getUserMap() {
|
||||
return cache;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue