01: package ru.emdev.EmForge.security.memory;
02:
03: import java.util.Collection;
04: import java.util.HashSet;
05: import java.util.Iterator;
06: import java.util.Map;
07: import java.util.Set;
08:
09: import org.acegisecurity.userdetails.UserDetails;
10: import org.acegisecurity.userdetails.memory.UserMap;
11:
12: /** EmForge Implementation of User-Map.
13: * Problem is - basic UserMap cannot return list of users, stored in it
14: * as well as map is private - so, there is no way to receive it.
15: *
16: * So, we should otheride addUser method to store list of users separatelly
17: *
18: * @author akakunin
19: *
20: */
21: public class EmForgeUserMap extends UserMap {
22: protected Set<String> userNames = new HashSet<String>();
23:
24: @Override
25: public void addUser(UserDetails i_user)
26: throws IllegalArgumentException {
27: userNames.add(i_user.getUsername());
28: super .addUser(i_user);
29: }
30:
31: @SuppressWarnings("unchecked")
32: @Override
33: public void setUsers(Map i_users) {
34: for (Iterator<?> iter = i_users.keySet().iterator(); iter
35: .hasNext();) {
36: String userName = (String) iter.next();
37: userNames.add(userName);
38: }
39:
40: super .setUsers(i_users);
41: }
42:
43: public Collection<String> getUserNames() {
44: return userNames;
45: }
46: }
|