1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.login;
18
19 import java.io.IOException;
20
21 import javax.servlet.ServletException;
22 import javax.servlet.http.HttpServlet;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 import javax.servlet.http.HttpSession;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.jetspeed.Jetspeed;
30 import org.apache.jetspeed.PortalReservedParameters;
31 import org.apache.jetspeed.engine.Engine;
32 import org.apache.jetspeed.exception.JetspeedException;
33 import org.apache.jetspeed.request.RequestContext;
34 import org.apache.jetspeed.request.RequestContextComponent;
35
36 /***
37 * LoginServlet
38 *
39 * @author <a href="mailto:ate@douma.nu">Ate Douma </a>
40 * @author <a href="mailto:shinsuke@yahoo.co.jp">Shinsuke Sugaya</a>
41 * @version $Id: LoginServlet.java 516881 2007-03-11 10:34:21Z ate $
42 */
43 public class LoginServlet extends HttpServlet
44 {
45 private static final Log log = LogFactory.getLog(LoginServlet.class);
46
47 public void doGet(HttpServletRequest request,
48 HttpServletResponse response) throws IOException, ServletException
49 {
50 HttpSession session = request.getSession(true);
51
52 if (request.getUserPrincipal() != null)
53 {
54 String destination = (String) session
55 .getAttribute(LoginConstants.DESTINATION);
56 if (destination == null)
57 destination = request.getContextPath() + "/";
58
59 response.sendRedirect(response.encodeURL(destination));
60 }
61
62 if (Jetspeed.getEngine() != null)
63 {
64 request.setAttribute(PortalReservedParameters.PIPELINE, PortalReservedParameters.LOGIN_PIPELINE);
65 Engine engine = Jetspeed.getEngine();
66 try
67 {
68 RequestContextComponent contextComponent = (RequestContextComponent) Jetspeed.getComponentManager()
69 .getComponent(RequestContextComponent.class);
70 RequestContext context = contextComponent.create(request, response, getServletConfig());
71 engine.service(context);
72 contextComponent.release(context);
73 }
74 catch (JetspeedException e)
75 {
76 log.warn("Jetspeed engine does not work properly.", e);
77
78 response.sendRedirect(response.encodeURL(request.getContextPath() + "/"));
79 }
80 }
81 else
82 {
83
84 response.sendRedirect(response.encodeURL(request.getContextPath() + "/"));
85 }
86 }
87
88 public final void doPost(HttpServletRequest request,
89 HttpServletResponse response) throws IOException, ServletException
90 {
91 doGet(request, response);
92 }
93 }