/// <summary> /// Elimina un utente in amministrazione /// </summary> /// <param name="utente"></param> /// <returns></returns> public EsitoOperazione EliminaUtenteAmm(OrgUtente utente) { EsitoOperazione ret = new EsitoOperazione(); string logMsg; IObjectService objSrvc = null; String repositoryName = DctmConfigurations.GetRepositoryName(); // test sui campi obbligatori if (string.IsNullOrEmpty(utente.UserId)) { logMsg = ERR_HEADER + "EliminaUtente: dati insufficienti"; ret.Codice = -1; ret.Descrizione = logMsg; logger.Debug(logMsg); return(ret); } try { // verifica se esistono più di un'occorrenza per utente if (CountGroupsByUser(utente.UserId) > 1) { // rimuove l'utente dal gruppo di root EliminaUtenteDaRuoloAmm(utente.UserId, utente.IDAmministrazione); } else { ObjectIdentitySet identitySet = new ObjectIdentitySet(); objSrvc = this.GetObjectServiceInstance(); ObjectIdentity userIdentity = Dfs4DocsPa.getUserIdentityByName(TypeUtente.getUserName(utente)); // Cancellazione dell'home cabinet per l'utente identitySet.AddIdentity(Dfs4DocsPa.getUserHomeFolderIdentity(utente.UserId)); identitySet.AddIdentity(userIdentity); OperationOptions opts = new OperationOptions(); opts.DeleteProfile = new DeleteProfile(); opts.DeleteProfile.IsPopulateWithReferences = true; objSrvc.Delete(identitySet, opts); logger.Debug(DEBUG_HEADER + "EliminaUtente completata con SUCCESSO"); } return(ret); } catch (Exception ex) { String st = ex.ToString(); logger.Debug(DEBUG_HEADER + "EliminaUtente FALLITA, Exception=" + st); ret.Codice = -1; ret.Descrizione = ERR_HEADER + "EliminaUtente"; return(ret); } }
/// <summary> /// Modifica password utente /// </summary> /// <param name="oldPassword"/></param> /// <param name="user"></param> ///// <returns></returns> public ValidationResultInfo ChangeUserPwd(DocsPaVO.utente.UserLogin user, string oldPassword) { ValidationResultInfo retValue = new ValidationResultInfo(); try { // La password deve essere modificata con le credenziali di superuser IObjectService objectService = DctmServiceFactory.GetServiceInstance <IObjectService>(UserManager.ImpersonateSuperUser()); ObjectIdentity identity = Dfs4DocsPa.getUserIdentityByName(TypeUtente.NormalizeUserName(user.UserName)); DataObject userDataObject = new DataObject(identity, ObjectTypes.UTENTE); userDataObject.Properties.Set <string>("user_password", user.Password); DataPackage dataPackage = new DataPackage(userDataObject); dataPackage = objectService.Update(dataPackage, null); retValue.Value = (dataPackage.DataObjects.Count > 0); if (!retValue.Value) { throw new ApplicationException("Password non aggiornata"); } else { RepositoryIdentity newIdentity = DctmRepositoryIdentityHelper.GetIdentity(DctmConfigurations.GetRepositoryName(), user.UserName, user.Password, string.Empty); user.DST = DctmRepositoryIdentityHelper.CreateAuthenticationToken(newIdentity); logger.Debug(string.Format("Documentum.ChangePassword: password modificata per l'utente {0}", user.UserName)); } } catch (Exception ex) { logger.Debug(string.Format("Errore in Documentum.ChangePassword:\n{0}", ex.ToString())); retValue.BrokenRules.Add(new BrokenRule("ChangePassword_ERROR", "Errore nella modifica della password per il documentale DOCUMENTUM", DocsPaVO.Validations.BrokenRule.BrokenRuleLevelEnum.Error)); } retValue.Value = (retValue.BrokenRules.Count == 0); return(retValue); }
private bool undoCreateUser(OrgUtente utente) { try { ObjectIdentity userIdentity = Dfs4DocsPa.getUserIdentityByName(TypeUtente.getUserName(utente)); ObjectIdentitySet idSet = new ObjectIdentitySet(userIdentity); IObjectService objSrvc = this.GetObjectServiceInstance(); objSrvc.Delete(idSet, null); return(true); } catch (Exception ex) { //se siamo arrivati qui, significa che siamo già in una condizione di errore //se si verifica un'eccezione qui, siamo nei guai: non riusciamo a fare un clean //in ogni caso è inutile rilanciare l'eccezione: già il chiamante è in gestione di una ecc. logger.Debug(DEBUG_HEADER + "GRAVE: impossibile annullare l'inserimento utente"); return(false); } }
/////// <summary> /////// Reperimento di tutti gli utenti dell'amministrazione /////// </summary> /////// <param name="infoUtente"></param> /////// <param name="amministrazione"></param> /////// <returns></returns> ////private static string[] GetUtenti(InfoAmministrazione amm) ////{ //// List<string> list = new List<string>(); //// using (DocsPaDB.DBProvider dbProvider = new DocsPaDB.DBProvider()) //// { //// string commandText = string.Format("SELECT user_id FROM PEOPLE WHERE id_amm = {0}", amm.IDAmm); //// using (System.Data.IDataReader reader = dbProvider.ExecuteReader(commandText)) //// { //// while (reader.Read()) //// { //// list.Add(DocsPaUtils.Data.DataReaderHelper.GetValue<string>(reader, "user_id", false)); //// } //// } //// } //// return list.ToArray(); ////} /// <summary> /// Cancellazione di un'amministrazione nel documentale. /// NB: L'operazione di rimozione deve essere effettuata con le credenziali /// dell'utente superuser /// </summary> /// <param name="info"></param> /// <param name="ruoliAmministrazione"> /// Ruoli docspa da rimuovere in documentum /// </param> /// <returns></returns> public EsitoOperazione Delete(InfoAmministrazione info, string[] ruoliAmministrazione) { logger.Debug(string.Format("Documentum.DeleteAmministrazione: inizio rimozione amministrazione. Codice: '{0}'", info.Codice)); EsitoOperazione retValue = new EsitoOperazione(); try { ObjectIdentitySet identitySet = new ObjectIdentitySet(); // Reperimento degli oggetti Identity relativi a tutti i gruppi e gli utenti dell'amministrazione IQueryService queryService = DctmServiceFactory.GetServiceInstance <IQueryService>(this.InfoUtente.dst); string[] users = Dfs4DocsPa.getUsersSystemGroup(info.Codice, queryService); // Cancellazione di tutti gli utenti legati al cabinet / amministrazione foreach (string userId in users) { string normalizedUserId = TypeUtente.NormalizeUserName(userId); // Reperimento oggetto identity per ogni utente identitySet.AddIdentity(Dfs4DocsPa.getUserIdentityByName(normalizedUserId)); // Cancellazione dell'home cabinet per ogni 'utente identitySet.AddIdentity(Dfs4DocsPa.getUserHomeFolderIdentity(normalizedUserId)); logger.Debug(string.Format("Documentum.DeleteAmministrazione: rimozione utente '{0}'", normalizedUserId)); } //foreach (string userId in GetUtenti(info)) //{ // string normalizedUserId = TypeUtente.NormalizeUserName(userId); // ObjectIdentity id = Dfs4DocsPa.getUserIdentityByName(normalizedUserId, queryService); // if (id != null) // { // identitySet.AddIdentity(id); // // Cancellazione dell'home cabinet per ogni 'utente // identitySet.AddIdentity(Dfs4DocsPa.getUserHomeFolderIdentity(normalizedUserId)); // } //} // Cancellazione del ruolo di sistema dell'amministrazione ObjectIdentity identity = Dfs4DocsPa.getSystemGroupIdentity(info.Codice, queryService); if (identity != null) { identitySet.AddIdentity(identity); } // Cancellazione del ruolo di sistema degli amministratori dell'amministrazione identity = Dfs4DocsPa.getAmmSystemGroupIdentity(info.Codice, queryService); if (identity != null) { identitySet.AddIdentity(identity); } // Cancellazione di tutti gli gruppi legati al cabinet / amministrazione foreach (string docspaGroupName in ruoliAmministrazione) { string normalizedGroupName = TypeGruppo.NormalizeGroupName(docspaGroupName); ObjectIdentity groupIdentity = Dfs4DocsPa.getGroupIdentityByName(normalizedGroupName, queryService); if (groupIdentity != null) { identitySet.AddIdentity(groupIdentity); logger.Debug(string.Format("Documentum.DeleteAmministrazione: rimozione ruolo '{0}'", normalizedGroupName)); } } // Reperimento oggetto Identity relativamente al cabinet da rimuovere identitySet.AddIdentity(Dfs4DocsPa.getCabinetIdentity(info.Codice)); OperationOptions opts = new OperationOptions(); opts.DeleteProfile = this.CreateDeleteProfile(); IObjectService objectService = this.GetObjectServiceInstance(); objectService.Delete(identitySet, opts); logger.Debug(string.Format("Documentum.DeleteAmministrazione: rimozione amministrazione. Codice: '{0}'", info.Codice)); // Cancellazione di tutte le ACL create per gli oggetti dell'amministrazione this.DeleteAcl(info); logger.Debug(string.Format("Documentum.DeleteAmministrazione: rimozione ACL amministrazione. Codice: '{0}'", info.Codice)); } catch (Exception ex) { logger.Debug(string.Format("Errore in Documentum.DeleteAmministrazione:\n{0}", ex.ToString())); retValue.Codice = -1; retValue.Descrizione = string.Format("Errore nella rimozione del cabinet {0} in Documentum", info.Codice); } return(retValue); }
/// <summary> /// Modifica dei dati di un utente in amministrazione /// </summary> /// <param name="utente"></param> /// <returns></returns> public EsitoOperazione ModificaUtente(OrgUtente utente) { EsitoOperazione ret = new EsitoOperazione(); string logMsg = string.Empty; IObjectService objSrvc = null; IQueryService qrySvc = null; string repositoryName = DctmConfigurations.GetRepositoryName(); bool wasSysAdmin = false; bool isSysAdmin = false; string gruppoSysAdm; string codiceAmm; // test sui campi obbligatori if (string.IsNullOrEmpty(utente.Codice) || string.IsNullOrEmpty(utente.Email) || string.IsNullOrEmpty(utente.IDPeople) || string.IsNullOrEmpty(utente.UserId)) { logMsg = ERR_HEADER + "ModificaUtente: dati insufficienti"; ret.Codice = -1; ret.Descrizione = logMsg; logger.Debug(logMsg); return(ret); } try { objSrvc = this.GetObjectServiceInstance(); qrySvc = this.GetQueryServiceInstance(); ObjectIdentity userIdentity = Dfs4DocsPa.getUserIdentityByName(TypeUtente.getUserName(utente)); // non è possibile cambiare il nome di un utente List <string> filters = new List <string>(); filters.Add("user_name"); DataObject oldData = DfsHelper.getAllPropsAndFolders(objSrvc, userIdentity, filters, false); Property oldName = oldData.Properties.Get("user_name"); if (oldName == null) { ret.Codice = -1; logMsg = ERR_HEADER + "ModificaUtente: impossibile leggere il vecchio nome dell'utente"; ret.Descrizione = logMsg; logger.Debug(logMsg); return(ret); } if (!oldName.GetValueAsString().Equals(utente.UserId, StringComparison.OrdinalIgnoreCase)) { ret.Codice = -1; logMsg = ERR_HEADER + "ModificaUtente: non è possibile modificare il nome dell'utente"; ret.Descrizione = logMsg; logger.Debug(logMsg); return(ret); } // dobbiamo capire se prima dell'update era sysAdmin oppure no codiceAmm = DocsPaQueryHelper.getCodiceAmministrazione(utente.IDAmministrazione); gruppoSysAdm = TypeGruppo.GetGroupNameForSysAdminAmministrazione(codiceAmm); wasSysAdmin = DfsHelper.isUserMemberOf(TypeUtente.getUserName(utente), gruppoSysAdm, qrySvc); isSysAdmin = (utente.Amministratore != null && utente.Amministratore != "0"); // verifico se sia stata modificata la password o meno // if (!string.IsNullOrEmpty(utente.Password)) // { // eliminato controllo su presenza password, gli altri dati dell'utente devono essere modificati // anche senza un cambio password (speriamo almeno..) Necessario per replicare stato attivazione rispetto a docspa. // il campo password non viene passato se non è valorizzato DataObject userData = new DataObject(userIdentity, ObjectTypes.UTENTE); // Reperimento properties utente userData.Properties.Properties.AddRange(Dfs4DocsPa.getUserProperties(utente)); DataPackage pkg = new DataPackage(userData); pkg = objSrvc.Update(pkg, null); if (pkg.DataObjects.Count > 0) { // eventuale inserimento nel gruppo dei syadmin if (isSysAdmin && !wasSysAdmin) { DfsHelper.insertUserInGroup(TypeUtente.getUserName(utente), gruppoSysAdm, qrySvc); } else if (wasSysAdmin && !isSysAdmin) { DfsHelper.removeUserFromGroup(TypeUtente.getUserName(utente), gruppoSysAdm, qrySvc); } ret.Codice = 0; ret.Descrizione = string.Empty; logger.Debug(DEBUG_HEADER + "ModificaUtente completata con SUCCESSO"); } else { throw new ApplicationException(); } /** } * else * { * ret.Codice = 0; * ret.Descrizione = string.Empty; * * logger.Debug(DEBUG_HEADER + "ModificaUtente completata con SUCCESSO"); * } */ return(ret); } catch (Exception ex) { String st = ex.ToString(); logger.Error(DEBUG_HEADER + "ModificaUtente FALLITA, Exception=" + st); ret.Codice = -1; ret.Descrizione = ERR_HEADER + "ModificaUtente"; return(ret); } }