01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: * SSOBasicDemoServlet - this will only run in Tomcat 4 and 5
29: * where there is a tomcat user name tomcat with the password tomcat
30: * and with a role named tomcat.
31: *
32: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
33: * @version $Id: SSOBasicDemoServlet.java 516448 2007-03-09 16:25:47Z ate $
34: */
35: public class SSOBasicDemoServlet extends HttpServlet {
36: public final static String DEMO_SSO_PRINCIPAL_PARAM = "sso-principal";
37: public final static String DEMO_SSO_CREDENTIAL_PARAM = "sso-credential";
38: public final static String DEMO_SSO_CREDENTIAL = "secret-password";
39:
40: public final void doGet(HttpServletRequest request,
41: HttpServletResponse response) throws IOException,
42: ServletException {
43: String authenticatedPrincipal = "";
44:
45: Principal userPrincipal = request.getUserPrincipal();
46: if (userPrincipal == null) {
47: authenticatedPrincipal = "guest";
48: } else {
49: authenticatedPrincipal = userPrincipal.toString();
50: }
51:
52: // create the session
53: request.getSession(true);
54:
55: // authenticated
56: response
57: .getWriter()
58: .println(
59: "<b>Welcome to the Basic Authentication SSO Gateway!</b><br/>");
60: response.getWriter().println(
61: "Remote Principal has been authenticated.<br/>");
62: response.getWriter().println(
63: "Remote User = " + authenticatedPrincipal + "<br/>");
64: }
65:
66: public final void doPost(HttpServletRequest req,
67: HttpServletResponse res) throws IOException,
68: ServletException {
69: doGet(req, res);
70: }
71:
72: }
|