@@ -942,24 +942,31 @@ public AccessTokenProvider getTokenProvider() throws TokenAccessProviderExceptio
942942 }
943943
944944 /**
945- * The following method chooses between a configured fixed sas token, and a user implementation of the SASTokenProvider interface,
946- * depending on which one is available. In case a user SASTokenProvider implementation is not present, and a fixed token is configured,
947- * it simply returns null, to set the sasTokenProvider object for current configuration instance to null.
948- * The fixed token is read and used later. This is done to:
949- * 1. check for cases where both are not set, while initializing AbfsConfiguration,
950- * to not proceed further than thi stage itself when none of the options are available.
951- * 2. avoid using similar tokenProvider implementation to just read the configured fixed token,
952- * as this could create confusion. The configuration is introduced
953- * primarily to avoid using any tokenProvider class/interface. Also,implementing the SASTokenProvider requires relying on the raw configurations.
954- * It is more stable to depend on the AbfsConfiguration with which a filesystem is initialized,
945+ * The user can choose between a configured fixed sas token, and a user
946+ * implementation of the SASTokenProvider interface. Preference will be given
947+ * to SASTokenProvider class provided as the value of "fs.azure.sas.token.provider.type".
948+ * If above config is not set, it is expected that user wants to use a
949+ * fixed SAS Token provided as value of "fs.azure.sas.fixed.token".
950+ * <ol>
951+ * <li>If both the configs are not provided,
952+ * initialization fails and {@link TokenAccessProviderException} is thrown.</li>
953+ * <li>If both are present, SASTokenProvider class will be used to generate SAS Token.</li>
954+ * <li>If only fixed SAS Token is configured, this will return null
955+ * and Fixed SAS token will be used to sign requests.</li>
956+ * </ol>
957+ * Avoid using a tokenProvider implementation just to read the configured fixed token,
958+ * as this could create confusion. Also,implementing the SASTokenProvider
959+ * requires relying on the raw configurations. It is more stable to depend on the
960+ * AbfsConfiguration with which a filesystem is initialized,
955961 * and eliminate chances of dynamic modifications and spurious situations.
956962 * @return sasTokenProvider object
957963 * @throws AzureBlobFileSystemException
958964 */
959965 public SASTokenProvider getSASTokenProvider () throws AzureBlobFileSystemException {
960966 AuthType authType = getEnum (FS_AZURE_ACCOUNT_AUTH_TYPE_PROPERTY_NAME , AuthType .SharedKey );
961967 if (authType != AuthType .SAS ) {
962- throw new SASTokenProviderException (String .format ("Invalid auth type: %s is being used, expecting SAS" , authType ));
968+ throw new SASTokenProviderException (String .format (
969+ "Invalid auth type: %s is being used, expecting SAS." , authType ));
963970 }
964971
965972 try {
@@ -970,30 +977,30 @@ public SASTokenProvider getSASTokenProvider() throws AzureBlobFileSystemExceptio
970977 String configuredFixedToken = this .rawConfig .get (FS_AZURE_SAS_FIXED_TOKEN ,
971978 null );
972979
973- Preconditions .checkArgument (!(sasTokenProviderImplementation == null
974- && configuredFixedToken == null ),
975- String .format (
976- "The value for both \" %s\" and \" %s\" cannot be invalid." ,
977- FS_AZURE_SAS_TOKEN_PROVIDER_TYPE , FS_AZURE_SAS_FIXED_TOKEN ));
980+ Preconditions .checkArgument (
981+ sasTokenProviderImplementation != null || configuredFixedToken != null ,
982+ "At least one of the \" %s\" and \" %s\" must be set." ,
983+ FS_AZURE_SAS_TOKEN_PROVIDER_TYPE , FS_AZURE_SAS_FIXED_TOKEN );
978984
985+ // Prefer SASTokenProvider Implementation if configured.
979986 if (sasTokenProviderImplementation != null ) {
980- LOG .trace (
981- "Using SASTokenProvider class because it is given precedence when it is set" );
987+ LOG .trace ("Using SASTokenProvider class because it is given precedence when it is set." );
982988 SASTokenProvider sasTokenProvider = ReflectionUtils .newInstance (
983989 sasTokenProviderImplementation , rawConfig );
984990 Preconditions .checkArgument (sasTokenProvider != null ,
985- String .format ("Failed to initialize %s" ,
986- sasTokenProviderImplementation ));
991+ "Failed to initialize %s" , sasTokenProviderImplementation );
987992
988993 LOG .trace ("Initializing {}" , sasTokenProviderImplementation .getName ());
989994 sasTokenProvider .initialize (rawConfig , accountName );
990995 LOG .trace ("{} init complete" , sasTokenProviderImplementation .getName ());
991996 return sasTokenProvider ;
992997 } else {
998+ // Configured Fixed SAS Token will be used to sign the requests.
993999 return null ;
9941000 }
9951001 } catch (Exception e ) {
996- throw new TokenAccessProviderException ("Unable to load SAS token provider class: " + e , e );
1002+ throw new TokenAccessProviderException (
1003+ "Unable to load SAS token provider class: " + e , e );
9971004 }
9981005 }
9991006
@@ -1006,14 +1013,14 @@ public EncryptionContextProvider createEncryptionContextProvider() {
10061013 Class <? extends EncryptionContextProvider > encryptionContextClass =
10071014 getAccountSpecificClass (configKey , null ,
10081015 EncryptionContextProvider .class );
1009- Preconditions .checkArgument (encryptionContextClass != null , String . format (
1016+ Preconditions .checkArgument (encryptionContextClass != null ,
10101017 "The configuration value for %s is invalid, or config key is not account-specific" ,
1011- configKey )) ;
1018+ configKey );
10121019
10131020 EncryptionContextProvider encryptionContextProvider =
10141021 ReflectionUtils .newInstance (encryptionContextClass , rawConfig );
10151022 Preconditions .checkArgument (encryptionContextProvider != null ,
1016- String . format ( "Failed to initialize %s" , encryptionContextClass ) );
1023+ "Failed to initialize %s" , encryptionContextClass );
10171024
10181025 LOG .trace ("{} init complete" , encryptionContextClass .getName ());
10191026 return encryptionContextProvider ;
0 commit comments