作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法在 SO 上找到答案(例如在这里。
Spring Security: Commence method in class extending BasicAuthenticationEntryPoint no being called )
我只想覆盖 BasicAuthenticationEntryPoint 而不覆盖其他过滤器和其他员工:
<bean id="authenticationEntryPoint" name="authenticationEntryPoint"
class="com.myclass.BasicAuthenticationEntryPoint">
<property name="realmName" value="myapp" />
</bean>
<security:http auto-config="true" ..
<sec:custom-filter ref="basicAuthenticationFilter"
before="BASIC_AUTH_FILTER" />
</sec:http>
<bean id="basicAuthenticationFilter"
class="org.springframework.security.web.authentication.www.BasicAuthenticationFilter">
<constructor-arg name="authenticationManager" ref="authenticationManager" />
<constructor-arg name="authenticationEntryPoint" ref="authenticationEntryPoint" />
</bean>
WARN 2015-10-29 09:44:05,330 [localhost-startStop-1::DefaultFilterChainValidator] [user:system] Possible error: Filters at position 2 and 3 are both instances of org.springframework.security.web.authentication.www.BasicAuthenticationFilter
<security:http auto-config="false" ...
最佳答案
这适用于 Spring Security 3(我认为它应该适用于 Spring 4),无需配置任何过滤器:
public class CustomBasicAuthenticationEntryPoint extends BasicAuthenticationEntryPoint {
@Override
public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException, ServletException {
response.setStatus( HttpServletResponse.SC_UNAUTHORIZED);
}
}
<bean id="authenticationEntryPoint" name="authenticationEntryPoint"
class="com.myclass.CustomBasicAuthenticationEntryPoint">
<property name="realmName" value="myapp" />
</bean>
<security:http entry-point-ref="authenticationEntryPoint" ...
关于spring-security - 在 SpringSecurity 4 中覆盖 BasicAuthenticationEntryPoint 的最简单方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33409105/
我无法在 SO 上找到答案(例如在这里。 Spring Security: Commence method in class extending BasicAuthenticationEntryPoi
我是一名优秀的程序员,十分优秀!