2013-03-05 4 views
0

После добавления весенней безопасности к моему приложению она возвращает только корень моего контроллера.Весенняя безопасность возвращает корень контроллера

Когда я помещаю URL-адрес, который должен возвращать json в «рабочей» версии, он возвращает json, как ожидалось. В версии, которая использует Spring, она возвращает только корень моего контроллера.

Ниже представлен мой вывод tomcat.

DEBUG - Converted URL to lowercase, from: '/service/products/2'; to: '/service/products/2' 
DEBUG - Candidate is: '/service/products/2'; pattern is /**; matched=true 
DEBUG - /service/products/2 at position 1 of 11 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter' 
DEBUG - No HttpSession currently exists 
DEBUG - No SecurityContext was available from the HttpSession: null. A new one will be created. 
DEBUG - /service/products/2 at position 2 of 11 in additional filter chain; firing Filter: 'LogoutFilter' 
DEBUG - /service/products/2 at position 3 of 11 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter' 
DEBUG - /service/products/2 at position 4 of 11 in additional filter chain; firing Filter: 'DefaultLoginPageGeneratingFilter' 
DEBUG - /service/products/2 at position 5 of 11 in additional filter chain; firing Filter: 'BasicAuthenticationFilter' 
DEBUG - /service/products/2 at position 6 of 11 in additional filter chain; firing Filter: 'RequestCacheAwareFilter' 
DEBUG - /service/products/2 at position 7 of 11 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter' 
DEBUG - /service/products/2 at position 8 of 11 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter' 
DEBUG - Populated SecurityContextHolder with anonymous token: 'org.sprin[email protected]9055c2bc: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS' 
DEBUG - /service/products/2 at position 9 of 11 in additional filter chain; firing Filter: 'SessionManagementFilter' 
DEBUG - Requested session ID8FA5D77A75BFF4D7EBDD063710EFF5F4 is invalid. 
DEBUG - /service/products/2 at position 10 of 11 in additional filter chain; firing Filter: 'ExceptionTranslationFilter' 
DEBUG - /service/products/2 at position 11 of 11 in additional filter chain; firing Filter: 'FilterSecurityInterceptor' 
DEBUG - Converted URL to lowercase, from: '/service/products/2'; to: '/service/products/2' 
DEBUG - Candidate is: '/service/products/2'; pattern is /service/products/removeproduct**; matched=false 
DEBUG - Public object - authentication not attempted 
DEBUG - /service/products/2 reached end of additional filter chain; proceeding with original chain 
DEBUG - DispatcherServlet with name 'cr' processing GET request for [/service/products/2] 
DEBUG - Matching patterns for request [/service/products/2] are [/service/products/{productId}] 
DEBUG - URI Template variables for request [/service/products/2] are {productId=2} 
DEBUG - Mapping [/service/products/2] to HandlerExecutionChain with handler [[email protected]] and 3 interceptors 
DEBUG - Last-Modified value for [/service/products/2] is: -1 
DEBUG - Invoking request handler method: public void com.cr.controllers.ProductsController.get(javax.servlet.ServletResponse) throws java.io.IOException 
DEBUG - Returning cached instance of singleton bean 'org.springframework.transaction.interceptor.TransactionInterceptor#0' 
DEBUG - Null ModelAndView returned to DispatcherServlet with name 'cr': assuming HandlerAdapter completed request handling 
DEBUG - Successfully completed request 
DEBUG - Chain processed normally 
DEBUG - SecurityContext is empty or anonymous - context will not be stored in HttpSession. 
DEBUG - SecurityContextHolder now cleared, as request processing completed 

Я добавил следующее к моей web.xml

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     classpath:applicationContext.xml 
     classpath:spring-security.xml 
    </param-value> 
</context-param> 
<!-- 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> 

весна-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" path-type="ant"> 
     <intercept-url pattern="/service/products/removeProduct**" access="ROLE_USER" /> 
    </http> 

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

</beans:beans> 

я съехал до версии 3.0.5 для весны , вот весковые зависимости в моем pom.xml. Рабочий вариант находится на 3.2.0/3.1.3

<properties> 
     <spring.version>3.0.5.RELEASE</spring.version> 
    </properties> 
    <dependencies> 
     <dependency> 
      <groupId>org.springframework.data</groupId> 
      <artifactId>spring-data-jpa</artifactId> 
      <version>1.0.3.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-context</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-core</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-web</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-webmvc</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <!-- Spring Security --> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-core</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-web</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-config</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-orm</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-tx</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 

ответ

0

Я обнаружил, что это была проблема с комбинациями весенних версий, которые я использовал. Я внес изменения в мой Pom и одно изменение в spring-security.xml, и оно решило проблему.

<properties> 
    <spring.version>3.2.0.RELEASE</spring.version> 
</properties> 
<dependencies> 
    <dependency> 
     <groupId>org.springframework.data</groupId> 
     <artifactId>spring-data-jpa</artifactId> 
     <version>1.0.3.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-web</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
    <!-- Spring Security --> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-core</artifactId> 
     <version>3.1.3.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-web</artifactId> 
     <version>3.1.3.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-config</artifactId> 
     <version>3.1.3.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-orm</artifactId> 
     <version>3.1.3.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-tx</artifactId> 
     <version>3.1.3.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>3.6.10.Final</version> 
    </dependency> 

обновление XML Spring безопасности

<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"> 
+1

Есть ли причина, по которой вы не согласны с номерами версий в ваших пространствах имен весов (XML) до версии весны, которая у вас есть в вашем POM-файле? –

+0

Я обновил пространства имен, однако для моей будущей ссылки, что было бы неблагоприятным эффектом от отсутствия правильного пространства имен? – zmanc

+1

В идеале это не вызовет никаких проблем. У меня есть проекты, которые идут в производство с несовместимыми версиями здесь без каких-либо известных проблем. Однако в прошлом у меня было приложение, которое даже не приступило бы к этой конкретной проблеме. Итак, теперь это одна вещь, на которую я смотрю при диагностировании приложения Spring. –

1

Если вы в том числе Spring 3.2 в файле POM (в частности, 3.2.0.RELEASE), то ваш конфигурационный файл должен начинаться с:

<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.2.xsd 
     http://www.springframework.org/schema/security 
     http://www.springframework.org/schema/security/spring-security-3.2.xsd" 
> 

Обратите внимание, что номера версий в расположении схемы соответствуют номеру версии (майор/минор) используемой вами Spring Framework.

[Я попытался добавить это как комментарий к вашему ответу zmanc, но строки, подобные URL-адресу, были переинтерпретированы системой и преобразованы в ссылки (минус протоколы, а с более длинными - усеченными).]

Смежные вопросы