internal override void DeleteRoles(string user, DbProviderFactory factory, DbConnection connection) { DbCommand command = DatabaseBase.GetCommand(connection); List <string> strs = new List <string>(); string[] database = new string[] { "SELECT sysusers1.name AS [role] FROM dbo.sysmembers sysmembers INNER JOIN dbo.sysusers sysusers1 ON sysmembers.groupuid = sysusers1.uid inner join ", connection.Database, "..sysusers sysusers2 ON sysmembers.memberuid = sysusers2.uid WHERE sysusers2.name = '", user, "'" }; using (DbDataReader dbDataReaders = base.ExecuteReader(string.Concat(database), command)) { while (dbDataReaders.Read()) { strs.Add(dbDataReaders.GetString(0)); } } foreach (string str in strs) { try { string[] strArrays = new string[] { "sp_droprolemember '", str, "','", user, "'" }; base.ExecuteNoneQuery(string.Concat(strArrays), command); } catch (Exception exception) { throw exception; } } }
public void Logout(string ssoLoginUsr) { ssoLoginUsr = ssoLoginUsr.Trim(); //string securityGateWayServer = this.SecurityGateWayServer; //object[] objArray = new object[] { "aMethodName=getDataBaseServerAssociations&aLoginID=", user, "&aSystemID=", this.ApplicationID, "&userIP=", this.GetIPAddress(), "&aUseSessionDBUser=true&aAgentVersion=SGLibraryNET_5.5" }; //string str = this.Request(securityGateWayServer, string.Concat(objArray)); //if (string.IsNullOrEmpty(str)) //{ // throw new Exception("Error leyendo la información de SG al efectuar 'getDataBaseServerAssociations'."); //} UserDTO userDTO = requestLogoutUser(ssoLoginUsr); this.ReturnCode = int.Parse(userDTO.ReturnCode); LOG.grabarLog(String.Format("BxSG - ReturnCode: {0}", ReturnCode)); LOG.grabarLog("BxSG - Comienza proceso de cierre de sesión por DB"); if (userDTO.DbInfo != null) { for (int i = 0; i < (int)userDTO.DbInfo.Length; i++) { DatabaseBase databaseBase = DatabaseFactory.Create(userDTO.DbInfo[i]); if (databaseBase != null) { if (userDTO.CSCredUser == null || userDTO.CSCredUser.Length <= 0) { databaseBase.RemoveUser(userDTO.DbInfo[i], ssoLoginUsr, false); } else { databaseBase.RemoveUser(userDTO.DbInfo[i], userDTO.CSCredUser, true); } } } for (int j = 0; j < (int)userDTO.DbInfo.Length; j++) { DatabaseBase databaseBase1 = DatabaseFactory.Create(userDTO.DbInfo[j]); if (databaseBase1 != null) { if (userDTO.CSCredUser == null || userDTO.CSCredUser.Length <= 0) { databaseBase1.RemoveLogin(userDTO.DbInfo[j], ssoLoginUsr); } else { databaseBase1.RemoveLogin(userDTO.DbInfo[j], userDTO.CSCredUser); } } } LOG.grabarLog("BxSG - ÉXITO: Finaliza el proceso de cierre de sesión por DB"); } else { LOG.grabarLog("BxSG - Error userDTO.DbInfo is null"); } }
internal void RemoveUser(DBInfoDTO dmInfoDto, string user, bool all) { DbProviderFactory providerFactory = this.GetProviderFactory(); using (DbConnection connectionString = providerFactory.CreateConnection()) { connectionString.ConnectionString = this.GetConnectionString(dmInfoDto); connectionString.Open(); this.DeleteUser(user, dmInfoDto, providerFactory, DatabaseBase.GetCommand(connectionString)); } }
internal override void AddUserInDB(string user, string password, string[] roles, DbProviderFactory factory, DbConnection connection) { DbCommand command = DatabaseBase.GetCommand(connection); try { base.ExecuteNoneQuery(string.Format("sp_addlogin '{0}', '{1}'", user, password), command); } catch (SqlException sqlException) { if (sqlException.Number != 15025) { throw; } } string serverVersion = connection.ServerVersion; try { serverVersion.CompareTo("09.00.00.0"); } catch (SqlException sqlException1) { throw sqlException1; } try { base.ExecuteNoneQuery(string.Format("sp_adduser '{0}'", user), command); } catch (SqlException sqlException2) { if (sqlException2.Number != 15023) { throw; } } if (roles != null) { string[] strArrays = roles; for (int i = 0; i < (int)strArrays.Length; i++) { string str = strArrays[i]; if (string.Compare(str, "public", true) != 0) { base.ExecuteNoneQuery(string.Format("sp_addrolemember '{0}', '{1}'", str, user), command); } } } base.ExecuteNoneQuery(string.Format("sp_password null,'{0}','{1}'", password, user), command); }
public void LogoutBx(string user) { user = user.Trim(); string securityGateWayServer = this.SecurityGateWayServer; object[] objArray = new object[] { "aMethodName=getDataBaseServerAssociations&aLoginID=", user, "&aSystemID=", this.ApplicationID, "&userIP=", this.GetIPAddress(), "&aUseSessionDBUser=true&aAgentVersion=SGLibraryNET_5.5" }; string str = this.Request(securityGateWayServer, string.Concat(objArray)); if (string.IsNullOrEmpty(str)) { throw new Exception("Error leyendo la información de SG al efectuar 'getDataBaseServerAssociations'."); } UserDTO userDTO = new UserDTO(); this.ReturnCode = int.Parse(userDTO.ReturnCode); if (userDTO.DbInfo != null) { for (int i = 0; i < (int)userDTO.DbInfo.Length; i++) { DatabaseBase databaseBase = DatabaseFactory.Create(userDTO.DbInfo[i]); if (databaseBase != null) { if (userDTO.CSCredUser == null || userDTO.CSCredUser.Length <= 0) { databaseBase.RemoveUser(userDTO.DbInfo[i], user, false); } else { databaseBase.RemoveUser(userDTO.DbInfo[i], userDTO.CSCredUser, true); } } } for (int j = 0; j < (int)userDTO.DbInfo.Length; j++) { DatabaseBase databaseBase1 = DatabaseFactory.Create(userDTO.DbInfo[j]); if (databaseBase1 != null) { if (userDTO.CSCredUser == null || userDTO.CSCredUser.Length <= 0) { databaseBase1.RemoveLogin(userDTO.DbInfo[j], user); } else { databaseBase1.RemoveLogin(userDTO.DbInfo[j], userDTO.CSCredUser); } } } } }
internal void RemoveLogin(DBInfoDTO dmInfoDto, string user) { try { DbProviderFactory providerFactory = this.GetProviderFactory(); using (DbConnection connectionString = providerFactory.CreateConnection()) { connectionString.ConnectionString = this.GetConnectionString(dmInfoDto); connectionString.Open(); this.Kill(user, connectionString); this.DeleteLogin(user, dmInfoDto, providerFactory, DatabaseBase.GetCommand(connectionString)); } } catch { } }
private void AddUser(UserDTO user) { DBInfoDTO[] dbInfo = user.DbInfo; for (int i = 0; i < (int)dbInfo.Length; i++) { DBInfoDTO dBInfoDTO = dbInfo[i]; try { //this._SGAdminPassword = dBInfoDTO.DatabasePassword; DatabaseBase databaseBase = DatabaseFactory.Create(dBInfoDTO); if (databaseBase != null) { databaseBase.AddUser(dBInfoDTO, user.CSCredUser); } } catch (Exception exception1) { Exception exception = exception1; object[] server = new object[] { dBInfoDTO.Server, dBInfoDTO.ServerPortNo, dBInfoDTO.DatabaseInstance, exception.Message }; throw new ApplicationException(string.Format("Error al crear usuario en {0}:{1}/{2}. {3}", server), exception); } } }