CustomPrincipal.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Security.Principal;
  6. namespace Bowin.Common
  7. {
  8. public class CustomPrincipal : IPrincipal
  9. {
  10. IIdentity iIdentity;
  11. string _UserName;
  12. string _logingID;
  13. Nullable<Guid> _OU_ID;
  14. string _OU_Name;
  15. Nullable<Guid> _UserID;
  16. public CustomPrincipal(IIdentity id, string data)
  17. {
  18. this.iIdentity = id;
  19. //Pengzw Add 2012-11-26
  20. var set = data.Split('|');
  21. this._logingID = set[0];
  22. this._UserName = set[1];
  23. this._OU_ID = string.IsNullOrEmpty(set[2]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[2]));
  24. this._OU_Name = set[3];
  25. this._UserID = string.IsNullOrEmpty(set[4]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[4]));
  26. this.CurrentRoleName = set[5];
  27. this.CurrentRoleID = string.IsNullOrEmpty(set[6]) ? new Nullable<Guid>() : new Nullable<Guid>(Guid.Parse(set[6]));
  28. }
  29. public Guid? CurrentRoleID { get; private set; }
  30. public string CurrentRoleName { get; private set; }
  31. public Nullable<Guid> UserID
  32. {
  33. get { return _UserID; }
  34. }
  35. public string UserName
  36. {
  37. get { return _UserName; }
  38. }
  39. public string LogingID
  40. {
  41. get { return _logingID; }
  42. }
  43. public Nullable<Guid> OU_ID
  44. {
  45. get { return _OU_ID; }
  46. }
  47. public string OU_Name
  48. {
  49. get { return _OU_Name; }
  50. }
  51. #region IPrincipal 成员
  52. public IIdentity Identity
  53. {
  54. get { return iIdentity; }
  55. }
  56. public bool IsInRole(string UserName)
  57. {
  58. if (!string.IsNullOrEmpty(UserName))
  59. {
  60. return true;
  61. }
  62. else
  63. {
  64. return false;
  65. }
  66. }
  67. #endregion
  68. }
  69. }