spring - Request from html client: how will I know that requested user is logged in or not? -
here spring login handler
public class loginsuccesshandler extends savedrequestawareauthenticationsuccesshandler { @override public void onauthenticationsuccess(httpservletrequest request, httpservletresponse response, authentication authentication) { httpsession session = request.getsession(); loggedinuser logginuserobj = (loggedinuser)authentication.getprincipal(); string userid = logginuserobj.getuserid(); session.setattribute("userid", userid); session.setattribute("username", logginuserobj.getname()); session.setattribute("hasphoto", user.getproperty(uservertex.profilephotouploaded.tostring())); if(logginuserobj.getactivatelink()!=null) session.setattribute("activatelink", logginuserobj.getactivatelink()); try { object referurl = session.getattribute("referer_url"); if(referurl != null){ session.removeattribute("referer_url"); response.sendredirect(referurl.tostring()); } else response.sendredirect("profile/"+userid); } catch (ioexception ex) { logger.error(ex); } } }
my client in plain html, jquery (in cordova). question if everytime user makes request, how know requested user logged in or not ?
e.g. here sample :
$.ajax({ url: "addnewpost", data:{} })
here loggedin user can add new post. when calling addnewpost
rest service in spring @restcontroller
how know request logged in user ?
since you're using success handler before request goes success handler goes authentication manager.in authentication manager if have configured authentication provider there authenticity of user check , if returns success call go onauthenticationsuccess.in authentication provider values in request header depending upon type of authentication provider using.if missing user not logged in.here better picture 1 example(here checking authorization admin)
you can refer link
hope gives clear picture!!
Comments
Post a Comment