| Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
| InMemoryDaoImpl |
|
| 1.0;1 |
| 1 | /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited |
|
| 2 | * |
|
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
| 4 | * you may not use this file except in compliance with the License. |
|
| 5 | * You may obtain a copy of the License at |
|
| 6 | * |
|
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 8 | * |
|
| 9 | * 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 | /** |
|
| 32 | * Retrieves user details from an in-memory list created by the bean context. |
|
| 33 | * |
|
| 34 | * @author Ben Alex |
|
| 35 | * @version $Id: InMemoryDaoImpl.java 1496 2006-05-23 13:38:33Z benalex $ |
|
| 36 | */ |
|
| 37 | 43 | public class InMemoryDaoImpl implements UserDetailsService, InitializingBean { |
| 38 | //~ Instance fields ================================================================================================ |
|
| 39 | ||
| 40 | private UserMap userMap; |
|
| 41 | ||
| 42 | //~ Methods ======================================================================================================== |
|
| 43 | ||
| 44 | public void afterPropertiesSet() throws Exception { |
|
| 45 | 7 | Assert.notNull(this.userMap, |
| 46 | "A list of users, passwords, enabled/disabled status and their granted authorities must be set"); |
|
| 47 | 5 | } |
| 48 | ||
| 49 | public UserMap getUserMap() { |
|
| 50 | 1 | return userMap; |
| 51 | } |
|
| 52 | ||
| 53 | public UserDetails loadUserByUsername(String username) |
|
| 54 | throws UsernameNotFoundException, DataAccessException { |
|
| 55 | 25 | return userMap.getUser(username); |
| 56 | } |
|
| 57 | ||
| 58 | public void setUserMap(UserMap userMap) { |
|
| 59 | 39 | this.userMap = userMap; |
| 60 | 39 | } |
| 61 | ||
| 62 | /** |
|
| 63 | * Modifies the internal <code>UserMap</code> to reflect the <code>Properties</code> instance passed. This |
|
| 64 | * helps externalise user information to another file etc. |
|
| 65 | * |
|
| 66 | * @param props the account information in a <code>Properties</code> object format |
|
| 67 | */ |
|
| 68 | public void setUserProperties(Properties props) { |
|
| 69 | 1 | UserMap userMap = new UserMap(); |
| 70 | 1 | this.userMap = UserMapEditor.addUsersFromProperties(userMap, props); |
| 71 | 1 | } |
| 72 | } |