Authorization Static Class

[namespace: Serenity, assembly: Serenity.Core]

Authorization class provides some shortcuts to information which is provided by services like IAuthorizationService, IPermissionService etc.

For example, instead of writing

  1. Dependency.Resolve<IAuthorizationService>().HasPermission("SomePermission")

you could use

  1. Authorization.HasPermission("SomePermission")
  1. public static class Authorization
  2. {
  3. public static bool IsLoggedIn { get; }
  4. public static IUserDefinition UserDefinition { get; }
  5. public static string UserId { get; }
  6. public static string Username { get; }
  7. public static bool HasPermission(string permission);
  8. public static void ValidateLoggedIn();
  9. public static void ValidatePermission(string permission);
  10. }

IsLoggedIn, UserDefinition, UserId, Username and HasPermission make use of corresponding service for you to access information easier about current user.

ValidateLoggedIn checks if there is a logged user and if not, throws a ValidationException with error code NotLoggedIn.

ValidatePermission checks if logged user has specified permission and throws a ValidationException with error code AccessDenied otherwise.