Skip to content

Instantly share code, notes, and snippets.

@zuk
Created October 25, 2011 02:22
Show Gist options
  • Select an option

  • Save zuk/1311132 to your computer and use it in GitHub Desktop.

Select an option

Save zuk/1311132 to your computer and use it in GitHub Desktop.
Logging in to Rollcall using Java in Play Framework
// authenticate with rollcall
String rollcallUrl = Play.configuration.getProperty("sail.rollcall.url");
WSRequest req = WS.url(rollcallUrl+"/login.json");
req.setParameter("session[login]", username);
req.setParameter("session[password]", password);
WS.HttpResponse res = req.post();
JsonElement json = res.getJson();
if (res.getStatus() == 201) { // session created successfully
JsonObject session = json.getAsJsonObject().getAsJsonObject("session");
JsonObject account = session.getAsJsonObject("account");
String token = session.get("token").getAsString();
String encryptedPassword = account.get("encrypted_password").getAsString();
// now check if we already have this user in the local database
} else { // some error during session creation
flash.put("error", "Rollcall authentication failed: "+json.toString());
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment