1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.demo.servlet;
18
19 import java.io.IOException;
20 import java.security.Principal;
21
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
28 /***
29 * SSOBasicDemoServlet - this will only run in Tomcat 4 and 5
30 * where there is a tomcat user name tomcat with the password tomcat
31 * and with a role named tomcat.
32 *
33 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
34 * @version $Id: SSOBasicDemoServlet.java 516448 2007-03-09 16:25:47Z ate $
35 */
36 public class SSOBasicDemoServlet extends HttpServlet
37 {
38 public final static String DEMO_SSO_PRINCIPAL_PARAM = "sso-principal";
39 public final static String DEMO_SSO_CREDENTIAL_PARAM = "sso-credential";
40 public final static String DEMO_SSO_CREDENTIAL = "secret-password";
41
42 public final void doGet(HttpServletRequest request, HttpServletResponse response)
43 throws IOException, ServletException
44 {
45 String authenticatedPrincipal = "";
46
47 Principal userPrincipal = request.getUserPrincipal();
48 if (userPrincipal == null)
49 {
50 authenticatedPrincipal = "guest";
51 }
52 else
53 {
54 authenticatedPrincipal = userPrincipal.toString();
55 }
56
57
58 request.getSession(true);
59
60
61 response.getWriter().println("<b>Welcome to the Basic Authentication SSO Gateway!</b><br/>");
62 response.getWriter().println("Remote Principal has been authenticated.<br/>");
63 response.getWriter().println("Remote User = " + authenticatedPrincipal + "<br/>");
64 }
65
66
67 public final void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
68 {
69 doGet(req, res);
70 }
71
72 }