--- Merge ---
Complexidade Senha - Tempo de Validade (fixed bug #5521) Tempo: 1 horas git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@36828 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
4ee1aff7a1
commit
cdd93ae5b7
|
@ -4,13 +4,6 @@
|
||||||
*/
|
*/
|
||||||
package com.rjconsultores.ventaboletos.dao.hibernate;
|
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.dao.UsuarioDAO;
|
|
||||||
import com.rjconsultores.ventaboletos.dao.sqlbuilder.SQLBuilder;
|
|
||||||
import com.rjconsultores.ventaboletos.entidad.Empleado;
|
|
||||||
import com.rjconsultores.ventaboletos.entidad.Usuario;
|
|
||||||
import com.rjconsultores.ventaboletos.vo.caja.UsuarioActivoVO;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
|
@ -26,6 +19,12 @@ 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.UsuarioDAO;
|
||||||
|
import com.rjconsultores.ventaboletos.dao.sqlbuilder.SQLBuilder;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Empleado;
|
||||||
|
import com.rjconsultores.ventaboletos.entidad.Usuario;
|
||||||
|
import com.rjconsultores.ventaboletos.vo.caja.UsuarioActivoVO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author rodrigo
|
* @author rodrigo
|
||||||
|
@ -77,7 +76,7 @@ public class UsuarioHibernateDAO extends GenericHibernateDAO<Usuario, Integer> i
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Usuario> buscarPelaCveUsuario(String cveUsuario) {
|
public List<Usuario> buscarPelaCveUsuario(String cveUsuario) {
|
||||||
Query query = getSession().createQuery("select u from Usuario u where u.activo =1 and u.claveUsuario = :clave order by u.claveUsuario" );
|
Query query = getSession().createQuery("select u from Usuario u where u.activo =1 and u.claveUsuario = :clave order by u.claveUsuario");
|
||||||
query.setParameter("clave", cveUsuario);
|
query.setParameter("clave", cveUsuario);
|
||||||
|
|
||||||
return query.list();
|
return query.list();
|
||||||
|
|
|
@ -6,6 +6,7 @@ package com.rjconsultores.ventaboletos.entidad;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -32,6 +33,11 @@ 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;
|
||||||
|
|
||||||
|
import com.rjconsultores.ventaboletos.service.ConstanteService;
|
||||||
|
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
|
||||||
|
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||||
|
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author rodrigo
|
* @author rodrigo
|
||||||
|
@ -66,7 +72,7 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
||||||
private String claveUsuario;
|
private String claveUsuario;
|
||||||
@Column(name = "DESCCORREO")
|
@Column(name = "DESCCORREO")
|
||||||
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)
|
||||||
private List<UsuarioPerfil> usuarioPerfilList;
|
private List<UsuarioPerfil> usuarioPerfilList;
|
||||||
@Column(name = "INDCORTEAUTOMATICO")
|
@Column(name = "INDCORTEAUTOMATICO")
|
||||||
|
@ -74,16 +80,17 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
||||||
@OneToOne
|
@OneToOne
|
||||||
@JoinColumn(name = "EMPLEADO_ID")
|
@JoinColumn(name = "EMPLEADO_ID")
|
||||||
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)
|
||||||
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)
|
||||||
private List<UsuarioUbicacion> usuarioUbicacionList;
|
private List<UsuarioUbicacion> usuarioUbicacionList;
|
||||||
|
|
||||||
|
@Column(name = "FECCONTRASENA")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date fecContrasena;
|
||||||
|
|
||||||
public String getClaveUsuario() {
|
public String getClaveUsuario() {
|
||||||
return claveUsuario;
|
return claveUsuario;
|
||||||
|
@ -164,7 +171,6 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
||||||
this.senha = senha;
|
this.senha = senha;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<UsuarioEmpresa> getUsuarioEmpresaList() {
|
public List<UsuarioEmpresa> getUsuarioEmpresaList() {
|
||||||
List<UsuarioEmpresa> tmp = new ArrayList<UsuarioEmpresa>();
|
List<UsuarioEmpresa> tmp = new ArrayList<UsuarioEmpresa>();
|
||||||
if (usuarioEmpresaList != null) {
|
if (usuarioEmpresaList != null) {
|
||||||
|
@ -195,7 +201,6 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<Empresa> getEmpresa() {
|
public List<Empresa> getEmpresa() {
|
||||||
List<Empresa> tmp = new ArrayList<Empresa>();
|
List<Empresa> tmp = new ArrayList<Empresa>();
|
||||||
if (usuarioEmpresaList != null) {
|
if (usuarioEmpresaList != null) {
|
||||||
|
@ -266,6 +271,20 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCredentialsNonExpired() {
|
public boolean isCredentialsNonExpired() {
|
||||||
|
if (ApplicationProperties.getInstance().contrasenaValidaComplejidad()) {
|
||||||
|
if (getFecContrasena() != null) {
|
||||||
|
ConstanteService constanteService = (ConstanteService) AppContext.getApplicationContext().getBean("constanteService");
|
||||||
|
Constante contante = constanteService.buscarPorNomeConstante("CANT_DIAS_CONTRASENA");
|
||||||
|
Integer maxPrazoCambioContrasena = Integer.valueOf(contante.getValorconstante());
|
||||||
|
Date maxFechaContrasena = DateUtil.somarDias(getFecContrasena(), maxPrazoCambioContrasena);
|
||||||
|
if (Calendar.getInstance().getTime().after(maxFechaContrasena)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,6 +322,7 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
||||||
public void setDescCorreo(String descCorreo) {
|
public void setDescCorreo(String descCorreo) {
|
||||||
this.descCorreo = descCorreo;
|
this.descCorreo = descCorreo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getIndCorteAutomatico() {
|
public Boolean getIndCorteAutomatico() {
|
||||||
return indCorteAutomatico;
|
return indCorteAutomatico;
|
||||||
}
|
}
|
||||||
|
@ -314,16 +334,24 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
||||||
public List<UsuarioUbicacion> getUsuarioUbicacionList() {
|
public List<UsuarioUbicacion> getUsuarioUbicacionList() {
|
||||||
List<UsuarioUbicacion> ubicacionActivos = new ArrayList<UsuarioUbicacion>();
|
List<UsuarioUbicacion> ubicacionActivos = new ArrayList<UsuarioUbicacion>();
|
||||||
|
|
||||||
if(usuarioUbicacionList != null)
|
if (usuarioUbicacionList != null)
|
||||||
for(UsuarioUbicacion ubicacion : usuarioUbicacionList)
|
for (UsuarioUbicacion ubicacion : usuarioUbicacionList)
|
||||||
if(ubicacion.getActivo())
|
if (ubicacion.getActivo())
|
||||||
ubicacionActivos.add(ubicacion);
|
ubicacionActivos.add(ubicacion);
|
||||||
|
|
||||||
|
|
||||||
return ubicacionActivos;
|
return ubicacionActivos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsuarioUbicacionList(List<UsuarioUbicacion> usuarioUbicacionList) {
|
public void setUsuarioUbicacionList(List<UsuarioUbicacion> usuarioUbicacionList) {
|
||||||
this.usuarioUbicacionList = usuarioUbicacionList;
|
this.usuarioUbicacionList = usuarioUbicacionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date getFecContrasena() {
|
||||||
|
return fecContrasena;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFecContrasena(Date fecContrasena) {
|
||||||
|
this.fecContrasena = fecContrasena;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,4 +32,6 @@ public interface UsuarioService {
|
||||||
public List<Usuario> buscarPelaCveUsuario(String claveUsuario);
|
public List<Usuario> buscarPelaCveUsuario(String claveUsuario);
|
||||||
|
|
||||||
public Usuario suscribirActualizar(Usuario entidad, String senha, Perfil perfil) throws BusinessException;
|
public Usuario suscribirActualizar(Usuario entidad, String senha, Perfil perfil) throws BusinessException;
|
||||||
|
|
||||||
|
public Usuario cambiarContrasena(Usuario entidad, String senha) throws BusinessException;
|
||||||
}
|
}
|
|
@ -10,6 +10,7 @@ import java.util.List;
|
||||||
|
|
||||||
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.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
|
@ -54,15 +55,15 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService {
|
||||||
|
|
||||||
@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 {
|
||||||
|
|
||||||
//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;
|
||||||
if (lsUsuario.isEmpty()) {
|
if (lsUsuario.isEmpty()) {
|
||||||
podeSalvar = true;
|
podeSalvar = true;
|
||||||
} else {
|
} else {
|
||||||
if (entidad.getUsuarioId() != null){
|
if (entidad.getUsuarioId() != null) {
|
||||||
for (Usuario u : lsUsuario) {
|
for (Usuario u : lsUsuario) {
|
||||||
if (u.getUsuarioId().equals(entidad.getUsuarioId())) {
|
if (u.getUsuarioId().equals(entidad.getUsuarioId())) {
|
||||||
podeSalvar = true;
|
podeSalvar = true;
|
||||||
|
@ -74,17 +75,17 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService {
|
||||||
if (!podeSalvar) {
|
if (!podeSalvar) {
|
||||||
throw new BusinessException("MSG.Registro.Existe");
|
throw new BusinessException("MSG.Registro.Existe");
|
||||||
}
|
}
|
||||||
if (senha != null){
|
if (senha != null) {
|
||||||
//validación complejidad contrasena
|
// validación complejidad contrasena
|
||||||
if (ApplicationProperties.getInstance().contrasenaValidaComplejidad()){
|
if (ApplicationProperties.getInstance().contrasenaValidaComplejidad()) {
|
||||||
ContrasenaUtileria.validarContrasenaCompleja(senha);
|
ContrasenaUtileria.validarContrasenaCompleja(senha);
|
||||||
}
|
}
|
||||||
|
|
||||||
//encriptación contrasena
|
// encriptación contrasena
|
||||||
entidad.setSenha(ContrasenaUtileria.encriptarContrasena(senha));
|
entidad.setSenha(ContrasenaUtileria.encriptarContrasena(senha));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Perfil
|
// Perfil
|
||||||
UsuarioPerfil up = new UsuarioPerfil();
|
UsuarioPerfil up = new UsuarioPerfil();
|
||||||
up.setUsuario(entidad);
|
up.setUsuario(entidad);
|
||||||
up.setPerfil(perfil);
|
up.setPerfil(perfil);
|
||||||
|
@ -102,17 +103,61 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService {
|
||||||
lsUp.add(up);
|
lsUp.add(up);
|
||||||
entidad.setUsuarioPerfilList(lsUp);
|
entidad.setUsuarioPerfilList(lsUp);
|
||||||
|
|
||||||
|
|
||||||
entidad.setUsuariomodifId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
entidad.setUsuariomodifId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
||||||
entidad.setFecmodif(Calendar.getInstance().getTime());
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||||
entidad.setActivo(Boolean.TRUE);
|
entidad.setActivo(Boolean.TRUE);
|
||||||
|
|
||||||
if (entidad.getUsuarioId() == null){
|
if (entidad.getUsuarioId() == null) {
|
||||||
return usuarioDAO.suscribir(entidad);
|
return usuarioDAO.suscribir(entidad);
|
||||||
}else{
|
} else {
|
||||||
return usuarioDAO.actualizacion(entidad);
|
return usuarioDAO.actualizacion(entidad);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = BusinessException.class)
|
||||||
|
@Override
|
||||||
|
public Usuario cambiarContrasena(Usuario entidad, String senha) 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!podeSalvar) {
|
||||||
|
throw new BusinessException("MSG.Registro.Existe");
|
||||||
|
}
|
||||||
|
if (senha != null) {
|
||||||
|
// validación complejidad contrasena
|
||||||
|
if (ApplicationProperties.getInstance().contrasenaValidaComplejidad()) {
|
||||||
|
ContrasenaUtileria.validarContrasenaCompleja(senha);
|
||||||
|
}
|
||||||
|
|
||||||
|
// encriptación contrasena
|
||||||
|
entidad.setSenha(ContrasenaUtileria.encriptarContrasena(senha));
|
||||||
|
}
|
||||||
|
|
||||||
|
entidad.setFecContrasena(Calendar.getInstance().getTime());
|
||||||
|
entidad.setUsuariomodifId(entidad.getUsuarioId());
|
||||||
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||||
|
entidad.setActivo(Boolean.TRUE);
|
||||||
|
|
||||||
|
if (entidad.getUsuarioId() != null) {
|
||||||
|
return usuarioDAO.actualizacion(entidad);
|
||||||
|
} else {
|
||||||
|
throw new BusinessException("MSG.Registro.Existe");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void borrar(Usuario entidad) {
|
public void borrar(Usuario entidad) {
|
||||||
|
|
||||||
|
@ -132,11 +177,12 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Usuario buscarPeloNomeSenha(String stUsuario, String senha) {
|
public Usuario buscarPeloNomeSenha(String stUsuario, String senha) {
|
||||||
|
senha = ContrasenaUtileria.encriptarContrasena(senha);
|
||||||
return usuarioDAO.buscarPeloNomeSenha(stUsuario, senha);
|
return usuarioDAO.buscarPeloNomeSenha(stUsuario, senha);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserDetails loadUserByUsername(String login) throws UsernameNotFoundException, DataAccessException {
|
public UserDetails loadUserByUsername(String login) throws UsernameNotFoundException, DataAccessException, CredentialsExpiredException {
|
||||||
if (login == null) {
|
if (login == null) {
|
||||||
throw new UsernameNotFoundException("Usuario não encontrado");
|
throw new UsernameNotFoundException("Usuario não encontrado");
|
||||||
}
|
}
|
||||||
|
@ -146,7 +192,15 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService {
|
||||||
throw new UsernameNotFoundException("Usuario não encontrado");
|
throw new UsernameNotFoundException("Usuario não encontrado");
|
||||||
}
|
}
|
||||||
|
|
||||||
return list.get(0);
|
Usuario user = list.get(0);
|
||||||
|
|
||||||
|
if (ApplicationProperties.getInstance().contrasenaValidaComplejidad()) {
|
||||||
|
if (!user.isCredentialsNonExpired()) {
|
||||||
|
throw new CredentialsExpiredException("Senha Expirada");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Usuario> buscarPorEmpleado(Empleado empleado) {
|
public List<Usuario> buscarPorEmpleado(Empleado empleado) {
|
||||||
|
|
|
@ -15,6 +15,9 @@ import java.util.logging.Logger;
|
||||||
|
|
||||||
public final class DateUtil {
|
public final class DateUtil {
|
||||||
|
|
||||||
|
public static Integer DIA = Integer.valueOf(1000 * 60 * 60 * 24);
|
||||||
|
public static Integer UM_DIA = Integer.valueOf(1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* No need for an instance
|
* No need for an instance
|
||||||
*/
|
*/
|
||||||
|
@ -532,4 +535,12 @@ public final class DateUtil {
|
||||||
return gcalendar.getTime();
|
return gcalendar.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Date somarDias(Date data, int quantidadeDias) {
|
||||||
|
Integer dias = UM_DIA * quantidadeDias;
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.setTime(data);
|
||||||
|
c.add(Calendar.DAY_OF_MONTH, dias);
|
||||||
|
return c.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue