Exemplo n.º 1
0
 void ThrowIfPermissionKnown(PermissionId permissionId)
 {
     if (IsKnownPermission(permissionId))
     {
         throw new Exception("Yo bro, the permission is already known to me.");
     }
 }
Exemplo n.º 2
0
 public void RemovePermission(PermissionId permissionId)
 {
     ThrowIfArchived();
     ThrowIfPermissionUnknown(permissionId);
     Apply(
         new RemovedPermissionFromRole(Id, permissionId));
 }
Exemplo n.º 3
0
 public void AddPermission(PermissionId permissionId)
 {
     ThrowIfArchived();
     ThrowIfPermissionKnown(permissionId);
     Apply(
         new AddedPermissionToRole(Id, permissionId));
 }
Exemplo n.º 4
0
 void ThrowIfPermissionUnknown(PermissionId permissionId)
 {
     if (IsUnknownPermission(permissionId))
     {
         throw new Exception("Yo bro, the permission is not known to me.");
     }
 }
Exemplo n.º 5
0
        public bool IsAllowed(PermissionId permissionId)
        {
            AccessDecision decision;

            if (_decisions.TryGetValue(permissionId, out decision))
            {
                return(decision == AccessDecision.Allow);
            }
            return(false);
        }
Exemplo n.º 6
0
 public void DenyPermission(PermissionId permissionId)
 {
     ThrowIfArchived();
     ThrowIfPermissionUnknown(permissionId);
     if (!IsPermissionDenied(permissionId))
     {
         Apply(
             new RolePermissionDenied(Id, permissionId));
     }
 }
        public IAccessDecisionCombinator CombineDecision(PermissionId permissionId, AccessDecision decision)
        {
            AccessDecision otherDecision;

            if (_decisions.TryGetValue(permissionId, out otherDecision))
            {
                _decisions[permissionId] = Combinations[new Tuple <AccessDecision, AccessDecision>(otherDecision, decision)];
            }
            else
            {
                _decisions[permissionId] = decision;
            }
            return(this);
        }
Exemplo n.º 8
0
 public RolePermission(PermissionId permissionId, AccessDecision accessDecision)
 {
     _permissionId   = permissionId;
     _accessDecision = accessDecision;
 }
Exemplo n.º 9
0
 RolePermission FindPermission(PermissionId permissionId)
 {
     return(_permissions.Find(permission => permission.PermissionId == permissionId));
 }
Exemplo n.º 10
0
 bool IsPermissionDenied(PermissionId permissionId)
 {
     return(_permissions.Find(permission => permission.PermissionId == permissionId).IsDenied());
 }
Exemplo n.º 11
0
 bool IsPermissionAllowed(PermissionId permissionId)
 {
     return(_permissions.Find(permission => permission.PermissionId == permissionId).IsAllowed());
 }
Exemplo n.º 12
0
 bool IsKnownPermission(PermissionId permissionId)
 {
     return(_permissions.Exists(permission => permission.PermissionId == permissionId));
 }