1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.userdetails.memory;
17
18 import java.util.Properties;
19
20 import org.acegisecurity.userdetails.UserDetails;
21 import org.acegisecurity.userdetails.UserDetailsService;
22 import org.acegisecurity.userdetails.UsernameNotFoundException;
23 import org.springframework.beans.factory.InitializingBean;
24 import org.springframework.dao.DataAccessException;
25 import org.springframework.util.Assert;
26
27
28 /***
29 * Retrieves user details from an in-memory list created by the bean context.
30 *
31 * @author Ben Alex
32 * @version $Id: InMemoryDaoImpl.java,v 1.9 2005/11/29 13:10:09 benalex Exp $
33 */
34 public class InMemoryDaoImpl implements UserDetailsService, InitializingBean {
35
36
37 private UserMap userMap;
38
39
40
41 public void setUserMap(UserMap userMap) {
42 this.userMap = userMap;
43 }
44
45 public UserMap getUserMap() {
46 return userMap;
47 }
48
49 /***
50 * Modifies the internal <code>UserMap</code> to reflect the
51 * <code>Properties</code> instance passed. This helps externalise user
52 * information to another file etc.
53 *
54 * @param props the account information in a <code>Properties</code> object
55 * format
56 */
57 public void setUserProperties(Properties props) {
58 UserMap userMap = new UserMap();
59 this.userMap = UserMapEditor.addUsersFromProperties(userMap, props);
60 }
61
62 public void afterPropertiesSet() throws Exception {
63 Assert.notNull(this.userMap,
64 "A list of users, passwords, enabled/disabled status and their granted authorities must be set");
65 }
66
67 public UserDetails loadUserByUsername(String username)
68 throws UsernameNotFoundException, DataAccessException {
69 return userMap.getUser(username);
70 }
71 }