【发布时间】:2016-03-20 03:42:56
【问题描述】:
我正在使用基于 Spring security 4 XML 的配置。
这是我的配置:
<security:http use-expressions="true" authentication-manager-ref="authenticationManager" entry-point-ref="authenticationEntryPoint">
<security:intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
<security:form-login authentication-success-handler-ref="authenticationSuccessHandler"
authentication-failure-handler-ref="authenticationFailureHandler"
/>
<security:logout success-handler-ref="logoutSuccessHandler"/>
<security:csrf disabled="true"/>
</security:http>
<security:authentication-manager id="authenticationManager">
<security:authentication-provider>
<security:user-service>
<security:user name="username" authorities="ROLE_USER" password="password"/>
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
<bean id="authenticationEntryPoint" class="package.CustomBasicAuthenticationEntryPoint">
authenticationEntryPoint 有以下实现:
public class CustomBasicAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
}
问题是,当我尝试进行身份验证时:
http://localhost:8080/myApp/api/j_spring_security_check 带有正文:j_password=password&j_username=username
由于我的自定义入口点,我总是有 401 错误状态。在我看来,spring security 没有调用身份验证管理器。我错过了什么吗?
感谢您的帮助。
更新
感谢您的回答,我一直在使用 Spring Security 3.2,我将 j_username、j_password 和 j_spring_security_check 更改为用户名、密码和登录名。我仍然有同样的问题:401 代码状态:Spring Security 正在调用自定义 authenticationEntryPoint,即使我尝试使用表单(POST)进行身份验证。
【问题讨论】:
标签: java spring spring-security