View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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          // create the session
58          request.getSession(true);
59          
60          // authenticated
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  }