RemoteUserAuthServlet xref

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  import edu.internet2.middleware.shibboleth.idp.authn.UsernamePrincipal;
    32
    33  /** Extracts the REMOTE_USER and places it in a request attribute to be used by the authentication engine. */
    34  public class RemoteUserAuthServlet extends HttpServlet {
    35
    36      /** Serial version UID. */
    37      private static final long serialVersionUID = -6153665874235557534L;
    38
    39      /** Class logger. */
    40      private final Logger log = LoggerFactory.getLogger(RemoteUserAuthServlet.class);
    41
    42      /** {@inheritDoc} */
    43      protected void service(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException,
    44              IOException {
    45          String principalName = httpRequest.getRemoteUser();
    46
    47          log.debug("Remote user identified as {} returning control back to authentication engine", principalName);
    48          httpRequest.setAttribute(LoginHandler.PRINCIPAL_KEY, new UsernamePrincipal(principalName));
    49          AuthenticationEngine.returnToAuthenticationEngine(httpRequest, httpResponse);
    50      }
    51  }