@@ -33,13 +33,21 @@ public FileIDTokenSource(String filePath) {
3333
3434 /**
3535 * Retrieves an ID Token from the file. The file is read using UTF-8 encoding and the first line
36- * is used as the token value.
36+ * is used as the token value. Any leading or trailing whitespace in the token is trimmed.
3737 *
38- * @param audience The intended recipient of the ID Token (not used).
38+ * @param audience The intended recipient of the ID Token. This parameter is not used in this
39+ * implementation as the token is read directly from the file.
3940 * @return An {@link IDToken} containing the token value from the file.
4041 * @throws IllegalArgumentException if the file path is null or empty.
41- * @throws DatabricksException if the file path is invalid, the file does not exist, is empty, or
42- * contains only whitespace.
42+ * @throws DatabricksException in the following cases:
43+ * <ul>
44+ * <li>If the file path is invalid or malformed
45+ * <li>If the file does not exist
46+ * <li>If there are security permission issues accessing the file
47+ * <li>If the file is empty or contains only whitespace
48+ * <li>If the file cannot be read due to I/O errors
49+ * <li>If the token format in the file is invalid
50+ * </ul>
4351 */
4452 @ Override
4553 public IDToken getIDToken (String audience ) {
@@ -54,8 +62,17 @@ public IDToken getIDToken(String audience) {
5462 throw new DatabricksException ("Invalid file path: " + filePath , e );
5563 }
5664
57- if (!Files .exists (path )) {
58- throw new DatabricksException ("File " + filePath + " does not exist" );
65+ try {
66+ if (!Files .exists (path )) {
67+ throw new DatabricksException ("File " + filePath + " does not exist" );
68+ }
69+ } catch (SecurityException e ) {
70+ throw new DatabricksException (
71+ "Security permission denied when checking if file "
72+ + filePath
73+ + " exists: "
74+ + e .getMessage (),
75+ e );
5976 }
6077
6178 List <String > lines ;
@@ -64,6 +81,9 @@ public IDToken getIDToken(String audience) {
6481 } catch (IOException e ) {
6582 throw new DatabricksException (
6683 "Failed to read ID token from file " + filePath + ": " + e .getMessage (), e );
84+ } catch (SecurityException e ) {
85+ throw new DatabricksException (
86+ "Security permission denied when reading file " + filePath + ": " + e .getMessage (), e );
6787 }
6888
6989 if (lines .isEmpty ()) {
@@ -74,7 +94,7 @@ public IDToken getIDToken(String audience) {
7494 String token ;
7595 try {
7696 token = lines .get (0 ).trim ();
77- } catch (IndexOutOfBoundsException | NullPointerException e ) {
97+ } catch (IndexOutOfBoundsException e ) {
7898 throw new DatabricksException ("Invalid token format in file " + filePath );
7999 }
80100 return new IDToken (token );
0 commit comments