JSF 身份验证和授权
为 JSF Web 应用程序实现身份验证和授权的最佳方法是什么? 我最好仍然想使用基于容器的安全性,因为我需要调用需要主体的 EJB。
我意识到基于表单的身份验证是 JSF 的一个主要难题,但我是否可以使用 PhaseListener 或类似的东西与编程登录一起对用户进行身份验证?
我还应该看看其他方法吗?
What is the best way to go about implementing authentication and authorization for a JSF web application? Preferrably I'd still want to use container-based security, as I need to call EJBs that require the principal.
I realize form-based authentication is a major struggle with JSF, but can I perhaps use a PhaseListener or something similar together with programmatic logon to authenticate the user?
Any other methods I should rather have a look at?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试查看将 JAAS 与 JSF 结合使用的博客
这是如何使用 JSF 部署 JAAS 进行身份验证和授权的示例。
我希望它有帮助。
老虎
Try to check out the blog for using JAAS with JSF.
This is the example of how to deploy the JAAS with JSF for authentication and authorization.
I hope it helps.
Tiger
您可以使用 Spring Security 框架,请参阅此处的说明 http:// ocpsoft.com/java/acegi-spring-security-jsf-login-page/
You can use the Spring Security framework, see instructions here http://ocpsoft.com/java/acegi-spring-security-jsf-login-page/
我使用 JSF Seam 并使用了 Seam 的内置身份验证和授权,发现它非常易于使用。
对于身份验证,您只需实现 1 个方法,
public boolean login(String username, a String password) { ... }
并返回布尔值。 然后你可以将页面标记为“需要登录”,seam 会处理剩下的事情。对于授权,Seam 为您提供一个
@Restrict
注解,您可以将其放在您的控制器或服务方法上,并且 Seam 会处理剩下的事情。高级授权:您还可以处理更多 Seam 的高级授权,其中角色是动态的 - 例如,在公告板上,您是某些帖子的“作者”,但只需将 @Restrict 注释委托给 Java 即可成为“读者”或其他帖子方法。
我鼓励您看看 Seam。 Seam 只是 JSF 之上的一层,因此从技术上讲,您仍然可以在 JSF 上运行。 如果由于某种原因您无法使用 Seam,也许您可以借鉴 Seam 在 JSF 中处理授权和身份验证的方式。
I use JSF Seam and have used Seam's built-in authentication and authorization and find it extremely easy to use.
For authentication, you simply implement 1 method,
public boolean login(String username, a String password) { ... }
and returns boolean. Then you can mark pages as "login-required" and seam takes care of the rest.For authorization, Seam gives you a
@Restrict
Annotation that you can put on your Controller or Service methods and again, Seam takes care of the rest.Advanced authorization: You can also handle more advanced authorization with Seam where roles are dynamic - e.g. in a bulletin board you are "author" of some posts, but "reader" or other posts, by simply delegating your @Restrict annotation to a Java method.
I would encourage you to take a look at Seam. Seam is just a layer on top of JSF so technically you would still be running on JSF . If for some reason you cannot use Seam, maybe you can borrow some ideas from how Seam handles Authorization and Authentication in JSF.
您可以使用 Servlet 3.0 HttpServletRequest API,如 JSF 2.0 问题的答案所示:
JSF 2.0 简单登录页面
You could use the Servlet 3.0 HttpServletRequest API as shown in this answer to a JSF 2.0 question:
JSF 2.0 Simple login page