public void ResetUser(UserIdentity identity, int deviceId, Dictionary<string, object> extendProperties) { this.user = UserPrincipal.FromIdentity(identity, deviceId, extendProperties); }
private static UserPrincipal Parse(string authTicketStr) { if (!String.IsNullOrEmpty(authTicketStr)) { Match match = regexAuthTicket.Match(authTicketStr); if (match.Success) { UserIdentity identity = new UserIdentity(Int32.Parse(match.Groups[1].Value), match.Groups[3].Value.DoTrim(), match.Groups[4].Value, String.IsNullOrEmpty(match.Groups[6].Value) ? 0 : Int32.Parse(match.Groups[6].Value)); identity.Authentication(); return new UserPrincipal(identity); } else { throw new RequestException(800, String.Format("{0} 自定义标头 “{1}” 格式不正确,正确的格式应为 {{UserId}}/{{UserName}}/{{Token}} 或者 {{UserId}}/{{UserName}}/{{Token}}/{{OrgId}}", XMS.Core.WCF.AuthorizationTicketHeader.Name, authTicketStr), null); } } else { return UserPrincipal.Guest; } }
/// <summary> /// 初始化 UserPrincipal 类的新实例。 /// </summary> /// <param name="identity"></param> private UserPrincipal(UserIdentity identity) : this(identity, 0, null) { }
/// <summary> /// 初始化 UserPrincipal 类的新实例。 /// </summary> /// <param name="identity"></param> /// <param name="deviceId"></param> /// <param name="extendProperties"></param> private UserPrincipal(UserIdentity identity, int deviceId, Dictionary<string, object> extendProperties) { if (identity == null) { throw new ArgumentNullException("identity"); } this.identity = identity; this.userAuthorization = this.identity.GetUserAuthorization(); this.roles = this.userAuthorization==null || this.userAuthorization.Roles == null || this.userAuthorization.Roles.Length == 0 ? Empty<string>.HashSet : new HashSet<string>(this.userAuthorization.Roles, StringComparer.InvariantCultureIgnoreCase); this.resources = this.userAuthorization == null || this.userAuthorization.Resources == null || this.userAuthorization.Resources.Length == 0 ? Empty<string>.HashSet : new HashSet<string>(this.userAuthorization.Resources, StringComparer.InvariantCultureIgnoreCase); this.deviceId = deviceId; this.extendProerties = extendProperties; }
/// <summary> /// 从身份标识初始化一个会员身份对象。 /// </summary> /// <param name="identity">身份标识。</param> /// <param name="deviceId">设备 Id。</param> /// <param name="extendProperties">扩展属性。</param> /// <returns>UserPrincipal 对象。</returns> public static UserPrincipal FromIdentity(UserIdentity identity, int deviceId, Dictionary<string, object> extendProperties) { return new UserPrincipal(identity, deviceId, extendProperties); }