Skip to content

Commit c877de3

Browse files
Minor refactor
1 parent 86c1971 commit c877de3

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Host/Startup/SecurityRequirementsOperationFilter.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,29 @@ public void Apply(Operation operation, OperationFilterContext context)
2525
}
2626

2727
var controllerAbpAuthorizeAttrs = controllerAttrs.OfType<AbpAuthorizeAttribute>().ToList();
28-
if (controllerAbpAuthorizeAttrs.Any() || actionAbpAuthorizeAttrs.Any())
28+
if (!controllerAbpAuthorizeAttrs.Any() && !actionAbpAuthorizeAttrs.Any())
2929
{
30-
operation.Responses.Add("401", new Response { Description = "Unauthorized" });
30+
return;
31+
}
3132

32-
var permissions = controllerAbpAuthorizeAttrs.Union(actionAbpAuthorizeAttrs)
33-
.SelectMany(p => p.Permissions)
34-
.Distinct().ToList();
33+
operation.Responses.Add("401", new Response { Description = "Unauthorized" });
3534

36-
if (permissions.Any())
37-
{
38-
operation.Responses.Add("403", new Response { Description = "Forbidden" });
39-
}
35+
var permissions = controllerAbpAuthorizeAttrs.Union(actionAbpAuthorizeAttrs)
36+
.SelectMany(p => p.Permissions)
37+
.Distinct().ToList();
4038

41-
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
42-
{
43-
new Dictionary<string, IEnumerable<string>>
44-
{
45-
{ "bearerAuth", permissions }
46-
}
47-
};
39+
if (permissions.Any())
40+
{
41+
operation.Responses.Add("403", new Response { Description = "Forbidden" });
4842
}
43+
44+
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
45+
{
46+
new Dictionary<string, IEnumerable<string>>
47+
{
48+
{ "bearerAuth", permissions }
49+
}
50+
};
4951
}
5052
}
5153
}

0 commit comments

Comments
 (0)