Yair Zaslavsky has uploaded a new change for review. Change subject: core: Moving Initializing code to InitBackendServiceOnStartup ......................................................................
core: Moving Initializing code to InitBackendServiceOnStartup The following moves some of the UsersDomainsCacheManageService initialization code to the InitOnStartup service. In the future, this code will move into the ExtensionManager that will be responsible for initializing "legacy" extensions (ldap/kerberos Authenticators and Directories). Change-Id: I5629d27f2bd7bd2f8ba88279e817c3b40e72c5bf Signed-off-by: Yair Zaslavsky <yzasl...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/UsersDomainsCacheManagerService.java 2 files changed, 91 insertions(+), 84 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/48/25448/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java index 6bdcdb3..e3a0490 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java @@ -1,7 +1,10 @@ package org.ovirt.engine.core.bll; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.EnumMap; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; @@ -17,6 +20,7 @@ import org.ovirt.engine.core.aaa.Directory; import org.ovirt.engine.core.aaa.provisional.ProvisionalAuthenticator; import org.ovirt.engine.core.aaa.provisional.ProvisionalDirectory; +import org.ovirt.engine.core.bll.adbroker.LDAPSecurityAuthentication; import org.ovirt.engine.core.bll.adbroker.LdapBrokerUtils; import org.ovirt.engine.core.bll.adbroker.UsersDomainsCacheManagerService; import org.ovirt.engine.core.bll.dwh.DwhHeartBeat; @@ -29,7 +33,11 @@ import org.ovirt.engine.core.bll.storage.StoragePoolStatusHandler; import org.ovirt.engine.core.common.action.MigrateVmParameters; import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.config.Config; +import org.ovirt.engine.core.common.config.ConfigValues; +import org.ovirt.engine.core.common.utils.EnumUtils; import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.generic.DomainsPasswordMap; import org.ovirt.engine.core.extensions.mgr.Extension.ExtensionProperties; import org.ovirt.engine.core.utils.customprop.DevicePropertiesUtils; import org.ovirt.engine.core.utils.customprop.VmPropertiesUtils; @@ -86,7 +94,10 @@ AuthenticationProfileRepository.getInstance(); - UsersDomainsCacheManagerService.getInstance().init(); + UsersDomainsCacheManagerService.getInstance().init(fillLdapServersMap(), + fillLdapSecurityAuthenticationMap(), + fillUsersMap(), + fillPasswordsMap()); AsyncTaskManager.getInstance().initAsyncTaskManager(); ResourceManager.getInstance().init(); OvfDataUpdater.getInstance().initOvfDataUpdater(); @@ -134,4 +145,75 @@ new DwhHeartBeat().init(); } + private Map<String, List<URI>> fillLdapServersMap() { + Map<String, List<URI>> ldapServerPerDomain = new HashMap<String, List<URI>>(); + String ldapServerPerDomainEntry = Config.<String> getValue(ConfigValues.LdapServers); + + if (!ldapServerPerDomainEntry.isEmpty()) { + String[] domainServerPairs = ldapServerPerDomainEntry.split(","); + int ldapPort = Config.<Integer> getValue(ConfigValues.LDAPServerPort); + + for (String domainServerPair : domainServerPairs) { + String[] parts = domainServerPair.split(":"); + String domain = parts[0].trim().toLowerCase(); + URI ldapURI = null; + + try { + String[] ldapServers = parts[1].trim().split(";"); + List<URI> uris = new ArrayList<URI>(); + for (String ldapServer : ldapServers) { + ldapURI = new URI("ldap://" + ldapServer.trim() + ":" + ldapPort); + uris.add(ldapURI); + } + } catch (URISyntaxException e) { + log.error(String.format("Failed constructing LDAP server URL for domain %1$s", domain)); + } + } + } + return ldapServerPerDomain; + } + + // This code is the exact code as in SysprepHandler, until we have a suitable location that them both can + // use + // Note that every change in one will probably require the same change in the other + private Map<String, String> fillUsersMap() { + String userPerDomainEntry = Config.<String> getValue(ConfigValues.AdUserName); + Map<String, String> userPerDomain = new HashMap<>(); + if (!userPerDomainEntry.isEmpty()) { + String[] domainUserPairs = userPerDomainEntry.split(","); + + for (String domainUserPair : domainUserPairs) { + String[] parts = domainUserPair.split(":"); + String domain = parts[0].trim().toLowerCase(); + String userName = parts[1].trim(); + userPerDomain.put(domain, userName); + } + } + return userPerDomain; + } + + private Map<String, String> fillPasswordsMap() { + return Config.<DomainsPasswordMap> getValue(ConfigValues.AdUserPassword); + } + + private Map<String, LDAPSecurityAuthentication> fillLdapSecurityAuthenticationMap() { + + Map<String, LDAPSecurityAuthentication> map = new HashMap<>(); + String ldapSecurityAuthEntry = Config.<String> getValue(ConfigValues.LDAPSecurityAuthentication); + if (!ldapSecurityAuthEntry.isEmpty()) { + String[] ldapSecurityPairs = ldapSecurityAuthEntry.split(","); + + for (String ldapSecurityPair : ldapSecurityPairs) { + String[] parts = ldapSecurityPair.split(":"); + String domain = parts[0].trim().toLowerCase(); + String authModeStr = parts[1].trim().toUpperCase(); + LDAPSecurityAuthentication authMode = + EnumUtils.valueOf(LDAPSecurityAuthentication.class, authModeStr, true); + + map.put(domain, authMode); + } + } + return map; + } + } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/UsersDomainsCacheManagerService.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/UsersDomainsCacheManagerService.java index 6e36d64..4de3792 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/UsersDomainsCacheManagerService.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/UsersDomainsCacheManagerService.java @@ -2,7 +2,6 @@ import java.net.URI; import java.net.URISyntaxException; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -13,8 +12,6 @@ import org.ovirt.engine.core.common.businessentities.LdapGroup; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; -import org.ovirt.engine.core.common.utils.EnumUtils; -import org.ovirt.engine.core.dal.dbbroker.generic.DomainsPasswordMap; import org.ovirt.engine.core.ldap.LdapProviderType; import org.ovirt.engine.core.ldap.LdapSRVLocator; import org.ovirt.engine.core.utils.dns.DnsSRVLocator.DnsSRVResult; @@ -23,13 +20,6 @@ import org.ovirt.engine.core.utils.log.Log; import org.ovirt.engine.core.utils.log.LogFactory; - -// Here we use a Singleton bean -// The @Startup annotation is to make sure the bean is initialized on startup. -// @ConcurrencyManagement - we use bean managed concurrency: -// Singletons that use bean-managed concurrency allow full concurrent access to all the -// business and timeout methods in the singleton. -// The developer of the singleton is responsible for ensuring that the state of the singleton is synchronized across all clients. // The @DependsOn annotation is in order to make sure it is started after the stated beans are initialized public class UsersDomainsCacheManagerService implements UsersDomainsCacheManager { @@ -53,76 +43,11 @@ private static volatile UsersDomainsCacheManagerService instance = null; - private void fillLdapServersMap() { - String ldapServerPerDomainEntry = Config.<String> getValue(ConfigValues.LdapServers); - if (!ldapServerPerDomainEntry.isEmpty()) { - String[] domainServerPairs = ldapServerPerDomainEntry.split(","); - int ldapPort = Config.<Integer> getValue(ConfigValues.LDAPServerPort); - for (String domainServerPair : domainServerPairs) { - String[] parts = domainServerPair.split(":"); - String domain = parts[0].trim().toLowerCase(); - URI ldapURI; - - try { - String[] ldapServers = parts[1].trim().split(";"); - List<URI> uris = ldapServerPerDomain.get(domain); - if (uris == null) { - uris = new ArrayList<URI>(); - ldapServerPerDomain.put(domain, uris); - } - for (String ldapServer : ldapServers) { - ldapURI = new URI("ldap://" + ldapServer.trim() + ":" + ldapPort); - uris.add(ldapURI); - } - } catch (URISyntaxException e) { - log.errorFormat("Failed constructing LDAP server URL for domain {0}", domain); - } - } - } - } - - // This code is the exact code as in SysprepHandler, until we have a suitable location that them both can - // use - // Note that every change in one will probably require the same change in the other - private void fillUsersMap() { - String userPerDomainEntry = Config.<String> getValue(ConfigValues.AdUserName); - if (!userPerDomainEntry.isEmpty()) { - String[] domainUserPairs = userPerDomainEntry.split(","); - - for (String domainUserPair : domainUserPairs) { - String[] parts = domainUserPair.split(":"); - String domain = parts[0].trim().toLowerCase(); - String userName = parts[1].trim(); - - userPerDomain.put(domain, userName); - } - } - } - - private void fillPasswordsMap() { - passwordPerDomain = Config.<DomainsPasswordMap> getValue(ConfigValues.AdUserPassword); - } - - private void fillLdapSecurityAuthenticationMap() { - - String ldapSecurityAuthEntry = Config.<String> getValue(ConfigValues.LDAPSecurityAuthentication); - if (!ldapSecurityAuthEntry.isEmpty()) { - String[] ldapSecurityPairs = ldapSecurityAuthEntry.split(","); - - for (String ldapSecurityPair : ldapSecurityPairs) { - String[] parts = ldapSecurityPair.split(":"); - String domain = parts[0].trim().toLowerCase(); - String authModeStr = parts[1].trim().toUpperCase(); - LDAPSecurityAuthentication authMode = - EnumUtils.valueOf(LDAPSecurityAuthentication.class, authModeStr, true); - - ldapSecurityAuthenticationPerDomain.put(domain, authMode); - } - } - } - - public void init() { + public void init(Map<String, List<URI>> ldapServersPerDomainMap, + Map<String, LDAPSecurityAuthentication> ldapSecurityAuthenticationMap, + Map<String, String> userMap, + Map<String, String> passwordMap) { log.info("Start initializing " + getClass().getSimpleName()); String authMethod = Config.<String> getValue(ConfigValues.AuthenticationMethod); @@ -131,10 +56,10 @@ } List<String> domains = LdapBrokerUtils.getDomainsList(true); Map<String, LdapProviderType> domainLDAPProviders = parseLDAPProviders(); - fillLdapServersMap(); - fillLdapSecurityAuthenticationMap(); - fillUsersMap(); - fillPasswordsMap(); + ldapServerPerDomain = ldapServersPerDomainMap; + ldapSecurityAuthenticationPerDomain = ldapSecurityAuthenticationMap; + userPerDomain = userMap; + passwordPerDomain = passwordMap; for (String domainName : domains) { domainName = domainName.toLowerCase(); -- To view, visit http://gerrit.ovirt.org/25448 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5629d27f2bd7bd2f8ba88279e817c3b40e72c5bf Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Yair Zaslavsky <yzasl...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches