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.Transient;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
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.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
*/
@AuditarClasse(nome = "USUARIO", tela = "Alteração de Usuário")
@Entity
@SequenceGenerator(name = "USUARIO_SEQ", sequenceName = "USUARIO_SEQ", allocationSize = 1)
@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;
private static final long serialVersionUID = 1L;
@AuditarID
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "USUARIO_SEQ")
@Basic(optional = false)
@ -79,6 +88,7 @@ public class Usuario implements Serializable, UserDetails/*, Authentication*/ {
private String descCorreo;
@OneToMany(mappedBy = "usuario", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT)
@AuditarLista(auditarEntidades = true, nome = "Perfil")
private List<UsuarioPerfil> usuarioPerfilList;
@Column(name = "INDCORTEAUTOMATICO")
private Boolean indCorteAutomatico;
@ -87,10 +97,12 @@ public class Usuario implements Serializable, UserDetails/*, Authentication*/ {
private Empleado empleado;
@OneToMany(mappedBy = "usuarioLog", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT)
@NaoAuditar
private List<UsuarioEmpresa> usuarioEmpresaList;
@OneToMany(mappedBy = "usuario", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT)
@NaoAuditar
private List<UsuarioUbicacion> usuarioUbicacionList;
@Column(name = "FECCONTRASENA")
@ -118,6 +130,10 @@ public class Usuario implements Serializable, UserDetails/*, Authentication*/ {
@Column(name = "INDRETORNATODASLOCALIDADES")
private Boolean indRetornaTodasLocalidades;
@Transient
@NaoAuditar
private Usuario usuarioClone;
public String getClaveUsuario() {
return claveUsuario;
@ -491,5 +507,38 @@ public class Usuario implements Serializable, UserDetails/*, Authentication*/ {
public void setIndRetornaTodasLocalidades(Boolean 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.Temporal;
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
*/
@AuditarClasse(nome = "USUARIO_PERFIL", tela = "Alteração de Usuário")
@Entity
@SequenceGenerator(name = "USUARIO_PERFIL_SEQ", sequenceName = "USUARIO_PERFIL_SEQ", allocationSize = 1)
@Table(name = "USUARIO_PERFIL")
public class UsuarioPerfil implements Serializable {
public class UsuarioPerfil implements Serializable, Auditavel<UsuarioPerfil> {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "USUARIO_PERFIL_SEQ")
@Column(name = "USUARIOPERFIL_ID")
@AuditarID
private Integer usuarioperfilId;
@Column(name = "ACTIVO")
private Boolean activo;
@ -43,10 +52,14 @@ public class UsuarioPerfil implements Serializable {
private Integer usuariomodifId;
@JoinColumn(name = "USUARIO_ID", referencedColumnName = "USUARIO_ID")
@ManyToOne
@AuditarEntidade
private Usuario usuario;
@JoinColumn(name = "PERFIL_ID", referencedColumnName = "PERFIL_ID")
@ManyToOne
private Perfil perfil;
@Transient
@NaoAuditar
private UsuarioPerfil usuarioPerfilClone;
public UsuarioPerfil() {
@ -128,4 +141,21 @@ public class UsuarioPerfil implements Serializable {
public String toString() {
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.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
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.UsuarioPerfil;
import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.service.LogAuditoriaService;
import com.rjconsultores.ventaboletos.service.UsuarioService;
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
import com.rjconsultores.ventaboletos.utilerias.CustomEnum;
@ -42,6 +44,10 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService {
private UsuarioDAO usuarioDAO;
@Autowired
private UsuarioPerfilDAO usuarioPerfilDAO;
@Autowired
private LogAuditoriaService logAuditoriaService;
private static Logger log = Logger.getLogger(UsuarioServiceImpl.class);
public List<Usuario> buscarPeloNome(String nome) {
return usuarioDAO.buscarPeloNome(nome);
@ -52,68 +58,86 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService {
}
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)
@Override
public Usuario suscribirActualizar(Usuario entidad, String senha, Perfil perfil) throws BusinessException {
// validación duplicado
List<Usuario> lsUsuario = this.buscarPelaCveUsuario(entidad.getClaveUsuario());
boolean podeSalvar = false;
if (lsUsuario.isEmpty()) {
podeSalvar = true;
} else {
if (entidad.getUsuarioId() != null) {
for (Usuario u : lsUsuario) {
if (u.getUsuarioId().equals(entidad.getUsuarioId())) {
podeSalvar = true;
try{
Usuario originalClone = entidad.getCloneObject();
// validación duplicado
List<Usuario> lsUsuario = this.buscarPelaCveUsuario(entidad.getClaveUsuario());
boolean podeSalvar = false;
if (lsUsuario.isEmpty()) {
podeSalvar = true;
} else {
if (entidad.getUsuarioId() != null) {
for (Usuario u : lsUsuario) {
if (u.getUsuarioId().equals(entidad.getUsuarioId())) {
podeSalvar = true;
}
}
}
}
}
if (!podeSalvar) {
throw new BusinessException("MSG.Registro.Existe");
}
if (senha != null) {
// validación complejidad contrasena
if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.CONTRASENA_VALIDA_COMPLEJIDAD.getDescricao())) {
ContrasenaUtileria contrasenaUtileria = new ContrasenaUtileria();
contrasenaUtileria.validarContrasenaCompleja(senha);
if (!podeSalvar) {
throw new BusinessException("MSG.Registro.Existe");
}
// encriptación contrasena
entidad.setSenha(ContrasenaUtileria.encriptarContrasena(senha));
}
// Perfil
UsuarioPerfil up = new UsuarioPerfil();
up.setUsuario(entidad);
up.setPerfil(perfil);
up.setActivo(Boolean.TRUE);
up.setFecmodif(Calendar.getInstance().getTime());
up.setUsuariomodifId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
if (entidad.getUsuarioId() != null) {
List<UsuarioPerfil> lsUsuarioPerfil = usuarioPerfilDAO.obtenerPorUsuario(entidad);
for (UsuarioPerfil up2 : lsUsuarioPerfil) {
usuarioPerfilDAO.borrar(up2);
if (senha != null) {
// validación complejidad contrasena
if (ApplicationProperties.getInstance().isCustomHabilitado(CustomEnum.CONTRASENA_VALIDA_COMPLEJIDAD.getDescricao())) {
ContrasenaUtileria contrasenaUtileria = new ContrasenaUtileria();
contrasenaUtileria.validarContrasenaCompleja(senha);
}
// encriptación contrasena
entidad.setSenha(ContrasenaUtileria.encriptarContrasena(senha));
}
}
List<UsuarioPerfil> lsUp = new ArrayList<UsuarioPerfil>();
lsUp.add(up);
entidad.setUsuarioPerfilList(lsUp);
entidad.setUsuariomodifId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
entidad.setFecmodif(Calendar.getInstance().getTime());
entidad.setActivo(Boolean.TRUE);
if (entidad.getUsuarioId() == null) {
return usuarioDAO.suscribir(entidad);
} else {
return usuarioDAO.actualizacion(entidad);
// Perfil
UsuarioPerfil up = new UsuarioPerfil();
up.setUsuario(entidad);
up.setPerfil(perfil);
up.setActivo(Boolean.TRUE);
up.setFecmodif(Calendar.getInstance().getTime());
up.setUsuariomodifId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
if (entidad.getUsuarioId() != null) {
List<UsuarioPerfil> lsUsuarioPerfil = usuarioPerfilDAO.obtenerPorUsuario(entidad);
for (UsuarioPerfil up2 : lsUsuarioPerfil) {
usuarioPerfilDAO.borrar(up2);
}
}
List<UsuarioPerfil> lsUp = new ArrayList<UsuarioPerfil>();
lsUp.add(up);
entidad.setUsuarioPerfilList(lsUp);
entidad.setUsuariomodifId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
entidad.setFecmodif(Calendar.getInstance().getTime());
entidad.setActivo(Boolean.TRUE);
if (entidad.getUsuarioId() == null) {
return usuarioDAO.suscribir(entidad);
} else {
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_VALIDAR_CONSTANTE_REMESSA("isValidarConstanteRemessa");
IS_VALIDAR_CONSTANTE_REMESSA("isValidarConstanteRemessa"),
IS_DESABILITA_USUARIO_ADMINISTRADORES_PERFIL("dasabilitaUsuarioAdministradoresPerfil");
private String descricao;

View File

@ -2,17 +2,25 @@ package com.rjconsultores.ventaboletos.vo.segurida;
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 String valorCaracter;
private PerfilJerarquia(Integer valor) {
this.valor = valor;
}
private PerfilJerarquia(String valorCaracter) {
this.valorCaracter = valorCaracter;
}
public Integer getValor() {
return valor;
}
public String getValorCaracter() {
return valorCaracter;
}
public static PerfilJerarquia buscar(Integer valor) {
@ -26,4 +34,16 @@ public enum PerfilJerarquia {
}
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;
}
}