Пример #1
0
        public override Dictionary <string, string> GetUrls()
        {
            _user    = GetCustomPrincipal();
            _service = new DocumentosUsuarioService(MarfilEntities.ConnectToSqlServer(_user.BaseDatos));
            // Get URLs and display names for all reports available in the storage.
            var result = new Dictionary <string, string>();

            try
            {
                var reportId = HttpUtility.ParseQueryString(HttpContext.Current.Request.UrlReferrer.PathAndQuery).GetValues("reportId")[0];
                TipoDocumentoImpresion TipoDocumentoImpresion;
                Guid   usuario;
                string name;
                DocumentosUsuarioService.GetFromCustomId(reportId, out TipoDocumentoImpresion, out usuario, out name);
                var items = _service.GetDocumentos(TipoDocumentoImpresion, _user.Id);
                foreach (var item in items)
                {
                    result.Add(item.CustomId, item.Nombre);
                }
            }
            catch (Exception ex)
            {
                string errores = ex.Message;
            }


            return(result);
        }
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            bool skipAuthorization = filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true) ||
                                     filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true);

            if (!skipAuthorization)
            {
                if (filterContext.HttpContext.User.Identity.IsAuthenticated)
                {
                    if (this.Roles == string.Empty)
                    {
                        return;
                    }

                    ICustomPrincipal principalUser = HttpContext.Current.User as ICustomPrincipal;
                    if (principalUser == null)
                    {
                        base.OnAuthorization(filterContext);
                    }

                    if (!principalUser.Has_Perm(filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, filterContext.ActionDescriptor.ActionName, this.Roles))
                    {
                        filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
                    }
                }
                else
                {
                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Usuario", action = "Login" }));
                }
            }
            base.OnAuthorization(filterContext);
        }
Пример #3
0
        private Initiator CreateInitiator(ICustomPrincipal principal)
        {
            Initiator initiator = new Initiator();

            if (principal != null && principal.Identity != null)
            {
                initiator.Account = new Account()
                {
                    Name   = principal.Identity.Name,
                    Domain = principal.Identity.Domain
                };
                initiator.Assertions = new List <object>()
                {
                    new
                    {
                        principal.Identity.Name,
                        principal.Identity.Domain,
                        principal.Identity.Username,
                        principal.IpAddress
                    }
                };
            }

            return(initiator);
        }
Пример #4
0
        /// <inheritdoc/>
        public async Task AddDefaultEventAsync(ICustomPrincipal principal, object data, SubEventType subEventType, OutcomeType outcomeType = OutcomeType.Success)
        {
            try
            {
                Ensure.ArgumentNotNull(principal, nameof(principal));

                if (!principal.IsInRole(RoleType.Service))
                {
                    XDASv2Event xdasEvent = CreateXDASEvent(principal, subEventType, outcomeType);

                    Target target = new Target()
                    {
                        Entity = CreateTargetEntity()
                    };

                    target.Data = data;

                    xdasEvent.Target = target;

                    var command = new CreateAuditEventCommand()
                    {
                        Event = xdasEvent
                    };

                    await mediator.Send(command);
                }
            }
            catch (Exception e)
            {
                logger.LogError(e, e.Message);
            }
        }
Пример #5
0
        public ICustomPrincipal GetAuthenticatedUser()
        {
            if (_signedInUser != null || _isAuthenticated)
            {
                return(_signedInUser);
            }

            var httpContext = HttpContext.Current;

            if (httpContext == null || !httpContext.Request.IsAuthenticated || !(httpContext.User.Identity is FormsIdentity))
            {
                return(null);
            }

            var formsIdentity = (FormsIdentity)httpContext.User.Identity;
            var userData      = formsIdentity.Ticket.UserData;
            int userId;

            if (!int.TryParse(userData, out userId))
            {
                LogHelper.WriteFatal("User id not a parsable integer");
                return(null);
            }

            _isAuthenticated = true;
            return(_signedInUser = null);
        }
        public static ClasseModeloDAO <T> Create(ICustomPrincipal User)
        {
            if (User.IdEmpresa == 0)
            {
                throw new Exception("Estabelecimento sem empresa. " + Environment.StackTrace);
            }

            ClasseModeloDAO <T> inst = null;

            //if (typeof(T) is IEstabelecimento)
            if (typeof(T).IsSubclassOf(TypeClasseModelEstab))
            {
                inst = new ClasseModeloDAO <T>()
                {
                    Empresa = User.IdEmpresa, Estabelecimento = User.IdEstab
                };
                inst.FiltroEstab = Expression.Eq("Estabelecimento.Id", inst.Estabelecimento);
            }
            else
            {
                inst = new ClasseModeloDAO <T>()
                {
                    Empresa = User.IdEmpresa
                };
            }

            inst.FiltroEmpresa = Expression.Eq("Empresa.Id", inst.Empresa);

            return(inst);
        }
        public static Estabelecimento EstabelecimentoLogado(ICustomPrincipal user)
        {
            ClasseModeloDAO <Estabelecimento> dao = ClasseModeloDAO <Estabelecimento> .Create(user);

            Estabelecimento es = dao.FindFirst();

            dao.Dispose();
            return(es);
        }
Пример #8
0
 private XDASv2Event CreateXDASEvent(ICustomPrincipal principal, SubEventType subEventType, OutcomeType outcomeType)
 {
     return(new XDASv2Event()
     {
         Initiator = CreateInitiator(principal),
         Observer = CreateObserver(),
         Action = CreateAction(subEventType, outcomeType)
     });
 }
Пример #9
0
        public ContextService()
        {
            _principal = HttpContext.Current.User as ICustomPrincipal;
            _servidor  = HttpContext.Current.Server;

            if (_principal == null)
            {
                _principal = new CustomPrincipal("");
            }
        }
        public static CustomClasseModelo CustomPrincipalLogado(ICustomPrincipal usr)
        {
            CustomClasseModelo user = new CustomClasseModelo()
            {
                IdEstab   = usr.IdEstab,
                IdEmpresa = usr.IdEmpresa
            };

            return(user);
        }
Пример #11
0
 public void Logout(ICustomPrincipal customPrincipal)
 {
     using (var db = MarfilEntities.ConnectToSqlServer(customPrincipal.BaseDatos))
     {
         var usuarioActivo = db.Usuariosactivos.SingleOrDefault(f => f.idconexion == customPrincipal.Idconexion);
         if (usuarioActivo != null)
         {
             db.Usuariosactivos.Remove(usuarioActivo);
             db.SaveChanges();
         }
     }
 }
Пример #12
0
        public override byte[] GetData(string url)
        {
            _user    = GetCustomPrincipal();
            _service = new DocumentosUsuarioService(MarfilEntities.ConnectToSqlServer(_user.BaseDatos));
            // Get the report data from the storage.
            TipoDocumentoImpresion TipoDocumentoImpresion;
            Guid   usuario;
            string name;

            DocumentosUsuarioService.GetFromCustomId(url, out TipoDocumentoImpresion, out usuario, out name);
            var obj = _service.GetDocumento(TipoDocumentoImpresion, usuario, name);

            return(obj.Datos);
        }
Пример #13
0
        public void AddedDetails(ICustomPrincipal principal)
        {
            var info = new CustomPrincipalInfo
            {
                Email      = principal.Email,
                UserId     = principal.UserId,
                Roles      = principal.Roles,
                HasDetails = true,
                IsVerified = principal.IsVerified
            };
            var cookie = info.CreateAuthenticationCookie(DateTime.Now, Timeout, true);

            HttpContext.Current.Response.Cookies.Add(cookie);
            HttpContext.Current.Session["IsLoggedIn"] = true;
        }
        public static bool Enabled(FeatureSwitches featureSwitchToCheck, ICustomPrincipal customPrincipal)
        {
            if (IsOverrideFeatureSwitchSettingsUser(customPrincipal)) 
                return true;

            if (ConfigurationManager.AppSettings[featureSwitchToCheck.ToString()] == null)
                return true;

            if (ConfigurationManager.AppSettings[featureSwitchToCheck.ToString()] == "true")
                return true;

            if (ConfigurationManager.AppSettings[featureSwitchToCheck.ToString()] == "false")
                return false;

            return false;
        }
