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 */ 018 019package org.apache.hadoop.fs.adl.oauth2; 020 021import org.apache.hadoop.classification.InterfaceAudience; 022import org.apache.hadoop.classification.InterfaceStability; 023import org.apache.hadoop.conf.Configuration; 024 025import java.io.IOException; 026import java.util.Date; 027 028/** 029 * Provide an Azure Active Directory supported 030 * OAuth2 access token to be used to authenticate REST calls against Azure data 031 * lake file system {@link org.apache.hadoop.fs.adl.AdlFileSystem}. 032 */ 033@InterfaceAudience.Public 034@InterfaceStability.Evolving 035public abstract class AzureADTokenProvider { 036 037 /** 038 * Initialize with supported configuration. This method is invoked when the 039 * {@link org.apache.hadoop.fs.adl.AdlFileSystem#initialize 040 * (URI, Configuration)} method is invoked. 041 * 042 * @param configuration Configuration object 043 * @throws IOException if instance can not be configured. 044 */ 045 public abstract void initialize(Configuration configuration) 046 throws IOException; 047 048 /** 049 * Obtain the access token that should be added to https connection's header. 050 * Will be called depending upon {@link #getExpiryTime()} expiry time is set, 051 * so implementations should be performant. Implementations are responsible 052 * for any refreshing of the token. 053 * 054 * @return String containing the access token 055 * @throws IOException if there is an error fetching the token 056 */ 057 public abstract String getAccessToken() throws IOException; 058 059 /** 060 * Obtain expiry time of the token. If implementation is performant enough to 061 * maintain expiry and expect {@link #getAccessToken()} call for every 062 * connection then safe to return current or past time. 063 * 064 * However recommended to use the token expiry time received from Azure Active 065 * Directory. 066 * 067 * @return Date to expire access token retrieved from AAD. 068 */ 069 public abstract Date getExpiryTime(); 070}