Ejemplo n.º 1
0
        /// <summary>
        /// 加载所有的权限节点信息
        /// </summary>
        private void LoadAuthorizationNodes(AuthorizationStore store)
        {
            using (WaitCursor cursor = new WaitCursor(true))
            {
                tlAuth.BeginUpdate();
                tlAuth.Nodes.Clear();
                try
                {
                    AuthorizationNode authNode = new AuthorizationNode()
                    {
                        Id   = "Shell",
                        Name = "系统权限"
                    };
                    authNode.AuthorizationUri = GlobalConstants.Uri_Separator + "Shell";
                    TreeListNode tlNode = tlAuth.AppendNode(new object[] { authNode.Name, authNode.Id }, -1, authNode);
                    tlNode.Tag = authNode;
                    ((AuthorizationNode)tlNode.Tag).AuthorizationUri = GetAuthrizationNodePath(tlNode);
                    tlNode.ImageIndex       = 0;
                    tlNode.SelectImageIndex = 1;

                    // 加载角色的相关权限节点
                    foreach (AuthorizationNode child in store.Nodes)
                    {
                        LoadAuthorizationNode(child, tlAuth.Nodes[0]);
                    }
                    tlAuth.Nodes[0].ExpandAll(); // 展开所有子节点
                }
                finally
                {
                    tlAuth.EndUpdate();
                }
            }
        }
Ejemplo n.º 2
0
 public void Delete(int id)
 {
     if (!AuthorizationStore.checkWritePermissions("article"))
     {
         return;
     }
     _repository.Delete(id);
 }
Ejemplo n.º 3
0
 public IEnumerable <Article> Get()
 {
     if (!AuthorizationStore.checkReadPermission("article"))
     {
         return(new List <Article>());
     }
     return(_repository.GetAll());
 }
Ejemplo n.º 4
0
        private void MembershipRoleView_Enter(object sender, EventArgs e)
        {
            if (WorkItem.State[Constants.CurrentRole] != null)
            {
                string role = (string)WorkItem.State[Constants.CurrentRole];
                RefreshCurrentRole(role);

                AuthorizationStore store = GetAuthorizationForRole(role);
                LoadAuthorizationNodes(store);
            }
        }
Ejemplo n.º 5
0
 public void Update([FromBody] Article model)
 {
     if (!AuthorizationStore.checkWritePermissions("article"))
     {
         return;
     }
     if (ModelState.IsValid)
     {
         _repository.Update(model);
     }
 }
Ejemplo n.º 6
0
        public IActionResult LogIn([FromBody] UserModel model)
        {
            var user = _context.Person.Where(x => model.password == x.Password && model.userName == x.UserName).SingleOrDefault();

            if (user != null)
            {
                AuthorizationStore.setRoleId(user.RoleId);
                return(new ObjectResult(user.RoleId));
            }
            return(new ObjectResult(0));
        }
Ejemplo n.º 7
0
 public IActionResult Register([FromBody] Person model)
 {
     if (ModelState.IsValid)
     {
         _context.Person.Add(model);
         _context.SaveChanges();
         AuthorizationStore.setRoleId(model.RoleId);
         return(new ObjectResult(model.RoleId));
     }
     else
     {
         return(new ObjectResult(0));
     }
 }
        public AuthzServiceHost()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["authzStore"].ConnectionString;
            Store = new AuthorizationStore(connectionString);

            var endPoint = new NetNamedPipeBinding();
            var uris = new[] { new Uri("net.pipe://localhost/lockdown.host") };

            host = new ServiceHost(typeof(AzmanAuthzService), uris);

            host.Description.Behaviors.Remove(typeof(ServiceDebugBehavior));
            host.Description.Behaviors.Add(new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true });

            host.AddServiceEndpoint(typeof(AuthorizationService), endPoint, uris[0]);
        }
Ejemplo n.º 9
0
 public Article GetById(int id)
 {
     if (!AuthorizationStore.checkReadPermission("article"))
     {
         return(new Article());
     }
     if (id == 0)
     {
         return(new Article());
     }
     else
     {
         return(_repository.GetById(id));
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 获取指定角色的权限信息
        /// </summary>
        /// <param name="role">角色名称</param>
        private AuthorizationStore GetAuthorizationForRole(string role)
        {
            authStore = Presenter.AuthorizationStoreService.GetAuthorizationsByRole(role);
            if (authStore == null)
            {
                authStore = new AuthorizationStore(role);

                IList <AuthorizationNode> lns = Presenter.AuthorizationNodeService.GetAll();
                foreach (AuthorizationNode an in lns)
                {
                    authStore.Store(an);
                }
                Presenter.AuthorizationStoreService.SaveAuthorization(authStore); // 保存角色的权限信息
            }
            return(authStore);
        }