PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/DotNetSlave.BusinessLogic/Security/CustomPrincipal.cs

#
C# | 35 lines | 27 code | 5 blank | 3 comment | 4 complexity | 19f28c808b30cc70e1ba2771dc0003bb MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. namespace BlogEngine.Core
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Security.Principal;
  8. using System.Web.Security;
  9. public class CustomPrincipal : IPrincipal
  10. {
  11. private IIdentity _identity;
  12. public IIdentity Identity
  13. {
  14. get { return _identity; }
  15. }
  16. public bool IsInRole(string roleName)
  17. {
  18. if (Identity == null || !Identity.IsAuthenticated || string.IsNullOrEmpty(Identity.Name))
  19. return false;
  20. // Note: Cannot use "Security.CurrentUser.IsInRole" or anything similar since
  21. // Security.CurrentUser.IsInRole will look to this IsInRole() method here --
  22. // resulting in an endless loop. Need to query the role provider directly.
  23. return Roles.IsUserInRole(Identity.Name, roleName);
  24. }
  25. public CustomPrincipal(IIdentity identity)
  26. {
  27. _identity = identity;
  28. }
  29. }
  30. }