View Javadoc

1   /*
2    * Copyright [2006] [University Corporation for Advanced Internet Development, Inc.]
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package edu.internet2.middleware.shibboleth.idp.authn.provider;
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  
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import edu.internet2.middleware.shibboleth.idp.authn.AuthenticationEngine;
30  import edu.internet2.middleware.shibboleth.idp.authn.LoginHandler;
31  
32  /**
33   * Extracts the REMOTE_USER and places it in a request attribute to be used by the authentication engine.
34   */
35  public class RemoteUserAuthServlet extends HttpServlet {
36  
37      /** Serial version UID. */
38      private static final long serialVersionUID = 1745454095756633626L;
39  
40      /** Class logger. */
41      private final Logger log = LoggerFactory.getLogger(RemoteUserAuthServlet.class);
42  
43      /** {@inheritDoc} */
44      protected void service(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException,
45              IOException {
46          String principalName = httpRequest.getRemoteUser();
47  
48          log.debug("Remote user identified as {} returning control back to authentication engine", principalName);
49          httpRequest.setAttribute(LoginHandler.PRINCIPAL_NAME_KEY, httpRequest.getRemoteUser());
50          AuthenticationEngine.returnToAuthenticationEngine(httpRequest, httpResponse);
51      }
52  }