关于JSF授权的建议
我学习了如何通过 JDBC 领域使用容器身份验证。 我在互联网上搜索了很多,但除了下面的文章之外,我找不到任何关于 JSF 授权的内容。 JSF 授权
我的目标是避免使用直接链接访问受保护的页面并显示/隐藏基于经过身份验证的用户权限的菜单项和表单组件。 最后一部分可以使用 JSF 标签的渲染属性来实现,但在创建我自己的肮脏且高耦合的解决方案之前,我想知道是否有一些特定的最佳实践或库可以提供帮助。事实上,要条件渲染的组件数量相当多,我不想为每个组件编写特定的函数。 也许我可以为每个经过身份验证的用户创建一个映射,其中包含所有条件渲染组件的名称(id)以及带有字符串参数(组件的唯一名称/id)的单个函数。这是个好主意吗?我还有什么选择? 我不想在项目中添加其他通用框架,例如 spring,因为它只使用其中的一小部分(安全框架)。
谢谢 菲利波
I learnt how to use container authentication with JDBC realm.
I searched a lot on internet but I couldn't find anything on JSF authorization except the following article.
JSF authorization
My goal is to avoid access to protected pages using direct links and to show/hide menu items and form components based on the authenticated user privileges.
The last part can be implemented using the rendered attribute of JSF tags but before creating my own dirty and high coupled solution I wonder if there are some specific best practices or libraries that can help. in fact the number of components to be conditionally rendered is quite high and I wouldn't like to write a specific function for each of them.
Perhaps I can create for each authenticated user a map with the names (id) of all the conditionally rendered components and a single function with a String parameter (the unique name/id of the component). Is that a good idea ? What alternatives do I have ?
I wouldn't like to add to the project other general purpose frameworks such as spring for using only a small part of them (the security one).
Thanks
Filippo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Java EE 6 中的表达式语言版本,您应该能够使用如下表达式:
对于旧版本,您可以创建以下形式的托管 bean:
然后测试可以采用以下形式表达:
第三方框架提供其他选项,例如 Apache Tomahawk 库的
visibleOnUserRole
组件属性。With the Expression Language version in Java EE 6 you should be able to use expressions like these:
With older versions, you can create a managed bean of this form:
The test can then be expression in the form:
Third party frameworks offer other options, such as the Apache Tomahawk library's
visibleOnUserRole
component attributes.看一下 Apache Shiro,一个专用的安全框架(据说比 Spring Security 更容易使用)。
Take a look at Apache Shiro, a dedicated security framework (and supposedly erasier to use than Spring Security).