По умолчанию Spring Security перенаправляется на favicon
Я использую 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>
Ответы
Ответ 1
Лучше всего полностью опустить этот путь из цепочки фильтров.
использование
<http pattern="/favicon.ico" security="none" />
<http auto-config="true">
<intercept-url pattern="/**" access="ROLE_ADMIN"/>
</http>
вместо.
Также помните, что вам нужно заказать элементы intercept-url
от большинства до наименее определенных шаблонов, поэтому ваша первоначальная конфигурация в любом случае проигнорировала бы шаблон favicon.
Я также рекомендовал бы, чтобы вы не использовали auto-config
но указали те функции, которые вы хотите использовать явно, чтобы было ясно, что добавляется в цепочку фильтров безопасности.