View Javadoc

1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.kpme.core.web;
17  
18  import javax.servlet.http.HttpServletRequest;
19  import javax.servlet.http.HttpServletResponse;
20  
21  import org.apache.log4j.Logger;
22  import org.apache.struts.action.ActionForm;
23  import org.apache.struts.action.ActionForward;
24  import org.apache.struts.action.ActionMapping;
25  import org.apache.struts.action.ActionRedirect;
26  import org.kuali.kpme.core.util.HrContext;
27  import org.kuali.rice.kns.web.struts.action.KualiAction;
28  import org.kuali.rice.krad.exception.AuthorizationException;
29  
30  public class KPMEAction extends KualiAction {
31  
32      private static final Logger LOG = Logger.getLogger(KPMEAction.class);
33  
34  
35      protected void checkTKAuthorization(ActionForm form, String methodToCall) throws AuthorizationException {
36      }
37  
38      @Override
39      public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
40          try {
41              String methodToCall = null;
42              if (form instanceof KPMEForm) {
43                  methodToCall = ((KPMEForm)form).getMethodToCall();
44              }
45              checkTKAuthorization(form, methodToCall);
46          } catch (AuthorizationException e) {
47              LOG.error("User: " + HrContext.getPrincipalId() + " Target: " + HrContext.getTargetPrincipalId(), e);
48              return mapping.findForward("unauthorized");
49          }
50  
51          // Run our logic / security first - For some reason kuali
52          // dispatches actions BEFORE checking the security...
53  
54          return super.execute(mapping, form, request, response);
55      }
56  
57  	public ActionForward userLogout(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
58  		request.getSession().invalidate();
59          ActionRedirect redirect = new ActionRedirect();
60          redirect.setPath("portal.do");
61  		return redirect;
62  	}
63  
64  }