public override void ProcessImport(String cacheId, String importId, Dictionary <String, Object> config, List <PluginConnectorBaseDeployPackageMapping> fieldMapping) { if (!CheckInputConfig(config, true, Log)) { return; } String lastStep = ""; try { GetLoginToken(config); setUserGrp(config); //List<string> methods = invoker.EnumerateServiceMethods("JiraSoapServiceService"); //A versão atual do JIRA não permite busca dos usuários sem um grupo/role, desta forma vamos utilizar o grupo padrão para listar os usuários //Busca o grupo padrão foreach (String g in defaultGroups) { WebServiceObjectInterface oGroup = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "getGroup", new Object[] { this.loginToken, g }); if ((oGroup.BaseObject != null) && (oGroup.GetType().Name == "RemoteGroup")) { Object[] users = oGroup.GetPropertyValue <Object[]>("users"); foreach (Object c in users) { PluginConnectorBaseImportPackageUser package = new PluginConnectorBaseImportPackageUser(importId); try { package.AddProperty("name", (String)GetPropertyValue(c, "name"), "string"); package.AddProperty("email", (String)GetPropertyValue(c, "email"), "string"); package.AddProperty("fullname", (String)GetPropertyValue(c, "fullname"), "string"); ImportPackageUser(package); } catch { } finally { package.Dispose(); package = null; } } } } //WebServiceObjectInterface oIssue = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "getUser", new Object[] { this.loginToken, "*****@*****.**" }); } catch (Exception ex) { Log(this, PluginLogType.Error, "Erro on import (" + lastStep + "): " + ex.Message + (ex.InnerException != null ? " " + ex.InnerException.Message : "")); Log2(this, PluginLogType.Error, 0, 0, "Erro on import (" + lastStep + "): " + ex.Message + (ex.InnerException != null ? " " + ex.InnerException.Message : ""), ""); throw ex; } }
public override void ProcessDelete(String cacheId, PluginConnectorBaseDeployPackage package, Dictionary <String, Object> config, List <PluginConnectorBaseDeployPackageMapping> fieldMapping) { if (!CheckInputConfig(config, true, Log)) { return; } /* * O JIRA permite a axclusão da conta, porém por questões de auditoria dos chamados a conta será somente desabilitada */ try { GetLoginToken(config); setUserGrp(config); String login = package.login; String email = ""; String container = package.container; foreach (PluginConnectorBasePackageData dt in package.pluginData) { if (dt.dataName.ToLower() == "login") { login = dt.dataValue; } else if (dt.dataName.ToLower() == "email") { email = dt.dataValue; } } if (login == "") { login = package.login; } if (login == "") { Log2(this, PluginLogType.Error, package.entityId, package.identityId, "IAM Login not found in properties list", ""); return; } if (email == "") { Log2(this, PluginLogType.Error, package.entityId, package.identityId, "IAM E-mail not found in properties list", ""); return; } if (container == "") { container = "IAMUsers"; } WebServiceObjectInterface oUser = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "getUser", new Object[] { this.loginToken, email }); if ((oUser == null) || (oUser.BaseObject == null)) { Log2(this, PluginLogType.Warning, package.entityId, package.identityId, "User not found", ""); return; } //Remove de todos os grupos if (oUser.BaseObject != null) { List <String> groups = GetUserGroups(config, email); foreach (String usrG in groups) { try { WebServiceObjectInterface oGrp = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "getGroup", new Object[] { this.loginToken, usrG }); WebServiceObjectInterface tst3 = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "removeUserFromGroup", new Object[] { this.loginToken, oGrp.BaseObject, oUser.BaseObject }); } catch (Exception ex) { Log2(this, PluginLogType.Error, package.entityId, package.identityId, "Error on remove user from group '" + usrG + "' " + ex.Message + (ex.InnerException != null ? " " + ex.InnerException.Message : ""), ""); } } } //O JIRA não permite o bloqueio da conta, a forma encontrada de bloquea-la é trocando a senha package.password = IAM.Password.RandomPassword.Generate(16); ChangePassword(config, email, package.password); ChangeUser(config, email, package.fullName.fullName + (package.locked || package.temp_locked ? " (deleted)" : ""), email); NotityDeletedUser(this, package.entityId, package.identityId); Log2(this, PluginLogType.Information, package.entityId, package.identityId, "User deleted", ""); } catch (Exception ex) { Log2(this, PluginLogType.Error, package.entityId, package.identityId, "Error on process deploy: " + ex.Message + (ex.InnerException != null ? " " + ex.InnerException.Message : ""), ""); } }
public override void ProcessDeploy(String cacheId, PluginConnectorBaseDeployPackage package, Dictionary <String, Object> config, List <PluginConnectorBaseDeployPackageMapping> fieldMapping) { if (!CheckInputConfig(config, true, Log)) { return; } StringBuilder processLog = new StringBuilder(); PluginLogType logType = PluginLogType.Information; try { GetLoginToken(config); setUserGrp(config); String login = package.login; foreach (PluginConnectorBasePackageData dt in package.pluginData) { if (dt.dataName.ToLower() == "login") { login = dt.dataValue; } } if (login == "") { login = package.login; } if (login == "") { logType = PluginLogType.Error; processLog.AppendLine("IAM Login not found in properties list"); Log2(this, PluginLogType.Error, package.entityId, package.identityId, "IAM Login not found in properties list", ""); return; } String email = ""; String container = package.container; //Busca o e-mail nas propriedades específicas da entidade foreach (PluginConnectorBasePackageData dt in package.entiyData) { if ((dt.dataName.ToLower() == "email") && (dt.dataValue.ToLower().IndexOf("@") > 1)) { email = dt.dataValue; } } //Busca o e-mail nas propriedades específicas deste plugin if ((email == null) || (email == "")) { foreach (PluginConnectorBasePackageData dt in package.pluginData) { if ((dt.dataName.ToLower() == "email") && (dt.dataValue.ToLower().IndexOf("@") > 1)) { email = dt.dataValue; } } } //Se não encontrou o e-mail testa nas propriedades maracas como ID if ((email == null) || (email == "")) { foreach (PluginConnectorBasePackageData dt in package.ids) { if ((dt.dataName.ToLower() == "email") && (dt.dataValue.ToLower().IndexOf("@") > 1)) { email = dt.dataValue; } } } //Se não encontrou o e-mail testa nas propriedades gerais if ((email == null) || (email == "")) { foreach (PluginConnectorBasePackageData dt in package.properties) { if ((dt.dataName.ToLower() == "email") && (dt.dataValue.ToLower().IndexOf("@") > 1)) { email = dt.dataValue; } } } if (email == "") { logType = PluginLogType.Error; processLog.AppendLine("IAM E-mail not found in properties list"); Log2(this, PluginLogType.Error, package.entityId, package.identityId, "IAM E-mail not found in properties list", ""); return; } if (container == "") { container = "IAMUsers"; } WebServiceObjectInterface oUser = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "getUser", new Object[] { this.loginToken, email }); if ((oUser == null) || (oUser.BaseObject == null)) { //User not found, create then if ((package.locked) || (package.temp_locked)) { logType = PluginLogType.Error; processLog.AppendLine("User not found in JIRA and user is locked. Accound not created"); Log2(this, PluginLogType.Warning, package.entityId, package.identityId, "User not found in JIRA and user is locked. Accound not created", ""); return; } if (package.password == "") { package.password = IAM.Password.RandomPassword.Generate(16); processLog.AppendLine("User not found in JIRA and IAM Password not found in properties list, creating a random password (" + package.password + ")"); } if ((package.locked) || (package.temp_locked)) { //O JIRA não permite o bloqueio da conta, a forma encontrada de bloquea-la é trocando a senha package.password = IAM.Password.RandomPassword.Generate(16); package.fullName.familyName += " (locked)"; } oUser = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "createUser", new Object[] { this.loginToken, email, package.password, package.fullName.fullName, email }); if ((oUser == null) || (oUser.BaseObject == null)) { logType = PluginLogType.Error; processLog.AppendLine("Unexpected error on add user on JIRA"); Log2(this, PluginLogType.Error, package.entityId, package.identityId, "Unexpected error on add user on JIRA", ""); return; } //Mantem somente os grupos padrões if (oUser.BaseObject != null) { List <String> groups = GetUserGroups(config, email); foreach (String usrG in groups) { Boolean remove = false; if ((package.locked) || (package.temp_locked)) { remove = true; } else if (!defaultGroups.Exists(g => (g.ToLower() == usrG.ToLower()))) { remove = true; } if (remove) //Remove o grupo do usuário { try { WebServiceObjectInterface oGrp = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "getGroup", new Object[] { this.loginToken, usrG }); if (oGrp.BaseObject == null) { processLog.AppendLine("Error on remove user from group '" + usrG + "' group not found"); Log2(this, PluginLogType.Error, package.entityId, package.identityId, "Error on remove user from group '" + usrG + "' group not found", ""); } else { WebServiceObjectInterface tst3 = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "removeUserFromGroup", new Object[] { this.loginToken, oGrp.BaseObject, oUser.BaseObject }); } } catch (Exception ex) { processLog.AppendLine("Error on remove user from group '" + usrG + "' " + ex.Message + (ex.InnerException != null ? " " + ex.InnerException.Message : "")); Log2(this, PluginLogType.Error, package.entityId, package.identityId, "Error on remove user from group '" + usrG + "' " + ex.Message + (ex.InnerException != null ? " " + ex.InnerException.Message : ""), ""); } } } } processLog.AppendLine("User added"); } else { //User found, update if ((package.locked) || (package.temp_locked)) { //O JIRA não permite o bloqueio da conta, a forma encontrada de bloquea-la é trocando a senha package.password = IAM.Password.RandomPassword.Generate(16); processLog.AppendLine("User locked, password temporarily changed to a random password " + package.password); } /* * oUser.SettPropertyValue("email", email); * oUser.SettPropertyValue("fullname", package.fullName.fullName + (package.locked ? " (locked)" : "")); * oUser.SettPropertyValue("name", email);*/ ChangeUser(config, email, package.fullName.fullName + (package.locked || package.temp_locked ? " (locked)" : ""), email); if (!String.IsNullOrWhiteSpace(package.password) && (ChangePassword(config, email, package.password))) { processLog.AppendLine("User updated with password"); } else { processLog.AppendLine("User updated without password"); } } //Verifica e redefine os grupos if (oUser.BaseObject != null) { List <String> groups = GetUserGroups(config, email); //Verifica os grupos padrões foreach (String dfG in defaultGroups) { if ((package.locked) || (package.temp_locked)) { foreach (String usrG in groups) { try { WebServiceObjectInterface oGrp = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "getGroup", new Object[] { this.loginToken, usrG }); WebServiceObjectInterface tst3 = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "removeUserFromGroup", new Object[] { this.loginToken, oGrp.BaseObject, oUser.BaseObject }); } catch (Exception ex) { processLog.AppendLine("Error on remove user from group '" + usrG + "' " + ex.Message + (ex.InnerException != null ? " " + ex.InnerException.Message : "")); Log2(this, PluginLogType.Error, package.entityId, package.identityId, "Error on remove user from group '" + usrG + "' " + ex.Message + (ex.InnerException != null ? " " + ex.InnerException.Message : ""), ""); } } } else if (!groups.Exists(g => (g.ToLower() == dfG.ToLower()))) { //Adiciona o grupo padrão try { WebServiceObjectInterface oGrp = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "getGroup", new Object[] { this.loginToken, dfG }); WebServiceObjectInterface tst3 = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "addUserToGroup", new Object[] { this.loginToken, oGrp.BaseObject, oUser.BaseObject }); } catch (Exception ex) { processLog.AppendLine("Error on add user to group '" + dfG + "': " + ex.Message + (ex.InnerException != null ? " " + ex.InnerException.Message : "")); Log2(this, PluginLogType.Error, package.entityId, package.identityId, "Error on add user to group '" + dfG + "': " + ex.Message + (ex.InnerException != null ? " " + ex.InnerException.Message : ""), ""); } } } NotityChangeUser(this, package.entityId); //Executa as ações do RBAC if ((package.pluginAction != null) && (package.pluginAction.Count > 0)) { foreach (PluginConnectorBaseDeployPackageAction act in package.pluginAction) { try { processLog.AppendLine("Role: " + act.roleName + " (" + act.actionType.ToString() + ") " + act.ToString()); switch (act.actionKey.ToLower()) { case "group": if ((act.actionType == PluginActionType.Add) && (!groups.Exists(g => (g == act.actionValue)))) { WebServiceObjectInterface oGrp = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "getGroup", new Object[] { this.loginToken, act.actionValue }); if (oGrp.BaseObject != null) { try { WebServiceObjectInterface tst3 = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "addUserToGroup", new Object[] { this.loginToken, oGrp.BaseObject, oUser.BaseObject }); processLog.AppendLine("User added in group " + act.actionValue + " by role " + act.roleName); } catch { } } else { processLog.AppendLine("Erro adding in group " + act.actionValue + " by role " + act.roleName + ": Group nor found"); Log2(this, PluginLogType.Information, package.entityId, package.identityId, "Erro adding in group " + act.actionValue + " by role " + act.roleName + ": Group nor found", ""); } } else if ((act.actionType == PluginActionType.Remove) && (groups.Exists(g => (g == act.actionValue)))) { WebServiceObjectInterface oGrp = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "getGroup", new Object[] { this.loginToken, act.actionValue }); if (oGrp.BaseObject != null) { try { WebServiceObjectInterface tst3 = new WebServiceObjectInterface(invoker, "JiraSoapServiceService", "addUserToGroup", new Object[] { this.loginToken, oGrp.BaseObject, oUser.BaseObject }); processLog.AppendLine("User removed in group " + act.actionValue + " by role " + act.roleName); } catch { } } else { processLog.AppendLine("Erro removing in group " + act.actionValue + " by role " + act.roleName + ": Group nor found"); Log2(this, PluginLogType.Information, package.entityId, package.identityId, "Erro removing in group " + act.actionValue + " by role " + act.roleName + ": Group nor found", ""); } } break; default: processLog.AppendLine("Action not recognized: " + act.actionKey); Log2(this, PluginLogType.Warning, package.entityId, package.identityId, "Action not recognized: " + act.actionKey, ""); break; } } catch (Exception ex) { processLog.AppendLine("Error on execute action (" + act.actionKey + "): " + ex.Message); Log2(this, PluginLogType.Error, package.entityId, package.identityId, "Error on execute action (" + act.actionKey + "): " + ex.Message, ""); } } } } } catch (Exception ex) { logType = PluginLogType.Error; processLog.AppendLine("Error on process deploy: " + ex.Message + (ex.InnerException != null ? " " + ex.InnerException.Message : "")); Log2(this, PluginLogType.Error, package.entityId, package.identityId, "Error on process deploy: " + ex.Message + (ex.InnerException != null ? " " + ex.InnerException.Message : ""), ""); } finally { Log2(this, logType, package.entityId, package.identityId, "Deploy executed", processLog.ToString()); processLog.Clear(); processLog = null; } }