01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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 edu.yale.its.tp.cas.servlet;
17:
18: import javax.servlet.ServletContext;
19: import javax.servlet.ServletContextEvent;
20: import javax.servlet.ServletContextListener;
21:
22: import edu.yale.its.tp.cas.ticket.GrantorCache;
23: import edu.yale.its.tp.cas.ticket.LoginTicketCache;
24: import edu.yale.its.tp.cas.ticket.ProxyGrantingTicket;
25: import edu.yale.its.tp.cas.ticket.ProxyTicket;
26: import edu.yale.its.tp.cas.ticket.ServiceTicket;
27: import edu.yale.its.tp.cas.ticket.ServiceTicketCache;
28: import edu.yale.its.tp.cas.ticket.TicketGrantingTicket;
29:
30: /**
31: * Sets up shared ticket caches for the CAS web application.
32: */
33: public class CacheInit implements ServletContextListener {
34:
35: // *********************************************************************
36: // KFSConstants
37:
38: private static final int GRANTING_TIMEOUT_DEFAULT = 2 * 60 * 60;
39: private static final int SERVICE_TIMEOUT_DEFAULT = 5 * 60;
40: private static final int LOGIN_TIMEOUT_DEFAULT = 12 * 60 * 60;
41:
42: // *********************************************************************
43: // Initialization
44:
45: public void contextInitialized(ServletContextEvent sce) {
46: // retrieve appropriate initialization parameters
47: ServletContext app = sce.getServletContext();
48: String grantingTimeoutString = app
49: .getInitParameter("edu.yale.its.tp.cas.grantingTimeout");
50: String serviceTimeoutString = app
51: .getInitParameter("edu.yale.its.tp.cas.serviceTimeout");
52: String loginTimeoutString = app
53: .getInitParameter("edu.yale.its.tp.cas.loginTimeout");
54: int grantingTimeout, serviceTimeout, loginTimeout;
55: try {
56: grantingTimeout = Integer.parseInt(grantingTimeoutString);
57: } catch (NumberFormatException ex) {
58: grantingTimeout = GRANTING_TIMEOUT_DEFAULT;
59: } catch (NullPointerException ex) {
60: grantingTimeout = GRANTING_TIMEOUT_DEFAULT;
61: }
62: try {
63: serviceTimeout = Integer.parseInt(serviceTimeoutString);
64: } catch (NumberFormatException ex) {
65: serviceTimeout = SERVICE_TIMEOUT_DEFAULT;
66: } catch (NullPointerException ex) {
67: serviceTimeout = SERVICE_TIMEOUT_DEFAULT;
68: }
69: try {
70: loginTimeout = Integer.parseInt(loginTimeoutString);
71: } catch (NumberFormatException ex) {
72: loginTimeout = LOGIN_TIMEOUT_DEFAULT;
73: } catch (NullPointerException ex) {
74: loginTimeout = LOGIN_TIMEOUT_DEFAULT;
75: }
76:
77: // set up the caches...
78: GrantorCache tgcCache = new GrantorCache(
79: TicketGrantingTicket.class, grantingTimeout);
80: GrantorCache pgtCache = new GrantorCache(
81: ProxyGrantingTicket.class, grantingTimeout);
82: ServiceTicketCache stCache = new ServiceTicketCache(
83: ServiceTicket.class, serviceTimeout);
84: ServiceTicketCache ptCache = new ServiceTicketCache(
85: ProxyTicket.class, serviceTimeout);
86: LoginTicketCache ltCache = new LoginTicketCache(loginTimeout);
87:
88: // ... and share them
89: app.setAttribute("tgcCache", tgcCache);
90: app.setAttribute("pgtCache", pgtCache);
91: app.setAttribute("stCache", stCache);
92: app.setAttribute("ptCache", ptCache);
93: app.setAttribute("ltCache", ltCache);
94: }
95:
96: public void contextDestroyed(ServletContextEvent sce) {
97: }
98:
99: }
|