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.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.jetspeed.Jetspeed;
28  import org.apache.jetspeed.PortalReservedParameters;
29  import org.apache.jetspeed.audit.AuditActivity;
30  
31  /***
32   * LoginRedirectorServlet
33   * 
34   * @author <a href="mailto:ate@douma.nu">Ate Douma </a>
35   * @version $Id: LoginRedirectorServlet.java 553804 2007-07-06 09:15:49Z taylor $
36   */
37  public class LoginRedirectorServlet extends HttpServlet
38  {
39  
40      public void doGet(HttpServletRequest request,
41              HttpServletResponse response) throws IOException, ServletException
42      {
43          HttpSession session = request.getSession(true);
44          String destination = (String) session
45                  .getAttribute(LoginConstants.DESTINATION);
46          if (destination == null || destination.equals(request.getContextPath()))
47              destination = request.getContextPath() + "/";
48          else
49              session.removeAttribute(LoginConstants.DESTINATION);
50  
51          String username = (String)session.getAttribute(LoginConstants.USERNAME);
52          
53          session.removeAttribute(LoginConstants.USERNAME);
54          session.removeAttribute(LoginConstants.PASSWORD);
55          session.removeAttribute(LoginConstants.RETRYCOUNT);
56          session.removeAttribute(PortalReservedParameters.PREFERED_LOCALE_ATTRIBUTE);
57  
58          AuditActivity audit = (AuditActivity)Jetspeed.getComponentManager().getComponent("org.apache.jetspeed.audit.AuditActivity");
59          if (audit != null)
60          {
61              audit.logUserActivity(username, request.getRemoteAddr(), AuditActivity.AUTHENTICATION_SUCCESS, "Active Authentication");
62          }
63          response.sendRedirect(response.encodeURL(destination));
64      }
65  
66      public final void doPost(HttpServletRequest request,
67              HttpServletResponse response) throws IOException, ServletException
68      {
69          doGet(request, response);
70      }    
71  }