All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.hadoop.crypto.key.KeyProviderDelegationTokenExtension Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.hadoop.crypto.key;

import org.apache.hadoop.security.Credentials;
import org.apache.hadoop.security.token.Token;

import java.io.IOException;

/**
 * A KeyProvider extension with the ability to add a renewer's Delegation
 * Tokens to the provided Credentials.
 */
public class KeyProviderDelegationTokenExtension extends
    KeyProviderExtension
     {

  private static DelegationTokenExtension DEFAULT_EXTENSION =
      new DefaultDelegationTokenExtension();

  /**
   * DelegationTokenExtension is a type of Extension that exposes methods to
   * needed to work with Delegation Tokens.
   */
  public interface DelegationTokenExtension extends
    KeyProviderExtension.Extension {

    /**
     * The implementer of this class will take a renewer and add all
     * delegation tokens associated with the renewer to the
     * Credentials object if it is not already present,
     * @param renewer the user allowed to renew the delegation tokens
     * @param credentials cache in which to add new delegation tokens
     * @return list of new delegation tokens
     * @throws IOException thrown if IOException if an IO error occurs.
     */
    public Token[] addDelegationTokens(final String renewer,
        Credentials credentials) throws IOException;
  }

  /**
   * Default implementation of {@link DelegationTokenExtension} that
   * implements the method as a no-op.
   */
  private static class DefaultDelegationTokenExtension implements
    DelegationTokenExtension {

    @Override
    public Token[] addDelegationTokens(String renewer,
        Credentials credentials) {
      return null;
    }

  }

  private KeyProviderDelegationTokenExtension(KeyProvider keyProvider,
      DelegationTokenExtension extensions) {
    super(keyProvider, extensions);
  }

  /**
   * Passes the renewer and Credentials object to the underlying
   * {@link DelegationTokenExtension}
   * @param renewer the user allowed to renew the delegation tokens
   * @param credentials cache in which to add new delegation tokens
   * @return list of new delegation tokens
   * @throws IOException thrown if IOException if an IO error occurs.
   */
  public Token[] addDelegationTokens(final String renewer,
      Credentials credentials) throws IOException {
    return getExtension().addDelegationTokens(renewer, credentials);
  }

  /**
   * Creates a KeyProviderDelegationTokenExtension using a given
   * {@link KeyProvider}.
   * 

* If the given KeyProvider implements the * {@link DelegationTokenExtension} interface the KeyProvider * itself will provide the extension functionality, otherwise a default * extension implementation will be used. * * @param keyProvider KeyProvider to use to create the * KeyProviderDelegationTokenExtension extension. * @return a KeyProviderDelegationTokenExtension instance * using the given KeyProvider. */ public static KeyProviderDelegationTokenExtension createKeyProviderDelegationTokenExtension(KeyProvider keyProvider) { DelegationTokenExtension delTokExtension = (keyProvider instanceof DelegationTokenExtension) ? (DelegationTokenExtension) keyProvider : DEFAULT_EXTENSION; return new KeyProviderDelegationTokenExtension( keyProvider, delTokExtension); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy