【问题标题】:Trying to add Security to my Spring Web Flow2 Project尝试将安全性添加到我的 Spring Web Flow2 项目
【发布时间】:2012-09-01 15:58:24
【问题描述】:

我有一个正在处理的 Web 流项目,现在是时候为其添加一些安全性了。我有用于演示的登录屏幕,但我想添加:

@PreAuthorize(isAuthenticated());

对于我在控制、服务和 dao 中的一些功能,我知道只有登录用户才能访问这些功能。 @PreAuthorize(isAuthenticated()) 不起作用,我真的不想使用 @PreAuthorize("hasRole('ROLE_USER')")

谁能告诉我如何更好地锁定我的代码

这是我的 security.xml 文件:

<?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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://www.springframework.org/schema/security
                        http://www.springframework.org/schema/security/spring-security-3.1.xsd">


    <global-method-security pre-post-annotations="enabled"/>

    <http use-expressions="true">
        <intercept-url access="hasRole('ROLE_USER')"    pattern="/visit**" />
        <intercept-url pattern='/*' access='permitAll' />
        <form-login   default-target-url="/visit" />

        <logout logout-success-url="/" />
    </http>

    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="user" password="user" authorities="ROLE_USER" />
            </user-service>

        </authentication-provider>
    </authentication-manager>
</beans:beans>

【问题讨论】:

  • 你能提供你的security.xml文件吗?
  • 并且比“它不起作用”更精确一点。你得到什么例外?你确定你的安全文件中有 吗?
  • 我的 xml 中有它。它喜欢@PreAuthorize() 但不喜欢@PreAuthorize(isAuthenticated());

标签: java spring spring-mvc spring-security spring-webflow


【解决方案1】:

尝试将isAuthenticated() 放在引号中。

@PreAuthorize("isAuthenticated()");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-18
    • 1970-01-01
    • 2012-08-29
    • 2015-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多