Exemplo n.º 1
0
 public WorkflowToolbarVm(ISecurityUser securityUser, int objectID, string objectType)
 {
     this.CurrentUser = securityUser;
     this.ObjectType = objectType;
     this.ObjectID = objectID;
     this.Stages = new List<StageVM>();
 }
Exemplo n.º 2
0
        /***************************** Context **************************/

        /// <summary>
        /// Creates a new instance of the SecurityContext using the passed user instance and the SecuritySystem.
        /// </summary>
        public SecurityContext(ISecurityUser currentUser, SecuritySystem securitySystem)
        {
            CurrentUser      = currentUser;
            SecuritySystem   = securitySystem;
            Evaluator        = new PermissionEvaluator(this);
            _permissionQuery = SecuritySystem.PermissionQuery;
        }
Exemplo n.º 3
0
        public WorkflowUserService(
            IUnitOfWork unitOfWork)
        {

            if (_manager == null)
            {
                var repository = unitOfWork.GetRepository<User>();

                var user = repository.Find(x => x.Login == "WorkflowManager");
                if (user == null)
                {
                    user = new User
                    {
                        Login = "******",
                        CategoryID = 1,
                        Roles = new List<Role> {
                            new Role {
                                ChildRoles = new List<ChildRole>(),
                                Permissions = new List<Permission>(),
                                Name = "WorkflowManagerRole",
                                SystemRole = SystemRole.Admin
                            }
                        },
                        FirstName = "Менеджер бизнес-процессов"
                    };

                    repository.Create(user);
                    unitOfWork.SaveChanges();
                }

                _manager = new SecurityUser(user);
            }
        }
Exemplo n.º 4
0
 public LocalContextSecurityUser(ISecurityUser newUser, ISecurityUser restoreUser, AppContextBootstrapper appContextBootstrapper)
 {
     _restoreUser = restoreUser;
     _appContextBootstrapper = appContextBootstrapper;
     _appContextBootstrapper.RemoveSecurityUser();
     _appContextBootstrapper.SetSecurityUser(newUser);
 }
        public virtual void Logon(string userName, string password)
        {
            ISecurityUser currentUser = GetUserByCredentials(userName, password);

            if (currentUser == null)
            {
                throw new InvalidOperationException("Logon is failed. Try enter right credentials.");
            }
            Logon(currentUser);
        }
Exemplo n.º 6
0
        public void SetSecurityUser(ISecurityUser securityUser)
        {
            if (securityUser == null)
                throw new ArgumentNullException("securityUser");

            //var user = GetSecurityUser();
            //if (user != null)
            //    throw new InvalidOperationException("The user should be set only once");

            CallContext.LogicalSetData(s_userKey, securityUser);
        }
Exemplo n.º 7
0
        public bool Authenticate(ISecurityUser user, out string token)
        {
            if (!string.Equals(user.Username, "admin") || !string.Equals(user.Password, "password"))
            {
                token = null;
                return(false);
            }

            token = Guid.NewGuid().ToString("N");
            userTokenMap[token] = user;
            return(true);
        }
Exemplo n.º 8
0
        private static string GetMessage(string msg, string path, int entityId, ISecurityUser user, PermissionTypeBase[] permissionTypes)
        {
            var sb = new StringBuilder(msg ?? "Access denied.");

            if (path != null)
            {
                sb.Append(" Path: ").Append(path);
            }
            if (entityId != default)
            {
                sb.Append(" EntityId: ").Append(entityId);
            }
            if (user != null)
            {
                sb.Append(" UserId: ").Append(user.Id);
            }
            if (permissionTypes != null)
            {
                sb.Append(" PermissionTypes: ").Append(string.Join(", ", permissionTypes.Select(pt => pt.Name)));
            }
            return(sb.ToString());
        }
