1 package org
.argeo
.security
.ui
.dialogs
;
3 import org
.argeo
.ArgeoException
;
4 import org
.argeo
.eclipse
.ui
.ErrorFeedback
;
5 import org
.eclipse
.jface
.dialogs
.IMessageProvider
;
6 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
7 import org
.eclipse
.swt
.SWT
;
8 import org
.eclipse
.swt
.graphics
.Point
;
9 import org
.eclipse
.swt
.layout
.GridData
;
10 import org
.eclipse
.swt
.layout
.GridLayout
;
11 import org
.eclipse
.swt
.widgets
.Composite
;
12 import org
.eclipse
.swt
.widgets
.Control
;
13 import org
.eclipse
.swt
.widgets
.Label
;
14 import org
.eclipse
.swt
.widgets
.Shell
;
15 import org
.eclipse
.swt
.widgets
.Text
;
16 import org
.springframework
.security
.userdetails
.UserDetailsManager
;
18 /** Dialog to change the current user password */
19 public class ChangePasswordDialog
extends TitleAreaDialog
{
20 private Text currentPassword
, newPassword1
, newPassword2
;
21 private UserDetailsManager userDetailsManager
;
23 public ChangePasswordDialog(Shell parentShell
,
24 UserDetailsManager securityService
) {
26 this.userDetailsManager
= securityService
;
29 protected Point
getInitialSize() {
30 return new Point(300, 250);
33 protected Control
createDialogArea(Composite parent
) {
34 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
35 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
36 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
37 composite
.setLayout(new GridLayout(2, false));
38 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
39 currentPassword
= createLP(composite
, "Current password");
40 newPassword1
= createLP(composite
, "New password");
41 newPassword2
= createLP(composite
, "Repeat new password");
43 setMessage("Change password", IMessageProvider
.INFORMATION
);
49 protected void okPressed() {
50 if (!newPassword1
.getText().equals(newPassword2
.getText()))
51 throw new ArgeoException("Passwords are different");
53 userDetailsManager
.changePassword(currentPassword
.getText(),
54 newPassword1
.getText());
56 } catch (Exception e
) {
57 ErrorFeedback
.show("Cannot change password", e
);
61 /** Creates label and password. */
62 protected Text
createLP(Composite parent
, String label
) {
63 new Label(parent
, SWT
.NONE
).setText(label
);
64 Text text
= new Text(parent
, SWT
.SINGLE
| SWT
.LEAD
| SWT
.PASSWORD
66 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
70 protected void configureShell(Shell shell
) {
71 super.configureShell(shell
);
72 shell
.setText("Change password");