Esempio n. 1
0
        public Boolean UserIsAllowed(Session userSession, Permission permission)
        {
            // Check if all roles in session are assigned to user

            List<Role> allUserRoles = null;
            try
            {
                allUserRoles = GetUserRolesHierarchy(userSession.User.Id);

            }
            catch (Exception ex)
            {

            }

            foreach (Role role in userSession.Roles)
            {
                if (allUserRoles.FirstOrDefault((r) => { return r.Id == role.Id;}) == null)
                {
                    return false;
                }
            }

            // Check if roles in session have access to the permission
            foreach(Role role in userSession.Roles)
            {
                foreach (Role childRole in GetAllChildRoles(role))
                {
                    // Checking if we have the pair Role <-> Permission
                    foreach (PermissionAssigment pa in permissionAssigmentRepository.LoadByRoleId(role.Id))
                    {
                        if (pa.Permission.Id == permission.Id)
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
Esempio n. 2
0
        public Boolean UserIsAllowed(Session userSession, Permission permission)
        {
            Permission[] permissions = GetUserPermissions(userSession);

            Permission perm = permissions.FirstOrDefault((p)=> { return p.Description == permission.Description; });

            return perm != null;
        }
        private String Serialize(Permission[] permissions)
        {
            StringBuilder sb = new StringBuilder();

            foreach (Permission p in permissions)
            {
                if (sb.Length != 0)
                {
                    sb.Append(",");
                }
                sb.Append(p.Description);
            }

            return sb.ToString();
        }