/// <summary> /// Initializes a new instance of the <see cref="ClientInfo"/> class. /// </summary> /// <param name="parent">An <see cref="ClientHelper"/> object.</param> public ClientInfo(ClientHelper parent) { m_clientID = Guid.Empty; m_clientType = Common.GetApplicationType(); m_machineName = Environment.MachineName; // Get the user login id. if (!string.IsNullOrEmpty(UserInfo.RemoteUserID)) m_userName = UserInfo.RemoteUserID; else m_userName = UserInfo.CurrentUserID; // Get the type of client application. if (ClientType == ApplicationType.WindowsCui || ClientType == ApplicationType.WindowsGui) m_clientName = AppDomain.CurrentDomain.FriendlyName; else if (ClientType == ApplicationType.Web) m_clientName = HttpContext.Current.Request.ApplicationPath; // Initialize the serialized identity token. m_serializedIdentityToken = string.Empty; if (parent != null && parent.AuthenticationMethod != IdentityToken.None) { SecurityToken token = null; StringWriter stringWriter = new StringWriter(); XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter); SerializableTokenWrapper<SecurityToken> serializer = new SerializableTokenWrapper<SecurityToken>(); try { // Create a token based on the selected method. if (parent.AuthenticationMethod == IdentityToken.Ntlm) { if (!string.IsNullOrEmpty(parent.AuthenticationInput) && parent.AuthenticationInput.Contains(":")) { // Input format: <username>:<password> string[] loginParts = parent.AuthenticationInput.Split(':'); token = new UsernameToken(loginParts[0], loginParts[1], PasswordOption.SendPlainText); } } else if (parent.AuthenticationMethod == IdentityToken.Kerberos) { if (!string.IsNullOrEmpty(parent.AuthenticationInput) && parent.AuthenticationInput.Contains("/")) { // Input format: host/<machine name> token = new KerberosToken(parent.AuthenticationInput, ImpersonationLevel.Impersonation); } } // Serialize the token to XML for transportation. if (token != null) { serializer.WriteToken(xmlTextWriter, token); m_serializedIdentityToken = stringWriter.ToString(); } } catch { // Identity token creation failed due to an exception. } } }
private void OnDeserialized(StreamingContext context) { if (!string.IsNullOrEmpty(SerializedIdentityToken)) { try { // Deserialize the serialized identity token. XmlTextReader xmlTextReader = new XmlTextReader(new StringReader(SerializedIdentityToken)); SerializableTokenWrapper<SecurityToken> deserializer = new SerializableTokenWrapper<SecurityToken>(); xmlTextReader.Read(); m_deserializedIdentityToken = deserializer.ReadToken(xmlTextReader); } catch { // Exception may be encountered when deserializing if authentication fails. } } }