我有一个简单的用例,我想在会话开始时获取会话变量,并且只允许根据结果访问某些页面。我不太清楚这是使用 bindInterceptor 拦截任何页面上的任何 @Get 或 @Post 方法最好还是使用过滤器更好。这是我想做但对替代方案持开放态度的草图:
At the start of a new session (@SessionScoped ?), check a session variable authentication token
If (authentication == admin) {
serveRegex("admin/(jsp|html)/.*").with(GuiceContainer.class); //only allow /admin subpages
req.getRequestDispatcher("/admin").forward(req, res); //fwd all initial page requests to /admin
}
else If (authentication == user) {
serveRegex("user/(jsp|html)/.*").with(GuiceContainer.class); //only allow /user subpages
req.getRequestDispatcher("/user").forward(req, res); //fwd all initial page requests to /user
}
else {
serveRegex("signin/(jsp|html)/.*").with(GuiceContainer.class); //only allow /signin subpages
req.getRequestDispatcher("/signin").forward(req, res); //fwd all initial page requests to /signin
}
哪种技术是管理此安全模型的首选方法(最少代码、最快等)?我很想看一个示例项目。
谢谢你的帮助!
-约翰