| 1 |
// |
| 2 |
// ======================================================================== |
| 3 |
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. |
| 4 |
// |
| 5 |
// This program and the accompanying materials are made available under the |
| 6 |
// terms of the Eclipse Public License v. 2.0 which is available at |
| 7 |
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| 8 |
// which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| 9 |
// |
| 10 |
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| 11 |
// ======================================================================== |
| 12 |
// |
| 13 |
|
| 14 |
package org.example; |
| 15 |
|
| 16 |
import java.io.IOException; |
| 17 |
|
| 18 |
import jakarta.servlet.ServletConfig; |
| 19 |
import jakarta.servlet.ServletException; |
| 20 |
import jakarta.servlet.ServletOutputStream; |
| 21 |
import jakarta.servlet.http.HttpServlet; |
| 22 |
import jakarta.servlet.http.HttpServletRequest; |
| 23 |
import jakarta.servlet.http.HttpServletResponse; |
| 24 |
|
| 25 |
/** |
| 26 |
* Dump Servlet Request. |
| 27 |
*/ |
| 28 |
public class LoginServlet extends HttpServlet |
| 29 |
{ |
| 30 |
|
| 31 |
@Override |
| 32 |
public void init(ServletConfig config) throws ServletException |
| 33 |
{ |
| 34 |
super.init(config); |
| 35 |
} |
| 36 |
|
| 37 |
@Override |
| 38 |
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException |
| 39 |
{ |
| 40 |
doGet(request, response); |
| 41 |
} |
| 42 |
|
| 43 |
@Override |
| 44 |
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException |
| 45 |
{ |
| 46 |
response.setContentType("text/html"); |
| 47 |
ServletOutputStream out = response.getOutputStream(); |
| 48 |
out.println("<html>"); |
| 49 |
out.println("<br/>Before getUserPrincipal=" + request.getUserPrincipal()); |
| 50 |
out.println("<br/>Before getRemoteUser=" + request.getRemoteUser()); |
| 51 |
String param = request.getParameter("action"); |
| 52 |
|
| 53 |
if ("login".equals(param)) |
| 54 |
{ |
| 55 |
request.login("jetty", "jetty"); |
| 56 |
} |
| 57 |
else if ("logout".equals(param)) |
| 58 |
{ |
| 59 |
request.logout(); |
| 60 |
} |
| 61 |
else if ("wrong".equals(param)) |
| 62 |
{ |
| 63 |
request.login("jetty", "123"); |
| 64 |
} |
| 65 |
|
| 66 |
out.println("<br/>After getUserPrincipal=" + request.getUserPrincipal()); |
| 67 |
out.println("<br/>After getRemoteUser=" + request.getRemoteUser()); |
| 68 |
out.println("</html>"); |
| 69 |
out.flush(); |
| 70 |
} |
| 71 |
} |