001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.security.token.delegation.web;
019
020import org.apache.hadoop.classification.InterfaceAudience;
021import org.apache.hadoop.classification.InterfaceStability;
022import org.apache.hadoop.security.UserGroupInformation;
023import org.apache.hadoop.security.authentication.client.PseudoAuthenticator;
024
025import java.io.IOException;
026
027/**
028 * The <code>PseudoDelegationTokenAuthenticator</code> provides support for
029 * Hadoop's pseudo authentication mechanism that accepts
030 * the user name specified as a query string parameter and support for Hadoop
031 * Delegation Token operations.
032 * <p/>
033 * This mimics the model of Hadoop Simple authentication trusting the
034 * {@link UserGroupInformation#getCurrentUser()} value.
035 */
036@InterfaceAudience.Public
037@InterfaceStability.Evolving
038public class PseudoDelegationTokenAuthenticator
039    extends DelegationTokenAuthenticator {
040
041  public PseudoDelegationTokenAuthenticator() {
042    super(new PseudoAuthenticator() {
043      @Override
044      protected String getUserName() {
045        try {
046          return UserGroupInformation.getCurrentUser().getShortUserName();
047        } catch (IOException ex) {
048          throw new RuntimeException(ex);
049        }
050      }
051    });
052  }
053
054}