Exemplo n.º 9
0
 public void ModifyObject(ISecurityUser securityUser, BaseObject src, IEnumerable<InitItem> inits)
 {
     _objectInitializer.InitializeObject(securityUser, src, src, inits);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Creates a new instance of the SecurityContext using the passed user instance
 /// and pointers to the ISecurityDataProvider, IMessageProvider and SecurityCache global objects.
 /// </summary>
 public SecurityContext(ISecurityUser currentUser)
 {
     CurrentUser  = currentUser;
     DataProvider = _securityDataProviderPrototype.CreateNew();
     Cache        = _cacheHolder;
 }
Exemplo n.º 11
0
        public BaseViewModel(BaseViewModel baseViewModel)
        {
            _securityUser = baseViewModel.SecurityUser;

            _viewModelConfigs = baseViewModel.ViewModelConfigs;
        }
 protected virtual IEnumerable <IPermission> GetAllPermissions(ISecurityUser securityUser)
 {
     return(securityUser.GetPermissions());
 }
 public MissingEntityResolverContext(ISecurityUser user) : base(user)
 {
 }
Exemplo n.º 14
0
 public Context(ISecurityUser currentUser, SecuritySystem securitySystem)
 {
     // Create a new instance.
     Security = new SecurityContext(currentUser, securitySystem);
 }
 public SecurityContextForConcurrencyTests(ISecurityUser currentUser) : base(currentUser)
 {
 }
Exemplo n.º 16
0
 private string GetUserKeyCache(ISecurityUser user)
 {
     return String.Format("{1}:{0}", _keyCache, user.GetKey());
 }
Exemplo n.º 17
0
 public ObjectAccessItem(ISecurityUser securityUser, BaseObject obj)
     : this(securityUser.ID, obj) { }
Exemplo n.º 18
0
 public BaseViewModel(BaseViewModel baseViewModel)
 {
     _securityUser = baseViewModel.SecurityUser;
     _uiFasade = baseViewModel.UiFasade;
 }
Exemplo n.º 19
0
 public void Clear(ISecurityUser user)
 {
     _cacheWrapper.Remove(GetUserKeyCache(user));
 }
Exemplo n.º 20
0
 public BaseViewModel(IBaseController controller)
 {
     _securityUser = controller.SecurityUser;
     _uiFasade = controller.UiFasade;
 }
Exemplo n.º 21
0
        public void InitializeObject(ISecurityUser securityUser, BaseObject src, BaseObject dest, IEnumerable<Entities.InitItem> inits)
        {
            var resultScript = String.Empty;

            try
            {
                var engine = Python.CreateEngine();

                engine.Runtime.LoadAssembly(Assembly.GetExecutingAssembly());

                var scope = engine.CreateScope(new Dictionary<string, object> { { "Dest", dest }, { "Src", src } });

                IEnumerable<RefObject> refObjects;

                var macroses = PrepareMacros(dest, inits, out refObjects);

                foreach (var refObj in refObjects)
                    scope.SetVariable(String.Format("_refobject_{0}", refObj.Property.Name), refObj.Object);

                foreach (var pair in macroses.AsEnumerable().Reverse())
                {
                    var script = new StringBuilder(String.Format("Dest.{0} =", pair.Property.Name));

                    foreach (var initItem in pair.Macroses)
                    {
                        switch (initItem.MacroType)
                        {
                            case MacroType.String:
                                script.AppendFormat(" '{0}'", initItem.Value);
                                break;
                            case MacroType.Number:
                                {
                                    if (pair.Property.PropertyType.IsEnum)
                                    {
                                        var tempName = String.Format("_enum{0}", pair.Property.Name);

                                        scope.SetVariable(tempName, Enum.Parse(pair.Property.PropertyType, initItem.Value));

                                        script.AppendFormat(tempName);

                                        break;
                                    }

                                    goto case MacroType.Operator;
                                }
                            case MacroType.Boolean:
                            {
                                script.AppendFormat(" '{0}'", initItem.Value);

                                break;
                            }
                            case MacroType.Operator:
                                script.AppendFormat(" {0}", initItem.Value);
                                break;
                            case MacroType.InitObject:
                                {
                                    script.AppendFormat(" Src.{0}", initItem.Value);
                                    break;
                                }
                            case MacroType.BaseObject:
                                if (dest is ICategorizedItem)
                                {
                                    var foreignKey = pair.Property.GetCustomAttribute<ForeignKeyAttribute>();

                                    if (foreignKey != null && foreignKey.Name == "CategoryID")
                                    {
                                        script.Append(" None");

                                        dest.GetType().GetProperty("CategoryID").SetValue(dest, JsonConvert.DeserializeObject<ObjectRefItem>(initItem.Value).ID);

                                        break;
                                    }
                                }

                                script.AppendFormat(" _refobject_{0}", pair.Property.Name);
                                break;
                            case MacroType.Function:
                                if (initItem.Value == "dtn()")
                                {
                                    var locVar = this.GenerateVaribleName();

                                    scope.SetVariable(locVar, DateTime.Now);

                                    script.AppendFormat(" {0}", locVar);
                                }
                                break;
                            case MacroType.DateTime:
                            {
                                DateTime dt;
                                if (DateTime.TryParse(initItem.Value, out dt))
                                {
                                    var locVar = this.GenerateVaribleName();

                                    scope.SetVariable(locVar, dt);

                                    script.AppendFormat(" {0}", locVar);

                                    break;
                                }

                                throw ExceptionHelper.ActionInvokeException(
                                    String.Format("Дата имеет неверный формат {0} -> {1}", pair.Property.Name, initItem.Value));
                            }
                            case MacroType.TimeSpan:
                            {
                                double minutes;
                                if (double.TryParse(initItem.Value, out minutes))
                                {
                                    var locVar = this.GenerateVaribleName();

                                    scope.SetVariable(locVar, TimeSpan.FromMinutes(minutes));

                                    script.AppendFormat(" {0}", locVar);

                                    break;
                                }

                                throw ExceptionHelper.ActionInvokeException(
                                    String.Format("Временной интервал имел неверный формат {0} -> {1}", pair.Property.Name, initItem.Value));
                            }

                            default:
                                throw new ArgumentOutOfRangeException();
                        }
                    }

                    script.Append(";");

                    resultScript = script.ToString();

                    engine.Execute(resultScript, scope);
                }
            }
            catch (Exception e)
            {
                throw new ScriptExecutionException("Ошибка выполнения макроса" + Environment.NewLine + resultScript, e)
                    .IfNotNull(x => x.Data["Script"] = resultScript);
            }
        }
Exemplo n.º 22
0
 public BaseViewModel(ISecurityUser securityUser, IReadOnlyList<ViewModelConfig> viewModelConfigs)
 {
     _securityUser = securityUser;
     _viewModelConfigs = viewModelConfigs;
 }
Exemplo n.º 23
0
 /// <summary>Initializes a new instance of the AccessDeniedException class.</summary>
 public AccessDeniedException(string message, string path, int entityId, ISecurityUser user, PermissionTypeBase[] permissionTypes)
     : base(GetMessage(message, path, entityId, user, permissionTypes))
 {
 }
Exemplo n.º 24
0
 public void Clear(ISecurityUser securityUser)
 {
     Clear(securityUser.Login);
 }
Exemplo n.º 25
0
 public bool IsEnabled(ISecurityUser user)
 {
     return Status == SupportQAStatus.Created;
 }
Exemplo n.º 26
0
 public BasePageViewModel(ISecurityUser securityUser, IReadOnlyList<ViewModelConfig> viewModelConfigs) : base(securityUser, viewModelConfigs)
 {
     ThemeColor = "#4a4560";
 }
Exemplo n.º 27
0
 public ObjectAccessItem(ISecurityUser securityUser, Type type, int id)
     : this(securityUser.ID, type, id) { }
Exemplo n.º 28
0
 public ContentPageViewModel(ISecurityUser securityUser, IReadOnlyList<ViewModelConfig> viewModelConfigs) : base(securityUser, viewModelConfigs)
 {
 }
Exemplo n.º 29
0
 public bool IsEnabled(ISecurityUser user)
 {
     return true;
     //return this.ContentItemStatus == ContentItemStatus.New
     //    || this.ContentItemStatus == ContentItemStatus.Rework;
 }
Exemplo n.º 30
0
 public IDisposable LocalContextSecurity(ISecurityUser securityUser)
 {
     return new LocalContextSecurityUser(securityUser, GetSecurityUser(), this);
 }
Exemplo n.º 31
0
 public TestSecurityContext(ISecurityUser currentUser) : base(currentUser)
 {
 }
 public ServiceSecurityContext(ISecurityUser currentUser, SecuritySystem securitySystem) : base(currentUser, securitySystem)
 {
 }
Exemplo n.º 33
0
        public virtual void Logon(ISecurityUser user)
        {
            IAuthorization authorization = (IAuthorization)this.GetService <IPermissionsProvider>();

            authorization.Logon(user);
        }
 public virtual void Logoff()
 {
     SecurityUser = null;
 }
Exemplo n.º 35
0
 public bool IsEnabled(ISecurityUser user)
 {
     return !this.Auto &&
            (this.AssignedFromID == user.ID &&
             (this.Status == TaskStatus.New || this.Status == TaskStatus.Redirection ||
              this.Status == TaskStatus.Refinement))
            ||
            (this.AssignedToID == user.ID &&
             (this.Status == TaskStatus.Viewed || this.Status == TaskStatus.InProcess ||
              this.Status == TaskStatus.Rework));
 }
Exemplo n.º 36
0
 public void InitializeObject(ISecurityUser securityUser, BaseObject src, BaseObject dest,
     IEnumerable<InitItem> inits)
 {
     _objectInitializer.InitializeObject(securityUser, src, dest, inits);
 }
Exemplo n.º 37
0
        public void OnEnterToExtendedStage(ISecurityUser securityUser, ExtendedStage extendedStage, BaseObject baseObject)
        {
            var service = GetExtenderService(extendedStage);

            service.OnStageEnter(securityUser, extendedStage, extendedStage.Extender, baseObject);
        }
Exemplo n.º 38
0
        public BaseViewModel(IBaseController controller)
        {
            _securityUser = controller.SecurityUser;

            _viewModelConfigs = controller.ViewModelConfigs;
        }
Exemplo n.º 39
0
        public void OnLeaveFromExtendedStage(ISecurityUser securityUser, ExtendedStage extendedStage, BaseObject baseObject)
        {
            var service = GetExtenderService(extendedStage);

            service.OnStageLeave(securityUser, extendedStage, extendedStage.Extender, baseObject);
        }
Exemplo n.º 40
0
        public IQueryable<Workflow> GetWorkflowList(ISecurityUser securityUser, Type type, BaseObject model, IQueryable<Workflow> all)
        {
            var listStrategy = _strategyService.GetCommonStrategyInstance<IWorkflowListStrategy>(x => x.EntityType == type) ??
                               new WorkflowListStrategy<BaseObject>();

            return listStrategy.GetWorkflows(securityUser, model, all).Where(x => x.ObjectType == type.FullName);
        }
Exemplo n.º 41
0
 public Context(ISecurityUser currentUser)
 {
     // Create a new instance.
     Security = new TestSecurityContext(currentUser);
 }
 public virtual void Logon(ISecurityUser securityUser)
 {
     this.SecurityUser = securityUser;
 }