2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.security
.jcr
;
18 import java
.util
.ArrayList
;
19 import java
.util
.HashSet
;
20 import java
.util
.List
;
23 import javax
.jcr
.Node
;
24 import javax
.jcr
.Repository
;
25 import javax
.jcr
.RepositoryException
;
26 import javax
.jcr
.Session
;
28 import org
.argeo
.ArgeoException
;
29 import org
.argeo
.jcr
.JcrUtils
;
30 import org
.argeo
.jcr
.UserJcrUtils
;
31 import org
.argeo
.security
.UserAdminService
;
32 import org
.springframework
.dao
.DataAccessException
;
33 import org
.springframework
.security
.userdetails
.User
;
34 import org
.springframework
.security
.userdetails
.UserDetails
;
35 import org
.springframework
.security
.userdetails
.UsernameNotFoundException
;
38 * Dummy user service to be used when running as a single OS user (typically
39 * desktop). TODO integrate with JCR user / groups
41 public class OsJcrUserAdminService
implements UserAdminService
{
42 private Repository repository
;
44 /** In memory roles provided by applications. */
45 private List
<String
> roles
= new ArrayList
<String
>();
47 // private Session adminSession;
51 // adminSession = repository.login();
52 // } catch (RepositoryException e) {
53 // throw new ArgeoException("Cannot initialize", e);
57 public void destroy() {
58 // JcrUtils.logoutQuietly(adminSession);
61 /** <b>Unsupported</b> */
62 public void createUser(UserDetails user
) {
63 throw new UnsupportedOperationException();
67 public void updateUser(UserDetails user
) {
71 /** <b>Unsupported</b> */
72 public void deleteUser(String username
) {
73 throw new UnsupportedOperationException();
76 /** <b>Unsupported</b> */
77 public void changePassword(String oldPassword
, String newPassword
) {
78 throw new UnsupportedOperationException();
81 public boolean userExists(String username
) {
82 if (getSPropertyUsername().equals(username
))
88 public UserDetails
loadUserByUsername(String username
)
89 throws UsernameNotFoundException
, DataAccessException
{
90 if (getSPropertyUsername().equals(username
)) {
91 UserDetails userDetails
;
92 if (repository
!= null) {
93 Session adminSession
= null;
95 adminSession
= repository
.login();
96 Node userProfile
= UserJcrUtils
.getUserProfile(
97 adminSession
, username
);
98 userDetails
= new JcrUserDetails(userProfile
, "",
99 OsJcrAuthenticationProvider
.getBaseAuthorities());
100 } catch (RepositoryException e
) {
101 throw new ArgeoException(
102 "Cannot retrieve user profile for " + username
, e
);
104 JcrUtils
.logoutQuietly(adminSession
);
107 userDetails
= new User(username
, "", true, true, true, true,
108 OsJcrAuthenticationProvider
.getBaseAuthorities());
112 throw new UnsupportedOperationException();
116 protected final String
getSPropertyUsername() {
117 return System
.getProperty("user.name");
120 public Set
<String
> listUsers() {
121 Set
<String
> set
= new HashSet
<String
>();
122 set
.add(getSPropertyUsername());
126 public Set
<String
> listUsersInRole(String role
) {
127 Set
<String
> set
= new HashSet
<String
>();
128 set
.add(getSPropertyUsername());
133 public void synchronize() {
136 /** <b>Unsupported</b> */
137 public void newRole(String role
) {
141 public Set
<String
> listEditableRoles() {
142 return new HashSet
<String
>(roles
);
145 /** <b>Unsupported</b> */
146 public void deleteRole(String role
) {
150 public void setRepository(Repository repository
) {
151 this.repository
= repository
;