Spring Security:如何制作匿名内容?

时间:2015-02-23 22:20:01

标签: spring-security roles

我想让我的项目中的某些页面只能被匿名用户访问(例如:/ login,/ signup),但由于某种原因,其他角色也可以访问它们。(它会杀了我,因为其他方式实际上工作..)

这是我的http配置:

<http authentication-manager-ref="dao-auth"
    access-decision-manager-ref="accessDecisionManager" 
    disable-url-rewriting="true">
    <intercept-url pattern="/pages/usermain.html" access="USER"></intercept-url>
    <intercept-url pattern="/pages/home.html" access="USER"></intercept-url>
    <intercept-url pattern="/home" access="USER"></intercept-url>
    <intercept-url pattern="/logout" access="USER"></intercept-url>
    <intercept-url pattern="/login" access="ROLE_ANONYMOUS"></intercept-url>
    <intercept-url pattern="/denied" access="ROLE_ANONYMOUS"></intercept-url>
    <form-login login-page="/login" authentication-failure-url="/login/bad"
        default-target-url="/home" 
        login-processing-url="/authenticate" 
        username-parameter="email" password-parameter="password" />
    <logout invalidate-session="true" logout-success-url="/"
        logout-url="/logout" />
    <access-denied-handler error-page="/denied" />
    <session-management invalid-session-url="/login">
        <concurrency-control max-sessions="1"
            expired-url="/login" />
    </session-management>
</http>

谢谢!

1 个答案:

答案 0 :(得分:0)

解决了它。

为了限制ROLE_ANONYMOUS我必须激活 use-expressions =“true” 在http标记中,然后将我对所有访问权限更改为等效的布尔表达式(仅相当于匿名是 access =“isAnonymous()”)。