1 package org.sourceforge.vlibrary.security.actions;
2
3 import java.util.ArrayList;
4 import javax.servlet.http.HttpServletRequest;
5 import javax.servlet.http.HttpServletResponse;
6 import org.apache.struts.action.ActionForm;
7 import org.apache.struts.action.ActionForward;
8 import org.apache.struts.action.ActionMapping;
9 import org.apache.struts.util.MessageResources;
10 import org.apache.log4j.Logger;
11
12 import org.sourceforge.vlibrary.Constants;
13 import org.sourceforge.vlibrary.exceptions.LibraryException;
14 import org.sourceforge.vlibrary.security.forms.AdminPasswordResetForm;
15 import org.sourceforge.vlibrary.security.forms.PasswordResetForm;
16 import org.sourceforge.vlibrary.user.exceptions.ReaderNotFoundException;
17 import org.sourceforge.vlibrary.user.actions.LibraryAction;
18
19
20
21
22
23
24
25 public class PasswordResetAction extends LibraryAction {
26
27
28 private static Logger logger =
29 Logger.getLogger(PasswordResetAction.class.getName());
30
31
32
33
34
35
36
37
38
39
40
41
42 public ActionForward executeAction(ActionMapping mapping, ActionForm form,
43 HttpServletRequest request, HttpServletResponse response,
44 MessageResources messages) throws Exception {
45 ArrayList errors = new ArrayList();
46
47
48
49
50
51 String uid = null;
52 String newPwd = null;
53
54 if (mapping.getPath().startsWith(Constants.ADMIN_PATH)) {
55 AdminPasswordResetForm frm = (AdminPasswordResetForm) form;
56 newPwd = frm.getPwd();
57 uid = frm.getUid();
58 } else {
59 PasswordResetForm frm = (PasswordResetForm) form;
60 newPwd = frm.getPwd();
61 uid = request.getRemoteUser();
62 }
63
64 try {
65 logger.info(messages.getMessage("reader.resetting.password", uid));
66
67
68
69 if (libraryManager.retrieveByUid(uid) == null) {
70 String errMsg = messages.getMessage(
71 "error.nonexistent.reader", uid);
72 logger.error(errMsg);
73 throw new ReaderNotFoundException(errMsg);
74 }
75
76 libraryManager.resetPassword(uid, newPwd);
77 logger.info(messages.getMessage("reader.password.reset.successful",
78 uid));
79 } catch (Throwable t) {
80 String errString = messages.getMessage("error.password.reset", uid);
81 logger.error(errString, t);
82 errors.add(new LibraryException(errString, t));
83 }
84
85 return standardForward(mapping, request, errors);
86 }
87 }