如何在 JSF 中使用 Spring Security Facelets 标签库
我想使用 Spring Security Facelets 标签库来保护我的 UI 组件 在我的 JSF 2 页面中,
我对 Spring Security 版本 3.0.5 有以下依赖项:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${spring-security.version}</version>
</dependency>
我配置了 applicationSecurity.xml 来进行 Spring Security 登录,并且工作正常 使用 UserDetailsService,当尝试添加安全定义时:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:pretty="http://ocpsoft.com/prettyfaces"
xmlns:sec="http://www.springframework.org/security/tags">
运行应用程序时,我收到以下错误:
Warning: This page calls for XML namespace http://www.springframework.org/security/tags declared with prefix sec but no taglibrary exists for that namespace.
参考:http://static.springsource.org/spring-security/site/petclinic-tutorial.html
请告知。
i want to use The Spring Security Facelets tag library to secure my UI components
in my JSF 2 pages
i have following dependencies for spring security version 3.0.5:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${spring-security.version}</version>
</dependency>
i configured applicationSecurity.xml to make spring security login, and it works fine
with UserDetailsService, and when tried to add the security definition:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:pretty="http://ocpsoft.com/prettyfaces"
xmlns:sec="http://www.springframework.org/security/tags">
and when running the application, i got following error:
Warning: This page calls for XML namespace http://www.springframework.org/security/tags declared with prefix sec but no taglibrary exists for that namespace.
Ref: http://static.springsource.org/spring-security/site/petclinic-tutorial.html
please advise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
成功实施:
除了正常的 Spring Security 依赖项之外,您
的 POM 文件中还需要以下两个额外的 Maven 依赖项。
对于 JSF 2,将以下内容保存为 /WEB-INF/springsecurity.taglib.xml
在 web.xml 中注册上述文件:
它将解决“没有标记库存在”警告,现在您可以在视图中使用标记库了。您可以使用授权标签有条件地包含嵌套内容:
参考:https://docs.spring.io/spring-webflow/docs/2.3.x/reference/html/spring-faces.html#spring-faces-security-taglib
Successfully implemented:
On top of your normal Spring Security dependencies you'll need the following two additional Maven dependencies
in your POM file.
For JSF 2 save the following as /WEB-INF/springsecurity.taglib.xml
Register the above file in web.xml:
It will resolve no taglibrary exists warning and now you are ready to use the tag library in your views. You can use the authorize tag to include nested content conditionally:
REFERENCE: https://docs.spring.io/spring-webflow/docs/2.3.x/reference/html/spring-faces.html#spring-faces-security-taglib
您需要先添加 springsecurity.taglib.xml
正如这里提到的:
http://docs.spring.io/autorepo/docs/webflow/2.3.x/reference/html/spring-faces.html#spring-faces-security-taglib
你应该有org.springframework.faces jar 到你的类路径中以便使用它。
然后使用安全标签,如下所示:
参考
You will need to add springsecurity.taglib.xml first
as mentioned here:
http://docs.spring.io/autorepo/docs/webflow/2.3.x/reference/html/spring-faces.html#spring-faces-security-taglib
and you should have the org.springframework.faces jar in your classpath in order to use it.
then use the security tags as follows:
Reference
使用 JSF 并不像使用 Spring MVC 那样容易...
但是您可以在此错误报告中找到一种方法来做到这一点
https://jira.springsource.org/browse/SWF-1333
来自 Rossen Stoyanchev 的最后一条消息
It's not as easy with JSF as it is with Spring MVC...
But you can find a way to do it in this bug report
https://jira.springsource.org/browse/SWF-1333
last message from Rossen Stoyanchev