Пример #15
0
        public override bool CanSetData(string url)
        {
            if (!_reportIdRegex.IsMatch(url))
            {
                return(false);
            }

            _user    = GetCustomPrincipal();
            _service = new DocumentosUsuarioService(MarfilEntities.ConnectToSqlServer(_user.BaseDatos));
            // Check if the URL is available in the report storage.
            TipoDocumentoImpresion tipoDocumentoImpresion;
            Guid   usuario;
            string name;

            DocumentosUsuarioService.GetFromCustomId(url, out tipoDocumentoImpresion, out usuario, out name);
            return(_service.ExisteDocumento(tipoDocumentoImpresion, usuario, name));
        }
        public static Usuario UsuarioLogado(ICustomPrincipal user)
        {
            Usuario usuario = null;

            try
            {
                ClasseModeloDAO <Usuario> daoUsuario = ClasseModeloDAO <Usuario> .Create(user);

                usuario = daoUsuario.FindByPrimaryKey(user.IdUsuario);
                daoUsuario.Dispose();
            }
            catch (Exception e)
            {
                LogErros.GravaLog(e, MethodBase.GetCurrentMethod().Name);
            }

            return(usuario);
        }
Пример #17
0
        public void SignIn(ClientUserData clientUserData, bool createPersistentCookie)
        {
            var    now      = DateTime.Now.ToLocalTime();
            string userData = JsonConvert.SerializeObject(clientUserData);

            var ticket = new FormsAuthenticationTicket(
                1 /*version*/,
                clientUserData.UserId.ToString(),
                now,
                now.Add(ExpirationTimeSpan),
                createPersistentCookie,
                userData,
                FormsAuthentication.FormsCookiePath);

            var encryptedTicket = FormsAuthentication.Encrypt(ticket);

            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
            {
                HttpOnly = true,
                Secure   = FormsAuthentication.RequireSSL,
                Path     = FormsAuthentication.FormsCookiePath
            };

            var httpContext = HttpContext.Current;

            if (FormsAuthentication.CookieDomain != null)
            {
                cookie.Domain = FormsAuthentication.CookieDomain;
            }

            if (createPersistentCookie)
            {
                cookie.Expires = ticket.Expiration;
            }

            httpContext.Response.Cookies.Add(cookie);

            _isAuthenticated = true;
            ICustomPrincipal user = new ICustomPrincipal(clientUserData);

            _signedInUser    = user;
            httpContext.User = user;
        }
Пример #18
0
        public override void SetData(XtraReport report, string url)
        {
            if (!_reportIdRegex.IsMatch(url))
            {
                return;
            }

            _user    = GetCustomPrincipal();
            _service = new DocumentosUsuarioService(MarfilEntities.ConnectToSqlServer(_user.BaseDatos));
            // Write a report to the storage under the specified URL.
            using (var stream = new MemoryStream())
            {
                TipoDocumentoImpresion TipoDocumentoImpresion;
                Guid   usuario;
                string name;

                DocumentosUsuarioService.GetFromCustomId(url, out TipoDocumentoImpresion, out usuario, out name);
                report.Name        = url;
                report.DisplayName = name;
                report.SaveLayout(stream);
                //_service.SetPreferencia(TipoDocumentoImpresion, usuario, name, stream.ToArray());
            }
        }
        public User GetCurrentUser()
        {
            if (HttpContext.Current == null)
            {
                throw new ApplicationException("The HTTP context current is null!");
            }

            ICustomPrincipal principal = HttpContext.Current.User as ICustomPrincipal;

            if (principal == null)
            {
                throw new ApplicationException("The HTTP current user principal cannot be used!");
            }

            User user = principal.User;

            if (user == null)
            {
                throw new ApplicationException("The user does not exist in the principal!");
            }

            return(user);
        }
