默认Spring Security重定向到favicon

me1*_*111 14 spring spring-security

我正在使用Spring Security 3.1.授权后重定向时出现问题.它重定向到favicon 404错误.role_anonymous为favicon 添加没有帮助.

<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.0.xsd
    http://www.springframework.org/schema/security 
    http://www.springframework.org/schema/security/spring-security-3.1.xsd">

<!--To enable spring security comment this string
    <http auto-config="true" security="none"/>-->

    <!-- To enable spring security remove comment from this code-->
        <http auto-config="true">
                <intercept-url pattern="/**" access="ROLE_ADMIN"/>
                <intercept-url pattern="/favicon.ico" access="ROLE_ANONYMOUS" />
        </http>


<authentication-manager>
    <authentication-provider>
        <user-service>
            <user name="hey" password="there" authorities="ROLE_ADMIN" />
        </user-service>
    </authentication-provider>
</authentication-manager>

</beans:beans>
Run Code Online (Sandbox Code Playgroud)

Sha*_*eep 28

您最好完全省略过滤器链中的路径.

使用

<http pattern="/favicon.ico" security="none" />

<http auto-config="true">
    <intercept-url pattern="/**" access="ROLE_ADMIN"/>
</http>
Run Code Online (Sandbox Code Playgroud)

代替.

还要记住,您需要intercept-url从最常用的模式到最不具体的模式对元素进行排序,因此在任何情况下,原始配置都会忽略favicon模式.

我还建议您不要使用,auto-config而是指定要明确使用的功能,以便清楚添加到安全筛选器链的内容.