Ejemplo n.º 1
0
 public virtual async Task CheckGettingPermissionAsync(AuthorizationHandlerConfiguration configuration, IBlobInfo blobInfo)
 {
     if (!configuration.GettingPolicy.IsNullOrEmpty() && !await AuthorizationService.IsGrantedAsync(configuration.GettingPolicy))
     {
         // TODO: 考虑异常改为 BusinessException
         throw new Volo.Abp.Authorization.AbpAuthorizationException("未授权");
     }
     else if (configuration.GettingRoles != null && configuration.GettingRoles.Any() && !CurrentUser.Roles.Intersect(configuration.GettingRoles).Any())
     {
         // TODO: 考虑异常改为 BusinessException
         throw new Volo.Abp.Authorization.AbpAuthorizationException("未授权");
     }
 }
Ejemplo n.º 2
0
        private async Task CheckDeletingPermissionAsync(IBlobInfo blobInfo)
        {
            var authorizationHandlerType = Configuration.GetConfigurationOrDefault <Type>(DigniteAbpBlobContainerConfigurationNames.AuthorizationHandler, null);

            if (authorizationHandlerType != null)
            {
                using (var scope = ServiceProvider.CreateScope())
                {
                    var authorizationConfiguration = new AuthorizationHandlerConfiguration(Configuration);
                    var handler = scope.ServiceProvider
                                  .GetRequiredService(authorizationHandlerType)
                                  .As <IAuthorizationHandler>();

                    await handler.CheckDeletingPermissionAsync(authorizationConfiguration, blobInfo);
                }
            }
        }
Ejemplo n.º 3
0
 public virtual async Task CheckDeletingPermissionAsync(AuthorizationHandlerConfiguration configuration, IBlobInfo blobInfo)
 {
     if (!CurrentUser.IsAuthenticated)
     {
         // TODO: 考虑异常改为 BusinessException
         throw new Volo.Abp.Authorization.AbpAuthorizationException("未授权");
         // throw new BusinessException(
         //     code: "Dignite.Abp.BlobStoring:010001",
         //     message: "Unauthorized!",
         //     details: "Current user is not authorized!"
         // );
     }
     else if (!configuration.DeletingPolicy.IsNullOrEmpty() && !await AuthorizationService.IsGrantedAsync(configuration.DeletingPolicy))
     {
         // TODO: 考虑异常改为 BusinessException
         throw new Volo.Abp.Authorization.AbpAuthorizationException("未授权");
     }
     else if (configuration.DeletingRoles != null && configuration.DeletingRoles.Any() && !CurrentUser.Roles.Intersect(configuration.DeletingRoles).Any())
     {
         // TODO: 考虑异常改为 BusinessException
         throw new Volo.Abp.Authorization.AbpAuthorizationException("未授权");
     }
 }