KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > communicator > admin > controller > ChangePasswordAction


1 /*
2  * ChangePasswordAction.java
3  *
4  * Created on May 8, 2003, 5:14 PM
5  */

6
7 package com.quikj.application.communicator.admin.controller;
8
9 import javax.servlet.http.*;
10 import org.apache.struts.action.*;
11 import java.sql.*;
12 import com.quikj.application.communicator.admin.model.*;
13 import com.quikj.server.framework.*;
14
15 /**
16  *
17  * @author bhm
18  */

19 public class ChangePasswordAction extends Action
20 {
21     
22     /** Creates a new instance of ChangePasswordAction */
23     public ChangePasswordAction()
24     {
25     }
26     
27     public ActionForward execute(ActionMapping mapping,
28     ActionForm form,
29     HttpServletRequest request,
30     HttpServletResponse response)
31     {
32         ChangePasswordForm f = (ChangePasswordForm)form; // get the form bean
33
ActionErrors errors = new ActionErrors();
34         
35         Connection c = (Connection)request.getSession().getAttribute("connection");
36         if (c == null)
37         {
38             errors.add(ActionErrors.GLOBAL_ERROR,
39             new ActionError("error.not.logged.in"));
40             saveErrors(request, errors);
41             return mapping.findForward("logon");
42         }
43         
44         AccountsTable accounts = new AccountsTable(AdminConfig.getInstance().getDBParams().getAdminDb());
45         accounts.setConnection(c);
46         
47         AccountElement element = (AccountElement)request.getSession().getAttribute("userInfo");
48         String JavaDoc name = element.getName();
49         
50         if (accounts.changePassword(name, f.getOldPassword(), f.getNewPassword()) == false)
51         {
52             AceLogger.Instance().log(AceLogger.WARNING, AceLogger.SYSTEM_LOG,
53             "ChangePasswordAction.execute()/by-"
54             + element.getName()
55             + ": "
56             + accounts.getErrorMessage());
57
58             errors.add(ActionErrors.GLOBAL_ERROR,
59             new ActionError("error.password.invalid"));
60         }
61         
62         // if errors were encountered
63
if (errors.isEmpty() == false)
64         {
65             // Report any errors we have discovered back to the original form
66
saveErrors(request, errors);
67             return (new ActionForward(mapping.getInput()));
68         }
69         
70         AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG,
71         "User " + name + " changed his/her own password");
72
73         // Remove the obsolete form bean
74
if (mapping.getAttribute() != null)
75         {
76             if (mapping.getScope().equals("request") == true)
77             {
78                 request.removeAttribute(mapping.getAttribute());
79             }
80             else
81             {
82                 request.getSession().removeAttribute(mapping.getAttribute());
83             }
84         }
85         
86         // forward control to the main menu
87
ActionMessages messages = new ActionMessages();
88         
89         messages.add(ActionMessages.GLOBAL_MESSAGE,
90         new ActionMessage("message.password.changed"));
91         saveMessages(request, messages);
92         return mapping.findForward("main_menu");
93     }
94 }
95
Popular Tags