java - Setting a Attribute for Every Request (Spring REST) -
i doing rest app in spring , have log out method below. dont have knowledge on spring searched around , made this.
@restcontroller public class logoutcontroller { @autowired private databaseservice databaseservice; @requestmapping(value = "/myapp/user/logout", method = get, produces = {"application/xml"}) public users performlogout(@requestheader("authenticationid") string authid, httpservletrequest request) throws datatypeconfigurationexception { return handlelogout(request, authid); } private users handlelogout(httpservletrequest request, string authid) throws datatypeconfigurationexception { logservice.info(this.getclass().getname(), "received logout request"); final usersxmlbuilder usersxmlbuilder = new usersxmlbuilder(); users usersxml = usersxmlbuilder.builddefaultuserstemplate(); httpsession session = request.getsession(); apputilities utils = new apputilities(); try { //checking regex if (utils.isvaliduuid(authtoken)) { //get user login record db authid , delete //invalidate session session.invalidate(); logservice.info(this.getclass().getname(), "session invaliated"); } else { logservice.info(this.getclass().getname(), "invalid authid found. not valid uuid"); usersxml.setresponsecode(-5); usersxml.setresponsetext("user session not valid"); } } catch (exception ex) { logservice.error(this.getclass().getname(), ex); usersxml.setresponsecode(-4); usersxml.setresponsetext("error occured!"); return usersxml; } { logservice.info(this.getclass().getname(), "logout process finished"); } return usersxml; } }
questions
1- possible can return xml message when spring gives white label error page when pass no authentication id in request.
2- how can authentication header , check null , give message authid missing.
3- how can set attribute explicitly , check in every controller if exists or not.
4- plan have table can store user login time , give session 10 mins time , update more 10 mins if request user authid. can have class or method can check incoming request? can detect authid , update table.
thank time , help.
you can use interceptor : http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-handlermapping-interceptor
the interceptor run every request. can stop request , response itself.
Comments
Post a Comment