jeudi 19 février 2015

session attribute null in my spring interceptor

I am having trouble with getting a value that I had put into a session. I want to check this value with an interceptor but I only get a null.


This is where I put the variable "trustedUser"



@RequestMapping(value = "/context/{token}", method = { RequestMethod.GET })
public @ResponseBody
ResponseEntity<ContexteUI> getContextByToken(@PathVariable("token") String token, HttpSession session)
throws ContextFault_Exception {

HttpStatus httpStatus = HttpStatus.OK;
if (validation(token)){
session.setAttribute("trustedUser","trustedUser");
} else {
httpStatus = HttpStatus.BAD_REQUEST;
}

return new ResponseEntity<ContexteUI>(contexte, httpStatus);
}


This is my interceptor:



public class AuthentificationInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {

System.out.println("Pre-handle");

String trustedUserTest = (String) request.getSession().getAttribute("trustedUser");
System.out.println("trustedUserTest: "+ trustedUserTest); // I only get null here, why ?

return true;

}
}


Where did I get wrong ?


Aucun commentaire:

Enregistrer un commentaire