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 java.io.IOException;
19: import java.io.PrintWriter;
20:
21: import javax.servlet.ServletConfig;
22: import javax.servlet.ServletException;
23: import javax.servlet.http.HttpServlet;
24: import javax.servlet.http.HttpServletRequest;
25: import javax.servlet.http.HttpServletResponse;
26:
27: import edu.yale.its.tp.cas.ticket.ServiceTicket;
28: import edu.yale.its.tp.cas.ticket.ServiceTicketCache;
29:
30: /**
31: * Handles simple ST validations for the Central Authentication Service.
32: */
33: public class LegacyValidate extends HttpServlet {
34:
35: // *********************************************************************
36: // Private state
37:
38: private ServiceTicketCache stCache;
39:
40: // *********************************************************************
41: // Initialization
42:
43: public void init(ServletConfig config) throws ServletException {
44: // retrieve the cache
45: stCache = (ServiceTicketCache) config.getServletContext()
46: .getAttribute("stCache");
47: }
48:
49: // *********************************************************************
50: // Request handling
51:
52: public void doGet(HttpServletRequest request,
53: HttpServletResponse response) {
54: try {
55: PrintWriter out = response.getWriter();
56: if (request.getParameter("service") == null
57: || request.getParameter("ticket") == null) {
58: out.print("no\n\n");
59: } else {
60: String ticket = request.getParameter("ticket");
61: String service = request.getParameter("service");
62: String renew = request.getParameter("renew");
63: ServiceTicket st = (ServiceTicket) stCache
64: .getTicket(ticket);
65:
66: if (st == null)
67: out.print("no\n\n");
68: else if ("true".equals(renew) && !st.isFromNewLogin())
69: out.print("no\n\n");
70: else if (!st.getService().equals(service))
71: out.print("no\n\n");
72: else
73: out.print("yes\n" + st.getUsername() + "\n");
74: }
75: } catch (Exception ex) {
76: try {
77: response.getWriter().print("no\n\n");
78: } catch (IOException ignoredEx) {
79: // ignore
80: }
81: }
82: }
83: }
|