use of io.cdap.cdap.security.auth.AccessToken in project cdap by caskdata.
the class RemoteExecutionTwillRunnerService method generateAndSaveRuntimeToken.
/**
* Generates a runtime token to talk back from the execution cluster to CDAP instance.
*/
private Location generateAndSaveRuntimeToken(ProgramRunId programRunId, Location keysDir) {
try {
long currentTimestamp = System.currentTimeMillis();
// TODO: Use a better identity & expiration
UserIdentity identity = new UserIdentity(Constants.Security.Authentication.RUNTIME_IDENTITY, UserIdentity.IdentifierType.INTERNAL, Collections.emptyList(), currentTimestamp, currentTimestamp + DEFAULT_EXPIRATION);
AccessToken accessToken = tokenManager.signIdentifier(identity);
byte[] encodedAccessToken = Base64.getEncoder().encode(accessTokenCodec.encode(accessToken));
Location location = keysDir.append(Constants.Security.Authentication.RUNTIME_TOKEN_FILE);
try (OutputStream os = location.getOutputStream()) {
os.write(encodedAccessToken);
}
return location;
} catch (IOException e) {
throw new RuntimeException("Failed to generate runtime token for " + programRunId, e);
}
}
Aggregations