|
@@ -123,7 +123,12 @@ public class S3ADelegationTokens extends AbstractDTService {
|
|
|
/**
|
|
|
* List of cred providers; unset until {@link #bindToDelegationToken(Token)}.
|
|
|
*/
|
|
|
- private Optional<AWSCredentialProviderList> credentialProviders
|
|
|
+ //private Optional<AWSCredentialProviderList> credentialProviders = Optional.empty();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * delegation binding information; unset until {@link #bindToDelegationToken(Token)}.
|
|
|
+ */
|
|
|
+ private Optional<DelegationBindingInfo> bindingInfo
|
|
|
= Optional.empty();
|
|
|
|
|
|
/**
|
|
@@ -235,10 +240,7 @@ public class S3ADelegationTokens extends AbstractDTService {
|
|
|
|
|
|
/**
|
|
|
* Perform the unbonded deployment operations.
|
|
|
- * Create the AWS credential provider chain to use
|
|
|
- * when talking to AWS when there is no delegation token to work with.
|
|
|
- * authenticating this client with AWS services, and saves it
|
|
|
- * to {@link #credentialProviders}
|
|
|
+ * Create and store the binding information.
|
|
|
*
|
|
|
* @throws IOException any failure.
|
|
|
*/
|
|
@@ -248,7 +250,7 @@ public class S3ADelegationTokens extends AbstractDTService {
|
|
|
checkState(!isBoundToDT(),
|
|
|
"Already Bound to a delegation token");
|
|
|
LOG.debug("No delegation tokens present: using direct authentication");
|
|
|
- credentialProviders = Optional.of(tokenBinding.deployUnbonded());
|
|
|
+ bindingInfo = Optional.of(tokenBinding.deploy(null));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -260,12 +262,12 @@ public class S3ADelegationTokens extends AbstractDTService {
|
|
|
* <ol>
|
|
|
* <li>{@link #boundDT} is set to the retrieved token.</li>
|
|
|
* <li>{@link #decodedIdentifier} is set to the extracted identifier.</li>
|
|
|
- * <li>{@link #credentialProviders} is set to the credential
|
|
|
- * provider(s) returned by the token binding.</li>
|
|
|
+ * <li>{@link #bindingInfo} is set to the information
|
|
|
+ * returned by the token binding.</li>
|
|
|
* </ol>
|
|
|
* If unsuccessful, {@link #deployUnbonded()} is called for the
|
|
|
* unbonded codepath instead, which will set
|
|
|
- * {@link #credentialProviders} to its value.
|
|
|
+ * {@link #bindingInfo} to its value.
|
|
|
*
|
|
|
* This means after this call (and only after) the token operations
|
|
|
* can be invoked.
|
|
@@ -276,14 +278,14 @@ public class S3ADelegationTokens extends AbstractDTService {
|
|
|
* @throws IOException selection/extraction/validation failure.
|
|
|
*/
|
|
|
private void bindToAnyDelegationToken() throws IOException {
|
|
|
- checkState(!credentialProviders.isPresent(), E_ALREADY_DEPLOYED);
|
|
|
+ checkState(!bindingInfo.isPresent(), E_ALREADY_DEPLOYED);
|
|
|
Token<AbstractS3ATokenIdentifier> token = selectTokenFromFSOwner();
|
|
|
if (token != null) {
|
|
|
bindToDelegationToken(token);
|
|
|
} else {
|
|
|
deployUnbonded();
|
|
|
}
|
|
|
- if (credentialProviders.get().size() == 0) {
|
|
|
+ if (getCredentialProviders().size() == 0) {
|
|
|
throw new DelegationTokenIOException("No AWS credential providers"
|
|
|
+ " created by Delegation Token Binding "
|
|
|
+ tokenBinding.getName());
|
|
@@ -306,7 +308,7 @@ public class S3ADelegationTokens extends AbstractDTService {
|
|
|
@VisibleForTesting
|
|
|
void resetTokenBindingToDT(final Token<AbstractS3ATokenIdentifier> token)
|
|
|
throws IOException{
|
|
|
- credentialProviders = Optional.empty();
|
|
|
+ bindingInfo = Optional.empty();
|
|
|
bindToDelegationToken(token);
|
|
|
}
|
|
|
|
|
@@ -317,8 +319,8 @@ public class S3ADelegationTokens extends AbstractDTService {
|
|
|
* <ol>
|
|
|
* <li>{@link #boundDT} is set to {@code token}.</li>
|
|
|
* <li>{@link #decodedIdentifier} is set to the extracted identifier.</li>
|
|
|
- * <li>{@link #credentialProviders} is set to the credential
|
|
|
- * provider(s) returned by the token binding.</li>
|
|
|
+ * <li>{@link #bindingInfo} is set to the info
|
|
|
+ * returned by the token binding.</li>
|
|
|
* </ol>
|
|
|
* @param token token to decode and bind to.
|
|
|
* @throws IOException selection/extraction/validation failure.
|
|
@@ -327,7 +329,7 @@ public class S3ADelegationTokens extends AbstractDTService {
|
|
|
public void bindToDelegationToken(
|
|
|
final Token<AbstractS3ATokenIdentifier> token)
|
|
|
throws IOException {
|
|
|
- checkState(!credentialProviders.isPresent(), E_ALREADY_DEPLOYED);
|
|
|
+ checkState(!bindingInfo.isPresent(), E_ALREADY_DEPLOYED);
|
|
|
boundDT = Optional.of(token);
|
|
|
AbstractS3ATokenIdentifier dti = extractIdentifier(token);
|
|
|
LOG.info("Using delegation token {}", dti);
|
|
@@ -335,8 +337,7 @@ public class S3ADelegationTokens extends AbstractDTService {
|
|
|
try (DurationInfo ignored = new DurationInfo(LOG, DURATION_LOG_AT_INFO,
|
|
|
"Creating Delegation Token")) {
|
|
|
// extract the credential providers.
|
|
|
- credentialProviders = Optional.of(
|
|
|
- tokenBinding.bindToTokenIdentifier(dti));
|
|
|
+ bindingInfo = Optional.of(tokenBinding.deploy(dti));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -470,8 +471,9 @@ public class S3ADelegationTokens extends AbstractDTService {
|
|
|
*/
|
|
|
public AWSCredentialProviderList getCredentialProviders()
|
|
|
throws IOException {
|
|
|
- return credentialProviders.orElseThrow(
|
|
|
- () -> new DelegationTokenIOException("Not yet bonded"));
|
|
|
+ return bindingInfo.map(DelegationBindingInfo::getCredentialProviders)
|
|
|
+ .orElseThrow(() ->
|
|
|
+ new DelegationTokenIOException("Not yet bonded"));
|
|
|
}
|
|
|
|
|
|
/**
|