我正在尝试将“Spring security 3.2.0”包含到我现有的 web 应用程序中,该应用程序是在没有 spring 的情况下使用 Primefaces 和 EJB 3 构建的。
当我从基本配置开始,并尝试访问没有 CSS 样式的页面显示时。下面的日志有一些关于路径的信息。我不确定我错过了什么。
非常感谢。
应用程序日志:-
05-02-2014 16:05:58 INFO DispatcherServlet:472 - FrameworkServlet 'spring': initialization completed in 831 ms
05-02-2014 16:05:58 DEBUG DispatcherServlet:141 - Servlet 'spring' configured successfully
05-02-2014 16:05:58 DEBUG DispatcherServlet:823 - DispatcherServlet with name 'spring' processing GET request for [/myapp/resources/css/myapp.css]
05-02-2014 16:05:58 DEBUG DispatcherServlet:823 - DispatcherServlet with name 'spring' processing GET request for [/myapp/resources/images/bg_myapp_header.gif]
05-02-2014 16:05:58 DEBUG DispatcherServlet:823 - DispatcherServlet with name 'spring' processing GET request for [/myapp/resources/js/myapp.js]
05-02-2014 16:05:58 DEBUG DispatcherServlet:823 - DispatcherServlet with name 'spring' processing GET request for [/myapp/resources/images/2_arial_white_myapp_bg.png]
05-02-2014 16:05:58 DEBUG DispatcherServlet:823 - DispatcherServlet with name 'spring' processing GET request for [/myapp/resources/images/logo.png]
05-02-2014 16:05:58 DEBUG RequestMappingHandlerMapping:209 - Looking up handler method for path /resources/css/myapp.css
05-02-2014 16:05:58 DEBUG RequestMappingHandlerMapping:209 - Looking up handler method for path /resources/js/myapp.js
05-02-2014 16:05:58 DEBUG RequestMappingHandlerMapping:219 - Did not find handler method for [/resources/js/myapp.js]
05-02-2014 16:05:58 DEBUG RequestMappingHandlerMapping:209 - Looking up handler method for path /resources/images/bg_myapp_header.gif
05-02-2014 16:05:58 DEBUG RequestMappingHandlerMapping:209 - Looking up handler method for path /resources/images/2_arial_white_myapp_bg.png
05-02-2014 16:05:58 DEBUG RequestMappingHandlerMapping:209 - Looking up handler method for path /resources/images/eba_logo.png
05-02-2014 16:05:58 DEBUG RequestMappingHandlerMapping:219 - Did not find handler method for [/resources/images/2_arial_white_myapp_bg.png]
05-02-2014 16:05:58 DEBUG RequestMappingHandlerMapping:219 - Did not find handler method for [/resources/images/bg_myapp_header.gif]
05-02-2014 16:05:58 DEBUG RequestMappingHandlerMapping:219 - Did not find handler method for [/resources/css/myapp.css]
05-02-2014 16:05:58 WARN PageNotFound:1108 - No mapping found for HTTP request with URI [/myapp/resources/images/bg_myapp_header.gif] in DispatcherServlet with name 'spring'
05-02-2014 16:05:58 WARN PageNotFound:1108 - No mapping found for HTTP request with URI [/myapp/resources/images/2_arial_white_myapp_bg.png] in DispatcherServlet with name 'spring'
05-02-2014 16:05:58 WARN PageNotFound:1108 - No mapping found for HTTP request with URI [/myapp/resources/js/myapp.js] in DispatcherServlet with name 'spring'
05-02-2014 16:05:58 DEBUG RequestMappingHandlerMapping:219 - Did not find handler method for [/resources/images/logo.png]
05-02-2014 16:05:58 DEBUG HttpSessionSecurityContextRepository:300 - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
05-02-2014 16:05:58 DEBUG HttpSessionSecurityContextRepository:300 - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
05-02-2014 16:05:58 DEBUG HttpSessionSecurityContextRepository:300 - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
05-02-2014 16:05:58 WARN PageNotFound:1108 - No mapping found for HTTP request with URI [/myapp/resources/css/myapp.css] in DispatcherServlet with name 'spring'
05-02-2014 16:05:58 DEBUG DispatcherServlet:946 - Successfully completed request
05-02-2014 16:05:58 DEBUG DispatcherServlet:946 - Successfully completed request
05-02-2014 16:05:58 DEBUG DispatcherServlet:946 - Successfully completed request
05-02-2014 16:05:58 WARN PageNotFound:1108 - No mapping found for HTTP request with URI [/myapp/resources/images/logo.png] in DispatcherServlet with name 'spring'
spring-security.xml
<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/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
<authentication-manager>
<authentication-provider>
<user-service>
<user name="jay" password="jay" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
<http pattern="/resources/css/**" security="none" />
<http pattern="/resources/images/**" security="none" />
<http pattern="/resources/js/**" security="none" />
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/faces/javax.faces.resource/**" access="permitAll" />
<intercept-url pattern="/faces/login.xhtml" access="permitAll" />
<intercept-url pattern="/faces/search.xhtml" access="permitAll" />
<intercept-url pattern="/faces/create.xhtml" access="hasRole('ROLE_USER')" />
<intercept-url pattern="/faces/update.xhtml" access="hasRole('ROLE_USER')" />
<intercept-url pattern="/**" access="permitAll" />
</http>
</beans:beans>
spring-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" 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.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<mvc:annotation-driven />
<import resource="spring-security.xml" />
<mvc:resources location="/css/**" mapping="/resources/css/" />
<mvc:resources location="/images/**" mapping="/resources/images/" />
<mvc:resources location="/js/**" mapping="/resources/js/" />
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<!-- JSF configuration -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<!-- Filter for not to have local cache, instead load from server -->
<filter>
<filter-name>NoCacheFilter</filter-name>
<filter-class>com.jai.NoCacheFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>NoCacheFilter</filter-name>
<url-pattern>/faces/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.jai.HttpSessionChecker</listener-class>
</listener>
<!-- Primefaces theme -->
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>aristo</param-value>
</context-param>
<!-- Spring security configuration -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-security.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>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
最佳答案
如果你删除路径中的资源会怎么样
<security:http pattern="/css/**" security="none"/>
<security:http pattern="/images/**" security="none"/>
<security:http pattern="/js/**" security="none"/>
关于java - Spring security 3.2 - CSS 显示问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21583301/