fixes bug#22760

qua:wally
dev:valdir

incluido o seguinte custom  : 	dasabilitaUsuarioAdministradoresPerfil
Para ser  uma regra especifica do usuario administradores

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@108760 d1611594-4594-4d17-8e1d-87c2c4800839
master
walace 2021-09-20 19:10:57 +00:00
parent 3ef51f81fa
commit ceed4087e5
5 changed files with 182 additions and 57 deletions

View File

@ -28,10 +28,10 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.Transient; import javax.persistence.Transient;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
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.Authentication;
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;
@ -41,18 +41,27 @@ import com.rjconsultores.ventaboletos.utilerias.CustomEnum;
import com.rjconsultores.ventaboletos.utilerias.DateUtil; import com.rjconsultores.ventaboletos.utilerias.DateUtil;
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.AuditarID;
import br.com.rjconsultores.auditador.annotations.AuditarLista;
import br.com.rjconsultores.auditador.annotations.NaoAuditar;
import br.com.rjconsultores.auditador.interfaces.Auditavel;
/** /**
* *
* @author rodrigo * @author rodrigo
*/ */
@AuditarClasse(nome = "USUARIO", tela = "Alteração de Usuário")
@Entity @Entity
@SequenceGenerator(name = "USUARIO_SEQ", sequenceName = "USUARIO_SEQ", allocationSize = 1) @SequenceGenerator(name = "USUARIO_SEQ", sequenceName = "USUARIO_SEQ", allocationSize = 1)
@Table(name = "USUARIO") @Table(name = "USUARIO")
public class Usuario implements Serializable, UserDetails/*, Authentication*/ {
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 final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@AuditarID
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "USUARIO_SEQ") @GeneratedValue(strategy = GenerationType.AUTO, generator = "USUARIO_SEQ")
@Basic(optional = false) @Basic(optional = false)
@ -79,6 +88,7 @@ public class Usuario implements Serializable, UserDetails/*, Authentication*/ {
private String descCorreo; private String descCorreo;
@OneToMany(mappedBy = "usuario", cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OneToMany(mappedBy = "usuario", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT) @Fetch(FetchMode.SELECT)
@AuditarLista(auditarEntidades = true, nome = "Perfil")
private List<UsuarioPerfil> usuarioPerfilList; private List<UsuarioPerfil> usuarioPerfilList;
@Column(name = "INDCORTEAUTOMATICO") @Column(name = "INDCORTEAUTOMATICO")
private Boolean indCorteAutomatico; private Boolean indCorteAutomatico;
@ -87,10 +97,12 @@ public class Usuario implements Serializable, UserDetails/*, Authentication*/ {
private Empleado empleado; private Empleado empleado;
@OneToMany(mappedBy = "usuarioLog", cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OneToMany(mappedBy = "usuarioLog", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT) @Fetch(FetchMode.SELECT)
@NaoAuditar
private List<UsuarioEmpresa> usuarioEmpresaList; private List<UsuarioEmpresa> usuarioEmpresaList;
@OneToMany(mappedBy = "usuario", cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OneToMany(mappedBy = "usuario", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT) @Fetch(FetchMode.SELECT)
@NaoAuditar
private List<UsuarioUbicacion> usuarioUbicacionList; private List<UsuarioUbicacion> usuarioUbicacionList;
@Column(name = "FECCONTRASENA") @Column(name = "FECCONTRASENA")
@ -119,6 +131,10 @@ public class Usuario implements Serializable, UserDetails/*, Authentication*/ {
@Column(name = "INDRETORNATODASLOCALIDADES") @Column(name = "INDRETORNATODASLOCALIDADES")
private Boolean indRetornaTodasLocalidades; private Boolean indRetornaTodasLocalidades;
@Transient
@NaoAuditar
private Usuario usuarioClone;
public String getClaveUsuario() { public String getClaveUsuario() {
return claveUsuario; return claveUsuario;
} }
@ -492,4 +508,37 @@ public class Usuario implements Serializable, UserDetails/*, Authentication*/ {
this.indRetornaTodasLocalidades = indRetornaTodasLocalidades; this.indRetornaTodasLocalidades = indRetornaTodasLocalidades;
} }
@Override
public void clonar() throws CloneNotSupportedException {
usuarioClone = new Usuario();
usuarioClone = (Usuario) this.clone();
if(this.getUsuarioPerfilList() != null) {
List<UsuarioPerfil> lsClones = new ArrayList<UsuarioPerfil>();
for (UsuarioPerfil usuarioPerfil : this.getUsuarioPerfilList()) {
if(BooleanUtils.isTrue(usuarioPerfil.getActivo())) {
usuarioPerfil.clonar();
lsClones.add(usuarioPerfil.getCloneObject());
}
}
usuarioClone.setUsuarioPerfilList((lsClones));
}
}
@Override
public Usuario getCloneObject() throws CloneNotSupportedException {
return usuarioClone;
}
@Override
public String getTextoInclusaoExclusao() {
return String.format("ID [%s]", getUsuarioId());
}
} }

View File

@ -18,21 +18,30 @@ import javax.persistence.SequenceGenerator;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.persistence.Transient;
import br.com.rjconsultores.auditador.annotations.AuditarClasse;
import br.com.rjconsultores.auditador.annotations.AuditarEntidade;
import br.com.rjconsultores.auditador.annotations.AuditarID;
import br.com.rjconsultores.auditador.annotations.NaoAuditar;
import br.com.rjconsultores.auditador.interfaces.Auditavel;
/** /**
* *
* @author Rafius * @author Rafius
*/ */
@AuditarClasse(nome = "USUARIO_PERFIL", tela = "Alteração de Usuário")
@Entity @Entity
@SequenceGenerator(name = "USUARIO_PERFIL_SEQ", sequenceName = "USUARIO_PERFIL_SEQ", allocationSize = 1) @SequenceGenerator(name = "USUARIO_PERFIL_SEQ", sequenceName = "USUARIO_PERFIL_SEQ", allocationSize = 1)
@Table(name = "USUARIO_PERFIL") @Table(name = "USUARIO_PERFIL")
public class UsuarioPerfil implements Serializable { public class UsuarioPerfil implements Serializable, Auditavel<UsuarioPerfil> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Id @Id
@Basic(optional = false) @Basic(optional = false)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "USUARIO_PERFIL_SEQ") @GeneratedValue(strategy = GenerationType.AUTO, generator = "USUARIO_PERFIL_SEQ")
@Column(name = "USUARIOPERFIL_ID") @Column(name = "USUARIOPERFIL_ID")
@AuditarID
private Integer usuarioperfilId; private Integer usuarioperfilId;
@Column(name = "ACTIVO") @Column(name = "ACTIVO")
private Boolean activo; private Boolean activo;
@ -43,10 +52,14 @@ public class UsuarioPerfil implements Serializable {
private Integer usuariomodifId; private Integer usuariomodifId;
@JoinColumn(name = "USUARIO_ID", referencedColumnName = "USUARIO_ID") @JoinColumn(name = "USUARIO_ID", referencedColumnName = "USUARIO_ID")
@ManyToOne @ManyToOne
@AuditarEntidade
private Usuario usuario; private Usuario usuario;
@JoinColumn(name = "PERFIL_ID", referencedColumnName = "PERFIL_ID") @JoinColumn(name = "PERFIL_ID", referencedColumnName = "PERFIL_ID")
@ManyToOne @ManyToOne
private Perfil perfil; private Perfil perfil;
@Transient
@NaoAuditar
private UsuarioPerfil usuarioPerfilClone;
public UsuarioPerfil() { public UsuarioPerfil() {
@ -128,4 +141,21 @@ public class UsuarioPerfil implements Serializable {
public String toString() { public String toString() {
return "com.rjconsultores.ventaboletos.dao.hibernate.UsuarioPerfil[usuarioperfilId=" + usuarioperfilId + "]"; return "com.rjconsultores.ventaboletos.dao.hibernate.UsuarioPerfil[usuarioperfilId=" + usuarioperfilId + "]";
} }
@Override
public void clonar() throws CloneNotSupportedException {
usuarioPerfilClone = new UsuarioPerfil();
usuarioPerfilClone = (UsuarioPerfil) this.clone();
}
@Override
public UsuarioPerfil getCloneObject() throws CloneNotSupportedException {
return usuarioPerfilClone;
}
@Override
public String getTextoInclusaoExclusao() {
return String.format("ID [%s]", getUsuarioperfilId());
}
} }

View File

@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.security.authentication.CredentialsExpiredException; import org.springframework.security.authentication.CredentialsExpiredException;
@ -24,6 +25,7 @@ import com.rjconsultores.ventaboletos.entidad.Perfil;
import com.rjconsultores.ventaboletos.entidad.Usuario; import com.rjconsultores.ventaboletos.entidad.Usuario;
import com.rjconsultores.ventaboletos.entidad.UsuarioPerfil; import com.rjconsultores.ventaboletos.entidad.UsuarioPerfil;
import com.rjconsultores.ventaboletos.exception.BusinessException; import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.service.LogAuditoriaService;
import com.rjconsultores.ventaboletos.service.UsuarioService; import com.rjconsultores.ventaboletos.service.UsuarioService;
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties; import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
import com.rjconsultores.ventaboletos.utilerias.CustomEnum; import com.rjconsultores.ventaboletos.utilerias.CustomEnum;
@ -42,6 +44,10 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService {
private UsuarioDAO usuarioDAO; private UsuarioDAO usuarioDAO;
@Autowired @Autowired
private UsuarioPerfilDAO usuarioPerfilDAO; private UsuarioPerfilDAO usuarioPerfilDAO;
@Autowired
private LogAuditoriaService logAuditoriaService;
private static Logger log = Logger.getLogger(UsuarioServiceImpl.class);
public List<Usuario> buscarPeloNome(String nome) { public List<Usuario> buscarPeloNome(String nome) {
return usuarioDAO.buscarPeloNome(nome); return usuarioDAO.buscarPeloNome(nome);
@ -52,13 +58,25 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService {
} }
public Usuario obtenerID(Integer id) { public Usuario obtenerID(Integer id) {
return usuarioDAO.obtenerID(id);
Usuario usuario = usuarioDAO.obtenerID(id);
try {
usuario.clonar();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return usuario;
} }
@Transactional(rollbackFor = BusinessException.class) @Transactional(rollbackFor = BusinessException.class)
@Override @Override
public Usuario suscribirActualizar(Usuario entidad, String senha, Perfil perfil) throws BusinessException { public Usuario suscribirActualizar(Usuario entidad, String senha, Perfil perfil) throws BusinessException {
try{
Usuario originalClone = entidad.getCloneObject();
// validación duplicado // validación duplicado
List<Usuario> lsUsuario = this.buscarPelaCveUsuario(entidad.getClaveUsuario()); List<Usuario> lsUsuario = this.buscarPelaCveUsuario(entidad.getClaveUsuario());
boolean podeSalvar = false; boolean podeSalvar = false;
@ -113,7 +131,13 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService {
if (entidad.getUsuarioId() == null) { if (entidad.getUsuarioId() == null) {
return usuarioDAO.suscribir(entidad); return usuarioDAO.suscribir(entidad);
} else { } else {
return usuarioDAO.actualizacion(entidad); entidad = usuarioDAO.actualizacion(entidad);
logAuditoriaService.auditar(originalClone, entidad, entidad.getEmpresa() != null && !entidad.getEmpresa().isEmpty()? entidad.getEmpresa().get(0).getEmpresaId(): null);
return entidad;
}
}catch (Exception e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
} }
} }

View File

@ -149,7 +149,9 @@ public enum CustomEnum {
IS_HABILITA_IE_DESCENTRALIZADA("isHabilitaIEDescentralizada"), IS_HABILITA_IE_DESCENTRALIZADA("isHabilitaIEDescentralizada"),
IS_VALIDAR_CONSTANTE_REMESSA("isValidarConstanteRemessa"); IS_VALIDAR_CONSTANTE_REMESSA("isValidarConstanteRemessa"),
IS_DESABILITA_USUARIO_ADMINISTRADORES_PERFIL("dasabilitaUsuarioAdministradoresPerfil");
private String descricao; private String descricao;

View File

@ -2,17 +2,25 @@ package com.rjconsultores.ventaboletos.vo.segurida;
public enum PerfilJerarquia { public enum PerfilJerarquia {
NORMAL(0), ADMIN(1), JERARQUIA_2(2), JERARQUIA_3(3), JERARQUIA_4(4); NORMAL(0), ADMIN(1), JERARQUIA_2(2), JERARQUIA_3(3), JERARQUIA_4(4), ADMINISTRADORES("ADMINISTRADORES");
private Integer valor; private Integer valor;
private String valorCaracter;
private PerfilJerarquia(Integer valor) { private PerfilJerarquia(Integer valor) {
this.valor = valor; this.valor = valor;
} }
private PerfilJerarquia(String valorCaracter) {
this.valorCaracter = valorCaracter;
}
public Integer getValor() { public Integer getValor() {
return valor; return valor;
} }
public String getValorCaracter() {
return valorCaracter;
}
public static PerfilJerarquia buscar(Integer valor) { public static PerfilJerarquia buscar(Integer valor) {
@ -26,4 +34,16 @@ public enum PerfilJerarquia {
} }
return null; return null;
} }
public static PerfilJerarquia buscar(String valorCaracter) {
if (valorCaracter == null)
return NORMAL;
for (PerfilJerarquia jerarquia : PerfilJerarquia.values()) {
if (jerarquia.getValor().equals(valorCaracter)) {
return jerarquia;
}
}
return null;
}
} }