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
.ui
.admin
.editors
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.RepositoryException
;
20 import javax
.jcr
.Session
;
22 import org
.argeo
.ArgeoException
;
23 import org
.argeo
.jcr
.UserJcrUtils
;
24 import org
.argeo
.security
.UserAdminService
;
25 import org
.argeo
.security
.jcr
.JcrUserDetails
;
26 import org
.argeo
.security
.ui
.admin
.SecurityAdminPlugin
;
27 import org
.argeo
.security
.ui
.admin
.views
.UsersView
;
28 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
29 import org
.eclipse
.ui
.IEditorInput
;
30 import org
.eclipse
.ui
.IEditorSite
;
31 import org
.eclipse
.ui
.IWorkbench
;
32 import org
.eclipse
.ui
.PartInitException
;
33 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
34 import org
.springframework
.security
.GrantedAuthority
;
36 /** Editor for an Argeo user. */
37 public class ArgeoUserEditor
extends FormEditor
{
38 public final static String ID
= "org.argeo.security.ui.admin.adminArgeoUserEditor";
40 private JcrUserDetails userDetails
;
41 // private Node userHome;
42 private Node userProfile
;
43 private UserAdminService userAdminService
;
44 private Session session
;
46 public void init(IEditorSite site
, IEditorInput input
)
47 throws PartInitException
{
48 super.init(site
, input
);
49 String username
= ((ArgeoUserEditorInput
) getEditorInput())
51 userProfile
= UserJcrUtils
.getUserProfile(session
, username
);
53 if (userAdminService
.userExists(username
)) {
54 userDetails
= (JcrUserDetails
) userAdminService
55 .loadUserByUsername(username
);
57 GrantedAuthority
[] authorities
= {};
59 userDetails
= new JcrUserDetails(session
, username
, null,
61 } catch (RepositoryException e
) {
62 throw new ArgeoException("Cannot retrieve disabled JCR profile");
66 this.setPartProperty("name", username
!= null ? username
: "<new user>");
67 setPartName(username
!= null ? username
: "<new user>");
70 protected void addPages() {
72 addPage(new DefaultUserMainPage(this, userProfile
));
73 addPage(new UserRolesPage(this, userDetails
, userAdminService
));
74 } catch (Exception e
) {
75 throw new ArgeoException("Cannot add pages", e
);
80 public void doSave(IProgressMonitor monitor
) {
82 // TODO: make it more generic
83 DefaultUserMainPage defaultUserMainPage
= (DefaultUserMainPage
) findPage(DefaultUserMainPage
.ID
);
84 if (defaultUserMainPage
.isDirty()) {
85 defaultUserMainPage
.doSave(monitor
);
86 String newPassword
= defaultUserMainPage
.getNewPassword();
87 defaultUserMainPage
.resetNewPassword();
88 if (newPassword
!= null)
89 userDetails
= userDetails
.cloneWithNewPassword(newPassword
);
92 UserRolesPage userRolesPage
= (UserRolesPage
) findPage(UserRolesPage
.ID
);
93 if (userRolesPage
.isDirty()) {
94 userRolesPage
.doSave(monitor
);
95 userDetails
= userDetails
.cloneWithNewRoles(userRolesPage
99 userAdminService
.updateUser(userDetails
);
101 // if (userAdminService.userExists(user.getUsername()))
102 // userAdminService.updateUser(user);
104 // userAdminService.newUser(user);
105 // setPartName(user.getUsername());
107 firePropertyChange(PROP_DIRTY
);
109 userRolesPage
.setUserDetails(userDetails
);
111 // refresh users view
112 IWorkbench iw
= SecurityAdminPlugin
.getDefault().getWorkbench();
113 UsersView usersView
= (UsersView
) iw
.getActiveWorkbenchWindow()
114 .getActivePage().findView(UsersView
.ID
);
119 public void doSaveAs() {
123 public boolean isSaveAsAllowed() {
127 public void refresh() {
128 UserRolesPage userRolesPage
= (UserRolesPage
) findPage(UserRolesPage
.ID
);
129 userRolesPage
.refresh();
132 public void setUserAdminService(UserAdminService userAdminService
) {
133 this.userAdminService
= userAdminService
;
136 public void setSession(Session session
) {
137 this.session
= session
;