Преглед на файлове

Clean up SecurityException

- Remove unused SecurityExceptionType
- Add missing constructor for InnerException
- Add missing documentation
Mark Monteiro преди 5 години
родител
ревизия
6d35dd6b32

+ 6 - 24
Emby.Server.Implementations/HttpServer/Security/AuthService.cs

@@ -108,18 +108,12 @@ namespace Emby.Server.Implementations.HttpServer.Security
         {
         {
             if (user.Policy.IsDisabled)
             if (user.Policy.IsDisabled)
             {
             {
-                throw new SecurityException("User account has been disabled.")
-                {
-                    SecurityExceptionType = SecurityExceptionType.Unauthenticated
-                };
+                throw new SecurityException("User account has been disabled.");
             }
             }
 
 
             if (!user.Policy.EnableRemoteAccess && !_networkManager.IsInLocalNetwork(request.RemoteIp))
             if (!user.Policy.EnableRemoteAccess && !_networkManager.IsInLocalNetwork(request.RemoteIp))
             {
             {
-                throw new SecurityException("User account has been disabled.")
-                {
-                    SecurityExceptionType = SecurityExceptionType.Unauthenticated
-                };
+                throw new SecurityException("User account has been disabled.");
             }
             }
 
 
             if (!user.Policy.IsAdministrator
             if (!user.Policy.IsAdministrator
@@ -128,10 +122,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
             {
             {
                 request.Response.Headers.Add("X-Application-Error-Code", "ParentalControl");
                 request.Response.Headers.Add("X-Application-Error-Code", "ParentalControl");
 
 
-                throw new SecurityException("This user account is not allowed access at this time.")
-                {
-                    SecurityExceptionType = SecurityExceptionType.ParentalControl
-                };
+                throw new SecurityException("This user account is not allowed access at this time.");
             }
             }
         }
         }
 
 
@@ -190,10 +181,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
             {
             {
                 if (user == null || !user.Policy.IsAdministrator)
                 if (user == null || !user.Policy.IsAdministrator)
                 {
                 {
-                    throw new SecurityException("User does not have admin access.")
-                    {
-                        SecurityExceptionType = SecurityExceptionType.Unauthenticated
-                    };
+                    throw new SecurityException("User does not have admin access.");
                 }
                 }
             }
             }
 
 
@@ -201,10 +189,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
             {
             {
                 if (user == null || !user.Policy.EnableContentDeletion)
                 if (user == null || !user.Policy.EnableContentDeletion)
                 {
                 {
-                    throw new SecurityException("User does not have delete access.")
-                    {
-                        SecurityExceptionType = SecurityExceptionType.Unauthenticated
-                    };
+                    throw new SecurityException("User does not have delete access.");
                 }
                 }
             }
             }
 
 
@@ -212,10 +197,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
             {
             {
                 if (user == null || !user.Policy.EnableContentDownloading)
                 if (user == null || !user.Policy.EnableContentDownloading)
                 {
                 {
-                    throw new SecurityException("User does not have download access.")
-                    {
-                        SecurityExceptionType = SecurityExceptionType.Unauthenticated
-                    };
+                    throw new SecurityException("User does not have download access.");
                 }
                 }
             }
             }
         }
         }

+ 1 - 1
MediaBrowser.Api/UserService.cs

@@ -426,7 +426,7 @@ namespace MediaBrowser.Api
             catch (SecurityException e)
             catch (SecurityException e)
             {
             {
                 // rethrow adding IP address to message
                 // rethrow adding IP address to message
-                throw new SecurityException($"[{Request.RemoteIp}] {e.Message}");
+                throw new SecurityException($"[{Request.RemoteIp}] {e.Message}", e);
             }
             }
         }
         }
 
 

+ 24 - 8
MediaBrowser.Controller/Net/SecurityException.cs

@@ -2,20 +2,36 @@ using System;
 
 
 namespace MediaBrowser.Controller.Net
 namespace MediaBrowser.Controller.Net
 {
 {
+    /// <summary>
+    /// The exception that is thrown when a user is authenticated, but not authorized to access a requested resource.
+    /// </summary>
     public class SecurityException : Exception
     public class SecurityException : Exception
     {
     {
+        /// <summary>
+        /// Initializes a new instance of the <see cref="SecurityException"/> class.
+        /// </summary>
+        public SecurityException()
+            : base()
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="SecurityException"/> class.
+        /// </summary>
+        /// <param name="message">The message that describes the error.</param>
         public SecurityException(string message)
         public SecurityException(string message)
             : base(message)
             : base(message)
         {
         {
-
         }
         }
 
 
-        public SecurityExceptionType SecurityExceptionType { get; set; }
-    }
-
-    public enum SecurityExceptionType
-    {
-        Unauthenticated = 0,
-        ParentalControl = 1
+        /// <summary>
+        /// Initializes a new instance of the <see cref="SecurityException"/> class.
+        /// </summary>
+        /// <param name="message">The message that describes the error</param>
+        /// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
+        public SecurityException(string message, Exception innerException)
+            : base(message, innerException)
+        {
+        }
     }
     }
 }
 }