예제 #1
0
 public INavigationBuilder Add(String name, Permission permission, Action<NavigationItemBuilder<NavigationItem>> itemBuilder, Int32 position = 0) {
     if (_menuCache.All(m => m.Name != name)) {
         var item = new NavigationItem {
             Name = name,
             Permission = permission,
             Position = position
         };
         var childBuilder = new NavigationItemBuilder<NavigationItem>(item);
         itemBuilder(childBuilder);
         _menuCache.Add(item);
     }
     return this;
 }
예제 #2
0
        public bool TryCheckAccess(Permission permission, IUser user) {
            if (user != null) {
                IEnumerable<string> permissions;
                if (!_accountPermissionContexts.TryGetValue(user.Id, out permissions)) {
                    var roleIds = _userRoleRepository.All.Where(m => m.Account_Id == user.Id).Select(it => it.Role_Id).Distinct().ToArray();
                    permissions = _rolePermissionRepository.All.Where(m => roleIds.Contains(m.Role_Id)).Select(m => m.Permission).ToArray();
                    _accountPermissionContexts.TryAdd(user.Id, permissions);
                }
                return permissions.Any(m => m.Equals(permission.Name));

            }
            return false;
        }
예제 #3
0
파일: Authorizer.cs 프로젝트: wolfweb/Ww
 public bool Authorize(Permission permission) {
     var user = _authenticationService.GetAuthenticatedUser();
     if (_authorizationService.TryCheckAccess(permission, user))
         return true;
     return false;
 }
예제 #4
0
 public INavigationBuilder Add(String name, Permission permission, Action<NavigationItemBuilder<NavigationItem>> itemBuilder, Int32 position = 0) {
     return this;
 }