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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s