001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.web.backdoor;
018:
019: import javax.servlet.http.HttpServletRequest;
020: import javax.servlet.http.HttpServletResponse;
021:
022: import org.apache.commons.lang.StringUtils;
023: import org.apache.struts.action.ActionForm;
024: import org.apache.struts.action.ActionForward;
025: import org.apache.struts.action.ActionMapping;
026: import org.apache.struts.action.ActionMessages;
027:
028: import edu.iu.uis.eden.EdenConstants;
029: import edu.iu.uis.eden.KEWServiceLocator;
030: import edu.iu.uis.eden.doctype.DocumentType;
031: import edu.iu.uis.eden.util.Utilities;
032: import edu.iu.uis.eden.web.WorkflowAction;
033: import edu.iu.uis.eden.web.session.UserSession;
034: import edu.iu.uis.eden.workgroup.GroupNameId;
035: import edu.iu.uis.eden.workgroup.Workgroup;
036: import edu.iu.uis.eden.workgroup.WorkgroupService;
037:
038: /**
039: * A Struts Action which permits a user to execute a backdoor login to masquerade
040: * as another user.
041: *
042: * @author rkirkend
043: */
044: public class BackdoorAction extends WorkflowAction {
045:
046: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
047: .getLogger(BackdoorAction.class);
048:
049: public ActionForward menu(ActionMapping mapping, ActionForm form,
050: HttpServletRequest request, HttpServletResponse response)
051: throws Exception {
052: LOG.debug("start");
053: BackdoorForm backdoorForm = (BackdoorForm) form;
054: backdoorForm
055: .setTargetName(Utilities
056: .getApplicationConstant("Config.Backdoor.TargetFrameName"));
057: return mapping.findForward("viewBackdoor");
058: }
059:
060: public ActionForward start(ActionMapping mapping, ActionForm form,
061: HttpServletRequest request, HttpServletResponse response)
062: throws Exception {
063: LOG.debug("start");
064: return portal(mapping, form, request, response);
065: }
066:
067: public ActionForward portal(ActionMapping mapping, ActionForm form,
068: HttpServletRequest request, HttpServletResponse response)
069: throws Exception {
070: LOG.debug("portal started");
071: BackdoorForm backdoorForm = (BackdoorForm) form;
072: backdoorForm
073: .setTargetName(Utilities
074: .getApplicationConstant("Config.Backdoor.TargetFrameName"));
075: //LOG.debug(backdoorForm.getGraphic());
076: return mapping.findForward("viewPortal");
077: }
078:
079: public ActionForward administration(ActionMapping mapping,
080: ActionForm form, HttpServletRequest request,
081: HttpServletResponse response) throws Exception {
082: LOG.debug("administration");
083: BackdoorForm backdoorForm = (BackdoorForm) form;
084: backdoorForm
085: .setTargetName(Utilities
086: .getApplicationConstant("Config.Backdoor.TargetFrameName"));
087: return mapping.findForward("administration");
088: }
089:
090: public ActionForward logout(ActionMapping mapping, ActionForm form,
091: HttpServletRequest request, HttpServletResponse response)
092: throws Exception {
093: LOG.debug("logout");
094: UserSession uSession = getUserSession(request);
095: uSession.clearBackdoor();
096: setFormGroupPermission((BackdoorForm) form, request);
097: //request.setAttribute("reloadPage","true");
098: return mapping.findForward("viewPortal");
099:
100: }
101:
102: public ActionForward login(ActionMapping mapping, ActionForm form,
103: HttpServletRequest request, HttpServletResponse response)
104: throws Exception {
105: LOG.debug("login");
106: /*
107: UserSession uSession = getUserSession(request);
108: BackdoorForm backdoorForm = (BackdoorForm) form;
109: try{
110: uSession.setBackdoorId(backdoorForm.getBackdoorId());
111: backdoorForm.setBackdoorId(uSession.getNetworkId());
112: //setFormGroupPermission(backdoorForm, request);
113: //set up preferences as backdoor person
114: //uSession.setPreferences(SpringServiceLocator.getPreferencesService().getPreferences(uSession.getWorkflowUser()));
115: //request.setAttribute("reloadPage","true");
116:
117: }catch(EdenUserNotFoundException ex){
118: uSession.setBackdoorId(null);
119: backdoorForm.setBackdoorId(null);
120: request.setAttribute("BackdoorException","No such user found. Login failure!");
121: }
122: setFormGroupPermission(backdoorForm, request);
123: uSession.setPreferences(SpringServiceLocator.getPreferencesService().getPreferences(uSession.getWorkflowUser()));
124: return mapping.findForward("viewPortal");
125: */
126: UserSession uSession = getUserSession(request);
127: BackdoorForm backdoorForm = (BackdoorForm) form;
128: if (!uSession.setBackdoorId(backdoorForm.getBackdoorId())) {
129: request.setAttribute("badbackdoor",
130: "Invalid backdoor Id given '"
131: + backdoorForm.getBackdoorId() + "'");
132: return mapping.findForward("viewBackdoor");
133: }
134: backdoorForm.setBackdoorId(uSession.getNetworkId());
135: setFormGroupPermission(backdoorForm, request);
136: //set up preferences as backdoor person
137: uSession.setPreferences(KEWServiceLocator
138: .getPreferencesService().getPreferences(
139: uSession.getWorkflowUser()));
140: //request.setAttribute("reloadPage","true");
141: return mapping.findForward("viewPortal");
142:
143: }
144:
145: private void setFormGroupPermission(BackdoorForm backdoorForm,
146: HttpServletRequest request) {
147: Workgroup workflowAdminGroup = getWorkgroupService()
148: .getWorkgroup(
149: new GroupNameId(
150: Utilities
151: .getApplicationConstant(EdenConstants.WORKFLOW_ADMIN_WORKGROUP_NAME_KEY)));
152: backdoorForm.setIsWorkflowAdmin(new Boolean(workflowAdminGroup
153: .hasMember(getUserSession(request).getWorkflowUser())));
154: }
155:
156: public ActionMessages establishRequiredState(
157: HttpServletRequest request, ActionForm form)
158: throws Exception {
159: BackdoorForm backdoorForm = (BackdoorForm) form;
160: String showBackdoorLoginValue = Utilities
161: .getApplicationConstant(EdenConstants.SHOW_BACK_DOOR_LOGIN_KEY);
162: // default to true if not defined
163: Boolean showBackdoorLogin = Boolean.TRUE;
164: if (!StringUtils.isEmpty(showBackdoorLoginValue)) {
165: showBackdoorLogin = new Boolean(showBackdoorLoginValue);
166: }
167: backdoorForm.setShowBackdoorLogin(showBackdoorLogin);
168: setFormGroupPermission(backdoorForm, request);
169: if (backdoorForm.getGraphic() != null) {
170: request.getSession().setAttribute("showGraphic",
171: backdoorForm.getGraphic());
172: }
173: return null;
174: }
175:
176: private WorkgroupService getWorkgroupService() {
177: return (WorkgroupService) KEWServiceLocator
178: .getService(KEWServiceLocator.WORKGROUP_SRV);
179: }
180: }
|