1
1
using FleetFlow . Api . Models ;
2
2
using FleetFlow . Service . Exceptions ;
3
3
using FleetFlow . Service . Interfaces . Authorizations ;
4
- using FleetFlow . Shared . Helpers ;
5
4
using Microsoft . AspNetCore . Mvc ;
6
5
using Microsoft . AspNetCore . Mvc . Controllers ;
7
6
using Microsoft . AspNetCore . Mvc . Filters ;
@@ -15,37 +14,37 @@ public CustomAuthorizeAttribute() : base(typeof(CustomAuthorizationFilter))
15
14
{
16
15
}
17
16
18
- public class CustomAuthorizationFilter : IAuthorizationFilter
17
+ public class CustomAuthorizationFilter : IAuthorizationFilter
19
18
{
20
- private readonly IRolePermissionService rolePermissionService ;
19
+ private readonly IRolePermissionService rolePermissionService ;
21
20
22
21
public CustomAuthorizationFilter ( IRolePermissionService rolePermissionService )
23
22
{
24
23
this . rolePermissionService = rolePermissionService ;
25
24
}
26
25
27
- public void OnAuthorization ( AuthorizationFilterContext context )
26
+ public void OnAuthorization ( AuthorizationFilterContext context )
28
27
{
29
28
30
29
var controllerDescriptor = context . ActionDescriptor as ControllerActionDescriptor ;
31
- var result = controllerDescriptor ? . ControllerName . ToLower ( ) + "." + controllerDescriptor ? . ActionName . ToLower ( ) ;
32
- var role = context . HttpContext ? . User ? . Claims ? . FirstOrDefault ( u => u . Type == ClaimTypes . Role ) ? . Value ?? string . Empty ;
33
- var res = this . rolePermissionService . CheckPermission ( role , result ) . GetAwaiter ( ) . GetResult ( ) ;
30
+ var result = controllerDescriptor ? . ControllerName . ToLower ( ) + "." + controllerDescriptor ? . ActionName . ToLower ( ) ;
31
+ var role = context . HttpContext ? . User ? . Claims ? . FirstOrDefault ( u => u . Type == ClaimTypes . Role ) ? . Value ?? string . Empty ;
32
+ var res = this . rolePermissionService . CheckPermission ( role , result ) . GetAwaiter ( ) . GetResult ( ) ;
34
33
35
34
if ( ! res )
35
+ {
36
+ var exception = new FleetFlowException ( 403 , "You do not have permission for this method" ) ;
37
+ context . Result = new ObjectResult ( new Response
36
38
{
37
- var exception = new FleetFlowException ( 403 , "You do not have permission for this method" ) ;
38
- context . Result = new ObjectResult ( new Response
39
- {
40
- Code = exception . Code ,
41
- Message = exception . Message
42
- } )
43
- {
44
- StatusCode = exception . Code
45
- } ;
46
- }
39
+ Code = exception . Code ,
40
+ Message = exception . Message
41
+ } )
42
+ {
43
+ StatusCode = exception . Code
44
+ } ;
45
+ }
47
46
}
48
47
49
48
}
50
-
49
+
51
50
}
0 commit comments