Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.DataOutput;
import java.io.IOException;
import java.net.URI;
import java.time.Clock;
import java.util.Objects;
import java.util.UUID;

Expand Down Expand Up @@ -140,6 +141,7 @@ protected AbstractS3ATokenIdentifier(
final URI uri) {
super(kind, owner, renewer, realUser);
this.uri = requireNonNull(uri);
initializeIssueDate();
}

/**
Expand All @@ -164,6 +166,13 @@ protected AbstractS3ATokenIdentifier(
*/
protected AbstractS3ATokenIdentifier(final Text kind) {
super(kind);
initializeIssueDate();
}

private void initializeIssueDate() {
Clock clock = Clock.systemDefaultZone();
long now = clock.millis();
setIssueDate(now);
}

public String getBucket() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
* Unit tests related to S3A DT support.
Expand All @@ -58,6 +59,14 @@ public void testSessionTokenKind() throws Throwable {
assertEquals(SESSION_TOKEN_KIND, identifier.getKind());
}

@Test
public void testSessionTokenIssueDate() throws Throwable {
AbstractS3ATokenIdentifier identifier
= new SessionTokenIdentifier();
assertEquals(SESSION_TOKEN_KIND, identifier.getKind());
assertTrue("issue date is not set", identifier.getIssueDate() > 0L);
}

@Test
public void testSessionTokenDecode() throws Throwable {
Text alice = new Text("alice");
Expand Down Expand Up @@ -90,6 +99,8 @@ public void testSessionTokenDecode() throws Throwable {
UserGroupInformation.AuthenticationMethod.TOKEN,
decodedUser.getAuthenticationMethod());
assertEquals("origin", decoded.getOrigin());
assertEquals("issue date", identifier.getIssueDate(),
decoded.getIssueDate());
}

@Test
Expand Down