1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kns.web.struts.action; |
18 | |
|
19 | |
import javax.servlet.http.HttpServletRequest; |
20 | |
import javax.servlet.http.HttpServletResponse; |
21 | |
|
22 | |
import org.apache.commons.lang.StringUtils; |
23 | |
import org.apache.struts.action.ActionForm; |
24 | |
import org.apache.struts.action.ActionForward; |
25 | |
import org.apache.struts.action.ActionMapping; |
26 | |
import org.kuali.rice.kew.util.KEWConstants; |
27 | |
import org.kuali.rice.kew.web.session.UserSession; |
28 | |
import org.kuali.rice.kim.bo.impl.KimAttributes; |
29 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
30 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
31 | |
import org.kuali.rice.kim.util.KimConstants; |
32 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
33 | |
import org.kuali.rice.kns.util.GlobalVariables; |
34 | |
import org.kuali.rice.kns.util.KNSConstants; |
35 | |
import org.kuali.rice.kns.web.struts.form.BackdoorForm; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public class BackdoorAction extends KualiAction { |
45 | |
|
46 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BackdoorAction.class); |
47 | |
|
48 | |
@Override |
49 | |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
50 | |
HttpServletRequest request, HttpServletResponse response) |
51 | |
throws Exception { |
52 | 0 | this.initForm(request, form); |
53 | 0 | return super.execute(mapping, form, request, response); |
54 | |
} |
55 | |
|
56 | |
public ActionForward menu(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
57 | 0 | LOG.debug("menu"); |
58 | 0 | return mapping.findForward("basic"); |
59 | |
} |
60 | |
|
61 | |
@Override |
62 | |
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
63 | 0 | return portal(mapping, form, request, response); |
64 | |
} |
65 | |
|
66 | |
public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
67 | 0 | LOG.debug("start"); |
68 | 0 | return portal(mapping, form, request, response); |
69 | |
} |
70 | |
|
71 | |
public ActionForward portal(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{ |
72 | 0 | LOG.debug("portal started"); |
73 | 0 | return mapping.findForward("viewPortal"); |
74 | |
} |
75 | |
|
76 | |
public ActionForward administration(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
77 | 0 | LOG.debug("administration"); |
78 | 0 | return mapping.findForward("administration"); |
79 | |
} |
80 | |
|
81 | |
public ActionForward logout(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
82 | 0 | LOG.debug("logout"); |
83 | |
|
84 | 0 | String forward = "viewPortal"; |
85 | 0 | UserSession uSession = getUserSession(request); |
86 | |
|
87 | 0 | if (uSession.isBackdoorInUse()) { |
88 | 0 | uSession.clearBackdoor(); |
89 | 0 | setFormGroupPermission((BackdoorForm)form, request); |
90 | |
|
91 | |
|
92 | |
org.kuali.rice.kns.UserSession KnsUserSession; |
93 | 0 | KnsUserSession = GlobalVariables.getUserSession(); |
94 | 0 | KnsUserSession.clearBackdoorUser(); |
95 | 0 | } |
96 | |
else { |
97 | 0 | forward = "logout"; |
98 | |
} |
99 | |
|
100 | 0 | return mapping.findForward(forward); |
101 | |
} |
102 | |
|
103 | |
public ActionForward login(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
104 | 0 | LOG.debug("login"); |
105 | 0 | UserSession uSession = getUserSession(request); |
106 | 0 | BackdoorForm backdoorForm = (BackdoorForm) form; |
107 | |
|
108 | |
|
109 | 0 | if (uSession.isBackdoorInUse() && |
110 | |
(StringUtils.isEmpty(backdoorForm.getBackdoorId()) |
111 | |
|| uSession.getActualPrincipal().getPrincipalName().equals(backdoorForm.getBackdoorId()))) { |
112 | 0 | return logout(mapping, form, request, response); |
113 | |
} |
114 | |
|
115 | 0 | if (!uSession.establishBackdoorWithPrincipalName(backdoorForm.getBackdoorId())) { |
116 | 0 | request.setAttribute("badbackdoor", "Invalid backdoor Id given '" + backdoorForm.getBackdoorId() + "'"); |
117 | 0 | return mapping.findForward("portal"); |
118 | |
} |
119 | |
|
120 | 0 | uSession.getAuthentications().clear(); |
121 | 0 | setFormGroupPermission(backdoorForm, request); |
122 | |
|
123 | 0 | return mapping.findForward("portal"); |
124 | |
} |
125 | |
|
126 | |
private void setFormGroupPermission(BackdoorForm backdoorForm, HttpServletRequest request) { |
127 | |
|
128 | |
|
129 | 0 | AttributeSet permissionDetails = new AttributeSet(); |
130 | 0 | permissionDetails.put(KimAttributes.NAMESPACE_CODE, KEWConstants.KEW_NAMESPACE); |
131 | 0 | permissionDetails.put(KimAttributes.ACTION_CLASS, "org.kuali.rice.kew.web.backdoor.AdministrationAction"); |
132 | 0 | boolean isAdmin = KIMServiceLocator.getIdentityManagementService().isAuthorizedByTemplateName(getUserSession(request).getPrincipalId(), KNSConstants.KNS_NAMESPACE, KimConstants.PermissionTemplateNames.USE_SCREEN, permissionDetails, new AttributeSet()); |
133 | 0 | backdoorForm.setIsAdmin(isAdmin); |
134 | 0 | } |
135 | |
|
136 | |
public void initForm(HttpServletRequest request, ActionForm form) throws Exception { |
137 | 0 | BackdoorForm backdoorForm = (BackdoorForm) form; |
138 | |
|
139 | 0 | Boolean showBackdoorLogin = KNSServiceLocator.getParameterService().getIndicatorParameter(KEWConstants.KEW_NAMESPACE, KNSConstants.DetailTypes.BACKDOOR_DETAIL_TYPE, KEWConstants.SHOW_BACK_DOOR_LOGIN_IND); |
140 | 0 | backdoorForm.setShowBackdoorLogin(showBackdoorLogin); |
141 | 0 | setFormGroupPermission(backdoorForm, request); |
142 | 0 | if (backdoorForm.getGraphic() != null) { |
143 | 0 | request.getSession().setAttribute("showGraphic", backdoorForm.getGraphic()); |
144 | |
} |
145 | 0 | } |
146 | |
|
147 | |
public static UserSession getUserSession(HttpServletRequest request) { |
148 | 0 | return UserSession.getAuthenticatedUser(); |
149 | |
} |
150 | |
} |