Search in sources :

Example 1 with RestHttpsClient

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;
}
Also used : RestHttpsClient(edu.pitt.dbmi.ccd.rest.client.RestHttpsClient) UserService(edu.pitt.dbmi.ccd.rest.client.service.user.UserService) JsonWebToken(edu.pitt.dbmi.ccd.rest.client.dto.user.JsonWebToken) Date(java.util.Date)

Aggregations

RestHttpsClient (edu.pitt.dbmi.ccd.rest.client.RestHttpsClient)1 JsonWebToken (edu.pitt.dbmi.ccd.rest.client.dto.user.JsonWebToken)1 UserService (edu.pitt.dbmi.ccd.rest.client.service.user.UserService)1 Date (java.util.Date)1