2013-07-03 81 views
1

我最近添加了使用spring安全性的過濾器來彈出以前使用過的mvc應用程序。該過濾器工作得很好,但春天無法找到.jsp文件。例如,我有一個綁定到映射到/upload的控制器的/autoPA/WEB-INF/views/csvuploadform.jsp中的jsp。 當我嘗試訪問/upload時,我必須進行身份驗證。一旦我有了,我可以訪問控制器(日誌證明它),但我在日誌中得到404和No mapping found for HTTP request with URI [/autoPA/WEB-INF/views/csvuploadform.jsp] in DispatcherServlet with name 'SocialServlet'設置Spring安全性後,無法再訪問jsp

由於我的代碼除了web.xml沒有任何變化,我認爲這裏有麻煩,但我看不到在哪裏。

這裏是上述文件:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
version="3.0"> 

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<context-param> 
    <param-name>spring.profiles.active</param-name> 
    <param-value>dev</param-value> 
</context-param> 

<filter> 
    <filter-name>encodingFilter</filter-name> 
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 
    <init-param> 
     <param-name>encoding</param-name> 
     <param-value>UTF-8</param-value> 
    </init-param> 
    <init-param> 
     <param-name>forceEncoding</param-name> 
     <param-value>true</param-value> 
    </init-param> 
</filter> 

<filter-mapping> 
    <filter-name>encodingFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

<filter> 
    <filter-name>hiddenHttpMethodFilter</filter-name> 
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>hiddenHttpMethodFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

<servlet> 
    <servlet-name>SocialServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
     /WEB-INF/social-context.xml   
     </param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
    <async-supported>true</async-supported> 
</servlet> 
<servlet-mapping> 
    <servlet-name>SocialServlet</servlet-name> 
    <url-pattern>/*</url-pattern> 
</servlet-mapping> 

<servlet> 
    <servlet-name>RESTServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/restapi-context.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>RESTServlet</servlet-name> 
    <url-pattern>/api/*</url-pattern> 
</servlet-mapping> 

<!-- Spring Security --> 
<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> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     /WEB-INF/applicationContext.xml, 
     /WEB-INF/spring-security.xml 
    </param-value> 
</context-param> 

這裏是彈簧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/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.0.3.xsd"> 

<http auto-config="true" use-expressions="true"> 
    <intercept-url pattern="/api/**" access="permitAll" /> 
    <intercept-url pattern="/**" access="hasRole('ROLE_USER')" /> 
</http> 

<authentication-manager> 
    <authentication-provider> 
     <user-service> 
      <user name="test" password="test" authorities="ROLE_USER" /> 
     </user-service> 
    </authentication-provider> 
</authentication-manager> 

這裏是社會語境.html:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" 
    xsi:schemaLocation=" 
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
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"> 


    <import resource="properties/socialProperties.xml" /> 


    <context:component-scan base-package="com.dynamease.web.social" /> 
    <context:annotation-config /> 

    <mvc:annotation-driven /> 


    <mvc:interceptors> 
     <bean class="com.dynamease.entity.springsocialentities.UserInterceptor"> 
      <constructor-arg ref="usersConnectionRepository" /> 
     </bean> 
    </mvc:interceptors> 

    <bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/WEB-INF/views/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 

    <!-- Allows users to sign-in with their provider accounts. --> 
    <bean class="org.springframework.social.connect.web.ProviderSignInController"> 
     <constructor-arg ref="connectionFactoryLocator" /> 
     <constructor-arg ref="usersConnectionRepository" /> 
     <constructor-arg> 
      <bean class="com.dynamease.entity.springsocialentities.SimpleSignInAdapter" /> 
     </constructor-arg> 
    </bean> 


    <mvc:view-controller path="/signin" /> 
    <mvc:view-controller path="/signout" /> 
    <mvc:view-controller path="/choice" /> 

    <!-- Upload --> 
    <!-- <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" 
     /> --> 
    <bean id="multipartResolver" 
     class="org.springframework.web.multipart.commons.CommonsMultipartResolver" /> 


</beans> 

我的一個控制器:`

@Controller 
@RequestMapping(value = "/upload") 
public class CSVUploadController { 
@Autowired 
private DynClassifierCSV csvClassifier; 
@Autowired 
private DynDirectoryServiceImpl dynDirectoryServiceImpl; 

@Autowired 
private DynCSVService csvService; 

private final Logger logger = LoggerFactory.getLogger(FileUpload.class); 

@RequestMapping(method = RequestMethod.GET) 
public String getUploadForm(Model model) { 
    model.addAttribute(new UploadItem()); 
    return "csvuploadform"; 
} 

}`

任何想法?

+0

您如何解決觀點? http://static.springsource.org/spring/docs/3.0.0.M3/reference/html/ch16s05.html – Dani

+0

我在我的social-context.xml中聲明瞭這個bean。正如我所說,它以前工作。 我正在添加文件。 – fxm

+0

你能顯示你的控制器代碼嗎? – Pastur

回答

1

我找到了麻煩:我通過<url-pattern>/</url-pattern>取代<url-pattern>/*</url-pattern>和它的作品。

0

您可以嘗試通過將線

<截距-URL模式改變彈簧的security.xml = 「/視圖/ **」 訪問= 「hasRole( 'ROLE_USER')」/ >

這樣/ autoPA/WEB-INF/views目錄將可供具有ROLE_USER角色的用戶使用。

希望幫助