Search in sources :

Example 1 with CookieResponse

use of com.runwaysdk.mvc.CookieResponse in project geoprism-registry by terraframe.

the class RegistrySessionController method login.

@Endpoint(method = ServletMethod.POST, error = ErrorSerialization.JSON)
public ResponseIF login(ServletRequestIF req, @RequestParamter(name = "username", required = true) String username, @RequestParamter(name = "password", required = true) String password) throws JSONException {
    if (username != null) {
        username = username.trim();
    }
    Locale[] locales = this.getLocales(req);
    // Locale sessionLocale = req.getLocale();
    // 
    // JSONArray installedLocalesArr = new JSONArray();
    // Collection<Locale> installedLocales = LocalizationFacade.getInstalledLocales();
    // for (Locale loc : installedLocales)
    // {
    // JSONObject locObj = new JSONObject();
    // locObj.put("language", loc.getDisplayLanguage(sessionLocale));
    // locObj.put("country", loc.getDisplayCountry(sessionLocale));
    // locObj.put("name", loc.getDisplayName(sessionLocale));
    // locObj.put("variant", loc.getDisplayVariant(sessionLocale));
    // 
    // installedLocalesArr.put(locObj);
    // }
    ClientRequestIF clientRequest = loginWithLocales(req, username, password, locales);
    JSONArray jaLocales = new JSONArray(ServiceFactory.getRegistryService().getLocales(clientRequest.getSessionId()).toString());
    JsonArray roles = JsonParser.parseString(RoleViewDTO.getCurrentRoles(clientRequest)).getAsJsonArray();
    JsonArray roleDisplayLabels = JsonParser.parseString(RoleViewDTO.getCurrentRoleDisplayLabels(clientRequest)).getAsJsonArray();
    JsonObject cookieValue = new JsonObject();
    cookieValue.addProperty("loggedIn", clientRequest.isLoggedIn());
    cookieValue.add("roles", roles);
    cookieValue.add("roleDisplayLabels", roleDisplayLabels);
    cookieValue.addProperty("userName", username);
    cookieValue.addProperty("version", ClientConfigurationService.getServerVersion());
    CookieResponse response = new CookieResponse("user", -1, cookieValue.toString());
    response.set("installedLocales", jaLocales);
    return response;
}
Also used : Locale(java.util.Locale) JsonArray(com.google.gson.JsonArray) JSONArray(org.json.JSONArray) JsonObject(com.google.gson.JsonObject) CookieResponse(com.runwaysdk.mvc.CookieResponse) ClientRequestIF(com.runwaysdk.constants.ClientRequestIF) Endpoint(com.runwaysdk.mvc.Endpoint)

Aggregations

JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 ClientRequestIF (com.runwaysdk.constants.ClientRequestIF)1 CookieResponse (com.runwaysdk.mvc.CookieResponse)1 Endpoint (com.runwaysdk.mvc.Endpoint)1 Locale (java.util.Locale)1 JSONArray (org.json.JSONArray)1