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.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: private static final Log log = LogFactory
45: .getLog(LoginServlet.class);
46:
47: public void doGet(HttpServletRequest request,
48: HttpServletResponse response) throws IOException,
49: ServletException {
50: HttpSession session = request.getSession(true);
51:
52: if (request.getUserPrincipal() != null) {
53: String destination = (String) session
54: .getAttribute(LoginConstants.DESTINATION);
55: if (destination == null)
56: destination = request.getContextPath() + "/";
57:
58: response.sendRedirect(response.encodeURL(destination));
59: }
60:
61: if (Jetspeed.getEngine() != null) {
62: request.setAttribute(PortalReservedParameters.PIPELINE,
63: PortalReservedParameters.LOGIN_PIPELINE);
64: Engine engine = Jetspeed.getEngine();
65: try {
66: RequestContextComponent contextComponent = (RequestContextComponent) Jetspeed
67: .getComponentManager().getComponent(
68: RequestContextComponent.class);
69: RequestContext context = contextComponent.create(
70: request, response, getServletConfig());
71: engine.service(context);
72: contextComponent.release(context);
73: } catch (JetspeedException e) {
74: log.warn("Jetspeed engine does not work properly.", e);
75: // forward to JetspeedServlet
76: response.sendRedirect(response.encodeURL(request
77: .getContextPath()
78: + "/"));
79: }
80: } else {
81: // forward to JetspeedServlet to create Engine
82: response.sendRedirect(response.encodeURL(request
83: .getContextPath()
84: + "/"));
85: }
86: }
87:
88: public final void doPost(HttpServletRequest request,
89: HttpServletResponse response) throws IOException,
90: ServletException {
91: doGet(request, response);
92: }
93: }
|