fixes bug #6660
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@48353 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
9e580b12c7
commit
720f870262
|
@ -9,5 +9,7 @@ public class Constantes {
|
|||
|
||||
public static final Long MVO_CANCEL_CANCELACION = new Long(31);
|
||||
public static final Long MVO_CANCEL_DEVOLUCAO = new Long(32);
|
||||
|
||||
public static String CLAVE_EDITAR_COMISSAO = "COM.RJCONSULTORES.ADMINISTRACION.PUNTOVENTA.EDITARCOMISSAO";
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import javax.persistence.SequenceGenerator;
|
|||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.annotations.Fetch;
|
||||
|
@ -92,6 +93,10 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
|||
@Column(name = "FECCONTRASENA")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date fecContrasena;
|
||||
|
||||
/* Lista de permissoes do usuario */
|
||||
@Transient
|
||||
private List<String> listClavesPermisos;
|
||||
|
||||
public String getClaveUsuario() {
|
||||
return claveUsuario;
|
||||
|
@ -369,4 +374,17 @@ public class Usuario implements Serializable, Authentication, UserDetails {
|
|||
return sNome.toString();
|
||||
}
|
||||
|
||||
public List<String> getListClavesPermisos() {
|
||||
return listClavesPermisos;
|
||||
}
|
||||
|
||||
public void setListClavesPermisos(List<String> listClavesPermisos) {
|
||||
this.listClavesPermisos = listClavesPermisos;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public boolean isPermisoClave(String clave) {
|
||||
return listClavesPermisos != null && listClavesPermisos.contains(clave);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,17 +4,29 @@
|
|||
*/
|
||||
package com.rjconsultores.ventaboletos.utilerias;
|
||||
|
||||
import com.rjconsultores.ventaboletos.entidad.Usuario;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.context.ContextLoaderListener;
|
||||
|
||||
import com.rjconsultores.ventaboletos.dao.UsuarioPerfilDAO;
|
||||
import com.rjconsultores.ventaboletos.entidad.PerfilFuncion;
|
||||
import com.rjconsultores.ventaboletos.entidad.Usuario;
|
||||
import com.rjconsultores.ventaboletos.entidad.UsuarioPerfil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rodrigo
|
||||
*/
|
||||
public class UsuarioLogado {
|
||||
|
||||
|
||||
private static Logger log = Logger.getLogger(UsuarioLogado.class);
|
||||
|
||||
public static Usuario getUsuarioLogado() {
|
||||
Usuario usuario = null;
|
||||
SecurityContext sc = SecurityContextHolder.getContext();
|
||||
|
@ -23,6 +35,10 @@ public class UsuarioLogado {
|
|||
|
||||
if ((authentication != null) && (authentication.getPrincipal() instanceof Usuario)) {
|
||||
usuario = (Usuario) authentication.getPrincipal();
|
||||
|
||||
if(usuario.getListClavesPermisos() == null) {
|
||||
cargaPermisoClave(usuario);
|
||||
}
|
||||
} else {
|
||||
usuario = null;
|
||||
}
|
||||
|
@ -30,4 +46,30 @@ public class UsuarioLogado {
|
|||
|
||||
return usuario;
|
||||
}
|
||||
|
||||
private static void cargaPermisoClave(Usuario usuario) {
|
||||
try {
|
||||
if(usuario != null && usuario.getListClavesPermisos() == null || usuario.getListClavesPermisos().isEmpty()) {
|
||||
ApplicationContext context = ContextLoaderListener.getCurrentWebApplicationContext();
|
||||
|
||||
if(context != null) {
|
||||
|
||||
UsuarioPerfilDAO usuarioPerfilDAO = context.getBean(UsuarioPerfilDAO.class);
|
||||
if(usuarioPerfilDAO != null) {
|
||||
usuario.setListClavesPermisos(new ArrayList<String>());
|
||||
List<UsuarioPerfil> listUsuarioPerfil = usuarioPerfilDAO.obtenerPorUsuario(usuario);
|
||||
for (UsuarioPerfil up : listUsuarioPerfil) {
|
||||
List<PerfilFuncion> listPerfilFuncion = up.getPerfil().getPerfilFuncionList();
|
||||
for (PerfilFuncion pf : listPerfilFuncion) {
|
||||
usuario.getListClavesPermisos().add(pf.getFuncionSistema().getDescruta());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue