use of edu.pitt.dbmi.ccd.rest.client.RestHttpsClient in project tetrad by cmu-phil.
the class JsonWebTokenManager method getJsonWebToken.
public synchronized JsonWebToken getJsonWebToken(final HpcAccount hpcAccount) throws Exception {
long now = System.currentTimeMillis();
JsonWebToken jsonWebToken = jsonWebTokenMap.get(hpcAccount);
if (jsonWebToken == null || (now - jsonWebTokenRequestTimeMap.get(hpcAccount).getTime()) > TOKEN_VALID_TIME) {
final String username = hpcAccount.getUsername();
final String password = hpcAccount.getPassword();
final String scheme = hpcAccount.getScheme();
final String hostname = hpcAccount.getHostname();
final int port = hpcAccount.getPort();
RestHttpsClient restClient = new RestHttpsClient(username, password, scheme, hostname, port);
// Authentication
UserService userService = new UserService(restClient, scheme, hostname, port);
// JWT token is valid for 1 hour
jsonWebToken = userService.requestJWT();
jsonWebTokenMap.put(hpcAccount, jsonWebToken);
jsonWebTokenRequestTimeMap.put(hpcAccount, new Date(System.currentTimeMillis()));
}
return jsonWebToken;
}
Aggregations