开发者

Spring MVC, how to have a controller handler handle all the requests before the mapped handlers?

开发者 https://www.devze.com 2023-02-11 01:22 出处:网络
I\'ve wrote a web app with its brave controllers and handler mapping, everything with Spring 3.0 and controller annotations. Now turns out that I need simple and custom autentication.开发者_高级运维 I

I've wrote a web app with its brave controllers and handler mapping, everything with Spring 3.0 and controller annotations. Now turns out that I need simple and custom autentication.开发者_高级运维 I don't want to use ACEGI for the moment, because I've no time to learn it. I'd like ideally that I could have a routine that gets called before every mapped handler, gets from the HttpSession the userId, checks if he is logged in and the session key and if not redirects to a login page. I've been thinking about an interceptor... the problem is that you have to use HandlerInterceptorAdapter, which has the following method:

 public boolean preHandle(
            HttpServletRequest request,
            HttpServletResponse response,
            Object handler) throws Exception {

that won't let me access the HttpSession associated with the request. How do I solve this?


Are you sure? You should be able to obtain the session through request.getSession().

0

精彩评论

暂无评论...
验证码 换一张
取 消