Set ajax response status code to 401(unauthorized) when the user is not authorized

public @ResponseBody String handleRequest() {

if (null == currentUser) {

return new ResponseEntity<String>(HttpStatus.UNAUTHORIZED);

} else {

// do stuff…

return “blahblah…”;

}

}

In the ajax function, when detect unauthorized header then re-direct to log in page:

if (responseStatus == 401) {

window.location.href=”/login”;

}

Advertisements