--- 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
|
||||
|
@ -35,57 +34,57 @@ public class UsuarioHibernateDAO extends GenericHibernateDAO<Usuario, Integer> i
|
|||
@Autowired
|
||||
private SQLBuilder sqlBuilder;
|
||||
|
||||
@Autowired
|
||||
public UsuarioHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||
setSessionFactory(factory);
|
||||
}
|
||||
@Autowired
|
||||
public UsuarioHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||||
setSessionFactory(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Usuario> obtenerTodos() {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
@Override
|
||||
public List<Usuario> obtenerTodos() {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
|
||||
return c.list();
|
||||
}
|
||||
return c.list();
|
||||
}
|
||||
|
||||
public List<Usuario> buscarPeloNome(String nome) {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
public List<Usuario> buscarPeloNome(String nome) {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
|
||||
c.add(Restrictions.eq("nombusuario", nome));
|
||||
c.addOrder(Order.asc("nombusuario"));
|
||||
c.add(Restrictions.eq("nombusuario", nome));
|
||||
c.addOrder(Order.asc("nombusuario"));
|
||||
|
||||
return c.list();
|
||||
}
|
||||
return c.list();
|
||||
}
|
||||
|
||||
public Usuario buscarPeloNomeSenha(String stUsuario, String senha) {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("claveUsuario", stUsuario));
|
||||
c.add(Restrictions.eq("senha", senha));
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
public Usuario buscarPeloNomeSenha(String stUsuario, String senha) {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("claveUsuario", stUsuario));
|
||||
c.add(Restrictions.eq("senha", senha));
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
|
||||
return (Usuario) c.uniqueResult();
|
||||
}
|
||||
return (Usuario) c.uniqueResult();
|
||||
}
|
||||
|
||||
public List<Usuario> buscarPorEmpleado(Empleado empleado) {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
public List<Usuario> buscarPorEmpleado(Empleado empleado) {
|
||||
Criteria c = getSession().createCriteria(getPersistentClass());
|
||||
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
||||
|
||||
c.add(Restrictions.eq("empleado", empleado));
|
||||
c.add(Restrictions.eq("empleado", empleado));
|
||||
|
||||
return c.list();
|
||||
}
|
||||
return c.list();
|
||||
}
|
||||
|
||||
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.setParameter("clave", 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.setParameter("clave", cveUsuario);
|
||||
|
||||
return query.list();
|
||||
}
|
||||
return query.list();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<UsuarioActivoVO> buscarUsuariosActivo() {
|
||||
String sqlBuscarUsuariosActivo = sqlBuilder.getSQLBuscarUsuariosActivo();
|
||||
String sqlBuscarUsuariosActivo = sqlBuilder.getSQLBuscarUsuariosActivo();
|
||||
|
||||
SQLQuery sql = getSession().createSQLQuery(sqlBuscarUsuariosActivo)
|
||||
.addScalar("usuarioId", IntegerType.INSTANCE)
|
||||
|
@ -94,6 +93,6 @@ public class UsuarioHibernateDAO extends GenericHibernateDAO<Usuario, Integer> i
|
|||
|
||||
sql.setResultTransformer(new AliasToBeanResultTransformer(UsuarioActivoVO.class));
|
||||
|
||||
return sql.list();
|
||||
}
|
||||
return sql.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
|
||||
|
@ -41,269 +47,283 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|||
@Table(name = "USUARIO")
|
||||
public class Usuario implements Serializable, Authentication, UserDetails {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "USUARIO_SEQ")
|
||||
@Basic(optional = false)
|
||||
@Column(name = "USUARIO_ID")
|
||||
private Integer usuarioId;
|
||||
@Column(name = "NOMBUSUARIO")
|
||||
private String nombusuario;
|
||||
@Column(name = "NOMBPATERNO")
|
||||
private String nombpaterno;
|
||||
@Column(name = "NOMBMATERNO")
|
||||
private String nombmaterno;
|
||||
@Column(name = "ACTIVO")
|
||||
private Boolean activo;
|
||||
@Column(name = "FECMODIF")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date fecmodif;
|
||||
@Column(name = "USUARIOMODIF_ID")
|
||||
private Integer usuariomodifId;
|
||||
@Column(name = "DESCCONTRASENA")
|
||||
private String senha;
|
||||
@Column(name = "CVEUSUARIO")
|
||||
private String claveUsuario;
|
||||
@Column(name = "DESCCORREO")
|
||||
private String descCorreo;
|
||||
@OneToMany(mappedBy = "usuario", cascade = CascadeType.ALL,fetch=FetchType.EAGER)
|
||||
@Fetch(FetchMode.SELECT)
|
||||
private List<UsuarioPerfil> usuarioPerfilList;
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO, generator = "USUARIO_SEQ")
|
||||
@Basic(optional = false)
|
||||
@Column(name = "USUARIO_ID")
|
||||
private Integer usuarioId;
|
||||
@Column(name = "NOMBUSUARIO")
|
||||
private String nombusuario;
|
||||
@Column(name = "NOMBPATERNO")
|
||||
private String nombpaterno;
|
||||
@Column(name = "NOMBMATERNO")
|
||||
private String nombmaterno;
|
||||
@Column(name = "ACTIVO")
|
||||
private Boolean activo;
|
||||
@Column(name = "FECMODIF")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date fecmodif;
|
||||
@Column(name = "USUARIOMODIF_ID")
|
||||
private Integer usuariomodifId;
|
||||
@Column(name = "DESCCONTRASENA")
|
||||
private String senha;
|
||||
@Column(name = "CVEUSUARIO")
|
||||
private String claveUsuario;
|
||||
@Column(name = "DESCCORREO")
|
||||
private String descCorreo;
|
||||
@OneToMany(mappedBy = "usuario", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@Fetch(FetchMode.SELECT)
|
||||
private List<UsuarioPerfil> usuarioPerfilList;
|
||||
@Column(name = "INDCORTEAUTOMATICO")
|
||||
private Boolean indCorteAutomatico;
|
||||
@OneToOne
|
||||
@JoinColumn(name = "EMPLEADO_ID")
|
||||
private Empleado empleado;
|
||||
@OneToMany(mappedBy = "usuarioLog", cascade = CascadeType.ALL,fetch=FetchType.EAGER)
|
||||
@Fetch(FetchMode.SELECT)
|
||||
private List<UsuarioEmpresa> usuarioEmpresaList;
|
||||
@OneToOne
|
||||
@JoinColumn(name = "EMPLEADO_ID")
|
||||
private Empleado empleado;
|
||||
@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)
|
||||
@Fetch(FetchMode.SELECT)
|
||||
private List<UsuarioUbicacion> usuarioUbicacionList;
|
||||
@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;
|
||||
}
|
||||
|
||||
public void setClaveUsuario(String claveUsuario) {
|
||||
this.claveUsuario = claveUsuario;
|
||||
}
|
||||
|
||||
public String getClaveUsuario() {
|
||||
return claveUsuario;
|
||||
}
|
||||
public Usuario() {
|
||||
}
|
||||
|
||||
public void setClaveUsuario(String claveUsuario) {
|
||||
this.claveUsuario = claveUsuario;
|
||||
}
|
||||
public Usuario(Integer usuarioId) {
|
||||
this.usuarioId = usuarioId;
|
||||
}
|
||||
|
||||
public Usuario() {
|
||||
}
|
||||
public Integer getUsuarioId() {
|
||||
return usuarioId;
|
||||
}
|
||||
|
||||
public Usuario(Integer usuarioId) {
|
||||
this.usuarioId = usuarioId;
|
||||
}
|
||||
public void setUsuarioId(Integer usuarioId) {
|
||||
this.usuarioId = usuarioId;
|
||||
}
|
||||
|
||||
public Integer getUsuarioId() {
|
||||
return usuarioId;
|
||||
}
|
||||
public String getNombusuario() {
|
||||
return nombusuario;
|
||||
}
|
||||
|
||||
public void setUsuarioId(Integer usuarioId) {
|
||||
this.usuarioId = usuarioId;
|
||||
}
|
||||
public void setNombusuario(String nombusuario) {
|
||||
this.nombusuario = nombusuario;
|
||||
}
|
||||
|
||||
public String getNombusuario() {
|
||||
return nombusuario;
|
||||
}
|
||||
public String getNombpaterno() {
|
||||
return nombpaterno;
|
||||
}
|
||||
|
||||
public void setNombusuario(String nombusuario) {
|
||||
this.nombusuario = nombusuario;
|
||||
}
|
||||
public void setNombpaterno(String nombpaterno) {
|
||||
this.nombpaterno = nombpaterno;
|
||||
}
|
||||
|
||||
public String getNombpaterno() {
|
||||
return nombpaterno;
|
||||
}
|
||||
public String getNombmaterno() {
|
||||
return nombmaterno;
|
||||
}
|
||||
|
||||
public void setNombpaterno(String nombpaterno) {
|
||||
this.nombpaterno = nombpaterno;
|
||||
}
|
||||
public void setNombmaterno(String nombmaterno) {
|
||||
this.nombmaterno = nombmaterno;
|
||||
}
|
||||
|
||||
public String getNombmaterno() {
|
||||
return nombmaterno;
|
||||
}
|
||||
public Boolean getActivo() {
|
||||
return activo;
|
||||
}
|
||||
|
||||
public void setNombmaterno(String nombmaterno) {
|
||||
this.nombmaterno = nombmaterno;
|
||||
}
|
||||
public void setActivo(Boolean activo) {
|
||||
this.activo = activo;
|
||||
}
|
||||
|
||||
public Boolean getActivo() {
|
||||
return activo;
|
||||
}
|
||||
public Date getFecmodif() {
|
||||
return fecmodif;
|
||||
}
|
||||
|
||||
public void setActivo(Boolean activo) {
|
||||
this.activo = activo;
|
||||
}
|
||||
public void setFecmodif(Date fecmodif) {
|
||||
this.fecmodif = fecmodif;
|
||||
}
|
||||
|
||||
public Date getFecmodif() {
|
||||
return fecmodif;
|
||||
}
|
||||
public Integer getUsuariomodifId() {
|
||||
return usuariomodifId;
|
||||
}
|
||||
|
||||
public void setFecmodif(Date fecmodif) {
|
||||
this.fecmodif = fecmodif;
|
||||
}
|
||||
public void setUsuariomodifId(Integer usuariomodifId) {
|
||||
this.usuariomodifId = usuariomodifId;
|
||||
}
|
||||
|
||||
public Integer getUsuariomodifId() {
|
||||
return usuariomodifId;
|
||||
}
|
||||
public String getSenha() {
|
||||
return senha;
|
||||
}
|
||||
|
||||
public void setUsuariomodifId(Integer usuariomodifId) {
|
||||
this.usuariomodifId = usuariomodifId;
|
||||
}
|
||||
public void setSenha(String senha) {
|
||||
this.senha = senha;
|
||||
}
|
||||
|
||||
public String getSenha() {
|
||||
return senha;
|
||||
}
|
||||
public List<UsuarioEmpresa> getUsuarioEmpresaList() {
|
||||
List<UsuarioEmpresa> tmp = new ArrayList<UsuarioEmpresa>();
|
||||
if (usuarioEmpresaList != null) {
|
||||
for (UsuarioEmpresa ce : this.usuarioEmpresaList) {
|
||||
if (ce.getActivo()) {
|
||||
tmp.add(ce);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setSenha(String senha) {
|
||||
this.senha = senha;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public void setUsuarioEmpresaList(List<UsuarioEmpresa> usuarioEmpresaList) {
|
||||
this.usuarioEmpresaList = usuarioEmpresaList;
|
||||
}
|
||||
|
||||
public List<UsuarioEmpresa> getUsuarioEmpresaList() {
|
||||
List<UsuarioEmpresa> tmp = new ArrayList<UsuarioEmpresa>();
|
||||
if (usuarioEmpresaList != null) {
|
||||
for (UsuarioEmpresa ce : this.usuarioEmpresaList) {
|
||||
if (ce.getActivo()) {
|
||||
tmp.add(ce);
|
||||
}
|
||||
}
|
||||
}
|
||||
public List<UsuarioPerfil> getUsuarioPerfilList() {
|
||||
List<UsuarioPerfil> tmp = new ArrayList<UsuarioPerfil>();
|
||||
if (usuarioPerfilList != null) {
|
||||
for (UsuarioPerfil cp : this.usuarioPerfilList) {
|
||||
if (cp.getActivo()) {
|
||||
tmp.add(cp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public void setUsuarioEmpresaList(List<UsuarioEmpresa> usuarioEmpresaList) {
|
||||
this.usuarioEmpresaList = usuarioEmpresaList;
|
||||
}
|
||||
public List<Empresa> getEmpresa() {
|
||||
List<Empresa> tmp = new ArrayList<Empresa>();
|
||||
if (usuarioEmpresaList != null) {
|
||||
for (UsuarioEmpresa cp : this.usuarioEmpresaList) {
|
||||
if ((cp.getActivo())) {
|
||||
tmp.add(cp.getEmpresa());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<UsuarioPerfil> getUsuarioPerfilList() {
|
||||
List<UsuarioPerfil> tmp = new ArrayList<UsuarioPerfil>();
|
||||
if (usuarioPerfilList != null) {
|
||||
for (UsuarioPerfil cp : this.usuarioPerfilList) {
|
||||
if (cp.getActivo()) {
|
||||
tmp.add(cp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
public void setUsuarioPerfilList(List<UsuarioPerfil> usuarioPerfilList) {
|
||||
this.usuarioPerfilList = usuarioPerfilList;
|
||||
}
|
||||
|
||||
public Empleado getEmpleado() {
|
||||
return empleado;
|
||||
}
|
||||
|
||||
public List<Empresa> getEmpresa() {
|
||||
List<Empresa> tmp = new ArrayList<Empresa>();
|
||||
if (usuarioEmpresaList != null) {
|
||||
for (UsuarioEmpresa cp : this.usuarioEmpresaList) {
|
||||
if ((cp.getActivo())) {
|
||||
tmp.add(cp.getEmpresa());
|
||||
}
|
||||
}
|
||||
}
|
||||
public void setEmpleado(Empleado empleado) {
|
||||
this.empleado = empleado;
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (usuarioId != null ? usuarioId.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
public void setUsuarioPerfilList(List<UsuarioPerfil> usuarioPerfilList) {
|
||||
this.usuarioPerfilList = usuarioPerfilList;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (!(object instanceof Usuario)) {
|
||||
return false;
|
||||
}
|
||||
Usuario other = (Usuario) object;
|
||||
if ((this.usuarioId == null && other.usuarioId != null) || (this.usuarioId != null && !this.usuarioId.equals(other.usuarioId))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Empleado getEmpleado() {
|
||||
return empleado;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "com.rjconsultores.ventaboletos.entidad.Usuario[usuarioId=" + usuarioId + "]";
|
||||
}
|
||||
|
||||
public void setEmpleado(Empleado empleado) {
|
||||
this.empleado = empleado;
|
||||
}
|
||||
public Collection<GrantedAuthority> getAuthorities() {
|
||||
return new ArrayList<GrantedAuthority>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (usuarioId != null ? usuarioId.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
public String getPassword() {
|
||||
return this.senha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (!(object instanceof Usuario)) {
|
||||
return false;
|
||||
}
|
||||
Usuario other = (Usuario) object;
|
||||
if ((this.usuarioId == null && other.usuarioId != null) || (this.usuarioId != null && !this.usuarioId.equals(other.usuarioId))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public String getUsername() {
|
||||
return this.nombusuario;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "com.rjconsultores.ventaboletos.entidad.Usuario[usuarioId=" + usuarioId + "]";
|
||||
}
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Collection<GrantedAuthority> getAuthorities() {
|
||||
return new ArrayList<GrantedAuthority>();
|
||||
}
|
||||
public boolean isAccountNonLocked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return this.senha;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.nombusuario;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
}
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isAccountNonLocked() {
|
||||
return true;
|
||||
}
|
||||
public Object getCredentials() {
|
||||
return new Object();
|
||||
}
|
||||
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return true;
|
||||
}
|
||||
public Object getDetails() {
|
||||
return new Object();
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
public Object getPrincipal() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Object getCredentials() {
|
||||
return new Object();
|
||||
}
|
||||
public boolean isAuthenticated() {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
public Object getDetails() {
|
||||
return new Object();
|
||||
}
|
||||
public void setAuthenticated(boolean bln) throws IllegalArgumentException {
|
||||
}
|
||||
|
||||
public Object getPrincipal() {
|
||||
return this;
|
||||
}
|
||||
public String getName() {
|
||||
return this.getNombusuario();
|
||||
}
|
||||
|
||||
public boolean isAuthenticated() {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
public String getDescCorreo() {
|
||||
return descCorreo;
|
||||
}
|
||||
|
||||
public void setAuthenticated(boolean bln) throws IllegalArgumentException {
|
||||
}
|
||||
public void setDescCorreo(String descCorreo) {
|
||||
this.descCorreo = descCorreo;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.getNombusuario();
|
||||
}
|
||||
|
||||
public String getDescCorreo() {
|
||||
return descCorreo;
|
||||
}
|
||||
|
||||
public void setDescCorreo(String descCorreo) {
|
||||
this.descCorreo = descCorreo;
|
||||
}
|
||||
public Boolean getIndCorteAutomatico() {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@ public interface UsuarioService {
|
|||
|
||||
public List<Usuario> obtenerTodos();
|
||||
|
||||
public Usuario obtenerID(Integer id);
|
||||
public Usuario obtenerID(Integer id);
|
||||
|
||||
public void borrar(Usuario entidad);
|
||||
public void borrar(Usuario entidad);
|
||||
|
||||
public List<Usuario> buscarPeloNome(String nome);
|
||||
|
||||
|
@ -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