1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.web.actions.admin.user;
20
21 import org.apache.log4j.Logger;
22 import org.apache.struts.action.*;
23 import org.itracker.model.User;
24 import org.itracker.model.util.UserUtilities;
25 import org.itracker.services.UserService;
26 import org.itracker.web.actions.base.ItrackerBaseAction;
27 import org.itracker.web.util.LoginUtilities;
28 import org.itracker.web.util.ServletContextUtils;
29
30 import javax.servlet.ServletException;
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.http.HttpServletResponse;
33 import java.io.IOException;
34
35
36 public class UnlockUserAction extends ItrackerBaseAction {
37 private static final Logger log = Logger.getLogger(UnlockUserAction.class);
38
39 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
40
41 ActionMessages errors = new ActionMessages();
42
43 if (!LoginUtilities.hasPermission(UserUtilities.PERMISSION_USER_ADMIN, request, response)) {
44 log.info("execute: forwarding to unauthorized for " + LoginUtilities.getCurrentUser(request));
45 return mapping.findForward("unauthorized");
46 }
47
48 try {
49 UserService userService = ServletContextUtils.getItrackerServices().getUserService();
50
51 Integer userId = Integer.valueOf((request.getParameter("id") == null ? "-1" : (request.getParameter("id"))));
52 User user = userService.getUser(userId);
53 if (log.isInfoEnabled()) {
54 log.info("Unlocking user " + user + " (id: " + userId + ")");
55 }
56 user.setStatus(UserUtilities.STATUS_ACTIVE);
57 userService.updateUser(user);
58 } catch (Exception e) {
59 log.error("execute: failed with unexpected exception", e);
60 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
61 }
62
63 if (!errors.isEmpty()) {
64 saveErrors(request, errors);
65 }
66 return mapping.findForward("listusers");
67 }
68
69 }
70