Package org.apache.hadoop.fs.s3a.auth
Class MarshalledCredentials
java.lang.Object
org.apache.hadoop.fs.s3a.auth.MarshalledCredentials
- All Implemented Interfaces:
Serializable,org.apache.hadoop.io.Writable
@Private
public final class MarshalledCredentials
extends Object
implements org.apache.hadoop.io.Writable, Serializable
Stores the credentials for a session or for a full login.
This structure is
Writable, so can be marshalled inside a
delegation token.
The class is designed so that keys inside are kept non-null; to be
unset just set them to the empty string. This is to simplify marshalling.
Important: Add no references to any AWS SDK class, to
ensure it can be safely deserialized whenever the relevant token
identifier of a token type declared in this JAR is examined.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of credential types for use in validation methods. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringError text on invalid non-empty credentials: "Invalid AWS credentials". -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.MarshalledCredentials(String accessKey, String secretKey, String sessionToken) Create from a set of properties. -
Method Summary
Modifier and TypeMethodDescriptionBuild an error string for when the credentials do not match those required.static MarshalledCredentialsempty()Return a set of empty credentials.booleanlongExpiration; will be 0 for none known.Get a temporal representing the time of expiration, if there is one.inthashCode()booleanDoes this set of credentials have a session token.booleanisEmpty()Is this empty: does it contain any credentials at all?booleanIs this a valid set of credentials tokens?voidreadFields(DataInput in) Read in the fields.voidsetAccessKey(String accessKey) voidsetExpiration(long expiration) voidsetRoleARN(String roleARN) voidsetSecretKey(String secretKey) voidsetSecretsInConfiguration(org.apache.hadoop.conf.Configuration config) Patch a configuration with the secrets.voidsetSessionToken(String sessionToken) toString()String value MUST NOT include any secrets.voidvalidate(String message, MarshalledCredentials.CredentialTypeRequired typeRequired) Verify that a set of credentials is valid.voidwrite(DataOutput out) Write the token.
-
Field Details
-
INVALID_CREDENTIALS
Error text on invalid non-empty credentials: "Invalid AWS credentials".- See Also:
-
-
Constructor Details
-
MarshalledCredentials
public MarshalledCredentials()Constructor. -
MarshalledCredentials
Create from a set of properties. No expiry time is expected/known here.- Parameters:
accessKey- access keysecretKey- secret keysessionToken- session token
-
-
Method Details
-
getAccessKey
-
getSecretKey
-
getSessionToken
-
getExpiration
public long getExpiration()Expiration; will be 0 for none known.- Returns:
- any expiration timestamp
-
setExpiration
public void setExpiration(long expiration) -
getExpirationDateTime
Get a temporal representing the time of expiration, if there is one. This is here to wrap up expectations about timestamps and zones.- Returns:
- the expiration time.
-
getRoleARN
-
setRoleARN
-
setAccessKey
-
setSecretKey
-
setSessionToken
-
equals
-
hashCode
public int hashCode() -
toString
String value MUST NOT include any secrets. -
isEmpty
public boolean isEmpty()Is this empty: does it contain any credentials at all? This test returns true if either the access key or secret key is empty.- Returns:
- true if there are no credentials.
-
isValid
Is this a valid set of credentials tokens?- Parameters:
required- credential type required.- Returns:
- true if the requirements are met.
-
hasSessionToken
public boolean hasSessionToken()Does this set of credentials have a session token.- Returns:
- true if there's a session token.
-
write
Write the token. Only works if valid.- Specified by:
writein interfaceorg.apache.hadoop.io.Writable- Parameters:
out- stream to serialize to.- Throws:
IOException- if the serialization failed.
-
readFields
Read in the fields.- Specified by:
readFieldsin interfaceorg.apache.hadoop.io.Writable- Throws:
IOException- IO problem
-
validate
public void validate(String message, MarshalledCredentials.CredentialTypeRequired typeRequired) throws IOException Verify that a set of credentials is valid.- Parameters:
message- message to prefix errors;typeRequired- credential type required.- Throws:
DelegationTokenIOException- if they aren'tIOException
-
buildInvalidCredentialsError
public String buildInvalidCredentialsError(MarshalledCredentials.CredentialTypeRequired typeRequired) Build an error string for when the credentials do not match those required.- Parameters:
typeRequired- credential type required.- Returns:
- an error string.
-
setSecretsInConfiguration
public void setSecretsInConfiguration(org.apache.hadoop.conf.Configuration config) Patch a configuration with the secrets. This does not set any per-bucket options (it doesn't know the bucket...). Warning: once done the configuration must be considered sensitive.- Parameters:
config- configuration to patch
-
empty
Return a set of empty credentials. These can be marshalled, but not used for login.- Returns:
- a new set of credentials.
-