--- 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;
|
||||
|
||||
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 org.hibernate.Criteria;
|
||||
|
@ -26,6 +19,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
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
|
||||
|
@ -77,7 +76,7 @@ public class UsuarioHibernateDAO extends GenericHibernateDAO<Usuario, Integer> i
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
return query.list();
|
||||
|
|
|
@ -6,6 +6,7 @@ package com.rjconsultores.ventaboletos.entidad;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
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.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
|
||||
|
@ -66,7 +72,7 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
|||
private String claveUsuario;
|
||||
@Column(name = "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)
|
||||
private List<UsuarioPerfil> usuarioPerfilList;
|
||||
@Column(name = "INDCORTEAUTOMATICO")
|
||||
|
@ -74,16 +80,17 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
|||
@OneToOne
|
||||
@JoinColumn(name = "EMPLEADO_ID")
|
||||
private Empleado empleado;
|
||||
@OneToMany(mappedBy = "usuarioLog", cascade = CascadeType.ALL,fetch=FetchType.EAGER)
|
||||
@OneToMany(mappedBy = "usuarioLog", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@Fetch(FetchMode.SELECT)
|
||||
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)
|
||||
private List<UsuarioUbicacion> usuarioUbicacionList;
|
||||
|
||||
|
||||
|
||||
@Column(name = "FECCONTRASENA")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date fecContrasena;
|
||||
|
||||
public String getClaveUsuario() {
|
||||
return claveUsuario;
|
||||
|
@ -164,7 +171,6 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
|||
this.senha = senha;
|
||||
}
|
||||
|
||||
|
||||
public List<UsuarioEmpresa> getUsuarioEmpresaList() {
|
||||
List<UsuarioEmpresa> tmp = new ArrayList<UsuarioEmpresa>();
|
||||
if (usuarioEmpresaList != null) {
|
||||
|
@ -195,7 +201,6 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
|||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
public List<Empresa> getEmpresa() {
|
||||
List<Empresa> tmp = new ArrayList<Empresa>();
|
||||
if (usuarioEmpresaList != null) {
|
||||
|
@ -266,6 +271,20 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -303,6 +322,7 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
|||
public void setDescCorreo(String descCorreo) {
|
||||
this.descCorreo = descCorreo;
|
||||
}
|
||||
|
||||
public Boolean getIndCorteAutomatico() {
|
||||
return indCorteAutomatico;
|
||||
}
|
||||
|
@ -314,16 +334,24 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
|||
public List<UsuarioUbicacion> getUsuarioUbicacionList() {
|
||||
List<UsuarioUbicacion> ubicacionActivos = new ArrayList<UsuarioUbicacion>();
|
||||
|
||||
if(usuarioUbicacionList != null)
|
||||
for(UsuarioUbicacion ubicacion : usuarioUbicacionList)
|
||||
if(ubicacion.getActivo())
|
||||
if (usuarioUbicacionList != null)
|
||||
for (UsuarioUbicacion ubicacion : usuarioUbicacionList)
|
||||
if (ubicacion.getActivo())
|
||||
ubicacionActivos.add(ubicacion);
|
||||
|
||||
|
||||
return ubicacionActivos;
|
||||
}
|
||||
|
||||
public void setUsuarioUbicacionList(List<UsuarioUbicacion> 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 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.dao.DataAccessException;
|
||||
import org.springframework.security.authentication.CredentialsExpiredException;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
@ -54,15 +55,15 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService {
|
|||
|
||||
@Transactional(rollbackFor = BusinessException.class)
|
||||
@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());
|
||||
boolean podeSalvar = false;
|
||||
if (lsUsuario.isEmpty()) {
|
||||
podeSalvar = true;
|
||||
} else {
|
||||
if (entidad.getUsuarioId() != null){
|
||||
if (entidad.getUsuarioId() != null) {
|
||||
for (Usuario u : lsUsuario) {
|
||||
if (u.getUsuarioId().equals(entidad.getUsuarioId())) {
|
||||
podeSalvar = true;
|
||||
|
@ -74,17 +75,17 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService {
|
|||
if (!podeSalvar) {
|
||||
throw new BusinessException("MSG.Registro.Existe");
|
||||
}
|
||||
if (senha != null){
|
||||
//validación complejidad contrasena
|
||||
if (ApplicationProperties.getInstance().contrasenaValidaComplejidad()){
|
||||
if (senha != null) {
|
||||
// validación complejidad contrasena
|
||||
if (ApplicationProperties.getInstance().contrasenaValidaComplejidad()) {
|
||||
ContrasenaUtileria.validarContrasenaCompleja(senha);
|
||||
}
|
||||
|
||||
//encriptación contrasena
|
||||
// encriptación contrasena
|
||||
entidad.setSenha(ContrasenaUtileria.encriptarContrasena(senha));
|
||||
}
|
||||
|
||||
//Perfil
|
||||
// Perfil
|
||||
UsuarioPerfil up = new UsuarioPerfil();
|
||||
up.setUsuario(entidad);
|
||||
up.setPerfil(perfil);
|
||||
|
@ -102,17 +103,61 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService {
|
|||
lsUp.add(up);
|
||||
entidad.setUsuarioPerfilList(lsUp);
|
||||
|
||||
|
||||
entidad.setUsuariomodifId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
||||
entidad.setFecmodif(Calendar.getInstance().getTime());
|
||||
entidad.setActivo(Boolean.TRUE);
|
||||
|
||||
if (entidad.getUsuarioId() == null){
|
||||
if (entidad.getUsuarioId() == null) {
|
||||
return usuarioDAO.suscribir(entidad);
|
||||
}else{
|
||||
} else {
|
||||
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
|
||||
public void borrar(Usuario entidad) {
|
||||
|
||||
|
@ -132,11 +177,12 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService {
|
|||
}
|
||||
|
||||
public Usuario buscarPeloNomeSenha(String stUsuario, String senha) {
|
||||
senha = ContrasenaUtileria.encriptarContrasena(senha);
|
||||
return usuarioDAO.buscarPeloNomeSenha(stUsuario, senha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String login) throws UsernameNotFoundException, DataAccessException {
|
||||
public UserDetails loadUserByUsername(String login) throws UsernameNotFoundException, DataAccessException, CredentialsExpiredException {
|
||||
if (login == null) {
|
||||
throw new UsernameNotFoundException("Usuario não encontrado");
|
||||
}
|
||||
|
@ -146,7 +192,15 @@ public class UsuarioServiceImpl implements UsuarioService, UserDetailsService {
|
|||
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) {
|
||||
|
|
|
@ -15,6 +15,9 @@ import java.util.logging.Logger;
|
|||
|
||||
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
|
||||
*/
|
||||
|
@ -532,4 +535,12 @@ public final class DateUtil {
|
|||
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