Exemplo n.º 1
0
        private void EvaluateEmergencyAccessClaims()
        {
            _canExecuteExerciseEmergencyAccess = AccessControlManager.CanAccess(new ResourceRequest {
                GetType().FullName
            });
            (ExerciseEmergencyAccessCommand as VirtualDelegateCommand).RaiseCanExecuteChanged();

            EmergencyAccessEnabled = _currentUserPermissionService.DoesUserHavePermission(InfrastructurePermission.EmergencyAccessPermission);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whether access to the specified resource request should be granted.
        /// </summary>
        /// <param name="resourceRequest">The resource request.</param>
        /// <returns>
        ///   <c>true</c> if this instance can access the specified resource request; otherwise, <c>false</c>.
        /// </returns>
        public bool CanAccess(ResourceRequest resourceRequest)
        {
            if (resourceRequest == null)
            {
                throw new ArgumentException("resource request is required.");
            }

            if (resourceRequest.ResourceHierarchy.Count == 0)
            {
                throw new ArgumentException("Invalid resource request.");
            }

            Permission requiredPermission = null;
            var        canAccess          = false;
            var        resourceList       = _resourceList;

            foreach (var resourceName in resourceRequest.ResourceHierarchy)
            {
                if (resourceList == null)
                {
                    break;
                }

                var name     = resourceName;
                var resource = resourceList.FirstOrDefault(r => r.Name == name);
                if (resource == null)
                {
                    break;
                }

                requiredPermission = resource.Permission;
                resourceList       = resource.Resources;
            }

            if (requiredPermission != null)
            {
                canAccess = _currentUserPermissionService.DoesUserHavePermission(requiredPermission);
                Logger.Debug(
                    "Permission ({0}) {1} for resource request ({2}).",
                    requiredPermission,
                    canAccess ? "granted" : "denied",
                    resourceRequest);
            }
            else
            {
                Logger.Debug("No permission defined for resource request ({0}).", resourceRequest);
            }

            return(canAccess);
        }