ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / password / PasswordWizard.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.ui.password;
11
12 import org.eclipse.jface.wizard.Wizard;
13 import org.eclipse.swt.widgets.Display;
14 import org.springframework.security.access.AccessDeniedException;
15 import org.springframework.security.core.AuthenticationException;
16
17 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
18 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
19 import eu.etaxonomy.cdm.api.service.IUserService;
20 import eu.etaxonomy.cdm.model.common.User;
21 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
22 import eu.etaxonomy.taxeditor.Messages;
23 import eu.etaxonomy.taxeditor.model.MessagingUtils;
24 import eu.etaxonomy.taxeditor.store.CdmStore;
25 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
26
27 /**
28 * @author n.hoffmann
29 * @created Mar 10, 2011
30 * @version 1.0
31 */
32 public class PasswordWizard extends Wizard implements IConversationEnabled{
33
34 private PasswordWizardPage passwordPage;
35 private final User user;
36 private final ConversationHolder conversation;
37
38 /**
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
42 */
43 public PasswordWizard(User user, ConversationHolder conversation){
44 this.conversation = conversation;
45 this.user = user;
46 setWindowTitle(Messages.PasswordWizardPage_CHANGE_PASSWORD);
47 }
48
49 @Override
50 public void addPages() {
51 CdmFormFactory formFactory = new CdmFormFactory(Display.getDefault());
52
53 passwordPage = new PasswordWizardPage(formFactory, getConversationHolder(), user);
54 addPage(passwordPage);
55 }
56
57 @Override
58 public boolean performFinish() {
59
60 ConversationHolder internalConversation = CdmStore.getCurrentApplicationConfiguration().NewConversation();
61 internalConversation.bind();
62 internalConversation.startTransaction();
63 String warningTitle = Messages.PasswordWizard_COULD_NOT_CHANGE_PWD;
64 String warningMessage = Messages.PasswordWizard_OLD_PWD_INCORRECT;
65 try{
66 if(passwordPage.isChangingOwnPassword()){
67 // change own password with validating of old one
68 CdmStore.getService(IUserService.class).changePassword(passwordPage.getOldPassword(), passwordPage.getNewPassword());
69 }else{
70 // change others passwords
71 CdmStore.getService(IUserService.class).changePasswordForUser(user.getUsername(), passwordPage.getNewPassword());
72 }
73 CdmStore.getService(IUserService.class).loadWithUpdate(user.getUuid());
74 internalConversation.commit(false);
75 internalConversation.unbind();
76 internalConversation.close();
77 return true;
78 }catch(AccessDeniedException e){
79 MessagingUtils.warningDialog(warningTitle, this, warningMessage);
80 return false;
81 }catch (AuthenticationException e){
82 MessagingUtils.warningDialog(warningTitle, this, warningMessage);
83
84 return false;
85 }catch(Exception e){
86 MessagingUtils.warningDialog(Messages.PasswordWizard_PROBLEM_WITH_CHANGING_PWD, this, Messages.PasswordWizard_PWD_COULD_NOT_BE_CHANGED + e.getMessage());
87 return false;
88 }finally{
89 if(conversation != null){
90 conversation.bind();
91 }
92 }
93 }
94
95 @Override
96 public void update(CdmDataChangeMap arg0) {
97 }
98
99 @Override
100 public ConversationHolder getConversationHolder() {
101 return conversation;
102 }
103
104 }