@RequestMapping(value = "/api/login", method = RequestMethod.GET) public void loginByGet(@RequestParam(value = "u") String username, @RequestParam(value = "p") String password, @RequestParam(value = "l", required = false) String localeStr, HttpServletRequest request, HttpServletResponse response) throws IOException, JSONException { doLogin(username, password, localeStr, request, response); }
@RequestMapping(value = "/api/logout", method = RequestMethod.GET) public void logoutByGet(@RequestParam(value = "session") String sessionUUID, HttpServletResponse response) throws IOException, JSONException { doLogout(sessionUUID, response); }
protected void doLogin(String username, String password, String localeStr, HttpServletRequest request, HttpServletResponse response) throws IOException, JSONException { Locale locale = localeFromString(localeStr); setSessionInfo(request, userSession); } finally { AppContext.setSecurityContext(null);
@RequestMapping(value = "/api/logout", method = RequestMethod.POST) public void logoutByPost(@RequestBody String requestBody, @RequestHeader(value = "Content-Type") MimeType contentType, HttpServletResponse response) throws IOException, JSONException { String sessionUUID; if (contentType.match(JSONConverter.MIME_TYPE_JSON)) { try { JSONObject json = new JSONObject(requestBody); sessionUUID = json.getString("session"); } catch (JSONException e) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } } else if (contentType.match(FORM_TYPE)) { String[] fields = requestBody.split("="); if (fields.length < 2) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } sessionUUID = URLEncodeUtils.decodeUtf8(fields[1]); } else { throw new IllegalStateException("Unsupported content type: " + contentType); } doLogout(sessionUUID, response); }
doLogin(username, password, localeStr, request, response);