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
.cms
.internal
.useradmin
;
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
.cms
.internal
.auth
.OsJcrAuthenticationProvider
;
30 import org
.argeo
.jcr
.JcrUtils
;
31 import org
.argeo
.jcr
.UserJcrUtils
;
32 import org
.argeo
.security
.UserAdminService
;
33 import org
.argeo
.security
.jcr
.JcrUserDetails
;
34 import org
.springframework
.dao
.DataAccessException
;
35 import org
.springframework
.security
.core
.userdetails
.User
;
36 import org
.springframework
.security
.core
.userdetails
.UserDetails
;
37 import org
.springframework
.security
.core
.userdetails
.UsernameNotFoundException
;
40 * Dummy user service to be used when running as a single OS user (typically
41 * desktop). TODO integrate with JCR user / groups
43 public class OsJcrUserAdminService
implements UserAdminService
{
44 private Repository repository
;
46 /** In memory roles provided by applications. */
47 private List
<String
> roles
= new ArrayList
<String
>();
49 // private Session adminSession;
53 // adminSession = repository.login();
54 // } catch (RepositoryException e) {
55 // throw new ArgeoException("Cannot initialize", e);
59 public void destroy() {
60 // JcrUtils.logoutQuietly(adminSession);
63 /** <b>Unsupported</b> */
64 public void createUser(UserDetails user
) {
65 throw new UnsupportedOperationException();
69 public void updateUser(UserDetails user
) {
73 /** <b>Unsupported</b> */
74 public void deleteUser(String username
) {
75 throw new UnsupportedOperationException();
78 /** <b>Unsupported</b> */
79 public void changePassword(String oldPassword
, String newPassword
) {
80 throw new UnsupportedOperationException();
83 public boolean userExists(String username
) {
84 if (getSPropertyUsername().equals(username
))
90 public UserDetails
loadUserByUsername(String username
)
91 throws UsernameNotFoundException
, DataAccessException
{
92 if (getSPropertyUsername().equals(username
)) {
93 UserDetails userDetails
;
94 if (repository
!= null) {
95 Session adminSession
= null;
97 adminSession
= repository
.login();
98 Node userProfile
= UserJcrUtils
.getUserProfile(
99 adminSession
, username
);
100 userDetails
= new JcrUserDetails(userProfile
, "",
101 OsJcrAuthenticationProvider
.getBaseAuthorities());
102 } catch (RepositoryException e
) {
103 throw new ArgeoException(
104 "Cannot retrieve user profile for " + username
, e
);
106 JcrUtils
.logoutQuietly(adminSession
);
109 userDetails
= new User(username
, "", true, true, true, true,
110 OsJcrAuthenticationProvider
.getBaseAuthorities());
114 throw new UnsupportedOperationException();
118 protected final String
getSPropertyUsername() {
119 return System
.getProperty("user.name");
122 public Set
<String
> listUsers() {
123 Set
<String
> set
= new HashSet
<String
>();
124 set
.add(getSPropertyUsername());
128 public Set
<String
> listUsersInRole(String role
) {
129 Set
<String
> set
= new HashSet
<String
>();
130 set
.add(getSPropertyUsername());
135 public void synchronize() {
138 /** <b>Unsupported</b> */
139 public void newRole(String role
) {
143 public Set
<String
> listEditableRoles() {
144 return new HashSet
<String
>(roles
);
147 /** <b>Unsupported</b> */
148 public void deleteRole(String role
) {
152 public void setRepository(Repository repository
) {
153 this.repository
= repository
;