-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomTokenProvider.java
More file actions
39 lines (32 loc) · 1.36 KB
/
CustomTokenProvider.java
File metadata and controls
39 lines (32 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.azurebfs.extensions.CustomTokenProviderAdaptee;
import java.util.Date;
public class CustomTokenProvider implements CustomTokenProviderAdaptee {
private String accessToken;
private Date expiresOn;
@Override
public void initialize(Configuration configuration, String accountName) {
// Retrieve token and expiry from the configuration
this.accessToken = configuration.get("fs.azure.account.custom.token");
String expiryStr = configuration.get("fs.azure.account.custom.token.expiry");
if (this.accessToken == null || expiryStr == null) {
throw new IllegalArgumentException("Token or expiry time is not provided in the configuration.");
}
try {
// Convert expiry to a Date object
long expiryEpochMillis = Long.parseLong(expiryStr);
this.expiresOn = new Date(expiryEpochMillis);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Expiry time is not a valid number: " + expiryStr, e);
}
System.out.println("Initializing CustomTokenProvider for account: " + accountName);
}
@Override
public String getAccessToken() {
return this.accessToken;
}
@Override
public Date getExpiryTime() {
return this.expiresOn;
}
}