2014-02-01 4 views
-1

Я знаю, что эта проблема здесь очень популярна. Но никто мне не помог.Spring Security 3.2 Конфигурация XML

Проблема в том, что я не могу настроить конфигурационный файл spring-security.xml. У меня также есть 404 ошибка на / страница.

web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" 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_2_5.xsd"> 

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      /WEB-INF/spring-context.xml 
      /WEB-INF/spring-data.xml 
      /WEB-INF/spring-security.xml 
      /WEB-INF/mvc-dispatcher-servlet.xml 
     </param-value> 
    </context-param> 

    <servlet> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

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

    <!-- utf8 Encoder --> 
    <filter> 
     <filter-name>charsetFilter</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>charsetFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

    <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> 

</web-app> 

весна-security.xml

<?xml version="1.0" encoding="UTF-8"?> 
<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"> 

    <http auto-config="true" use-expressions="true"> 
     <intercept-url pattern="/*" access="permitAll" /> 
     <intercept-url pattern="/**" access="hasRole('ROLE_USER')" /> 
     <form-login login-page="/" default-target-url="/home" authentication-failure-url="/?error=true"/> 
     <logout logout-success-url="/" /> 
    </http> 

    <authentication-manager> 
     <authentication-provider user-service-ref="userDetailsService" /> 
    </authentication-manager> 

</beans:beans> 

Пожалуйста, помогите мне с моей проблемой. Благодаря!

=== UPDATE: ===

MVC-диспетчерская-servlet.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:beans="http://www.springframework.org/schema/beans" 
     xsi:schemaLocation=" 
       http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
       http://www.springframework.org/schema/mvc 
       http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> 

    <annotation-driven /> 

    <resources mapping="/res/**" location="file:/home/piotr/Work/apache-tomcat-7.0.42/work-dir/res/" /> 

    <beans:bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <beans:property name="prefix" value="/WEB-INF/pages/"/> 
     <beans:property name="suffix" value=".jsp" /> 
    </beans:bean> 

    <beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 
     <beans:property name="maxUploadSize" value="1000000000"/> 
    </beans:bean> 

    <beans:bean id="fileUploadService" class="com.petrez.service.FileUploadServiceImpl"> 
     <beans:property name="savePath" value="/home/piotr/Work/apache-tomcat-7.0.42/work-dir" /> 
    </beans:bean> 
</beans:beans> 

пружинно-context.xml

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

    <annotation-config /> 

    <component-scan base-package="com.petrez" /> 

</beans:beans> 

весенне data.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:tx="http://www.springframework.org/schema/tx" 
     xsi:schemaLocation=" 
       http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> 

    <tx:annotation-driven transaction-manager="transactionManager" /> 

    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
     <property name="sessionFactory" ref="sessionFactory"/> 
    </bean> 

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
     <property name="url" value="jdbc:mysql://localhost:3306/Library" /> 
     <property name="username" value="root" /> 
     <property name="password" value="G190419g" /> 
    </bean> 

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
     <property name="packagesToScan" value="com.petrez" /> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 
       <prop key="show_sql">false</prop> 
      </props> 
     </property> 
     <property name="annotatedClasses"> 
      <list> 
       <value>com.petrez.model.User</value> 
       <value>com.petrez.model.Role</value> 
       <value>com.petrez.model.Book</value> 
       <value>com.petrez.model.BookGenre</value> 
      </list> 
     </property> 
    </bean> 

    <bean id="userDetailsService" class="com.petrez.service.CustomUserDetailsService" /> 

    <bean id="messageSource" 
      class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
     <property name="basename" value="classpath:messages" /> 
     <property name="defaultEncoding" value="UTF-8" /> 
    </bean> 
</beans> 
+1

404 на «/» - у вас есть контроллер (метод), отображаемый на «/»? –

+0

@ Evgeni конечно. Я только что вернул старую конфигурацию весны xml, которая была до ее редактирования. –

+0

Любые исключения в журнале? Если вы удалите защищенность, снова начните? Лучший способ справиться с проблемами Spring Security - включить ведение журнала (log4j.logger.org.springframework.security = All для log4j) и отслеживать, как обрабатываются запросы. –

ответ

0

@Petr, я знаю, что эта нить длинной спиной один, но я думаю, что вы, возможно, пропустили какой-либо из следующих весенних библиотек,

  • весна-безопасности ядро ​​
  • весна-безопасности веб
  • весна-безопасности контекст

Из документации Spring Security в https://docs.spring.io/spring-security/site/docs/3.0.x/reference/ns-config.html, я нашел следующую цитату

Чтобы начать использовать пространство имен безопасности в контексте приложения, сначала необходимо убедиться, что весна-безопасности config.jar на вашем пути к классам. Затем все, что вам нужно сделать, это добавить объявление схемы в файл контекста приложения:

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