[英]<sec:authorize> doesn't work
我有以下用戶xhtml頁面:
<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:p="http://primefaces.org/ui"
xmlns:sec="http://www.springframework.org/security/tags">
<head>
<title>User</title>
</head>
<body>
<p>User</p>
<sec:authorize access="hasRole('ROLE_ADMIN')">
<p>Only admin can see this !</p>
</sec:authorize>
</body>
</html>
但是當我使用沒有角色ROLE_ADMIN的用戶訪問該頁面時,他仍然可以看到“只有管理員可以看到這個!”
編輯:
這是我的spring安全配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.2.xsd">
<http pattern="/resources" security="none" />
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/login**" access="permitAll" />
<intercept-url pattern="/denied**" access="permitAll" />
<intercept-url pattern="/user/*" access="hasRole('ROLE_USER')" />
<intercept-url pattern="/admin/*" access="hasRole('ROLE_ADMIN')" />
<form-login login-page="/login.xhtml"
authentication-failure-url="/denied.xhtml"
authentication-success-handler-ref="securityAuthenticationSuccessHandler" />
<access-denied-handler error-page="/denied.xhtml" />
<logout logout-success-url="/login.xhtml" delete-cookies="JSESSIONID"
invalidate-session="true" />
</http>
<authentication-manager>
<authentication-provider user-service-ref="securityProviderServiceImpl">
<password-encoder hash="md5" />
</authentication-provider>
</authentication-manager>
</beans:beans>
它有什么問題嗎?
謝謝..
編輯2:
我對安全標記lib “xmlns:sec =”http://www.springframework.org/security/tags“” 發出警告
NLS missing message: CANNOT_FIND_FACELET_TAGLIB in: org.eclipse.jst.jsf.core.validation.internal.facelet.messages
那很重要么? 這是問題的原因嗎?
我的maven安全依賴項:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${org.springframework.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${org.springframework.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${org.springframework.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${org.springframework.security.version}</version>
</dependency>
最后我解決了這個問題。
以下鏈接對我有很大幫助:
1)此處“Amreesh Tyagi”的答案如何在JSF中使用Spring Security Facelets標記庫 。
和
2)本文的第3部分(Facelet的III安全標簽) http://doanduyhai.wordpress.com/2012/02/26/spring-security-part-v-security-tags/
我使用了Amreesh Tyagi的springsecurity.taglib.xml文件而不是文章中的一篇,因為我遇到了訪問函數的問題。
在這里添加一個答案,因為我有相同的症狀,但發現了一個不同的問題。 我們的標簽沒有按預期工作。 每個人都可以看到安全的內容。 解決方案是我們的XML命名空間在頁面上拼寫錯誤。
xmlns="http://www.sprinfgramework.org/schema/security"
這需要一段時間才能找到,因為錯誤拼寫沒有產生錯誤(這是令人驚訝的),它只是忽略了安全標記並顯示了它包含的內容。
希望這有助於某人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.