Пример #20
0
        public override string SetNewData(XtraReport report, string defaultUrl)
        {
            if (_reportIdRegex.IsMatch(defaultUrl))
            {
                throw new Exception("No se pude guardar el nuevo report");
            }

            _user    = GetCustomPrincipal();
            _service = new DocumentosUsuarioService(MarfilEntities.ConnectToSqlServer(_user.BaseDatos));
            using (var stream = new MemoryStream())
            {
                var objTag = report.Name;
                var vector = objTag.Split(';');
                var TipoDocumentoImpresion = (TipoDocumentoImpresion)Enum.Parse(typeof(TipoDocumentoImpresion), vector[1]);
                var usuario  = new Guid(vector[0]);
                var idReport = DocumentosUsuarioService.CreateCustomId(TipoDocumentoImpresion, usuario, defaultUrl);
                report.Name        = idReport;
                report.DisplayName = defaultUrl;
                report.SaveLayout(stream);
                //_service.SetPreferencia(TipoDocumentoImpresion, usuario, defaultUrl, stream.ToArray());
                return(idReport);
            }
        }
Пример #21
0
        private void SetCustomPrincipal(ICustomPrincipal principal)
        {
            IAuthenticationService authenticationService = IOCContainer.Instance.Resolve <IAuthenticationService>();
            LTCUserData            clientUserData        = new LTCUserData()
            {
                UserId          = principal.UserId,
                LoginName       = principal.LoginName,
                EmpNo           = principal.EmpNo,
                EmpName         = principal.EmpName,
                EmpGroup        = principal.EmpGroup,
                JobTitle        = principal.JobTitle,
                JobType         = principal.JobType,
                OrgId           = principal.OrgId,
                GovId           = principal.GovId,
                RoleId          = principal.RoleId,
                RoleType        = principal.RoleType,
                SysType         = principal.SysType,
                CurrentLoginSys = principal.CurrentLoginSys,
                LTCRoleType     = principal.LTCRoleType,
                DCRoleType      = principal.DCRoleType
            };

            authenticationService.SignIn(clientUserData, true);
        }
 public IEmployeeViewModelFactory WithCurrentUser(ICustomPrincipal currentUser)
 {
     _currentUser = currentUser;
     return this;
 }
Пример #23
0
 public void SetAuthenticatedUserForRequest(ICustomPrincipal user)
 {
     _signedInUser    = user;
     _isAuthenticated = true;
 }
Пример #24
0
 public void SignOut()
 {
     _signedInUser    = null;
     _isAuthenticated = false;
     FormsAuthentication.SignOut();
 }
 private static bool IsEmailSpecifiedInWebConfig(ICustomPrincipal customPrincipal)
 {
     var emailsWithOverrideFeatureSwitchSettings = ConfigurationManager.AppSettings[FeatureSwitchOverrideEmailsKey];
     return !string.IsNullOrEmpty(emailsWithOverrideFeatureSwitchSettings) &&
            emailsWithOverrideFeatureSwitchSettings.Contains(customPrincipal.Email.ToLower());
 }
Пример #26
0
 public MockupContextService()
 {
     _principal = HttpContext.Current.User as ICustomPrincipal;
 }
 public virtual bool FeatureSwitchEnabled(FeatureSwitches featureSwitch, ICustomPrincipal customPrincipal)
 {
     return FeatureSwitchChecker.Enabled(featureSwitch, customPrincipal);
 }
 public virtual bool SalvaEmOutroModelo(ref int idRetorno, Estabelecimento estabelecimento, ICustomPrincipal user)
 {
     return(false);
 }
        public override bool SalvaEmOutroModelo(ref int idRetorno, Estabelecimento estabelecimento, ICustomPrincipal user)
        {
            if (this.Id.HasValue)
            {
                Update(estabelecimento.Empresa);
            }
            else
            {
                Create(estabelecimento.Empresa);
            }

            return(true);
        }
 private static bool IsOverrideFeatureSwitchSettingsUser(ICustomPrincipal customPrincipal)
 {
     return HasUserGotEmailAddress(customPrincipal) && IsEmailSpecifiedInWebConfig(customPrincipal);
 }
 private static bool HasUserGotEmailAddress(ICustomPrincipal customPrincipal)
 {
     return customPrincipal.Email.Length > 0;
 }
Пример #32
0
 public ContextLogin(ICustomPrincipal context)
 {
 }
Пример #33
0
 public void Logout(ICustomPrincipal customPrincipal)
 {
     throw new NotImplementedException();
 }
Пример #34
0
 public ContextConfiguracion()
 {
     _principal = HttpContext.Current.User as ICustomPrincipal;
 }