private async Task <List <SecurityContractDefaultConfigurationLdapAuthMode> > RetrieveDefaultConfigLdapAuthenticationModes() { var contractLdapAuthModeList = new List <SecurityContractDefaultConfigurationLdapAuthMode>(); List <LdapAuthenticationModeModel> ldapAuthenticationModes = await ldapAuthenticationModeRepository.GetListAsync(includePassword : false); foreach (var ldapAuthMode in ldapAuthenticationModes.OrderBy(o => o.SysPeriod.LowerBound)) { logger.Debug($"Retrieving default configuration contract definition for Ldap Auth Mode [{ldapAuthMode.Name}]."); var contractLdapAuthMode = new SecurityContractDefaultConfigurationLdapAuthMode() { Name = ldapAuthMode.Name, HostName = ldapAuthMode.HostName, Port = ldapAuthMode.Port, IsLdaps = ldapAuthMode.IsLdaps, Account = ldapAuthMode.Account, BaseDn = ldapAuthMode.BaseDn, LdapAttributes = new List <SecurityContractDefaultConfigurationLdapAttributeLink>() }; foreach (var attribute in ldapAuthMode.LdapAttributes.OrderBy(o => o.SysPeriod.LowerBound)) { contractLdapAuthMode.LdapAttributes.Add(new SecurityContractDefaultConfigurationLdapAttributeLink() { UserField = attribute.UserField, LdapField = attribute.LdapField }); } contractLdapAuthModeList.Add(contractLdapAuthMode); } return(contractLdapAuthModeList); }
private async Task ApplyIndividualDefaultLdapAuthMode(SecurityContractDefaultConfigurationLdapAuthMode defaultLdapAuthMode, Guid updatedById) { logger.Debug($"Operating on default ldap auth mode '{defaultLdapAuthMode.Name}'."); var defaultLdapAuthToApply = new LdapAuthenticationModeModel(); bool newLdapAuthMode = false; var existingLdapAuthMode = await ldapAuthenticationModeRepository.GetByNameAsync(defaultLdapAuthMode.Name, false); if (existingLdapAuthMode != null) { logger.Debug($"Default LDAP Auth Mode: '{defaultLdapAuthMode.Name}' already exist. Updating it."); defaultLdapAuthToApply = existingLdapAuthMode; } else { logger.Debug($"Default LDAP Auth Mode: '{defaultLdapAuthMode.Name}' does not exist. Creating it."); newLdapAuthMode = true; } // Map the base components. defaultLdapAuthToApply.Name = defaultLdapAuthMode.Name; defaultLdapAuthToApply.HostName = defaultLdapAuthMode.HostName; defaultLdapAuthToApply.Port = defaultLdapAuthMode.Port; defaultLdapAuthToApply.IsLdaps = defaultLdapAuthMode.IsLdaps; defaultLdapAuthToApply.Account = defaultLdapAuthMode.Account; defaultLdapAuthToApply.Password = string.Empty; defaultLdapAuthToApply.BaseDn = defaultLdapAuthMode.BaseDn; defaultLdapAuthToApply.ChangedBy = updatedById; defaultLdapAuthToApply.LdapAttributes = new List <LdapAuthenticationModeLdapAttributeModel>(); foreach (var attributeToApply in defaultLdapAuthMode.LdapAttributes) { defaultLdapAuthToApply.LdapAttributes.Add(new LdapAuthenticationModeLdapAttributeModel() { UserField = attributeToApply.UserField, LdapField = attributeToApply.LdapField }); } if (newLdapAuthMode) { logger.Debug($"Persisting new Ldap Auth Mode '{defaultLdapAuthMode.Name}' into the database."); await ldapAuthenticationModeRepository.CreateAsync(defaultLdapAuthToApply); } else { logger.Debug($"Updating existing Ldap Auth Mode '{defaultLdapAuthMode.Name}' into the database."); await ldapAuthenticationModeRepository.UpdateAsync(defaultLdapAuthToApply); } }