public static WriteToEventLog ( |
||
e | ||
action | string | |
Résultat | void |
public void RemoveUserOpenIdLinkByUserId(object userId) { SqlConnection conn = new SqlConnection(_connectionString); SqlCommand cmd = new SqlCommand("OpenId_DeleteUserOpenIdLink", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@ClaimedIdentifier", SqlDbType.NVarChar).Value = DBNull.Value; cmd.Parameters.Add("@userId", SqlDbType.NVarChar).Value = userId.ToString(); try { conn.Open(); cmd.ExecuteNonQuery(); } catch (SqlException e) { if (WriteExceptionsToEventLog) { Utility.WriteToEventLog(e, "LinkUserWithOpenId "); } throw new OpenIdMembershipProviderException("RemoveUserOpenIdLinkByUserId failed.", e); } finally { conn.Close(); } }
public void RemoveUserOpenIdLinkByUserId(object userId) { var conn = new OdbcConnection(_connectionString); var cmd = new OdbcCommand("{call OpenId_DeleteUserOpenIdLink(?)}", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@OpenId_Url", OdbcType.NVarChar).Value = DBNull.Value; cmd.Parameters.Add("@userId", OdbcType.NVarChar).Value = userId.ToString(); try { conn.Open(); cmd.ExecuteNonQuery(); } catch (OdbcException e) { if (WriteExceptionsToEventLog) { Utility.WriteToEventLog(e, "LinkUserWithOpenId "); } throw new OpenIdMembershipProviderException(e.Message, e.Source, e.StackTrace); } finally { conn.Close(); } }
public override bool DeleteUser(string username, bool deleteAllRelatedData) { var conn = new OdbcConnection(_connectionString); var cmd = new OdbcCommand("{call OpenId_DeleteUserOpenIdLink(?)}", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@userId", OdbcType.VarChar, 255).Value = NonOpenIdMembershiProvider.GetUser(username, false).ProviderUserKey.ToString(); try { conn.Open(); cmd.ExecuteNonQuery(); return(NonOpenIdMembershiProvider.DeleteUser(username, deleteAllRelatedData)); } catch (OdbcException e) { if (WriteExceptionsToEventLog) { Utility.WriteToEventLog(e, "DeleteUser"); } throw new OpenIdMembershipProviderException(e.Message, e.Source, e.StackTrace); } finally { conn.Close(); } }
public override bool DeleteUser(string username, bool deleteAllRelatedData) { SqlConnection conn = new SqlConnection(_connectionString); SqlCommand cmd = new SqlCommand("OpenId_DeleteUserOpenIdLink", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@userId", SqlDbType.VarChar, 255).Value = NonOpenIdMembershiProvider.GetUser(username, false).ProviderUserKey.ToString(); try { conn.Open(); cmd.ExecuteNonQuery(); return(NonOpenIdMembershiProvider.DeleteUser(username, deleteAllRelatedData)); } catch (SqlException e) { if (WriteExceptionsToEventLog) { Utility.WriteToEventLog(e, "DeleteUser"); } throw new OpenIdMembershipProviderException("DeleteUser failed.", e); } finally { conn.Close(); } }
public override void Initialize(string name, NameValueCollection config) { try { // Initialize values from web.config. if (config == null) { throw new ArgumentNullException("config"); } if (name == null || name.Length == 0) { name = "OpenIDMembershipProvider"; } if (String.IsNullOrEmpty(config["description"])) { config.Remove("description"); config.Add("description", "OpenID Membership Provider"); } // Initialize the abstract base class. base.Initialize(name, config); _applicationName = Utility.GetConfigValue(config["applicationName"], System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath); _WriteExceptionsToEventLog = Convert.ToBoolean(Utility.GetConfigValue(config["writeExceptionsToEventLog"], "false")); // Initialize the OpenID Attributes _optionalInformation = Utility.GetConfigValue(config["OptionalInformation"], ""); NonOpenIdMemebershipProviderName = Utility.GetConfigValue(config["NonOpenIdMembershipProviderName"], ""); _minutesSinceLastActivity = int.Parse(Utility.GetConfigValue(config["MinutesSinceLastActivity"], "20")); // Initialize the SqlConnection. ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]]; if (ConnectionStringSettings == null || ConnectionStringSettings.ConnectionString.Trim() == "") { throw new ProviderException("Connection string cannot be blank."); } _connectionString = ConnectionStringSettings.ConnectionString; } catch (Exception e) { if (this.WriteExceptionsToEventLog) { Utility.WriteToEventLog(e, "Initialize"); } throw new OpenIdMembershipProviderException(e.Message, e.Source, e.StackTrace); } }
public IList <OpenIdMembershipUser> GetAllOpenIdUsers(out int totalRecords) { var conn = new OdbcConnection(_connectionString); var cmd = new OdbcCommand("{call OpenId_Membership_GetAllUsers(?)}", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@ApplicationName", OdbcType.VarChar, 255).Value = ApplicationName; IList <OpenIdMembershipUser> users = new List <OpenIdMembershipUser>(); OdbcDataReader reader = null; totalRecords = 0; try { conn.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { OpenIdMembershipUser u = GetUserFromReader(reader); users.Add(u); totalRecords++; } } catch (OdbcException e) { if (WriteExceptionsToEventLog) { Utility.WriteToEventLog(e, "GetAllUsers "); throw new ProviderException(EXCEPTION_MESSAGE); } throw new OpenIdMembershipProviderException(e.Message, e.Source, e.StackTrace); } finally { if (reader != null) { reader.Close(); } conn.Close(); } return(users); }
public IList <string> GetOpenIdsByUserName(string userName) { object userId = null; userId = NonOpenIdMembershiProvider.GetUser(userName, false).ProviderUserKey; if (userId == null) { return(null); } IList <string> openIds = new List <string>(); OdbcConnection conn = new OdbcConnection(_connectionString); OdbcCommand cmd = new OdbcCommand("{call OpenId_GetOpenIdsByUserId(?)}", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@userId", OdbcType.NVarChar).Value = userId.ToString(); OdbcDataReader reader; try { conn.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { openIds.Add(reader.GetString(0)); } } catch (OdbcException e) { if (WriteExceptionsToEventLog) { Utility.WriteToEventLog(e, "GetOpenIdsByUserName "); } throw new OpenIdMembershipProviderException(e.Message, e.Source, e.StackTrace); } finally { conn.Close(); } return(openIds); }
public MembershipUser GetUserByOpenId(string openId, bool userIsOnline) { var conn = new OdbcConnection(_connectionString); var cmd = new OdbcCommand("{CALL OpenId_GetUserIdByOpenld(?)}", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("openIdurl", openId); OdbcDataReader reader = null; try { conn.Open(); reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); var userId = new Guid(reader.GetValue(0).ToString()); var temp = userId.ToString(); return(Membership.GetUser(userId, userIsOnline));; } } catch (OdbcException e) { if (WriteExceptionsToEventLog) { Utility.WriteToEventLog(e, "GetUserByOpenId "); } throw new OpenIdMembershipProviderException(e.Message, e.Source, e.StackTrace); } finally { if (reader != null) { reader.Close(); } conn.Close(); } return(null); }
public MembershipUser GetUserByOpenId(string openId, bool userIsOnline) { SqlConnection conn = new SqlConnection(_connectionString); SqlCommand cmd = new SqlCommand("OpenId_GetUserIdByOpenId", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@ClaimedIdentifier", SqlDbType.NVarChar).Value = openId; SqlDataReader reader = null; try { conn.Open(); reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); Guid userId = reader.GetGuid(0); return(NonOpenIdMembershiProvider.GetUser(userId, userIsOnline)); } } catch (SqlException e) { if (WriteExceptionsToEventLog) { Utility.WriteToEventLog(e, "GetUserByOpenId "); } throw new OpenIdMembershipProviderException("GetUserByOpenId failed.", e); } finally { if (reader != null) { reader.Close(); } conn.Close(); } return(null); }
public override bool ValidateUser(string username, string password) { _loginURL = HttpContext.Current.Request.Url.AbsoluteUri; if (string.IsNullOrEmpty(username)) { return(false); } try { var request = consumer.CreateRequest(username); if (request == null) { // Not a valid OpenID. return(false); } // The following illustrates how to use SREG. // TODO: use _optionalInformation contents instead of hard-coding it. request.AddExtension(new ClaimsRequest { Email = DemandLevel.Request, }); // Redirect the user to the OpenID provider Page request.RedirectToProvider(); return(true); // never executed because Redirect throws an exception, but C# requires it. } catch (ProtocolException fexc) { if (WriteExceptionsToEventLog) { Utility.WriteToEventLog(fexc, "ValidateOpenIDUser"); } throw new OpenIdMembershipProviderException("ValidateUser failed.", fexc); } }
public bool ValidateOpenIDUser() { try { var response = consumer.GetResponse(); if (response.Status != AuthenticationStatus.Authenticated) { return(false); } _sreg = response.GetExtension <ClaimsResponse>(); MembershipUser user = GetUserByOpenId(response.ClaimedIdentifier, true); if (user != null) { FormsAuthentication.RedirectFromLoginPage(user.UserName, false); return(true); // never reached, due to redirect } else { throw new OpenIdNotLinkedException(response.ClaimedIdentifier); } } catch (ProtocolException ex) { if (WriteExceptionsToEventLog) { Utility.WriteToEventLog(ex, "ValidateOpenIDUser"); } return(false); } catch (OpenIdNotLinkedException nlEx) { throw nlEx; } }
public bool ValidateOpenIDUser() { bool ret = true; HttpContext Context = HttpContext.Current; HttpSessionState Session = Context.Session; HttpRequest Request = Context.Request; Janrain.OpenId.Consumer.Consumer consumer; try { if (consumerSession == null) { consumerSession = new Janrain.OpenId.Session.SimpleSessionState(); } consumer = new Janrain.OpenId.Consumer.Consumer(consumerSession, Janrain.OpenId.Store.MemoryStore.GetInstance()); } catch { return(false); } if (Request.QueryString["openid.mode"] != null && Request.QueryString["openid.mode"] != "Cancel") { try { _country = (Request.QueryString["openid.sreg.country"] ?? ""); _dayOfBirth = (Request.QueryString["openid.sreg.dob"] ?? ""); _email = (Request.QueryString["openid.sreg.email"] ?? ""); _fullname = (Request.QueryString["openid.sreg.fullname"] ?? ""); _gender = (Request.QueryString["openid.sreg.gender"] ?? ""); _language = (Request.QueryString["openid.sreg.language"] ?? ""); _nickname = (Request.QueryString["openid.sreg.nickname"] ?? ""); _postcode = (Request.QueryString["openid.sreg.postcode"] ?? ""); _timezone = (Request.QueryString["openid.sreg.timezone"] ?? ""); ConsumerResponse resp = consumer.Complete(Request.QueryString); string userIdentity = Utility.IdentityUrlToDisplayString(resp.IdentityUrl); MembershipUser user = GetUserByOpenId(userIdentity, true); ret = (user != null); if (ret) { FormsAuthentication.RedirectFromLoginPage(user.UserName, false); } else { OpenIdNotLinkedException exception = new OpenIdNotLinkedException(userIdentity); throw exception; } } catch (FailureException fexc) { if (WriteExceptionsToEventLog) { Utility.WriteToEventLog(fexc, "ValidateOpenIDUser"); } ret = false; } catch (OpenIdNotLinkedException nlEx) { throw nlEx; } catch (Exception fe) { if (WriteExceptionsToEventLog) { Utility.WriteToEventLog(fe, "ValidateOpenIDUser"); } throw new OpenIdMembershipProviderException(fe.Message, fe.Source, fe.StackTrace); } } else { ret = false; } return(ret); }