001 /** 002 * Copyright 2004-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.hr.time.base.web; 017 018 import javax.servlet.http.HttpServletRequest; 019 import javax.servlet.http.HttpServletResponse; 020 021 import org.apache.log4j.Logger; 022 import org.apache.struts.action.ActionForm; 023 import org.apache.struts.action.ActionForward; 024 import org.apache.struts.action.ActionMapping; 025 import org.apache.struts.action.ActionRedirect; 026 import org.kuali.hr.time.util.TKContext; 027 import org.kuali.hr.time.util.TKUser; 028 import org.kuali.hr.time.util.TkConstants; 029 import org.kuali.rice.kns.web.struts.action.KualiAction; 030 import org.kuali.rice.krad.UserSession; 031 import org.kuali.rice.krad.exception.AuthorizationException; 032 import org.kuali.rice.krad.util.GlobalVariables; 033 034 public class TkAction extends KualiAction { 035 036 private static final Logger LOG = Logger.getLogger(TkAction.class); 037 038 039 protected void checkTKAuthorization(ActionForm form, String methodToCall) throws AuthorizationException { 040 } 041 042 @Override 043 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 044 try { 045 String methodToCall = null; 046 if (form instanceof TkForm) { 047 methodToCall = ((TkForm)form).getMethodToCall(); 048 } 049 checkTKAuthorization(form, methodToCall); 050 } catch (AuthorizationException e) { 051 LOG.error("User: " + TKContext.getPrincipalId() + " Target: " + TKContext.getTargetPrincipalId(), e); 052 return mapping.findForward("unauthorized"); 053 } 054 055 // Run our logic / security first - For some reason kuali 056 // dispatches actions BEFORE checking the security... 057 058 return super.execute(mapping, form, request, response); 059 } 060 061 public ActionForward userLogout(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 062 TKContext.clear(); 063 request.getSession().invalidate(); 064 ActionRedirect redirect = new ActionRedirect(); 065 redirect.setPath("portal.do"); 066 return redirect; 067 } 068 069 }