2012-06-28 31 views
13

Tôi đang sử dụng Spring Security 3.1. Tôi gặp sự cố khi chuyển hướng sau khi ủy quyền. Nó chuyển hướng đến lỗi 404 favicon. Thêm role_anonymous cho favicon không giúp được gì.Mặc định Spring Security chuyển hướng đến 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> 

Trả lời

27

Tốt nhất bạn nên bỏ qua đường dẫn đó khỏi chuỗi bộ lọc hoàn toàn.

Sử dụng

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

<http auto-config="true"> 
    <intercept-url pattern="/**" access="ROLE_ADMIN"/> 
</http> 

để thay thế.

Cũng nên nhớ rằng bạn cần đặt hàng các thành phần intercept-url từ hầu hết các mẫu ít nhất là cụ thể, vì vậy cấu hình ban đầu của bạn sẽ bỏ qua mẫu favicon trong mọi trường hợp.

Tôi cũng khuyên bạn không nên sử dụng auto-config nhưng chỉ định các tính năng bạn muốn sử dụng một cách rõ ràng để bạn rõ ràng những gì đang được thêm vào chuỗi bộ lọc bảo mật.

Các vấn đề liên quan