View Javadoc

1   /**
2    * Copyright 2004-2012 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.hr.time.base.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.hr.time.util.TKContext;
27  import org.kuali.hr.time.util.TKUser;
28  import org.kuali.hr.time.util.TkConstants;
29  import org.kuali.rice.kns.web.struts.action.KualiAction;
30  import org.kuali.rice.krad.UserSession;
31  import org.kuali.rice.krad.exception.AuthorizationException;
32  import org.kuali.rice.krad.util.GlobalVariables;
33  
34  public class TkAction extends KualiAction {
35  
36      private static final Logger LOG = Logger.getLogger(TkAction.class);
37  
38  
39      protected void checkTKAuthorization(ActionForm form, String methodToCall) throws AuthorizationException {
40      }
41  
42      @Override
43      public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
44          try {
45              String methodToCall = null;
46              if (form instanceof TkForm) {
47                  methodToCall = ((TkForm)form).getMethodToCall();
48              }
49              checkTKAuthorization(form, methodToCall);
50          } catch (AuthorizationException e) {
51              LOG.error("User: " + TKContext.getPrincipalId() + " Target: " + TKContext.getTargetPrincipalId(), e);
52              return mapping.findForward("unauthorized");
53          }
54  
55          // Run our logic / security first - For some reason kuali
56          // dispatches actions BEFORE checking the security...
57  
58          return super.execute(mapping, form, request, response);
59      }
60  
61  	public ActionForward userLogout(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
62          TKContext.clear();
63  		request.getSession().invalidate();
64  		return new ActionRedirect(mapping.findForward("basic"));
65  	}
66  
67  }