Browse Source

[Authentication] Added logs for auth filter

develop
Robin Thoni 9 years ago
parent
commit
cb60bacddd
1 changed files with 16 additions and 1 deletions
  1. 16
    1
      Authentication/Business/AuthFilter.cs

+ 16
- 1
Authentication/Business/AuthFilter.cs View File

2
 using System.Linq;
2
 using System.Linq;
3
 using System.Web.Http;
3
 using System.Web.Http;
4
 using System.Web.Http.Controllers;
4
 using System.Web.Http.Controllers;
5
+using iiie.Logs.DataAccess;
6
+using iiie.Logs.DBO;
5
 
7
 
6
 namespace iiie.Authentication.Business
8
 namespace iiie.Authentication.Business
7
 {
9
 {
31
         /// <returns>True if user can access, false otherwise</returns>
33
         /// <returns>True if user can access, false otherwise</returns>
32
         protected override bool IsAuthorized(HttpActionContext context)
34
         protected override bool IsAuthorized(HttpActionContext context)
33
         {
35
         {
34
-            return !UserRoles.Any() || (UserStorage.BasicUserDbo != null && UserRoles.Contains(UserStorage.BasicUserDbo.Role));
36
+            if (!UserRoles.Any())
37
+                return true;
38
+            if (UserStorage.BasicUserDbo == null)
39
+            {
40
+                OpResult<bool>.Error(ResultStatus.PermissionError, "User is not recognized. Missing token?").Log();
41
+                return false;
42
+            }
43
+            if (!UserRoles.Contains(UserStorage.BasicUserDbo.Role))
44
+            {
45
+                OpResult<bool>.Error(ResultStatus.PermissionError, string.Format("User has role {0}, but only {1} are allowed",
46
+                    UserStorage.BasicUserDbo.Role, string.Join(",", UserRoles.Select(x => x.ToString())))).Log();
47
+                return false;
48
+            }
49
+            return true;
35
         }
50
         }
36
     }
51
     }
37
 }
52
 }

Loading…
Cancel
Save