【发布时间】:2016-08-02 02:59:05
【问题描述】:
我有一个 Spring rest 服务,我正在尝试为其添加安全性。我关注了this tutorial,但是当我尝试直接访问该服务时,出现以下错误:
出现意外错误(类型=内部服务器错误, 状态=500)。无法评估表达式“ROLE_USER”
这是我的安全配置:
webSecurityConfig.xml
<http entry-point-ref="restAuthenticationEntryPoint">
<intercept-url pattern="/**" access="ROLE_USER"/>
<form-login
authentication-success-handler-ref="mySuccessHandler"
authentication-failure-handler-ref="myFailureHandler"
/>
<logout />
</http>
<beans:bean id="mySuccessHandler"
class="com.eficid.cloud.security.rest.AuthenticationSuccessHandler"/>
<beans:bean id="myFailureHandler" class=
"org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"/>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="temp" password="temp" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
SpringSecurityConfig:
public class SpringSecurityConfig {
public SpringSecurityConfig() {
super();
}
}
我在尝试使用 curl 登录时也遇到此错误:
{
"timestamp":1460399841286,
"status":403,"error":"Forbidden",
"message":"Could not verify the provided CSRF token because your session was not found.",
"path":"/spring-security-rest/login"
}
我需要手动将 csrf 令牌添加到命令中吗?该服务有一个自签名证书,如果这有什么不同的话。
【问题讨论】:
-
您似乎没有 HTTP 会话。
标签: spring spring-security csrf self-signed