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