1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.modules.actions;
18
19
20 import org.apache.jetspeed.services.JetspeedSecurity;
21 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
22 import org.apache.jetspeed.services.logging.JetspeedLogger;
23 import org.apache.jetspeed.services.resources.JetspeedResources;
24 import org.apache.jetspeed.om.security.JetspeedUser;
25 import org.apache.jetspeed.services.rundata.JetspeedRunData;
26 import org.apache.jetspeed.services.Profiler;
27
28
29 import org.apache.turbine.modules.Action;
30 import org.apache.turbine.modules.ActionLoader;
31 import org.apache.turbine.services.localization.Localization;
32 import org.apache.turbine.util.RunData;
33 import org.apache.turbine.TurbineConstants;
34
35 /***
36 * Performs change password action
37 *
38 * @author <a href="morciuch@apache.org">Mark Orciuch</a>
39 * @version $Id: ChangePassword.java,v 1.7 2004/02/23 02:59:06 jford Exp $
40 */
41 public class ChangePassword extends Action
42 {
43
44 /***
45 * Static initialization of the logger for this class
46 */
47 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(ChangePassword.class.getName());
48
49 public void doPerform(RunData rundata) throws Exception
50 {
51
52 String cancelBtn = rundata.getParameters().getString(Localization.getString(rundata, "PASSWORDFORM_CANCEL"));
53 String username = rundata.getParameters().getString("username" , "");
54 String oldPassword = JetspeedSecurity.convertPassword(rundata.getParameters().getString("old_password" , ""));
55 String password = JetspeedSecurity.convertPassword(rundata.getParameters().getString("password", ""));
56 String password2 = JetspeedSecurity.convertPassword(rundata.getParameters().getString("password_confirm", ""));
57
58
59
60
61
62 if (cancelBtn != null && cancelBtn.equalsIgnoreCase(Localization.getString(rundata, "PASSWORDFORM_CANCEL")))
63 {
64 return;
65 }
66
67 String returnTemplate = JetspeedResources.getString(JetspeedResources.CHANGE_PASSWORD_TEMPLATE, "ChangePassword");
68
69 try
70 {
71
72 JetspeedUser user = JetspeedSecurity.getUser(username);
73
74 if (!password.equals(password2))
75 {
76 rundata.setMessage(Localization.getString(rundata, "UPDATEACCOUNT_PWNOTMATCH"));
77 rundata.setScreenTemplate(returnTemplate);
78 return;
79 }
80
81 if (password.equals(oldPassword))
82 {
83 rundata.setMessage(Localization.getString(rundata, "PASSWORDFORM_THESAME_MSG"));
84 rundata.setScreenTemplate(returnTemplate);
85 return;
86 }
87
88
89 JetspeedSecurity.changePassword(user, oldPassword, password);
90 rundata.setMessage(Localization.getString(rundata, "PASSWORDFORM_DONE"));
91
92
93 rundata.getParameters().setString("username", username);
94 rundata.getParameters().setString("password", password);
95 String userRequestsRememberMe = rundata.getParameters().getString("rememberme");
96 rundata.getParameters().setString("rememberme", userRequestsRememberMe);
97 ActionLoader.getInstance().getInstance(
98 JetspeedResources.getString(TurbineConstants.ACTION_LOGIN)
99 ).doPerform(rundata);
100
101
102 JetspeedRunData jdata = (JetspeedRunData) rundata;
103 jdata.setProfile(Profiler.getProfile(jdata));
104
105 }
106 catch (Exception e)
107 {
108 logger.error("Exception", e);
109 rundata.setMessage(e.getMessage() != null ? e.getMessage() : e.toString());
110 rundata.setScreenTemplate(returnTemplate);
111 }
112 }
113
114 }