use of org.vcell.rest.common.AccessTokenRepresentation in project vcell by virtualcell.
the class AccessTokenServerResource method get_json.
@Override
public AccessTokenRepresentation get_json() {
VCellApiApplication application = ((VCellApiApplication) getApplication());
String clientId = getQueryValue(PARAM_CLIENT_ID);
String userId = getQueryValue(PARAM_USER_ID);
String userPassword = getQueryValue(PARAM_USER_PASSWORD);
try {
ApiClient apiClient = application.getUserVerifier().getApiClient(clientId);
if (apiClient == null) {
throw new RuntimeException("client not found");
}
User authenticatedUser = application.getUserVerifier().authenticateUser(userId, userPassword.toCharArray());
if (authenticatedUser == null) {
throw new RuntimeException("unable to authenticate user");
}
ApiAccessToken apiAccessToken = application.getUserVerifier().generateApiAccessToken(apiClient.getKey(), authenticatedUser);
AccessTokenRepresentation tokenRep = new AccessTokenRepresentation(apiAccessToken);
//
// indicate no caching of response.
//
ArrayList<CacheDirective> cacheDirectives = new ArrayList<CacheDirective>();
cacheDirectives.add(CacheDirective.noCache());
getResponse().setCacheDirectives(cacheDirectives);
return tokenRep;
} catch (Exception e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage(), e);
}
}
Aggregations