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
.Messages
;
24 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
30 * @created Mar 10, 2011
33 public class PasswordWizard
extends Wizard
implements IConversationEnabled
{
35 private PasswordWizardPage passwordPage
;
36 private final User user
;
37 private final ConversationHolder conversation
;
40 * @param user the user to change the password for
41 * @param conversation this optional parameter can be null. Only supply conversation if you
42 * need to run this wizard is a nested conversation
44 public PasswordWizard(User user
, ConversationHolder conversation
){
45 this.conversation
= conversation
;
47 setWindowTitle(Messages
.PasswordWizardPage_CHANGE_PASSWORD
);
51 public void addPages() {
52 CdmFormFactory formFactory
= new CdmFormFactory(Display
.getDefault());
54 passwordPage
= new PasswordWizardPage(formFactory
, getConversationHolder(), user
);
55 addPage(passwordPage
);
59 public boolean performFinish() {
61 ConversationHolder internalConversation
= CdmStore
.getCurrentApplicationConfiguration().NewConversation();
62 internalConversation
.bind();
63 internalConversation
.startTransaction();
64 String warningTitle
= Messages
.PasswordWizard_COULD_NOT_CHANGE_PWD
;
65 String warningMessage
= Messages
.PasswordWizard_OLD_PWD_INCORRECT
;
67 if(passwordPage
.isChangingOwnPassword()){
68 // change own password with validating of old one
69 CdmStore
.getService(IUserService
.class).changePassword(passwordPage
.getOldPassword(), passwordPage
.getNewPassword());
71 // change others passwords
72 CdmStore
.getService(IUserService
.class).changePasswordForUser(user
.getUsername(), passwordPage
.getNewPassword());
74 CdmStore
.getService(IUserService
.class).loadWithUpdate(user
.getUuid());
75 internalConversation
.commit(false);
76 internalConversation
.unbind();
77 internalConversation
.close();
79 }catch(AccessDeniedException e
){
80 MessagingUtils
.warningDialog(warningTitle
, this, warningMessage
);
82 }catch (AuthenticationException e
){
83 MessagingUtils
.warningDialog(warningTitle
, this, warningMessage
);
87 MessagingUtils
.warningDialog(Messages
.PasswordWizard_PROBLEM_WITH_CHANGING_PWD
, this, Messages
.PasswordWizard_PWD_COULD_NOT_BE_CHANGED
+ e
.getMessage());
90 if(conversation
!= null){
97 public void update(CdmDataChangeMap arg0
) {
101 public ConversationHolder
getConversationHolder() {