Atualização do log4j
commit
b927769f02
15
pom.xml
15
pom.xml
|
@ -1,9 +1,10 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd ">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>br.com.rjconsultores</groupId>
|
<groupId>br.com.rjconsultores</groupId>
|
||||||
<artifactId>ModelWeb</artifactId>
|
<artifactId>ModelWeb</artifactId>
|
||||||
<version>1.20.0</version>
|
<version>1.24.0</version>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
<id>rj-releases</id>
|
<id>rj-releases</id>
|
||||||
|
@ -203,7 +204,7 @@
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-core</artifactId>
|
<artifactId>log4j-core</artifactId>
|
||||||
<version>2.21.1</version>
|
<version>2.21.1</version>
|
||||||
|
@ -229,7 +230,13 @@
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-jcl</artifactId>
|
<artifactId>log4j-jcl</artifactId>
|
||||||
<version>2.21.1</version>
|
<version>2.21.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.nimbusds</groupId>
|
||||||
|
<artifactId>nimbus-jose-jwt</artifactId>
|
||||||
|
<classifier>jdk16</classifier>
|
||||||
|
<version>4.11.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
|
|
@ -5,10 +5,14 @@
|
||||||
package com.rjconsultores.ventaboletos.dao;
|
package com.rjconsultores.ventaboletos.dao;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.entidad.AsientoExclusivo;
|
import com.rjconsultores.ventaboletos.entidad.AsientoExclusivo;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author rodrigo
|
* @author rodrigo
|
||||||
*/
|
*/
|
||||||
public interface AsientoExclusivoDAO extends GenericDAO<AsientoExclusivo, Integer> {
|
public interface AsientoExclusivoDAO extends GenericDAO<AsientoExclusivo, Integer> {
|
||||||
|
|
||||||
|
void borrarByCorrida(Corrida corrida);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package com.rjconsultores.ventaboletos.dao;
|
package com.rjconsultores.ventaboletos.dao;
|
||||||
|
|
||||||
import java.util.List;
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.entidad.CorridaInfo;
|
import com.rjconsultores.ventaboletos.entidad.CorridaInfo;
|
||||||
import com.rjconsultores.ventaboletos.entidad.EsquemaCorridaInfo;
|
|
||||||
|
|
||||||
public interface CorridaInfoDAO extends GenericDAO<CorridaInfo, Integer> {
|
public interface CorridaInfoDAO extends GenericDAO<CorridaInfo, Integer> {
|
||||||
|
|
||||||
|
void borrarByCorrida(Corrida corrida);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.rjconsultores.ventaboletos.dao;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Disponibilidad;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author wallace
|
||||||
|
*/
|
||||||
|
public interface DisponibilidadDAO extends GenericDAO<Disponibilidad, Integer> {
|
||||||
|
|
||||||
|
void borrarByCorrida(Corrida corrida);
|
||||||
|
|
||||||
|
}
|
|
@ -74,4 +74,6 @@ public interface EmpresaDAO {
|
||||||
|
|
||||||
public List<Empresa> buscarEmpresaPtoVtaComissao();
|
public List<Empresa> buscarEmpresaPtoVtaComissao();
|
||||||
|
|
||||||
|
public boolean isPrimeiraVezLicenca();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.rjconsultores.ventaboletos.dao;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.HeaderTabelaEsquemaCorrida;
|
||||||
|
|
||||||
|
public interface HeaderEsquemaCorridaDAO extends GenericDAO<HeaderTabelaEsquemaCorrida, Integer> {
|
||||||
|
|
||||||
|
public HeaderTabelaEsquemaCorrida buscarHeader();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,7 +1,10 @@
|
||||||
package com.rjconsultores.ventaboletos.dao;
|
package com.rjconsultores.ventaboletos.dao;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
import com.rjconsultores.ventaboletos.entidad.IntegracaoTotvs;
|
import com.rjconsultores.ventaboletos.entidad.IntegracaoTotvs;
|
||||||
|
|
||||||
public interface IntegracaoTotvsDAO extends GenericDAO<IntegracaoTotvs, Integer> {
|
public interface IntegracaoTotvsDAO extends GenericDAO<IntegracaoTotvs, Integer> {
|
||||||
|
|
||||||
|
public void borrarByCorrida(Corrida corrida);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
package com.rjconsultores.ventaboletos.dao;
|
|
||||||
|
|
||||||
import org.hibernate.SessionFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.dao.hibernate.GenericHibernateDAO;
|
|
||||||
import com.rjconsultores.ventaboletos.entidad.IntegracaoTotvs;
|
|
||||||
|
|
||||||
@Repository("IntgeracaoTotvsDAO")
|
|
||||||
public class IntgeracaoTotvsHibernateDAO extends GenericHibernateDAO<IntegracaoTotvs, Integer>
|
|
||||||
implements IntegracaoTotvsDAO {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public IntgeracaoTotvsHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
|
||||||
setSessionFactory(factory);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -4,19 +4,23 @@
|
||||||
*/
|
*/
|
||||||
package com.rjconsultores.ventaboletos.dao.hibernate;
|
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.dao.AsientoExclusivoDAO;
|
|
||||||
import com.rjconsultores.ventaboletos.entidad.AsientoExclusivo;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
|
import org.hibernate.SQLQuery;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.dao.AsientoExclusivoDAO;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.AsientoExclusivo;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author rodrigo
|
* @author walace
|
||||||
*/
|
*/
|
||||||
@Repository("asientoExclusivoDAO")
|
@Repository("asientoExclusivoDAO")
|
||||||
public class AsientoExclusivoHibernateDAO extends GenericHibernateDAO<AsientoExclusivo, Integer>
|
public class AsientoExclusivoHibernateDAO extends GenericHibernateDAO<AsientoExclusivo, Integer>
|
||||||
|
@ -34,4 +38,17 @@ public class AsientoExclusivoHibernateDAO extends GenericHibernateDAO<AsientoExc
|
||||||
|
|
||||||
return c.list();
|
return c.list();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarByCorrida(Corrida corrida) {
|
||||||
|
|
||||||
|
StringBuilder sQuery = new StringBuilder("DELETE FROM ASIENTO_EXCLUSIVO WHERE corrida_Id = :corridaId AND TRUNC(feccorrida) = :feccorrida ");
|
||||||
|
SQLQuery qrUpdate = getSession().createSQLQuery(sQuery.toString());
|
||||||
|
|
||||||
|
qrUpdate.setParameter("feccorrida", corrida.getId().getFeccorrida());
|
||||||
|
qrUpdate.setParameter("corridaId", corrida.getId().getCorridaId());
|
||||||
|
qrUpdate.executeUpdate();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package com.rjconsultores.ventaboletos.dao.hibernate;
|
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||||
|
|
||||||
|
import org.hibernate.SQLQuery;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.dao.CorridaInfoDAO;
|
import com.rjconsultores.ventaboletos.dao.CorridaInfoDAO;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
import com.rjconsultores.ventaboletos.entidad.CorridaInfo;
|
import com.rjconsultores.ventaboletos.entidad.CorridaInfo;
|
||||||
|
|
||||||
@Repository("corridaInfoDAO")
|
@Repository("corridaInfoDAO")
|
||||||
|
@ -15,5 +17,18 @@ public class CorridaInfoHibernateDAO extends GenericHibernateDAO<CorridaInfo, In
|
||||||
public CorridaInfoHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
public CorridaInfoHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||||
setSessionFactory(factory);
|
setSessionFactory(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarByCorrida(Corrida corrida) {
|
||||||
|
|
||||||
|
StringBuilder sQuery = new StringBuilder("DELETE FROM Corrida_Info WHERE corrida_Id = :corridaId AND TRUNC(feccorrida) = :feccorrida ");
|
||||||
|
SQLQuery qrUpdate = getSession().createSQLQuery(sQuery.toString());
|
||||||
|
|
||||||
|
qrUpdate.setParameter("feccorrida", corrida.getId().getFeccorrida());
|
||||||
|
qrUpdate.setParameter("corridaId", corrida.getId().getCorridaId());
|
||||||
|
qrUpdate.executeUpdate();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||||
|
|
||||||
|
import org.hibernate.SQLQuery;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.dao.DisponibilidadDAO;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Disponibilidad;
|
||||||
|
|
||||||
|
@Repository("disponibilidadDAO")
|
||||||
|
public class DisponibilidadHibernateDAO extends GenericHibernateDAO<Disponibilidad, Integer> implements DisponibilidadDAO {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DisponibilidadHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||||
|
setSessionFactory(factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarByCorrida(Corrida corrida) {
|
||||||
|
|
||||||
|
StringBuilder sQuery = new StringBuilder("DELETE FROM Disponibilidad WHERE corrida_Id = :corridaId AND TRUNC(feccorrida) = :feccorrida ");
|
||||||
|
SQLQuery qrUpdate = getSession().createSQLQuery(sQuery.toString());
|
||||||
|
|
||||||
|
qrUpdate.setParameter("feccorrida", corrida.getId().getFeccorrida());
|
||||||
|
qrUpdate.setParameter("corridaId", corrida.getId().getCorridaId());
|
||||||
|
qrUpdate.executeUpdate();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.List;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.Query;
|
import org.hibernate.Query;
|
||||||
|
@ -21,6 +22,7 @@ import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.criterion.MatchMode;
|
import org.hibernate.criterion.MatchMode;
|
||||||
import org.hibernate.criterion.Order;
|
import org.hibernate.criterion.Order;
|
||||||
|
import org.hibernate.criterion.Projections;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
import org.hibernate.type.BooleanType;
|
import org.hibernate.type.BooleanType;
|
||||||
import org.hibernate.type.IntegerType;
|
import org.hibernate.type.IntegerType;
|
||||||
|
@ -50,6 +52,7 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO<Empresa, Integer> i
|
||||||
|
|
||||||
|
|
||||||
private static String FS_BPE = "FS_BPE_";
|
private static String FS_BPE = "FS_BPE_";
|
||||||
|
private static Logger log = Logger.getLogger(EmpresaHibernateDAO.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
@ -106,6 +109,36 @@ public class EmpresaHibernateDAO extends GenericHibernateDAO<Empresa, Integer> i
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indica se está no momento em que nenhuma empresa tem a licença.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isPrimeiraVezLicenca(){
|
||||||
|
|
||||||
|
Criteria c = makeCriteria();
|
||||||
|
c.setProjection(Projections.rowCount());
|
||||||
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||||
|
c.add(Restrictions.ne("empresaId", -1));
|
||||||
|
|
||||||
|
Long cantEmpresasBaseDados = HibernateFix.count(c.list());
|
||||||
|
|
||||||
|
c = makeCriteria();
|
||||||
|
c.setProjection(Projections.rowCount());
|
||||||
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||||
|
c.add(Restrictions.ne("empresaId", -1));
|
||||||
|
c.add(Restrictions.isNull("licenca"));
|
||||||
|
|
||||||
|
Long cantEmpresasSemLicenca = HibernateFix.count(c.list());
|
||||||
|
|
||||||
|
return (cantEmpresasBaseDados.equals(cantEmpresasSemLicenca));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Empresa> listarEmpresasSemLicenca(){
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public List<Empresa> obtenerIndExternoFalse() {
|
public List<Empresa> obtenerIndExternoFalse() {
|
||||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||||
|
|
||||||
|
import org.hibernate.Criteria;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.dao.HeaderEsquemaCorridaDAO;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.HeaderTabelaEsquemaCorrida;
|
||||||
|
|
||||||
|
@Repository("headerEsquemaCorridaHibernateDAO")
|
||||||
|
public class HeaderEsquemaCorridaHibernateDAO extends GenericHibernateDAO<HeaderTabelaEsquemaCorrida, Integer> implements HeaderEsquemaCorridaDAO {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public HeaderEsquemaCorridaHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||||
|
setSessionFactory(factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HeaderTabelaEsquemaCorrida buscarHeader() {
|
||||||
|
try {
|
||||||
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||||
|
c.add(Restrictions.eq("headerEsquemaCorridaId", 1));
|
||||||
|
|
||||||
|
c.setMaxResults(1);
|
||||||
|
|
||||||
|
return (HeaderTabelaEsquemaCorrida) c.uniqueResult();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||||
|
|
||||||
|
import org.hibernate.SQLQuery;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.dao.IntegracaoTotvsDAO;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.IntegracaoTotvs;
|
||||||
|
|
||||||
|
@Repository("integracaoTotvsDAO")
|
||||||
|
public class IntegracaoTotvsHibernateDAO extends GenericHibernateDAO<IntegracaoTotvs, Integer> implements IntegracaoTotvsDAO {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public IntegracaoTotvsHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||||
|
setSessionFactory(factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarByCorrida(Corrida corrida) {
|
||||||
|
|
||||||
|
StringBuilder sQuery = new StringBuilder("DELETE FROM INTEGRACAO_TOTVS_CORRIDA WHERE corrida_Id = :corridaId AND TRUNC(feccorrida) = :feccorrida ");
|
||||||
|
SQLQuery qrUpdate = getSession().createSQLQuery(sQuery.toString());
|
||||||
|
|
||||||
|
qrUpdate.setParameter("feccorrida", corrida.getId().getFeccorrida());
|
||||||
|
qrUpdate.setParameter("corridaId", corrida.getId().getCorridaId());
|
||||||
|
qrUpdate.executeUpdate();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.rjconsultores.ventaboletos.entidad;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.Basic;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.JoinColumns;
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
|
import javax.persistence.SequenceGenerator;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author wallace
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@SequenceGenerator(name = "DISPONIBILIDAD_SEQ", sequenceName = "DISPONIBILIDAD_SEQ", allocationSize = 1)
|
||||||
|
@Table(name = "DISPONIBILIDAD")
|
||||||
|
public class Disponibilidad implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
@Id
|
||||||
|
@Basic(optional = false)
|
||||||
|
@Column(name = "DISPONIBILIDAD_ID")
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO, generator = "DISPONIBILIDAD_SEQ")
|
||||||
|
private long disponibilidadId;
|
||||||
|
@OneToOne
|
||||||
|
@JoinColumns({
|
||||||
|
@JoinColumn(name = "CORRIDA_ID"),
|
||||||
|
@JoinColumn(name = "FECCORRIDA")})
|
||||||
|
private Corrida corrida;
|
||||||
|
@Column(name = "ACTIVO")
|
||||||
|
private Boolean activo;
|
||||||
|
@Basic(optional = false)
|
||||||
|
@Column(name = "FECMODIF")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date fecmodif;
|
||||||
|
@Column(name = "USUARIO_ID")
|
||||||
|
private Integer usuarioId;
|
||||||
|
|
||||||
|
public long getDisponibilidadId() {
|
||||||
|
return disponibilidadId;
|
||||||
|
}
|
||||||
|
public void setDisponibilidadId(long disponibilidadId) {
|
||||||
|
this.disponibilidadId = disponibilidadId;
|
||||||
|
}
|
||||||
|
public Corrida getCorrida() {
|
||||||
|
return corrida;
|
||||||
|
}
|
||||||
|
public void setCorrida(Corrida corrida) {
|
||||||
|
this.corrida = corrida;
|
||||||
|
}
|
||||||
|
public Boolean getActivo() {
|
||||||
|
return activo;
|
||||||
|
}
|
||||||
|
public void setActivo(Boolean activo) {
|
||||||
|
this.activo = activo;
|
||||||
|
}
|
||||||
|
public Date getFecmodif() {
|
||||||
|
return fecmodif;
|
||||||
|
}
|
||||||
|
public void setFecmodif(Date fecmodif) {
|
||||||
|
this.fecmodif = fecmodif;
|
||||||
|
}
|
||||||
|
public Integer getUsuarioId() {
|
||||||
|
return usuarioId;
|
||||||
|
}
|
||||||
|
public void setUsuarioId(Integer usuarioId) {
|
||||||
|
this.usuarioId = usuarioId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -421,6 +421,9 @@ public class Empresa implements Serializable, Auditavel<Empresa> {
|
||||||
@Column(name = "INDTAXACONVENIENCIASOVENDA")
|
@Column(name = "INDTAXACONVENIENCIASOVENDA")
|
||||||
private Boolean indTaxaConvenienciaSoVenda;
|
private Boolean indTaxaConvenienciaSoVenda;
|
||||||
|
|
||||||
|
@Column(name = "LICENCA")
|
||||||
|
private String licenca;
|
||||||
|
|
||||||
@Column(name = "HORAINICIOEMBARQUE")
|
@Column(name = "HORAINICIOEMBARQUE")
|
||||||
@Temporal(TemporalType.TIME)
|
@Temporal(TemporalType.TIME)
|
||||||
@AuditarAtributo(pattern = "HH:mm")
|
@AuditarAtributo(pattern = "HH:mm")
|
||||||
|
@ -435,6 +438,10 @@ public class Empresa implements Serializable, Auditavel<Empresa> {
|
||||||
@NaoAuditar
|
@NaoAuditar
|
||||||
private Empresa empresaClone;
|
private Empresa empresaClone;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
@NaoAuditar
|
||||||
|
private String token;
|
||||||
|
|
||||||
public Empresa() {
|
public Empresa() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
@ -1586,4 +1593,22 @@ public class Empresa implements Serializable, Auditavel<Empresa> {
|
||||||
public void setHoraFimEmbarque(Date horaFimEmbarque) {
|
public void setHoraFimEmbarque(Date horaFimEmbarque) {
|
||||||
this.horaFimEmbarque = horaFimEmbarque;
|
this.horaFimEmbarque = horaFimEmbarque;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getToken() {
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToken(String token) {
|
||||||
|
this.token = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLicenca() {
|
||||||
|
return licenca;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLicenca(String licenca) {
|
||||||
|
this.licenca = licenca;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.rjconsultores.ventaboletos.entidad;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.persistence.Basic;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.SequenceGenerator;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author valdir.cordeiro
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@SequenceGenerator(name = "HEADER_ESQUEMA_CORRIDA_SEQ", sequenceName = "HEADER_ESQUEMA_CORRIDA_SEQ", allocationSize = 1)
|
||||||
|
@Table(name = "HEADER_ESQUEMA_CORRIDA")
|
||||||
|
public class HeaderTabelaEsquemaCorrida implements Serializable{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
@Id
|
||||||
|
@Basic(optional = false)
|
||||||
|
@Column(name = "HEADERESQUEMACORRIDA_ID")
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO, generator = "HEADER_ESQUEMA_CORRIDA_SEQ")
|
||||||
|
private Integer headerEsquemaCorridaId;
|
||||||
|
|
||||||
|
@Column(name = "SEQUENCIA_HEADER")
|
||||||
|
private String sequenciaHeader;
|
||||||
|
|
||||||
|
public HeaderTabelaEsquemaCorrida() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public HeaderTabelaEsquemaCorrida(int id, String sequencia) {
|
||||||
|
this.headerEsquemaCorridaId = id;
|
||||||
|
this.sequenciaHeader = sequencia;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getHeaderEsquemaCorridaId() {
|
||||||
|
return headerEsquemaCorridaId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeaderEsquemaCorridaId(Integer headerEsquemaCorridaId) {
|
||||||
|
this.headerEsquemaCorridaId = headerEsquemaCorridaId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSequenciaHeader() {
|
||||||
|
return sequenciaHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSequenciaHeader(String sequenciaHeader) {
|
||||||
|
this.sequenciaHeader = sequenciaHeader;
|
||||||
|
}
|
||||||
|
}
|
|
@ -346,6 +346,9 @@ public class PuntoVenta implements Serializable, Auditavel<PuntoVenta> {
|
||||||
@Column(name = "INDBLOQUEARDESCONTOWEB")
|
@Column(name = "INDBLOQUEARDESCONTOWEB")
|
||||||
private Boolean indBloquearDescontoWEB;
|
private Boolean indBloquearDescontoWEB;
|
||||||
|
|
||||||
|
@Column(name = "INDTAXACONVORGAOCONCEDENTE")
|
||||||
|
private Boolean indTaxaConvenienciaOrgaoConcedente;
|
||||||
|
|
||||||
public List<CobrancaAdcPuntoVenta> getCobrancaAdicionalList() {
|
public List<CobrancaAdcPuntoVenta> getCobrancaAdicionalList() {
|
||||||
return cobrancaAdicionalList;
|
return cobrancaAdicionalList;
|
||||||
}
|
}
|
||||||
|
@ -1378,5 +1381,13 @@ public class PuntoVenta implements Serializable, Auditavel<PuntoVenta> {
|
||||||
this.tempoMaxServicoEmVenda = tempoMaxServicoEmVenda;
|
this.tempoMaxServicoEmVenda = tempoMaxServicoEmVenda;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean getIndTaxaConvenienciaOrgaoConcedente() {
|
||||||
|
return indTaxaConvenienciaOrgaoConcedente;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndTaxaConvenienciaOrgaoConcedente(Boolean indTaxaConvenienciaOrgaoConcedente) {
|
||||||
|
this.indTaxaConvenienciaOrgaoConcedente = indTaxaConvenienciaOrgaoConcedente;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -30,15 +30,18 @@ import javax.persistence.Transient;
|
||||||
|
|
||||||
import org.apache.commons.lang.BooleanUtils;
|
import org.apache.commons.lang.BooleanUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.hibernate.annotations.Fetch;
|
import org.hibernate.annotations.Fetch;
|
||||||
import org.hibernate.annotations.FetchMode;
|
import org.hibernate.annotations.FetchMode;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.service.ConstanteService;
|
import com.rjconsultores.ventaboletos.service.ConstanteService;
|
||||||
|
import com.rjconsultores.ventaboletos.service.impl.EmpresaServiceImpl;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
|
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.CustomEnum;
|
import com.rjconsultores.ventaboletos.utilerias.CustomEnum;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||||
|
import com.rjconsultores.ventaboletos.web.utilerias.security.SecurityEmpresaToken;
|
||||||
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;
|
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;
|
||||||
|
|
||||||
import br.com.rjconsultores.auditador.annotations.AuditarClasse;
|
import br.com.rjconsultores.auditador.annotations.AuditarClasse;
|
||||||
|
@ -59,6 +62,7 @@ import br.com.rjconsultores.auditador.interfaces.Auditavel;
|
||||||
public class Usuario implements Serializable, UserDetails, Auditavel<Usuario> {
|
public class Usuario implements Serializable, UserDetails, Auditavel<Usuario> {
|
||||||
|
|
||||||
public final static int CANT_DIAS_CONTRASENA = 999;
|
public final static int CANT_DIAS_CONTRASENA = 999;
|
||||||
|
private static Logger log = Logger.getLogger(Usuario.class);
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@AuditarID
|
@AuditarID
|
||||||
|
@ -255,10 +259,25 @@ public class Usuario implements Serializable, UserDetails, Auditavel<Usuario> {
|
||||||
|
|
||||||
public List<Empresa> getEmpresa() {
|
public List<Empresa> getEmpresa() {
|
||||||
List<Empresa> tmp = new ArrayList<Empresa>();
|
List<Empresa> tmp = new ArrayList<Empresa>();
|
||||||
|
|
||||||
|
SecurityEmpresaToken security = new SecurityEmpresaToken();
|
||||||
|
|
||||||
if (usuarioEmpresaList != null) {
|
if (usuarioEmpresaList != null) {
|
||||||
for (UsuarioEmpresa cp : this.usuarioEmpresaList) {
|
for (UsuarioEmpresa cp : this.usuarioEmpresaList) {
|
||||||
if ((cp.getActivo())) {
|
if ((cp.getActivo())) {
|
||||||
tmp.add(cp.getEmpresa());
|
Empresa empresa = cp.getEmpresa();
|
||||||
|
boolean licenseValidate = false;
|
||||||
|
|
||||||
|
try{
|
||||||
|
licenseValidate = security.licenseValidate(empresa.getLicenca(), empresa.getEmpresaId(), empresa.getCnpj());
|
||||||
|
}catch(Throwable th){
|
||||||
|
log.error(String.format("Licença não validada para a empresaId: %s e cnpj: %s", empresa.getEmpresaId(),empresa.getCnpj()), th);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (licenseValidate){
|
||||||
|
tmp.add(cp.getEmpresa());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,14 @@
|
||||||
package com.rjconsultores.ventaboletos.service;
|
package com.rjconsultores.ventaboletos.service;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.entidad.AsientoExclusivo;
|
import com.rjconsultores.ventaboletos.entidad.AsientoExclusivo;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author rodrigo
|
* @author rodrigo
|
||||||
*/
|
*/
|
||||||
public interface AsientoExclusivoService extends GenericService<AsientoExclusivo, Integer> {
|
public interface AsientoExclusivoService extends GenericService<AsientoExclusivo, Integer> {
|
||||||
|
|
||||||
|
void borrarByCorrida(Corrida corrida);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package com.rjconsultores.ventaboletos.service;
|
package com.rjconsultores.ventaboletos.service;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
import com.rjconsultores.ventaboletos.entidad.CorridaInfo;
|
import com.rjconsultores.ventaboletos.entidad.CorridaInfo;
|
||||||
|
|
||||||
public interface CorridaInfoService extends GenericService<CorridaInfo, Integer> {
|
public interface CorridaInfoService extends GenericService<CorridaInfo, Integer> {
|
||||||
|
|
||||||
|
void borrarByCorrida(Corrida corrida);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.rjconsultores.ventaboletos.service;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Disponibilidad;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author wallace
|
||||||
|
*/
|
||||||
|
public interface DisponibilidadService extends GenericService<Disponibilidad, Integer> {
|
||||||
|
|
||||||
|
public void borrarByCorrida(Corrida corrida);
|
||||||
|
}
|
|
@ -64,4 +64,17 @@ public interface EmpresaService {
|
||||||
|
|
||||||
public List<Empresa> buscarEmpresaPtoVtaComissao();
|
public List<Empresa> buscarEmpresaPtoVtaComissao();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Atualiza se necessário as licenças no primeiro acesso
|
||||||
|
*
|
||||||
|
* @return A quantidade de empresas atualizadas
|
||||||
|
*/
|
||||||
|
public Integer atualizarLicencaEmpresasPrimeiraVez();
|
||||||
|
|
||||||
|
public List<Empresa> filtrarApenasEmpresasLicencaValida(List<Empresa> lsEmpresa);
|
||||||
|
|
||||||
|
public String token(Empresa empresa);
|
||||||
|
|
||||||
|
public String validarTokenLicensa(Empresa empresa, String tokenLicenca);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.rjconsultores.ventaboletos.service;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.HeaderTabelaEsquemaCorrida;
|
||||||
|
|
||||||
|
public interface HeaderEsquemaCorridaService extends GenericService<HeaderTabelaEsquemaCorrida, Integer> {
|
||||||
|
|
||||||
|
public Integer[] buscarHeader();
|
||||||
|
|
||||||
|
public void salvarPosicoesHeader(Integer[] posicoesColunasTabela);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package com.rjconsultores.ventaboletos.service;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||||
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
|
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Usuario;
|
import com.rjconsultores.ventaboletos.entidad.Usuario;
|
||||||
|
@ -19,4 +20,6 @@ public interface IntegracaoTotvsService {
|
||||||
|
|
||||||
public Integer solicitaReIntegracaoBilhete(Empresa empresa, Date dataInicial, Date dataFinal, PuntoVenta puntoVenta, Usuario usuario) throws BusinessException;
|
public Integer solicitaReIntegracaoBilhete(Empresa empresa, Date dataInicial, Date dataFinal, PuntoVenta puntoVenta, Usuario usuario) throws BusinessException;
|
||||||
|
|
||||||
|
public void borrarByCorrida(Corrida corrida);
|
||||||
|
|
||||||
}
|
}
|
|
@ -6,6 +6,7 @@ package com.rjconsultores.ventaboletos.service.impl;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.dao.AsientoExclusivoDAO;
|
import com.rjconsultores.ventaboletos.dao.AsientoExclusivoDAO;
|
||||||
import com.rjconsultores.ventaboletos.entidad.AsientoExclusivo;
|
import com.rjconsultores.ventaboletos.entidad.AsientoExclusivo;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
import com.rjconsultores.ventaboletos.service.AsientoExclusivoService;
|
import com.rjconsultores.ventaboletos.service.AsientoExclusivoService;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
@ -62,4 +63,10 @@ public class AsientoExclusivoServiceImpl implements AsientoExclusivoService {
|
||||||
|
|
||||||
asientoExclusivoDAO.actualizacion(entidad);
|
asientoExclusivoDAO.actualizacion(entidad);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarByCorrida(Corrida corrida) {
|
||||||
|
asientoExclusivoDAO.borrarByCorrida(corrida);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.dao.CorridaInfoDAO;
|
import com.rjconsultores.ventaboletos.dao.CorridaInfoDAO;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
import com.rjconsultores.ventaboletos.entidad.CorridaInfo;
|
import com.rjconsultores.ventaboletos.entidad.CorridaInfo;
|
||||||
import com.rjconsultores.ventaboletos.service.CorridaInfoService;
|
import com.rjconsultores.ventaboletos.service.CorridaInfoService;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||||
|
@ -59,4 +60,11 @@ public class CorridaInfoServiceImpl implements CorridaInfoService {
|
||||||
corridaInfoDAO.actualizacion(entidad);
|
corridaInfoDAO.actualizacion(entidad);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarByCorrida(Corrida corrida) {
|
||||||
|
corridaInfoDAO.borrarByCorrida(corrida);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.rjconsultores.ventaboletos.service.impl;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.dao.DisponibilidadDAO;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Disponibilidad;
|
||||||
|
import com.rjconsultores.ventaboletos.service.DisponibilidadService;
|
||||||
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author wallace
|
||||||
|
*/
|
||||||
|
@Service("disponibilidadService")
|
||||||
|
public class DisponibilidadServiceImpl implements DisponibilidadService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DisponibilidadDAO disponibilidadDAO;
|
||||||
|
|
||||||
|
public List<Disponibilidad> obtenerTodos() {
|
||||||
|
return disponibilidadDAO.obtenerTodos();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Disponibilidad obtenerID(Integer id) {
|
||||||
|
return disponibilidadDAO.obtenerID(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Disponibilidad suscribir(Disponibilidad entidad) {
|
||||||
|
Integer usuarioId = 1;
|
||||||
|
if (UsuarioLogado.getUsuarioLogado() != null){
|
||||||
|
usuarioId = UsuarioLogado.getUsuarioLogado().getUsuarioId();
|
||||||
|
}
|
||||||
|
entidad.setUsuarioId(usuarioId);
|
||||||
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||||
|
entidad.setActivo(Boolean.TRUE);
|
||||||
|
|
||||||
|
return disponibilidadDAO.suscribir(entidad);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Disponibilidad actualizacion(Disponibilidad entidad) {
|
||||||
|
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
||||||
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||||
|
entidad.setActivo(Boolean.TRUE);
|
||||||
|
|
||||||
|
return disponibilidadDAO.actualizacion(entidad);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void borrar(Disponibilidad entidad) {
|
||||||
|
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
||||||
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||||
|
entidad.setActivo(Boolean.FALSE);
|
||||||
|
|
||||||
|
disponibilidadDAO.actualizacion(entidad);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarByCorrida(Corrida corrida) {
|
||||||
|
disponibilidadDAO.borrarByCorrida(corrida);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
package com.rjconsultores.ventaboletos.service.impl;
|
package com.rjconsultores.ventaboletos.service.impl;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -30,6 +31,7 @@ import com.rjconsultores.ventaboletos.service.LogAuditoriaService;
|
||||||
import com.rjconsultores.ventaboletos.service.MarcaService;
|
import com.rjconsultores.ventaboletos.service.MarcaService;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.RegistroConDependenciaException;
|
import com.rjconsultores.ventaboletos.utilerias.RegistroConDependenciaException;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||||
|
import com.rjconsultores.ventaboletos.web.utilerias.security.SecurityEmpresaToken;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -61,6 +63,8 @@ public class EmpresaServiceImpl implements EmpresaService {
|
||||||
public Empresa obtenerID(Integer id) {
|
public Empresa obtenerID(Integer id) {
|
||||||
|
|
||||||
Empresa empresa = empresaDAO.obtenerID(id);
|
Empresa empresa = empresaDAO.obtenerID(id);
|
||||||
|
empresa.setToken(this.token(empresa));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
empresa.clonar();
|
empresa.clonar();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -86,6 +90,7 @@ public class EmpresaServiceImpl implements EmpresaService {
|
||||||
entidad = empresaDAO.suscribir(entidad);
|
entidad = empresaDAO.suscribir(entidad);
|
||||||
logAuditoriaService.auditar(null, entidad, null);
|
logAuditoriaService.auditar(null, entidad, null);
|
||||||
|
|
||||||
|
entidad.setToken(this.token(entidad));
|
||||||
|
|
||||||
gerarMarca(entidad);
|
gerarMarca(entidad);
|
||||||
|
|
||||||
|
@ -139,7 +144,7 @@ public class EmpresaServiceImpl implements EmpresaService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Empresa> buscarTodosExceto(List<Empresa> empresa, Integer... idEmpresa) {
|
public List<Empresa> buscarTodosExceto(List<Empresa> empresa, Integer... idEmpresa) {
|
||||||
return empresaDAO.buscarTodosExceto(empresa, idEmpresa);
|
return this.filtrarApenasEmpresasLicencaValida(empresaDAO.buscarTodosExceto(empresa, idEmpresa));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Empresa> obtenerIndExternoFalse() {
|
public List<Empresa> obtenerIndExternoFalse() {
|
||||||
|
@ -171,9 +176,31 @@ public class EmpresaServiceImpl implements EmpresaService {
|
||||||
empresaDAO.actualizaInscEstadual(inscricaoEstadual);
|
empresaDAO.actualizaInscEstadual(inscricaoEstadual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Empresa> filtrarApenasEmpresasLicencaValida(List<Empresa> lsEmpresa){
|
||||||
|
SecurityEmpresaToken security = new SecurityEmpresaToken();
|
||||||
|
List<Empresa> lsRetorno = new ArrayList<>();
|
||||||
|
|
||||||
|
if (lsEmpresa == null || lsEmpresa.isEmpty()){
|
||||||
|
return lsEmpresa;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Empresa empresa:lsEmpresa){
|
||||||
|
boolean licenseValidate = security.licenseValidate(empresa.getLicenca(), empresa.getEmpresaId(), empresa.getCnpj());
|
||||||
|
if (!licenseValidate){
|
||||||
|
log.info(String.format("Empresa sem licença válida", empresa.getEmpresaId()));
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
lsRetorno.add(empresa);
|
||||||
|
}
|
||||||
|
return lsRetorno;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public List<Empresa> buscaLike(String nombempresa) {
|
public List<Empresa> buscaLike(String nombempresa) {
|
||||||
return empresaDAO.buscaLike(nombempresa);
|
List<Empresa> lsEmpresa = empresaDAO.buscaLike(nombempresa);
|
||||||
|
|
||||||
|
return this.filtrarApenasEmpresasLicencaValida(lsEmpresa);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -242,8 +269,64 @@ public class EmpresaServiceImpl implements EmpresaService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String validarTokenLicensa(Empresa empresa,String tokenLicenca){
|
||||||
|
if (tokenLicenca == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
SecurityEmpresaToken security = new SecurityEmpresaToken();
|
||||||
|
|
||||||
|
final String license = security.tokenValidate(tokenLicenca);
|
||||||
|
|
||||||
|
return license;
|
||||||
|
}catch(Throwable th){
|
||||||
|
log.error("Erro ao validar token",th);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String token(Empresa empresa){
|
||||||
|
|
||||||
|
SecurityEmpresaToken security = new SecurityEmpresaToken();
|
||||||
|
final String bodyRequest = security.bodyRequestGenerate(empresa.getEmpresaId(), empresa.getCnpj());
|
||||||
|
final String request = security.requestGenerate(bodyRequest);
|
||||||
|
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Empresa> buscarEmpresaPtoVtaComissao() {
|
public List<Empresa> buscarEmpresaPtoVtaComissao() {
|
||||||
return empresaDAO.buscarEmpresaPtoVtaComissao();
|
return empresaDAO.buscarEmpresaPtoVtaComissao();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Integer atualizarLicencaEmpresasPrimeiraVez(){
|
||||||
|
boolean primeiraVezLicenca = empresaDAO.isPrimeiraVezLicenca();
|
||||||
|
int cantEmpresasAtualizadas = 0;
|
||||||
|
|
||||||
|
log.info(String.format("primeiraVezLicenca: %s", primeiraVezLicenca));
|
||||||
|
|
||||||
|
if (primeiraVezLicenca){
|
||||||
|
SecurityEmpresaToken security = new SecurityEmpresaToken();
|
||||||
|
List<Empresa> lsEmpresas = empresaDAO.obtenerTodos();
|
||||||
|
|
||||||
|
for(Empresa empresa:lsEmpresas){
|
||||||
|
String licenseDefaultGenerate = security.licenseDefaultGenerate(empresa.getEmpresaId(), empresa.getCnpj());
|
||||||
|
|
||||||
|
log.info(String.format("licenseDefaultGenerate: %s", licenseDefaultGenerate));
|
||||||
|
|
||||||
|
empresa.setLicenca(licenseDefaultGenerate);
|
||||||
|
|
||||||
|
empresaDAO.actualizacion(empresa);
|
||||||
|
cantEmpresasAtualizadas++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return cantEmpresasAtualizadas;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,107 @@
|
||||||
|
package com.rjconsultores.ventaboletos.service.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.dao.HeaderEsquemaCorridaDAO;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.HeaderTabelaEsquemaCorrida;
|
||||||
|
import com.rjconsultores.ventaboletos.service.HeaderEsquemaCorridaService;
|
||||||
|
|
||||||
|
@Service("headerEsquemaCorridaService")
|
||||||
|
public class HeaderEsquemaCorridaServiceImpl implements HeaderEsquemaCorridaService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HeaderEsquemaCorridaDAO headerEsquemaCorridaDAO;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<HeaderTabelaEsquemaCorrida> obtenerTodos() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HeaderTabelaEsquemaCorrida obtenerID(Integer id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer[] buscarHeader() {
|
||||||
|
HeaderTabelaEsquemaCorrida header = headerEsquemaCorridaDAO.buscarHeader();
|
||||||
|
|
||||||
|
if(header == null) {
|
||||||
|
//Se for nulo retorna com o valor padrao
|
||||||
|
header = new HeaderTabelaEsquemaCorrida(1, "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16");
|
||||||
|
}
|
||||||
|
|
||||||
|
String headerString = header.getSequenciaHeader();
|
||||||
|
|
||||||
|
String[] arrayString = headerString.split(",");
|
||||||
|
|
||||||
|
Integer[] arrayInt = new Integer[16];
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for(String pos : arrayString) {
|
||||||
|
arrayInt[i] = Integer.valueOf(pos);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(arrayString.length == 15) {
|
||||||
|
arrayInt[15] = 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
return arrayInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public HeaderTabelaEsquemaCorrida suscribir(HeaderTabelaEsquemaCorrida entidad) {
|
||||||
|
//o Id vai ser sempre 1
|
||||||
|
entidad.setHeaderEsquemaCorridaId(1);
|
||||||
|
return headerEsquemaCorridaDAO.suscribir(entidad);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public HeaderTabelaEsquemaCorrida actualizacion(HeaderTabelaEsquemaCorrida entidad) {
|
||||||
|
entidad.setHeaderEsquemaCorridaId(1);
|
||||||
|
return headerEsquemaCorridaDAO.actualizacion(entidad);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrar(HeaderTabelaEsquemaCorrida entidad) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void salvarPosicoesHeader(Integer[] posicoesColunasTabela) {
|
||||||
|
HeaderTabelaEsquemaCorrida header = headerEsquemaCorridaDAO.buscarHeader();
|
||||||
|
|
||||||
|
StringBuilder pos = new StringBuilder();
|
||||||
|
|
||||||
|
int i = 1;
|
||||||
|
for(Integer posicao : posicoesColunasTabela) {
|
||||||
|
|
||||||
|
if(i < 16) {
|
||||||
|
pos.append(posicao).append(",");
|
||||||
|
} else {
|
||||||
|
pos.append(posicao);
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(header == null) {
|
||||||
|
//Se for nulo retorna com o valor padrao
|
||||||
|
header = new HeaderTabelaEsquemaCorrida(1, pos.toString());
|
||||||
|
suscribir(header);
|
||||||
|
} else {
|
||||||
|
header.setSequenciaHeader(pos.toString());
|
||||||
|
actualizacion(header);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ import com.rjconsultores.ventaboletos.dao.EsquemaCorridaDAO;
|
||||||
import com.rjconsultores.ventaboletos.dao.IntegracaoTotvsDAO;
|
import com.rjconsultores.ventaboletos.dao.IntegracaoTotvsDAO;
|
||||||
import com.rjconsultores.ventaboletos.dao.MarcaDAO;
|
import com.rjconsultores.ventaboletos.dao.MarcaDAO;
|
||||||
import com.rjconsultores.ventaboletos.dao.PuntoVentaDAO;
|
import com.rjconsultores.ventaboletos.dao.PuntoVentaDAO;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Corrida;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||||
import com.rjconsultores.ventaboletos.entidad.IntegracaoTotvs;
|
import com.rjconsultores.ventaboletos.entidad.IntegracaoTotvs;
|
||||||
import com.rjconsultores.ventaboletos.entidad.Marca;
|
import com.rjconsultores.ventaboletos.entidad.Marca;
|
||||||
|
@ -96,4 +97,10 @@ public class IntegracaoTotvsServiceImpl implements IntegracaoTotvsService {
|
||||||
}
|
}
|
||||||
return corridaDao.atualizaCorridasIntegracaoTotvs(marca, dataInicial, dataFinal, numCorrida);
|
return corridaDao.atualizaCorridasIntegracaoTotvs(marca, dataInicial, dataFinal, numCorrida);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarByCorrida(Corrida corrida) {
|
||||||
|
integracaoTotvsDAO.borrarByCorrida(corrida);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,106 @@
|
||||||
|
package com.rjconsultores.ventaboletos.web.utilerias.security;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.security.spec.InvalidKeySpecException;
|
||||||
|
import java.security.spec.KeySpec;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
import javax.crypto.SecretKey;
|
||||||
|
import javax.crypto.SecretKeyFactory;
|
||||||
|
import javax.crypto.spec.GCMParameterSpec;
|
||||||
|
import javax.crypto.spec.PBEKeySpec;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.DecoderException;
|
||||||
|
import org.apache.commons.codec.binary.Hex;
|
||||||
|
|
||||||
|
public class AESGSMHelper {
|
||||||
|
private final String SECRET_KEY = "RJ@2019#c0n5ul10r35";
|
||||||
|
private final String SALT = "HrqoFr44GtkAhhYN+jP8Ag==";
|
||||||
|
private final String ENCRYPT_ALGO = "AES/GCM/NoPadding";
|
||||||
|
private final int TAG_LENGTH_BIT = 128;
|
||||||
|
private final int IV_LENGTH_BYTE = 12;
|
||||||
|
|
||||||
|
private final Charset UTF_8 = StandardCharsets.UTF_8;
|
||||||
|
|
||||||
|
public String encrypt(String value) throws Exception {
|
||||||
|
SecretKey secret = getAESKeyFromPassword(SECRET_KEY.toCharArray());
|
||||||
|
|
||||||
|
byte[] pText = value.getBytes(StandardCharsets.UTF_8);
|
||||||
|
byte[] iv = getRandomNonce(12);
|
||||||
|
byte[] cipherText = encrypt(pText, secret, iv);
|
||||||
|
|
||||||
|
byte[] cipherTextWithIv = ByteBuffer.allocate(iv.length + cipherText.length)
|
||||||
|
.put(iv)
|
||||||
|
.put(cipherText)
|
||||||
|
.array();
|
||||||
|
|
||||||
|
return hex(cipherTextWithIv);
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] encrypt(byte[] pText, SecretKey secret, byte[] iv) throws Exception {
|
||||||
|
Cipher cipher = Cipher.getInstance(ENCRYPT_ALGO);
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, secret, new GCMParameterSpec(TAG_LENGTH_BIT, iv));
|
||||||
|
|
||||||
|
byte[] encryptedText = cipher.doFinal(pText);
|
||||||
|
|
||||||
|
return encryptedText;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String decrypt(String value) throws Exception {
|
||||||
|
SecretKey secret = getAESKeyFromPassword(SECRET_KEY.toCharArray());
|
||||||
|
|
||||||
|
byte[] cText = unhex(value);
|
||||||
|
|
||||||
|
ByteBuffer bb = ByteBuffer.wrap(cText);
|
||||||
|
|
||||||
|
byte[] iv = new byte[IV_LENGTH_BYTE];
|
||||||
|
bb.get(iv);
|
||||||
|
|
||||||
|
byte[] cipherText = new byte[bb.remaining()];
|
||||||
|
bb.get(cipherText);
|
||||||
|
|
||||||
|
String plainText = decrypt(cipherText, secret, iv);
|
||||||
|
|
||||||
|
return plainText;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String decrypt(byte[] cText, SecretKey secret, byte[] iv) throws Exception {
|
||||||
|
Cipher cipher = Cipher.getInstance(ENCRYPT_ALGO);
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, secret, new GCMParameterSpec(TAG_LENGTH_BIT, iv));
|
||||||
|
|
||||||
|
byte[] plainText = cipher.doFinal(cText);
|
||||||
|
|
||||||
|
return new String(plainText, UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] getRandomNonce(int numBytes) {
|
||||||
|
byte[] nonce = new byte[numBytes];
|
||||||
|
new SecureRandom().nextBytes(nonce);
|
||||||
|
|
||||||
|
return nonce;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SecretKey getAESKeyFromPassword(char[] password) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||||
|
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
|
||||||
|
|
||||||
|
KeySpec spec = new PBEKeySpec(password, SALT.getBytes(), 65536, 256);
|
||||||
|
SecretKeySpec secret = new SecretKeySpec(factory.generateSecret(spec).getEncoded(), "AES");
|
||||||
|
|
||||||
|
return secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String hex(byte[] bytes) {
|
||||||
|
char[] result = Hex.encodeHex(bytes);
|
||||||
|
return new String(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] unhex(String hex) throws DecoderException {
|
||||||
|
return Hex.decodeHex(hex.toCharArray());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,145 @@
|
||||||
|
package com.rjconsultores.ventaboletos.web.utilerias.security;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
import javax.xml.bind.DatatypeConverter;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.nimbusds.jose.JWSAlgorithm;
|
||||||
|
import com.nimbusds.jose.JWSHeader;
|
||||||
|
import com.nimbusds.jose.JWSObject;
|
||||||
|
import com.nimbusds.jose.Payload;
|
||||||
|
import com.nimbusds.jose.crypto.MACSigner;
|
||||||
|
import com.nimbusds.jwt.JWTClaimsSet;
|
||||||
|
|
||||||
|
import net.minidev.json.JSONObject;
|
||||||
|
|
||||||
|
public class SecurityEmpresaToken {
|
||||||
|
private static Logger log = Logger.getLogger(SecurityEmpresaToken.class);
|
||||||
|
|
||||||
|
private String secret = "#KO&Fm4_k.sU9M8`6Mx'F\\\"H:*Qxu]6F4r,)JmZ2Jwafd)I.2[RET'1:)VQ6mG9,";
|
||||||
|
private static final Duration ttl = Duration.ofDays(7);
|
||||||
|
|
||||||
|
private Gson gson = new Gson();
|
||||||
|
|
||||||
|
public String bodyRequestGenerate(final Integer empresaId, final String cnpj) throws SecurityException {
|
||||||
|
try {
|
||||||
|
AESGSMHelper crypto = new AESGSMHelper();
|
||||||
|
|
||||||
|
JsonObject json = new JsonObject();
|
||||||
|
json.addProperty("empresaId", empresaId);
|
||||||
|
json.addProperty("CNPJ", cnpj);
|
||||||
|
|
||||||
|
return crypto.encrypt(json.toString());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Erro ao gerar o body usado no request da licença: " + e.getMessage(), e);
|
||||||
|
|
||||||
|
throw new SecurityException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String licenseDefaultGenerate(final Integer empresaId, final String cnpj) throws SecurityException {
|
||||||
|
try {
|
||||||
|
AESGSMHelper crypto = new AESGSMHelper();
|
||||||
|
|
||||||
|
JsonObject json = new JsonObject();
|
||||||
|
json.addProperty("empresaId", empresaId);
|
||||||
|
json.addProperty("CNPJ", cnpj);
|
||||||
|
json.addProperty("aprovado", 1);
|
||||||
|
|
||||||
|
return crypto.encrypt(json.toString());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Erro ao gerar a licença padrão para as empresas existentes: " + e.getMessage(), e);
|
||||||
|
|
||||||
|
throw new SecurityException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean licenseValidate(final String license, final Integer empresaId, final String cnpj) {
|
||||||
|
try {
|
||||||
|
if (StringUtils.isBlank(license)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
AESGSMHelper crypto = new AESGSMHelper();
|
||||||
|
|
||||||
|
final String value = crypto.decrypt(license);
|
||||||
|
final JsonObject json = gson.fromJson(value, JsonObject.class);
|
||||||
|
|
||||||
|
if (json.has("empresaId") && json.get("empresaId").getAsInt() == empresaId.intValue()
|
||||||
|
&& json.has("CNPJ") && json.get("CNPJ").getAsString().equals(cnpj)
|
||||||
|
&& json.has("aprovado")) {
|
||||||
|
log.debug("[empresaId=" + json.get("empresaId").getAsString() + ", CNPJ=" + json.get("CNPJ").getAsString() + ", aprovado=" + json.get("aprovado").getAsString() + "]");
|
||||||
|
|
||||||
|
return json.get("aprovado").getAsString().equals("1");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Erro ao gerar o body usado no request da licença: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String requestGenerate(String licenseRequest) throws SecurityException {
|
||||||
|
return requestGenerate(licenseRequest, ttl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String requestGenerate(String licenseRequest, Duration ttl) throws SecurityException {
|
||||||
|
try {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.add(Calendar.MILLISECOND, (int) ttl.toMillis());
|
||||||
|
|
||||||
|
JWTClaimsSet claims = new JWTClaimsSet.Builder()
|
||||||
|
.expirationTime(cal.getTime())
|
||||||
|
.claim("sub", licenseRequest)
|
||||||
|
.claim("userId", "adm")
|
||||||
|
.claim("role", "ROLE_TOKEN")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
JWSObject jwsObject = new JWSObject(new JWSHeader(JWSAlgorithm.HS256), new Payload(claims.toJSONObject()));
|
||||||
|
|
||||||
|
jwsObject.sign(new MACSigner(DatatypeConverter.parseBase64Binary(secret)));
|
||||||
|
|
||||||
|
return jwsObject.serialize();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Erro ao gerar a request: " + e.getMessage(), e);
|
||||||
|
|
||||||
|
throw new SecurityException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String tokenValidate(final String token) throws SecurityException {
|
||||||
|
try {
|
||||||
|
JWSObject jwsObject = JWSObject.parse(token);
|
||||||
|
JSONObject jsonPayload = jwsObject.getPayload().toJSONObject();
|
||||||
|
JWTClaimsSet claims = JWTClaimsSet.parse(jsonPayload);
|
||||||
|
|
||||||
|
if (claims.getExpirationTime().compareTo(Calendar.getInstance().getTime()) < 0) {
|
||||||
|
throw new SecurityException("Token expirado");
|
||||||
|
}
|
||||||
|
|
||||||
|
return claims.getSubject();
|
||||||
|
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
throw e;
|
||||||
|
|
||||||
|
} catch (ParseException e) {
|
||||||
|
log.error("Erro no parser do token: " + e.getMessage(), e);
|
||||||
|
|
||||||
|
throw new SecurityException(e);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Erro ao validar o token: " + e.getMessage(), e);
|
||||||
|
|
||||||
|
throw new SecurityException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue