2 * Copyright (C) 2007-2012 Mathieu Baudier
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
.dialogs
;
18 import org
.argeo
.ArgeoException
;
19 import org
.argeo
.eclipse
.ui
.ErrorFeedback
;
20 import org
.eclipse
.jface
.dialogs
.IMessageProvider
;
21 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
22 import org
.eclipse
.swt
.SWT
;
23 import org
.eclipse
.swt
.graphics
.Point
;
24 import org
.eclipse
.swt
.layout
.GridData
;
25 import org
.eclipse
.swt
.layout
.GridLayout
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Control
;
28 import org
.eclipse
.swt
.widgets
.Label
;
29 import org
.eclipse
.swt
.widgets
.Shell
;
30 import org
.eclipse
.swt
.widgets
.Text
;
31 import org
.springframework
.security
.userdetails
.UserDetailsManager
;
33 /** Dialog to change the current user password */
34 public class ChangePasswordDialog
extends TitleAreaDialog
{
35 private Text currentPassword
, newPassword1
, newPassword2
;
36 private UserDetailsManager userDetailsManager
;
38 public ChangePasswordDialog(Shell parentShell
,
39 UserDetailsManager securityService
) {
41 this.userDetailsManager
= securityService
;
44 protected Point
getInitialSize() {
45 return new Point(300, 250);
48 protected Control
createDialogArea(Composite parent
) {
49 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
50 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
51 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
52 composite
.setLayout(new GridLayout(2, false));
53 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
54 currentPassword
= createLP(composite
, "Current password");
55 newPassword1
= createLP(composite
, "New password");
56 newPassword2
= createLP(composite
, "Repeat new password");
58 setMessage("Change password", IMessageProvider
.INFORMATION
);
64 protected void okPressed() {
65 if (!newPassword1
.getText().equals(newPassword2
.getText()))
66 throw new ArgeoException("Passwords are different");
68 userDetailsManager
.changePassword(currentPassword
.getText(),
69 newPassword1
.getText());
71 } catch (Exception e
) {
72 ErrorFeedback
.show("Cannot change password", e
);
76 /** Creates label and password. */
77 protected Text
createLP(Composite parent
, String label
) {
78 new Label(parent
, SWT
.NONE
).setText(label
);
79 Text text
= new Text(parent
, SWT
.SINGLE
| SWT
.LEAD
| SWT
.PASSWORD
81 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
85 protected void configureShell(Shell shell
) {
86 super.configureShell(shell
);
87 shell
.setText("Change password");