Наследование: System.MarshalByRefObject, IIdentity
Пример #1
0
 /// <summary>
 /// Creates a new instance of an identity, but impersonated by the specified user.
 /// </summary>
 /// <param name="userID">The unique identity of the user to impersonate.</param>
 /// <param name="name">The name of the user to impersonate.</param>
 /// <param name="impersonator">The impersonator's authenticated identity.</param>
 public UserIdentity(Guid userID, string name, UserIdentity impersonator)
 {
     while (impersonator.ImpersonatorIdentity != null) // should be max 1 level deep
         impersonator = impersonator.ImpersonatorIdentity; //don't impersonate multiple levels deep.
     if (impersonator == null || !impersonator.IsAuthenticated || impersonator.Ticket == null ||
         impersonator.Ticket.UserSession == null || impersonator.Ticket.UserSession.ExpirationDate < DateTime.UtcNow)
         throw new ApplicationException("You cannot impersonate at this time, because your session has ended.");
     Ticket = new AuthenticationHistory
                  {
                      CreatedDate = DateTime.Now,
                      IPAddress = impersonator.Ticket.IPAddress,
                      IsAuthenticated = impersonator.Ticket.IsAuthenticated,
                      UserName = name,
                      SessionID = impersonator.Ticket.SessionID,
                      UserSession =
                          new UserSession
                              {
                                  CreatedDate = DateTime.Now,
                                  ExpirationDate = impersonator.Ticket.UserSession.ExpirationDate,
                                  RenewalToken = impersonator.Ticket.UserSession.RenewalToken,
                                  RenewedDate = impersonator.Ticket.UserSession.RenewedDate,
                                  SessionID = impersonator.Ticket.SessionID,
                                  UserID = userID
                              }
                  };
     ImpersonatorIdentity = impersonator;
 }
Пример #2
0
 /// <summary>
 /// Creates a principal from another identity
 /// </summary>
 public UserPrincipal(UserIdentity identity)
 {
     Identity = identity;
 }
Пример #3
0
 /// <summary>
 /// Creates an anonymous principal
 /// </summary>
 public UserPrincipal()
 {
     Identity = new UserIdentity();
 }