use of cbit.vcell.modeldb.ApiClient in project vcell by virtualcell.
the class VCellCookieAuthenticator method login.
@Override
protected void login(Request request, Response response) {
// Login detected
Representation entity = request.getEntity();
Form form = new Form(entity);
Parameter identifier = form.getFirst(getIdentifierFormName());
Parameter secret = form.getFirst(getSecretFormName());
Parameter redirectURL = form.getFirst(getRedirectQueryName());
UserLoginInfo.DigestedPassword digestedPassword = new UserLoginInfo.DigestedPassword(secret.getValue());
try {
User user = vcellApiApplication.getUserVerifier().authenticateUser(identifier.getValue(), digestedPassword.getString().toCharArray());
if (user == null) {
response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
return;
}
ApiClient apiClient = vcellApiApplication.getUserVerifier().getApiClient(VCellApiApplication.BROWSER_CLIENTID);
ApiAccessToken accessToken = vcellApiApplication.getUserVerifier().generateApiAccessToken(apiClient.getKey(), user);
// Set credentials
ChallengeResponse cr = new ChallengeResponse(getScheme(), CustomAuthHelper.ACCESS_TOKEN, accessToken.getToken());
request.setChallengeResponse(cr);
getCredentialsCookie(request, response).setMaxAge(0);
getLogger().log(Level.INFO, "MyCookieAuthenticator.login(request,response) - created new accessToken '" + accessToken.getToken() + "' and assignd to ChallengeResponse, redirectURL='" + redirectURL.getValue() + "'");
response.redirectSeeOther(Reference.decode(redirectURL.getValue()));
} catch (SQLException e) {
e.printStackTrace();
getLogger().log(Level.SEVERE, "MyCookieAuthenticator.login(request,response) - exception", e);
} catch (DataAccessException e) {
e.printStackTrace();
getLogger().log(Level.SEVERE, "MyCookieAuthenticator.login(request,response) - exception", e);
}
}
use of cbit.vcell.modeldb.ApiClient 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