Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shesha.Configuration.Security;
using Shesha.Domain.Enums;
using Shesha.Extensions;
using Shesha.Permissions;
using Shesha.Reflection;
Expand Down Expand Up @@ -44,9 +45,8 @@ public override async Task AuthorizeAsync(MethodInfo methodInfo, Type type)
return;
}

if (type.HasAttribute<AllowAnonymousAttribute>() || methodInfo.HasAttribute<AllowAnonymousAttribute>()
|| type.HasAttribute<AbpAllowAnonymousAttribute>() || methodInfo.HasAttribute<AbpAllowAnonymousAttribute>())
return;
var hasCodeAllowAnonymous = type.HasAttribute<AllowAnonymousAttribute>() || methodInfo.HasAttribute<AllowAnonymousAttribute>()
|| type.HasAttribute<AbpAllowAnonymousAttribute>() || methodInfo.HasAttribute<AbpAllowAnonymousAttribute>();

var shaServiceType = typeof(ApplicationService);
var controllerType = typeof(ControllerBase);
Expand All @@ -61,19 +61,25 @@ public override async Task AuthorizeAsync(MethodInfo methodInfo, Type type)
return;

var securitySettings = await _securitySettings?.SecuritySettings?.GetValueAsync();
var settings = securitySettings?.DefaultEndpointAccess;
var defaultAccess = securitySettings?.DefaultEndpointAccess;

if (settings == null)
if (defaultAccess == null)
throw new NullReferenceException("Cannot get DefaultEndpointAccess");

// ToDo: add RequireAll flag
// If code-level [AllowAnonymous] is present, use it as the fallback for Inherited.
// Database configuration with an explicit access level will still take precedence.
var replaceInherited = hasCodeAllowAnonymous
? RefListPermissionedAccess.AllowAnonymous
: defaultAccess;

// Note: requireAll is intentionally false — multiple permissions are OR'd (any single permission grants access)
await _objectPermissionChecker.AuthorizeAsync(
false,
typeName,
methodName,
ShaPermissionedObjectsTypes.WebApiAction,
AbpSession.UserId.HasValue,
settings
replaceInherited
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Abp.Events.Bus.Exceptions;
using Abp.Web.Models;
using Castle.Core.Logging;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
Expand Down Expand Up @@ -39,13 +38,6 @@ public SheshaAuthorizationFilter(

public virtual async Task OnAuthorizationAsync(AuthorizationFilterContext context)
{
var endpoint = context?.HttpContext?.GetEndpoint();
// Allow Anonymous skips all authorization
if (endpoint?.Metadata.GetMetadata<IAllowAnonymous>() != null)
{
return;
}

if (!context.ActionDescriptor.IsControllerAction())
{
return;
Expand Down