01: package ru.emdev.EmForge.security.memory;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05: import java.util.Properties;
06:
07: import org.acegisecurity.userdetails.UserDetails;
08: import org.acegisecurity.userdetails.UsernameNotFoundException;
09: import org.acegisecurity.userdetails.memory.InMemoryDaoImpl;
10: import org.acegisecurity.userdetails.memory.UserMap;
11: import org.springframework.dao.DataAccessException;
12:
13: import ru.emdev.EmForge.security.EmForgeUserDetailsService;
14: import ru.emdev.EmForge.security.EmForgeUserImpl;
15:
16: /** EmForge Specific Memory-Based User-Details Service
17: * It allows to add emforge-specific attributes into user-properties
18: * @author akakunin
19: *
20: */
21: public class MemoryUserDetailsService extends InMemoryDaoImpl implements
22: EmForgeUserDetailsService {
23:
24: @Override
25: public void setUserProperties(Properties props) {
26: UserMap userMap = new UserMap();
27: EmForgeUserMapEditor.addUsersFromProperties(userMap, props);
28:
29: setUserMap(userMap);
30: }
31:
32: @Override
33: public UserDetails loadUserByUsername(String username)
34: throws UsernameNotFoundException, DataAccessException {
35: UserDetails user = super .loadUserByUsername(username);
36:
37: // if use ris EmForgeUserImpl
38: if (user instanceof EmForgeUserImpl) {
39: EmForgeUserImpl emForgeUser = (EmForgeUserImpl) user;
40:
41: // to return manager property user details should contain reference to user-details service...
42: // Seems it is good place to set it
43: emForgeUser.setUserDetailsService(this );
44: }
45: return user;
46: }
47:
48: /** Currently not implemented
49: * @todo Seems to implement this method we will need to rewrite UserMap class to be able to get list of users from it
50: */
51: public Collection<UserDetails> getAllUsers() {
52: Collection<UserDetails> allUsers = new ArrayList<UserDetails>();
53:
54: EmForgeUserMap userMap = (EmForgeUserMap) getUserMap();
55: for (String user : userMap.getUserNames()) {
56: allUsers.add(loadUserByUsername(user));
57: }
58: return allUsers;
59: }
60: }
|