Ejemplo n.º 1
0
 /// <summary>
 /// Validates the specified <paramref name="rule" /> as an asynchronous operation.
 /// </summary>
 /// <param name="manager">The <see cref="SecurityManager" /> that can be used to retrieve user properties.</param>
 /// <param name="objectType">The type of the shared object to be found.</param>
 /// <param name="objectId">The primary key of the shared object to be found.</param>
 /// <param name="rule">The rule to validate.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken" /> used to propagate notifications that the operation should be canceled.</param>
 /// <returns>
 /// The <see cref="Task" /> that represents the asynchronous operation, containing the <see cref="ValidationResult" /> of the validation operation.
 /// </returns>
 protected virtual Task <ValidationResult> ValidateUserAsync(SecurityManager manager, AccessObjectType objectType, int objectId, AccessRuleItem rule, CancellationToken cancellationToken)
 {
     if (rule.Permission == AccessPermission.Unknown)
     {
         return(ValidationResultTask.Failed(string.Format(CultureInfo.CurrentCulture, SecurityResources.UserPermissionRequired)));
     }
     if (rule.Visibility != AccessVisibility.Unknown)
     {
         return(ValidationResultTask.Failed(string.Format(CultureInfo.CurrentCulture, SecurityResources.AccessVisibilityNotSupported)));
     }
     return(AtLeastOneOwnerRequired(manager, objectType, objectId, rule, cancellationToken));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Validates the specified <paramref name="rule" /> as an asynchronous operation.
 /// </summary>
 /// <param name="manager">The <see cref="SecurityManager" /> that can be used to retrieve user properties.</param>
 /// <param name="objectType">The type of the shared object to be found.</param>
 /// <param name="objectId">The primary key of the shared object to be found.</param>
 /// <param name="rule">The rule to validate.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken" /> used to propagate notifications that the operation should be canceled.</param>
 /// <returns>
 /// The <see cref="Task" /> that represents the asynchronous operation, containing the <see cref="ValidationResult" /> of the validation operation.
 /// </returns>
 protected virtual Task <ValidationResult> ValidateAnyoneAsync(SecurityManager manager, AccessObjectType objectType, int objectId, AccessRuleItem rule, CancellationToken cancellationToken)
 {
     if (rule.Permission != AccessPermission.CanView)
     {
         return(ValidationResultTask.Failed(string.Format(CultureInfo.CurrentCulture, SecurityResources.AccessPermissionNotSupported)));
     }
     if (rule.Visibility == AccessVisibility.Unknown)
     {
         return(ValidationResultTask.Failed(string.Format(CultureInfo.CurrentCulture, SecurityResources.AnyoneVisibilityRequired)));
     }
     return(ValidationResultTask.Success);
 }