01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-util/tool-lib/src/java/org/sakaiproject/metaobj/shared/control/CheckForTimeout.java $
03: * $Id: CheckForTimeout.java 14230 2006-09-05 18:02:51Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.metaobj.shared.control;
21:
22: import java.util.List;
23:
24: import javax.servlet.http.HttpServletRequest;
25: import javax.servlet.http.HttpServletResponse;
26:
27: import org.sakaiproject.metaobj.security.AuthenticationManager;
28: import org.sakaiproject.metaobj.shared.model.Agent;
29: import org.springframework.web.servlet.HandlerInterceptor;
30: import org.springframework.web.servlet.ModelAndView;
31:
32: public class CheckForTimeout implements HandlerInterceptor {
33: private AuthenticationManager authenticationManager;
34: private String timeoutUrl;
35: private List ignoreList;
36:
37: public boolean preHandle(HttpServletRequest request,
38: HttpServletResponse response, Object handler)
39: throws Exception {
40: if (getIgnoreList().contains(request.getServletPath())) {
41: return true;
42: }
43: Agent agent = getAuthenticationManager().getAgent();
44: boolean timeOut = (agent == null || agent.getId() == null || agent
45: .getId().getValue().length() == 0);
46: if (timeOut) {
47: response.sendRedirect(getTimeoutUrl());
48: }
49: return !timeOut;
50: }
51:
52: public void postHandle(HttpServletRequest request,
53: HttpServletResponse response, Object handler,
54: ModelAndView modelAndView) throws Exception {
55: }
56:
57: public void afterCompletion(HttpServletRequest request,
58: HttpServletResponse response, Object handler, Exception ex)
59: throws Exception {
60: }
61:
62: public AuthenticationManager getAuthenticationManager() {
63: return authenticationManager;
64: }
65:
66: public void setAuthenticationManager(
67: AuthenticationManager authenticationManager) {
68: this .authenticationManager = authenticationManager;
69: }
70:
71: public String getTimeoutUrl() {
72: return timeoutUrl;
73: }
74:
75: public void setTimeoutUrl(String timeoutUrl) {
76: this .timeoutUrl = timeoutUrl;
77: }
78:
79: public List getIgnoreList() {
80: return ignoreList;
81: }
82:
83: public void setIgnoreList(List ignoreList) {
84: this.ignoreList = ignoreList;
85: }
86: }
|