Exemple #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;
 }
Exemple #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;
        }
Exemple #3
0
 public bool Authorize(Permission permission) {
     var user = _authenticationService.GetAuthenticatedUser();
     if (_authorizationService.TryCheckAccess(permission, user))
         return true;
     return false;
 }
Exemple #4
0
 public INavigationBuilder Add(String name, Permission permission, Action<NavigationItemBuilder<NavigationItem>> itemBuilder, Int32 position = 0) {
     return this;
 }