01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.acegisecurity.userdetails.memory;
17:
18: import org.acegisecurity.userdetails.UserDetails;
19: import org.acegisecurity.userdetails.UserDetailsService;
20: import org.acegisecurity.userdetails.UsernameNotFoundException;
21:
22: import org.springframework.beans.factory.InitializingBean;
23:
24: import org.springframework.dao.DataAccessException;
25:
26: import org.springframework.util.Assert;
27:
28: import java.util.Properties;
29:
30: /**
31: * Retrieves user details from an in-memory list created by the bean context.
32: *
33: * @author Ben Alex
34: * @version $Id: InMemoryDaoImpl.java 1496 2006-05-23 13:38:33Z benalex $
35: */
36: public class InMemoryDaoImpl implements UserDetailsService,
37: InitializingBean {
38: //~ Instance fields ================================================================================================
39:
40: private UserMap userMap;
41:
42: //~ Methods ========================================================================================================
43:
44: public void afterPropertiesSet() throws Exception {
45: Assert
46: .notNull(
47: this .userMap,
48: "A list of users, passwords, enabled/disabled status and their granted authorities must be set");
49: }
50:
51: public UserMap getUserMap() {
52: return userMap;
53: }
54:
55: public UserDetails loadUserByUsername(String username)
56: throws UsernameNotFoundException, DataAccessException {
57: return userMap.getUser(username);
58: }
59:
60: public void setUserMap(UserMap userMap) {
61: this .userMap = userMap;
62: }
63:
64: /**
65: * Modifies the internal <code>UserMap</code> to reflect the <code>Properties</code> instance passed. This
66: * helps externalise user information to another file etc.
67: *
68: * @param props the account information in a <code>Properties</code> object format
69: */
70: public void setUserProperties(Properties props) {
71: UserMap userMap = new UserMap();
72: this.userMap = UserMapEditor.addUsersFromProperties(userMap,
73: props);
74: }
75: }
|