2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 * This document is a part of the source code and related artifacts
25 * for CollectionSpace, an open source collections management system
26 * for museums and related institutions:
28 * http://www.collectionspace.org
29 * http://wiki.collectionspace.org
31 * Copyright 2009 University of California at Berkeley
33 * Licensed under the Educational Community License (ECL), Version 2.0.
34 * You may not use this file except in compliance with this License.
36 * You may obtain a copy of the ECL 2.0 License at
38 * https://source.collectionspace.org/collection-space/LICENSE.txt
40 * Unless required by applicable law or agreed to in writing, software
41 * distributed under the License is distributed on an "AS IS" BASIS,
42 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43 * See the License for the specific language governing permissions and
44 * limitations under the License.
47 * To change this template, choose Tools | Templates
48 * and open the template in the editor.
50 package org.collectionspace.authentication.spring;
52 import java.util.HashMap;
53 import java.util.List;
56 import org.springframework.dao.DataAccessException;
57 import org.springframework.security.core.GrantedAuthority;
58 import org.springframework.security.core.authority.AuthorityUtils;
59 import org.springframework.security.core.userdetails.User;
60 import org.springframework.security.core.userdetails.UserDetails;
61 import org.springframework.security.core.userdetails.UserDetailsService;
62 import org.springframework.security.core.userdetails.UsernameNotFoundException;
65 * A CollectionSpace UserDetailsService for spring
67 //FIXME remove test/mockup code
68 public class CSpaceUserDetailsService implements UserDetailsService {
70 private Map<String, User> users = new HashMap<String, User>();
71 private List<GrantedAuthority> auths = AuthorityUtils.createAuthorityList("ROLE_USER");
73 public CSpaceUserDetailsService() {
74 users.put("test", new User("test", "", true, true, true, true, auths));
75 users.put("valid", new User("valid", "", true, true, true, true, auths));
76 users.put("locked", new User("locked", "", true, true, true, false, auths));
77 users.put("disabled", new User("disabled", "", false, true, true, true, auths));
78 users.put("credentialsExpired", new User("credentialsExpired", "", true, true, false, true, auths));
79 users.put("expired", new User("expired", "", true, false, true, true, auths));
82 public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
83 if (users.get(username) == null) {
84 throw new UsernameNotFoundException("User not found: " + username);
87 return users.get(username);