3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.ui
.password
;
13 import org
.eclipse
.jface
.wizard
.Wizard
;
14 import org
.eclipse
.swt
.widgets
.Display
;
15 import org
.springframework
.security
.access
.AccessDeniedException
;
16 import org
.springframework
.security
.core
.AuthenticationException
;
18 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
19 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
20 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
21 import eu
.etaxonomy
.cdm
.model
.common
.User
;
22 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
23 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
24 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
29 * @created Mar 10, 2011
32 public class PasswordWizard
extends Wizard
implements IConversationEnabled
{
34 private PasswordWizardPage passwordPage
;
35 private final User user
;
36 private final ConversationHolder conversation
;
39 * @param user the user to change the password for
40 * @param conversation this optional parameter can be null. Only supply conversation if you
41 * need to run this wizard is a nested conversation
43 public PasswordWizard(User user
, ConversationHolder conversation
){
44 this.conversation
= conversation
;
46 setWindowTitle("Change password");
50 public void addPages() {
51 CdmFormFactory formFactory
= new CdmFormFactory(Display
.getDefault());
53 passwordPage
= new PasswordWizardPage(formFactory
, getConversationHolder(), user
);
54 addPage(passwordPage
);
58 public boolean performFinish() {
60 ConversationHolder internalConversation
= CdmStore
.getCurrentApplicationConfiguration().NewConversation();
61 internalConversation
.bind();
62 internalConversation
.startTransaction();
64 if(passwordPage
.isChangingOwnPassword()){
65 // change own password with validating of old one
66 CdmStore
.getService(IUserService
.class).changePassword(passwordPage
.getOldPassword(), passwordPage
.getNewPassword());
68 // change others passwords
69 CdmStore
.getService(IUserService
.class).changePasswordForUser(user
.getUsername(), passwordPage
.getNewPassword());
71 CdmStore
.getService(IUserService
.class).loadWithUpdate(user
.getUuid());
72 internalConversation
.commit(false);
73 internalConversation
.unbind();
74 internalConversation
.close();
76 }catch(AccessDeniedException e
){
77 MessagingUtils
.warningDialog("Could not change password", this, "The old password is not correct.");
79 }catch (AuthenticationException e
){
80 MessagingUtils
.warningDialog("Could not change password", this, "The old password is not correct.");
84 MessagingUtils
.warningDialog("Problem with changing password", this, "The password could not be changed. " + e
.getMessage());
87 if(conversation
!= null){
94 public void update(CdmDataChangeMap arg0
) {
98 public ConversationHolder
getConversationHolder() {