2013-07-08 14 views
5

Chcę zaimplementować niestandardowe strony błędów dla aplikacji WWW. Używam następujący sposób:Spring MVC: strony błędów i główne informacje

web.xml

<error-page> 
    <error-code>404</error-code> 
    <location>/404/</location> 
</error-page> 

wiosna-security.xml

<http use-expressions="true"> 
    <form-login ... /> 
    <access-denied-handler error-page="/403/" /> 
    .... 
</http> 

Obie strony są obsługiwane przez odpowiedniego kontrolera. Ale wydaje się, że principal jest w tym przypadku nieosiągalny, tj. Nie mogę uzyskać żadnych informacji o aktualnie zalogowanym użytkowniku.

Czy to zachowanie domyślne, czy też mam błąd w kodzie?

Dziękuję

UPD # 1: Mój config:

<listener> 
    <listener-class> 
      org.springframework.web.context.ContextLoaderListener 
     </listener-class> 
    </listener> 
    <context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     /WEB-INF/spring-service.xml 
     /WEB-INF/spring-security.xml 
     /WEB-INF/spring-data.xml 
     /WEB-INF/spring-mail.xml 
    </param-value> 
    </context-param> 
    <filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
    </filter> 
    <filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
    </filter-mapping> 
    <filter> 
    <filter-name>hibernateFilter</filter-name> 
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> 
    <init-param> 
     <param-name>sessionFactoryBeanName</param-name> 
     <param-value>sessionFactory</param-value> 
    </init-param> 
    </filter> 
    <filter-mapping> 
    <filter-name>hibernateFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
    </filter-mapping> 
    <servlet> 
    <servlet-name>spring</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>0</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>spring</servlet-name> 
    <url-pattern>/</url-pattern> 
    </servlet-mapping> 
+0

how czy mapujesz filtr bezpieczeństwa w pliku web.xml? – Pastur

+0

@AbelPastur patrz aktualizacja – nKognito

Odpowiedz

6

Aby uzyskać dostęp do głównych danych ze stron błędów, trzeba mapować filtr zabezpieczający sprężynowy jak:

<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>REQUEST</dispatcher> 
    <dispatcher>ERROR</dispatcher> 
</filter-mapping>