Kaynağa Gözat

[Authentication] Added logs for auth filter

develop
Robin Thoni 9 yıl önce
ebeveyn
işleme
cb60bacddd
1 değiştirilmiş dosya ile 16 ekleme ve 1 silme
  1. 16
    1
      Authentication/Business/AuthFilter.cs

+ 16
- 1
Authentication/Business/AuthFilter.cs Dosyayı Görüntüle

@@ -2,6 +2,8 @@
2 2
 using System.Linq;
3 3
 using System.Web.Http;
4 4
 using System.Web.Http.Controllers;
5
+using iiie.Logs.DataAccess;
6
+using iiie.Logs.DBO;
5 7
 
6 8
 namespace iiie.Authentication.Business
7 9
 {
@@ -31,7 +33,20 @@ namespace iiie.Authentication.Business
31 33
         /// <returns>True if user can access, false otherwise</returns>
32 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…
İptal
Kaydet