1 package org
.argeo
.app
.ui
.people
;
3 import java
.util
.Arrays
;
7 import org
.argeo
.api
.acr
.Content
;
8 import org
.argeo
.api
.acr
.QNamed
;
9 import org
.argeo
.api
.acr
.ldap
.LdapAttrs
;
10 import org
.argeo
.api
.acr
.ldap
.LdapObjs
;
11 import org
.argeo
.app
.api
.SuiteRole
;
12 import org
.argeo
.app
.ui
.SuiteMsg
;
13 import org
.argeo
.app
.ui
.SuiteStyle
;
14 import org
.argeo
.app
.ui
.SuiteUiUtils
;
15 import org
.argeo
.cms
.CmsMsg
;
16 import org
.argeo
.cms
.CmsUserManager
;
17 import org
.argeo
.cms
.Localized
;
18 import org
.argeo
.cms
.auth
.CmsRole
;
19 import org
.argeo
.cms
.auth
.CurrentUser
;
20 import org
.argeo
.cms
.auth
.RoleNameUtils
;
21 import org
.argeo
.cms
.auth
.SystemRole
;
22 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
23 import org
.argeo
.cms
.swt
.Selected
;
24 import org
.argeo
.cms
.swt
.acr
.SwtSection
;
25 import org
.argeo
.cms
.swt
.acr
.SwtUiProvider
;
26 import org
.argeo
.cms
.swt
.dialogs
.CmsFeedback
;
27 import org
.argeo
.cms
.swt
.widgets
.EditableText
;
28 import org
.eclipse
.swt
.SWT
;
29 import org
.eclipse
.swt
.events
.MouseAdapter
;
30 import org
.eclipse
.swt
.events
.MouseEvent
;
31 import org
.eclipse
.swt
.events
.SelectionEvent
;
32 import org
.eclipse
.swt
.events
.SelectionListener
;
33 import org
.eclipse
.swt
.layout
.GridData
;
34 import org
.eclipse
.swt
.layout
.GridLayout
;
35 import org
.eclipse
.swt
.widgets
.Button
;
36 import org
.eclipse
.swt
.widgets
.Composite
;
37 import org
.eclipse
.swt
.widgets
.Control
;
38 import org
.eclipse
.swt
.widgets
.Label
;
39 import org
.eclipse
.swt
.widgets
.Text
;
40 import org
.osgi
.service
.useradmin
.User
;
42 /** Edit a suite user. */
43 public class PersonUiProvider
implements SwtUiProvider
{
44 private CmsUserManager cmsUserManager
;
47 public Control
createUiPart(Composite parent
, Content context
) {
48 SwtSection main
= new SwtSection(parent
, SWT
.NONE
, context
);
49 main
.setLayoutData(CmsSwtUtils
.fillAll());
51 main
.setLayout(new GridLayout(2, false));
53 User user
= context
.adapt(User
.class);
55 String roleContext
= RoleNameUtils
.getContext(user
.getName());
57 if (context
.hasContentClass(LdapObjs
.person
.qName())) {
59 addFormLine(main
, SuiteMsg
.firstName
, context
, LdapAttrs
.givenName
);
60 addFormLine(main
, SuiteMsg
.lastName
, context
, LdapAttrs
.sn
);
61 addFormLine(main
, SuiteMsg
.email
, context
, LdapAttrs
.mail
);
64 if (context
.hasContentClass(LdapObjs
.posixAccount
.qName())) {
66 SwtSection rolesSection
= new SwtSection(main
, SWT
.NONE
);
67 rolesSection
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 2, 1));
68 rolesSection
.setLayout(new GridLayout(2, false));
69 List
<String
> roles
= Arrays
.asList(cmsUserManager
.getUserRoles(user
.getName()));
70 addRoleCheckBox(rolesSection
, SuiteMsg
.coworkerRole
, SuiteRole
.coworker
, roleContext
, roles
);
71 addRoleCheckBox(rolesSection
, SuiteMsg
.publisherRole
, SuiteRole
.publisher
, roleContext
, roles
);
72 addRoleCheckBox(rolesSection
, SuiteMsg
.userAdminRole
, CmsRole
.userAdmin
, roleContext
, roles
);
74 // Composite facetsSection = new Composite(main, SWT.NONE);
75 // facetsSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
76 // facetsSection.setLayout(new GridLayout());
77 // if (context.hasContentClass(LdapObjs.groupOfNames.qName())) {
78 // String[] members = context.attr(LdapAttrs.member.qName()).split("\n");
79 // for (String member : members) {
80 // new Label(facetsSection, SWT.NONE).setText(member);
83 if (CurrentUser
.implies(CmsRole
.userAdmin
, roleContext
)) {
84 SwtSection changePasswordSection
= new SwtSection(main
, SWT
.BORDER
);
85 changePasswordSection
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 2, 1));
86 changePasswordSection
.setLayout(new GridLayout(2, false));
87 // SuiteUiUtils.addFormLabel(changePasswordSection, CmsMsg.changePassword)
88 // .setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, false, false, 2, 1));
89 SuiteUiUtils
.addFormLabel(changePasswordSection
, CmsMsg
.newPassword
);
90 Text newPasswordT
= SuiteUiUtils
.addFormTextField(changePasswordSection
, null, null,
91 SWT
.PASSWORD
| SWT
.BORDER
);
92 newPasswordT
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
93 SuiteUiUtils
.addFormLabel(changePasswordSection
, CmsMsg
.repeatNewPassword
);
94 Text repeatNewPasswordT
= SuiteUiUtils
.addFormTextField(changePasswordSection
, null, null,
95 SWT
.PASSWORD
| SWT
.BORDER
);
96 repeatNewPasswordT
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
97 Button apply
= new Button(changePasswordSection
, SWT
.FLAT
);
98 apply
.setLayoutData(new GridData(SWT
.END
, SWT
.CENTER
, false, false, 2, 1));
99 apply
.setText(CmsMsg
.changePassword
.lead());
100 apply
.addSelectionListener((Selected
) (e
) -> {
102 char[] newPassword
= newPasswordT
.getTextChars();
103 char[] repeatNewPassword
= repeatNewPasswordT
.getTextChars();
104 if (newPassword
.length
> 0 && Arrays
.equals(newPassword
, repeatNewPassword
)) {
105 cmsUserManager
.resetPassword(user
.getName(), newPassword
);
106 CmsFeedback
.show(CmsMsg
.passwordChanged
.lead());
108 CmsFeedback
.error(CmsMsg
.invalidPassword
.lead(), null);
110 } catch (Exception e1
) {
111 CmsFeedback
.error(CmsMsg
.invalidPassword
.lead(), e1
);
120 private void addFormLine(SwtSection parent
, Localized msg
, Content content
, QNamed attr
) {
121 SuiteUiUtils
.addFormLabel(parent
, msg
.lead());
122 EditableText text
= new EditableText(parent
, SWT
.SINGLE
| SWT
.FLAT
);
123 text
.setLayoutData(CmsSwtUtils
.fillWidth());
124 text
.setStyle(SuiteStyle
.simpleInput
);
125 String txt
= content
.attr(attr
);
126 if (txt
== null) // FIXME understand why email is not found in IPA
129 text
.setMouseListener(new MouseAdapter() {
131 private static final long serialVersionUID
= 1L;
134 public void mouseDoubleClick(MouseEvent e
) {
135 String currentTxt
= text
.getText();
137 text
.setText(currentTxt
);
138 ((Text
) text
.getControl()).addSelectionListener(new SelectionListener() {
140 private static final long serialVersionUID
= 1L;
143 public void widgetSelected(SelectionEvent e
) {
147 public void widgetDefaultSelected(SelectionEvent e
) {
148 String editedTxt
= text
.getText();
150 text
.setText(editedTxt
);
151 text
.getParent().layout(new Control
[] { text
.getControl() });
159 private void addRoleCheckBox(SwtSection parent
, Localized msg
, SystemRole systemRole
, String roleContext
,
160 List
<String
> roles
) {
161 Button radio
= new Button(parent
, SWT
.CHECK
);
162 radio
.setSelection(false);
163 roles
: for (String dn
: roles
) {
164 if (systemRole
.implied(dn
, roleContext
)) {
165 radio
.setSelection(true);
170 if (systemRole
.equals(CmsRole
.userAdmin
))
171 radio
.setEnabled(CurrentUser
.implies(CmsRole
.groupAdmin
, roleContext
));
173 radio
.setEnabled(CurrentUser
.implies(CmsRole
.userAdmin
, roleContext
));
175 new Label(parent
, 0).setText(msg
.lead());
179 public void setCmsUserManager(CmsUserManager cmsUserManager
) {
180 this.cmsUserManager
= cmsUserManager
;
183 // private String getUserProperty(Object element, String key) {
184 // Object value = ((User) element).getProperties().get(key);
185 // return value != null ? value.toString() : null;
188 public void init(Map
<String
, Object
> properties
) {