首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 ><sec:authorize>不起作用

<sec:authorize>不起作用
EN

Stack Overflow用户
提问于 2014-04-28 17:16:16
回答 2查看 11.1K关注 0票数 4

我有以下用户xhtml页面:

代码语言:javascript
复制
<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安全配置:

代码语言:javascript
复制
<?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"",我有一个警告

代码语言:javascript
复制
NLS missing message: CANNOT_FIND_FACELET_TAGLIB in: org.eclipse.jst.jsf.core.validation.internal.facelet.messages

重要吗?是问题的原因吗?

我的maven安全依赖项:

代码语言:javascript
复制
        <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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-05-13 09:23:07

最后我解决了这个问题。

以下是帮助我的链接:

1) "Amreesh Tyagi“的答案,How to use the Spring Security Facelets tag library in JSF

2)本文的第三部分( http://doanduyhai.wordpress.com/2012/02/26/spring-security-part-v-security-tags/ )第三部分(用于Facelet的安全标签)

我使用了Amreesh Tyagi的springsecurity.taglib.xml文件,而不是本文中的文件,因为我在访问函数方面遇到了问题。

票数 3
EN

Stack Overflow用户

发布于 2018-04-06 14:21:29

在这里添加一个答案,因为我有相同的症状,但发现了一个不同的问题。我们的标签不像预期的那样工作。每个人都能看到安全的内容。解决方案是我们的XML名称空间在页面上拼写错误。

代码语言:javascript
复制
 xmlns="http://www.sprinfgramework.org/schema/security"

这需要一段时间才能找到,因为拼写错误没有产生任何错误(这是令人惊讶的),它只是忽略了安全标签并显示了它包含的内容。

希望这能帮上忙。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23347241

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档