Problems with loading the spring and spring security config XML

0

Good I have problems to implement the spring security, I had previously configured the spring freamworks and its beans and it works perfect. Now that I have put the spring security beans when I use java, I get a NullPointer error. The problem is eliminated if one removes the spring security, which is not the idea. I leave the main files.

Web.XML

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
     http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/spring-security.xml
        /WEB-INF/spring-config.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>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>

<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>*.xhtml</url-pattern>
</servlet-mapping>

Faces-Config.XML

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
          http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">

<application>
    <el-resolver>
        org.springframework.web.jsf.el.SpringBeanFacesELResolver
    </el-resolver>
</application>

<navigation-rule>
    <from-view-id>/Logins.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>success</from-outcome>
        <to-view-id>/Security/Inicio.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

Spring-Config.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:p="http://www.springframework.org/schema/p"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:jee="http://www.springframework.org/schema/jee"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:task="http://www.springframework.org/schema/task"
   xsi:schemaLocation="http://www.springframework.org/schema/aop
   http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
   http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-4.2.xsd
   http://www.springframework.org/schema/jee
   http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
   http://www.springframework.org/schema/tx
   http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
   http://www.springframework.org/schema/task
   http://www.springframework.org/schema/task/spring-task-4.2.xsd">

<!-- support spring annotation -->
<context:annotation-config />
<!-- support annotation transaction -->
<tx:annotation-driven transaction-manager="transactionManager" />

<!-- declare datasource -->
<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/controlgasto" />
    <property name="username" value="root" />
    <property name="password" value="" />
</bean>

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

<!--Hibernate session factory configuration -->
<bean id="sessionFactory"
      class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <!-- load hibernate configuration file -->
    <property name="configLocation" value="/WEB-INF/hibernate.cfg.xml" />
    <!-- where to find the ORM classes -->
    <property name="packagesToScan" value="com.controlGasto.hibernate.model" />
</bean>

<!--Hibernate session factory configuration -->
<bean id="sessionFactoryMySQL"
      class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSourceMysqlInicial" />
    <!-- load hibernate configuration file -->
    <property name="configLocation" value="/WEB-INF/hibernate.cfg.xml" />
</bean>

<!-- Transaction manager -->
<bean id="transactionManager"
      class="org.springframework.orm.hibernate5.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!-- service -->
<bean id="usuarioService" class="com.controlGasto.hibernate.services.UsuarioServiceImpl" />
<bean id="efectivoService" class="com.controlGasto.hibernate.services.EfectivoServiceImpl"/>
<bean id="calendarioService" class="com.controlGasto.hibernate.services.CalendarioServiceImpl"/>
<bean id="crearBaseDatoService" class="com.controlGasto.hibernate.services.CrearBaseDatoServiceImpl"/>
<bean id="java_LocaleService" class="com.controlGasto.hibernate.services.Java_LocaleServiceImpl"/>
<bean id="configuracionService" class="com.controlGasto.hibernate.services.ConfiguracionServiceImpl"/>
<bean id="tipo_OperacionService" class="com.controlGasto.hibernate.services.Tipo_OperacionServiceImpl"/>
<bean id="banco_listadoService" class="com.controlGasto.hibernate.services.Banco_ListadoServiceImpl"/>

<!-- dao -->
<bean id="usuarioDao" class="com.controlGasto.hibernate.DAO.UsuarioDaoImpl" />
<bean id="efectivoDao" class="com.controlGasto.hibernate.DAO.EfectivoDaoImpl"/>
<bean id="calendarioDao" class="com.controlGasto.hibernate.DAO.CalendarioDaoImpl"/>
<bean id="crearBaseDatoDao" class="com.controlGasto.hibernate.DAO.CrearBaseDatoDaoImpl"/>
<bean id="java_LocaleDao" class="com.controlGasto.hibernate.DAO.Java_LocaleDaoImpl"/>
<bean id="configuracionDao" class="com.controlGasto.hibernate.DAO.ConfiguracionDaoImpl"/>
<bean id="tipo_OperacionDao" class="com.controlGasto.hibernate.DAO.Tipo_OperacionDaoImpl"/>
<bean id="banco_listadoDao" class="com.controlGasto.hibernate.DAO.Banco_listadoDaoImpl"/>

<!--SPRING SECURITY ENCRIPTING-->
<bean id="encriptar" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder">
    <constructor-arg value="12"/>
</bean>
<bean id="loginBean" class="com.controlGasto.jsf.beans.Login.LoginBean">
    <property name="authenticationManager" ref="authenticationManager"/>
</bean>

Spring-Security.XML

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

<bean:import resource="spring-config.xml"/>

<http auto-config="true" use-expressions="false">
    <intercept-url pattern="/Security/**" access="ROLE_Usuario" />
    <form-login login-page="/Logins.xhtml"
                default-target-url="/index.xhtml"
                authentication-failure-url="/Login-Error.xhtml"/>
    <csrf disabled="true"/>
</http>

<authentication-manager alias="authenticationManager">
    <authentication-provider>
        <password-encoder ref="encriptar"/>
        <user-service>
            <user name="manuel"  password="$2a$12$d/9IWBc1AVHifA9g4cDzuev3T28yS6BXu7Y1Jm6HSQjtZp8eq84LO" authorities="ROLE_Usuario" />
        </user-service>
    </authentication-provider>
</authentication-manager>

    
asked by David Valado 03.02.2018 в 00:31
source

0 answers