public ActionResult CargaInicialAplicacion() { ActionResult actionResult = null; ManejadorLogEventos manejadorLogEventos = new ManejadorLogEventos(); RequestConsultaParametroNegocio requestParametroNegocio = new RequestConsultaParametroNegocio(); ResponseCargaInicial response = new ResponseCargaInicial(); ResponseUsuarioMscDTO usuario = HelperSeguridad.ObtenerSessionUsuarioMsc(); ListaTipoCambioViewModel request = new ListaTipoCambioViewModel(); ResponseListarTipoCambio responseListarTipoCambio = new ResponseListarTipoCambio(); try { request.CodigoMoneda = ConfigurationManager.AppSettings["strDefaultMonedaTipoCambio"]; request.Fecha = DateTime.Now; responseListarTipoCambio = new MaestrosAgente().ListarTipoCambio(GR.Frameworks.Helper.MiMapper <ListaTipoCambioViewModel, RequestBusquedaTipoCambio>(request)); response.TipoCambio = responseListarTipoCambio; response.PermisosBotones = usuario.Usuario.PermisosBotones; response.Resultado = new Result { Satisfactorio = true }; actionResult = Json(JsonConvert.SerializeObject(response), JsonRequestBehavior.AllowGet); } catch (Exception ex) { response.Resultado = new Result(); HelperCtrl.GrabarLog(ex, "", PoliticaExcepcion.Web); } return(actionResult); }
public static string ObtenerJsonMenu() { try { var objResponse = new ResponseMenuPrincipalDTO(); //obtengo los datos necesarios ResponseUsuarioMscDTO resp = (ResponseUsuarioMscDTO)System.Web.HttpContext.Current.Session["usuario"]; if (resp == null) { throw new Exception("La sesión a expirado"); } ResponseInfoUsuarioDTO resp2 = (new SeguridadProxyRest()).TraerInformacionUsuario(new RequestInfoUsuario() { IdPerfilUsuario = resp.Usuario.IdPerfilUsuario }); //hago la tabla hash var tablaHash = new List <string>(); HacerTablaHash(resp2.OpcionesUI, ref tablaHash); resp2.TablaHash = tablaHash; objResponse.MenuPrincipal = Newtonsoft.Json.JsonConvert.SerializeObject(resp2.OpcionesUI); objResponse.NombreUsuario = resp.Usuario.NombrePersona + " (" + resp.Usuario.RolDescripcion + ")"; objResponse.EsExterno = resp.Usuario.esExterno; return(Newtonsoft.Json.JsonConvert.SerializeObject(objResponse)); } catch (Exception ex) { (new ManejadorLog()).RegistrarEvento(string.Format("{0}{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace)); return(null); } }
public override ActionResult Login(string usuario, string password) { var actionresult = base.Login(usuario, password); ResponseUsuarioMscDTO objUsuarioDto = (ResponseUsuarioMscDTO)GR.Frameworks.Helper.GetSession("usuario"); if (objUsuarioDto != null) { ResponseUsuarioAgmaDTO objUsarioAgmaDto = new ResponseUsuarioAgmaDTO(); objUsarioAgmaDto.Usuario = GR.Frameworks.Helper.MiMapper <UsuarioDTO, UsuarioAgmaDTO>(objUsuarioDto.Usuario); objUsarioAgmaDto.Usuario.ListaCodigosLineas = objUsuarioDto.Usuario.Recursos.FindAll(x => x.Descripcion.Contains("Lineas Tramarsa")) .Select(x => x.Codigo) .ToList(); objUsarioAgmaDto.Usuario.ListaCodigosPuertos = objUsuarioDto.Usuario.Recursos.FindAll(x => x.Descripcion.Contains("Puertos Internacionales")) .Select(x => x.Codigo) .ToList(); objUsarioAgmaDto.Usuario.ListaCodigosSucursales = objUsuarioDto.Usuario.Recursos.FindAll(x => x.Descripcion.Contains("Sucursales Tramarsa")) .Select(x => x.Codigo) .ToList(); objUsarioAgmaDto.Usuario.CodigoUsuario = objUsuarioDto.Usuario.CodigoUsuario; objUsarioAgmaDto.Usuario.Menu = objUsuarioDto.Usuario.Menu; objUsarioAgmaDto.Usuario.Email = objUsuarioDto.Usuario.Email; objUsarioAgmaDto.Usuario.NombrePersona = objUsuarioDto.Usuario.NombrePersona; objUsarioAgmaDto.Usuario.RolDescripcion = objUsuarioDto.Usuario.RolDescripcion; GR.Frameworks.Helper.SetSession("usuarioCliente", objUsarioAgmaDto); } return(actionresult); }
public virtual ActionResult ObtenerMenus() { bool success = false; List <ResponseOpcionUI> menu = new List <ResponseOpcionUI>(); string nombreUsuario = ""; string rolUsuario = ""; string email = ""; string codigoUsuario = ""; if (Session["usuario"] != null) { ResponseUsuarioMscDTO data = (ResponseUsuarioMscDTO)Session["usuario"]; menu = data.Usuario.Menu; nombreUsuario = data.Usuario.NombrePersona; rolUsuario = data.Usuario.RolDescripcion; email = data.Usuario.Email; codigoUsuario = data.Usuario.CodigoUsuario; success = true; } return(Json(new MenuDTO { Satisfactorio = success, MenuIzquierdo = menu, NombreUsuario = nombreUsuario, RolUsuario = rolUsuario, Email = email, CodigoUsuario = codigoUsuario }, JsonRequestBehavior.AllowGet)); }
public static bool VerificarPrivilegio(string codigo) { ResponseUsuarioMscDTO usuario = HelperSeguridad.ObtenerSessionUsuarioMsc(); return(usuario.Usuario.Permisos.Contains(codigo)); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { bool autenticado = false; var routeDataTemp = httpContext.Request.RequestContext.RouteData; string controllerTemp = Convert.ToString(routeDataTemp.Values["controller"]); string actionTemp = Convert.ToString(routeDataTemp.Values["action"]); //string UsuarioPorDefecto = System.Configuration.ConfigurationManager.AppSettings["UsuarioPorDefecto"].ToString(); if (httpContext.Response.StatusCode == 440) { return(false); } ManejadorLog manejadorLog = new ManejadorLog(); if (ValidarAutorizacion) { if (httpContext.User.Identity.IsAuthenticated) //|| UsuarioPorDefecto.Length > 0) { //COMENTADO POR AHORA //CuentaController cuentaController = new CuentaController(); string usuarioLogueado = httpContext.User.Identity.Name; manejadorLog.GrabarLog("Usuario Autenticado:" + usuarioLogueado); ResponseUsuarioMscDTO usuario = HelperSeguridad.GetUsuario(); //Primera vez que se logea el usuario o session expiró if (usuario == null) { manejadorLog.GrabarLog("Usuario es null"); //COMENTADO POR AHORA //autenticado = cuentaController.ValidarAutenticacion(usuarioLogueado, httpContext); //autenticado = true; //if (autenticado) //{ // manejadorLog.GrabarLog("Usuario es Autenticado"); // if (ValidarAutorizacion) // { // string opcionValidar = Opcion; // if (String.IsNullOrEmpty(opcionValidar)) // { // var routeData = httpContext.Request.RequestContext.RouteData; // string controller = Convert.ToString(routeData.Values["controller"]); // string action = Convert.ToString(routeData.Values["action"]); // opcionValidar = action; // } // //COMENTADO POR AHORA // autenticado = HelperSeguridad.GetUsuario().Usuario.Permisos.Contains(opcionValidar);//cuentaController.ValidarAutorizacion(opcionValidar); // } //} } else { manejadorLog.GrabarLog("Usuario no es null"); manejadorLog.GrabarLog("Usuario Sesion: " + usuario.Usuario.CodigoUsuario); if (usuario.Usuario.CodigoUsuario.ToUpper() != usuarioLogueado.ToUpper()) { manejadorLog.GrabarLog("Usuario Sesion: " + usuario.Usuario.CodigoUsuario); manejadorLog.GrabarLog("Usuario Logueado: " + usuarioLogueado.ToUpper()); //COMENTADO POR AHORA //autenticado = cuentaController.ValidarAutenticacion(usuarioLogueado, httpContext); } else { if (ValidarAutorizacion) { string opcionValidar = Opcion; if (String.IsNullOrEmpty(opcionValidar)) { var routeData = httpContext.Request.RequestContext.RouteData; string controller = Convert.ToString(routeData.Values["controller"]); string action = Convert.ToString(routeData.Values["action"]); opcionValidar = action; } //COMENTADO POR AHORA autenticado = HelperSeguridad.GetUsuario().Usuario.Permisos.Contains(opcionValidar);//autenticado = cuentaController.ValidarAutorizacion(opcionValidar); } else { autenticado = true; } } } } } else { autenticado = true; } return(autenticado); }
public override void OnAuthorization(AuthorizationContext filterContext) { //ManejadorLog log = new ManejadorLog(); try { //log.RegistrarEvento("OnAuthorization"); //log.RegistrarEvento(string.Format("parametro = {0}", Newtonsoft.Json.JsonConvert.SerializeObject(filterContext))); var section = (Hashtable)ConfigurationManager.GetSection("PaginasAnonimas"); ResponseUsuarioMscDTO usuario = (ResponseUsuarioMscDTO)(filterContext.RequestContext.HttpContext.Session["usuario"]); var routeDataTemp = filterContext.RequestContext.RouteData; String UrlAcceso = ""; if (routeDataTemp.Values.Values.ToArray()[1] == "ModuloSeguridadGR" || HelperSeguridad.PerteneceAsembliesScriptor(routeDataTemp.Values.Values.ToArray()[1]) || HelperSeguridad.PerteneceCadena(routeDataTemp.Values.Values.ToArray()[1], WebConfigReader.ModulosRegistrar)) { UrlAcceso = "/" + routeDataTemp.Values.Values.ToArray()[1] + "/" + routeDataTemp.Values.Values.ToArray()[0]; } else { UrlAcceso = "/" + routeDataTemp.Values.Values.ToArray()[0] + "/" + routeDataTemp.Values.Values.ToArray()[1]; } // log.RegistrarEvento(string.Format("Urlacceso = {0}", UrlAcceso)); Dictionary <string, string> dicSection = section.Cast <DictionaryEntry>().ToDictionary(d => (string)d.Key, d => (string)d.Value); var encuentra = (from xx in dicSection where xx.Value.ToUpper() == UrlAcceso.ToUpper() || xx.Value.ToUpper() + "/" == UrlAcceso.ToUpper() select xx).Count(); ////log.RegistrarEvento(string.Format("dicSection = {0}", Newtonsoft.Json.JsonConvert.SerializeObject(dicSection))); //log.RegistrarEvento(string.Format("encuentra = {0}", encuentra)); ////log.RegistrarEvento("paths 1=" + routeDataTemp.Values.Values.ToArray()[0] + "\n" + // "paths 2=" + routeDataTemp.Values.Values.ToArray()[1] + "\n" + // //"paths 3=" + routeDataTemp.Values.Values.ToArray()[2] + "\n" + // "encuentra" + encuentra.ToString()); ////log.RegistrarEvento("WebSiteChannel=" + Viatecla.Factory.Scriptor.ModularSite.Models.Common.WebSiteChannel.Name); //if (Viatecla.Factory.Scriptor.ModularSite.Models.Common.WebSiteChannel.Name != WebConfigReader.WebSiteChannelName) // return; //Prueba //encuentra = 1; // Prueba if (encuentra == 0) { //if (filterContext.HttpContext.User != null) if (usuario != null) { base.OnAuthorization(filterContext); } else { filterContext.RequestContext.HttpContext.Response.StatusCode = 440; base.OnAuthorization(filterContext); } } } catch (Exception ex) { (new ManejadorLog()).RegistrarEvento(MethodBase.GetCurrentMethod().Name, ex.Message, ex.StackTrace); // log.RegistrarEvento(ex.StackTrace); } }
protected override bool AuthorizeCore(HttpContextBase httpContext) { //Prueba // return true; //Pruena // ManejadorLog log = new ManejadorLog(); // log.RegistrarEvento(string.Format("metodo = {0}", MethodBase.GetCurrentMethod().Name)); try { if (httpContext.Response.StatusCode == 440) { return(false); } bool autenticado = false; ResponseUsuarioMscDTO usuario = HelperSeguridad.ObtenerSessionUsuarioMsc(); var routeDataTemp = httpContext.Request.RequestContext.RouteData; string controllerTemp = Convert.ToString(routeDataTemp.Values["controller"]); string actionTemp = Convert.ToString(routeDataTemp.Values["action"]); // log.RegistrarEvento(httpContext.User.Identity.IsAuthenticated.ToString()); if (usuario != null) //if (httpContext.User.Identity.IsAuthenticated) { // log.RegistrarEvento("entro if session"); String UrlAcceso = ""; if (routeDataTemp.Values.Values.ToArray()[1] == "ModuloSeguridad" || HelperSeguridad.PerteneceAsembliesScriptor(routeDataTemp.Values.Values.ToArray()[1]) || HelperSeguridad.PerteneceCadena(routeDataTemp.Values.Values.ToArray()[1], WebConfigReader.ModulosRegistrar)) { UrlAcceso = "/" + routeDataTemp.Values.Values.ToArray()[1] + "/" + routeDataTemp.Values.Values.ToArray()[0]; } else { UrlAcceso = "/" + routeDataTemp.Values.Values.ToArray()[0] + "/" + routeDataTemp.Values.Values.ToArray()[1]; } //log.RegistrarEvento("UrlAcceso=" + UrlAcceso); var encontrar = (from xx in usuario.Usuario.Permisos where xx.ToUpper() == UrlAcceso.ToUpper() || xx.ToUpper() + "/" == UrlAcceso.ToUpper() || "/ES-PE" + xx.ToUpper() == UrlAcceso.ToUpper() || "ES-PE" + xx.ToUpper() == UrlAcceso.ToUpper() || "ES-PE/" + xx.ToUpper() + "/" == UrlAcceso.ToUpper() || "/ES-PE/" + xx.ToUpper() + "/" == UrlAcceso.ToUpper() || "/ES-PE" + xx.ToUpper() == UrlAcceso.ToUpper() + "/" || "ES-PE" + xx.ToUpper() == UrlAcceso.ToUpper() + "/" || "/" + xx.ToUpper() == UrlAcceso.ToUpper() + "/" || xx.ToUpper() == UrlAcceso.ToUpper() + "/" select xx).Count(); //var encontrar = (from xx in usuario.Usuario.Permisos where xx.ToUpper() == UrlAcceso.ToUpper() || xx.ToUpper() + "/" == UrlAcceso.ToUpper() select xx).Count(); // log.RegistrarEvento("encontrar="+encontrar.ToString()); //log.RegistrarEvento("salio autorizar"); //Prueba encontrar = 1; //Prueba return(encontrar > 0); } else { //log.RegistrarEvento("salio autorizar"); return(false); } } catch (Exception ex) { (new ManejadorLog()).RegistrarEvento(MethodBase.GetCurrentMethod().Name, ex.Message, ex.StackTrace); //log.RegistrarEvento(ex.Message); //log.RegistrarEvento(ex.StackTrace); return(false); } return(true); }
public virtual ActionResult Login(string usuario, string password) { SeguridadBL seguridadBL = new SeguridadBL(); var hashPermisosBotones = new List <string>(); try { //ContentResult loginResponse = (ContentResult)(new SeguridadController()).Login(usuario, password); //GR.Scriptor.Membership.Entidades.ResponseLoginUsuario responseLoginUsuario = Newtonsoft.Json.JsonConvert.DeserializeObject<GR.Scriptor.Membership.Entidades.ResponseLoginUsuario>(loginResponse.Content); //OBTENEMOS EL LOGIN ResponseLoginUsuario objLogin = seguridadBL.Login(new RequestLogin { Clave = password, CodigoUsuario = usuario }); if (objLogin == null) { throw new Exception("Servicio Login no disponible."); } if (objLogin.ResultadoLogin == false) { throw new Exception(objLogin.MensajeError); } (new ManejadorLog()).RegistrarEvento(MethodBase.GetCurrentMethod().Name, Newtonsoft.Json.JsonConvert.SerializeObject(objLogin)); //OBTENEMOS LOS DATOS DE SEGURIDAD DEL USUARIO ResponseInfoUsuarioDTO objInfo = seguridadBL.GetInformacionUsuario(objLogin.IdPerfilUsuario); (new ManejadorLog()).RegistrarEvento(MethodBase.GetCurrentMethod().Name, Newtonsoft.Json.JsonConvert.SerializeObject(objInfo)); objInfo.IdPerfilUsuario = objLogin.IdPerfilUsuario; var tablaHash = new List <string>(); List <ResponseOpcionUI> menuOrdenado = new List <ResponseOpcionUI>(); seguridadBL.HacerTablaHash(objInfo.OpcionesUI, ref tablaHash, ref menuOrdenado, ref hashPermisosBotones); Session["usuario"] = new ResponseUsuarioMscDTO() { Usuario = new UsuarioDTO() { IdUsuario = objInfo.IdUsuario, IdPerfilUsuario = objLogin.IdPerfilUsuario, CodigoCargo = objInfo.CodigoCargo, CodigoUsuario = objInfo.CodigoUsuario, Email = objInfo.Correo, NombrePersona = objInfo.NombresCompletos.Split('(')[0], NombreUsuario = objInfo.CodigoUsuario.Split('\\')[1], Menu = menuOrdenado, Recursos = objInfo.RecursosAdicionales, Sedes = objInfo.Sedes, //TipoReclamo = objInfo.TipoReclamo, //Permisos = permisos, Permisos = tablaHash, RolDescripcion = objInfo.Roles[0].Descripcion, esExterno = objInfo.TipoUsuario == "E" ? true : false, TipoUsuario = objInfo.TipoUsuario, Alias = objInfo.Alias, PermisosBotones = hashPermisosBotones, Roles = objInfo.Roles }, }; FormsAuthentication.SetAuthCookie(objInfo.CodigoUsuario, false); return(Json(new Result { Satisfactorio = true }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { (new ManejadorLog()).RegistrarEvento(MethodBase.GetCurrentMethod().Name, ex.Message, ex.StackTrace); return(Json(new Result { Satisfactorio = false, Mensaje = ex.Message, Data = hashPermisosBotones }, JsonRequestBehavior.AllowGet)); } }