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
.internal
.parts
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import org
.argeo
.ArgeoException
;
22 import org
.argeo
.security
.ui
.admin
.SecurityAdminPlugin
;
23 import org
.argeo
.security
.ui
.admin
.internal
.UserAdminConstants
;
24 import org
.argeo
.security
.ui
.admin
.internal
.UserAdminWrapper
;
25 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
26 import org
.eclipse
.ui
.IEditorInput
;
27 import org
.eclipse
.ui
.IEditorSite
;
28 import org
.eclipse
.ui
.PartInitException
;
29 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
30 import org
.osgi
.service
.useradmin
.Authorization
;
31 import org
.osgi
.service
.useradmin
.Role
;
32 import org
.osgi
.service
.useradmin
.User
;
33 import org
.osgi
.service
.useradmin
.UserAdmin
;
34 import org
.osgi
.service
.useradmin
.UserAdminEvent
;
36 /** Editor for a user, might be a user or a group. */
37 public class UserEditor
extends FormEditor
implements UserAdminConstants
{
38 private static final long serialVersionUID
= 8357851520380820241L;
40 public final static String ID
= SecurityAdminPlugin
.PLUGIN_ID
43 /* DEPENDENCY INJECTION */
44 private UserAdminWrapper userAdminWrapper
;
45 private UserAdmin userAdmin
;
49 private String username
;
51 public void init(IEditorSite site
, IEditorInput input
)
52 throws PartInitException
{
53 super.init(site
, input
);
54 username
= ((UserEditorInput
) getEditorInput()).getUsername();
55 user
= (User
) userAdmin
.getRole(username
);
57 String commonName
= getProperty(KEY_CN
);
59 setPartName(commonName
!= null ? commonName
: "username");
61 // TODO: following has been disabled because it causes NPE after a
62 // login/logout on RAP
63 // Image titleIcon = user.getType() == Role.GROUP ?
64 // SecurityAdminImages.ICON_GROUP
65 // : SecurityAdminImages.ICON_USER;
66 // setTitleImage(titleIcon);
70 * returns the list of all authorisation for the given user or of the
71 * current displayed user if parameter is null
73 protected List
<User
> getFlatGroups(User aUser
) {
74 Authorization currAuth
;
76 currAuth
= userAdmin
.getAuthorization(this.user
);
78 currAuth
= userAdmin
.getAuthorization(aUser
);
80 String
[] roles
= currAuth
.getRoles();
82 List
<User
> groups
= new ArrayList
<User
>();
83 for (String roleStr
: roles
) {
84 User currRole
= (User
) userAdmin
.getRole(roleStr
);
85 if (!groups
.contains(currRole
))
91 /** Exposes the user (or group) that is displayed by the current editor */
92 protected User
getDisplayedUser() {
96 void updateEditorTitle(String title
) {
100 protected void addPages() {
102 if (user
.getType() == Role
.GROUP
)
103 addPage(new GroupMainPage(this, userAdminWrapper
));
105 addPage(new UserMainPage(this, userAdminWrapper
));
106 } catch (Exception e
) {
107 throw new ArgeoException("Cannot add pages", e
);
111 protected String
getProperty(String key
) {
112 Object obj
= user
.getProperties().get(key
);
120 * Updates the property in the working copy. The transaction must be
121 * explicitly committed to persist the update.
123 @SuppressWarnings("unchecked")
124 protected void setProperty(String key
, String value
) {
125 user
.getProperties().put(key
, value
);
129 public void doSave(IProgressMonitor monitor
) {
130 userAdminWrapper
.beginTransactionIfNeeded();
132 firePropertyChange(PROP_DIRTY
);
133 userAdminWrapper
.notifyListeners(new UserAdminEvent(null,
134 UserAdminEvent
.ROLE_REMOVED
, user
));
138 public void doSaveAs() {
142 public boolean isSaveAsAllowed() {
146 public void refresh() {
151 public void dispose() {
155 /* DEPENDENCY INJECTION */
156 public void setUserAdminWrapper(UserAdminWrapper userAdminWrapper
) {
157 this.userAdminWrapper
= userAdminWrapper
;
158 this.userAdmin
= userAdminWrapper
.getUserAdmin();