From e8ee54110701b8e64648be5d1f4deb24749a1783 Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Thu, 05 Dec 2013 10:38:37 +0000
Subject: [PATCH] OpenDJ 3 : config framework
---
/dev/null | 353 --------------------------------------------------
opendj-sdk/opendj-admin/src/main/java/org/opends/server/core/DirectoryServer.java | 10 -
2 files changed, 1 insertions(+), 362 deletions(-)
diff --git a/opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/AdministrationConnector.java b/opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/AdministrationConnector.java
deleted file mode 100644
index 60a078c..0000000
--- a/opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/AdministrationConnector.java
+++ /dev/null
@@ -1,791 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2006-2010 Sun Microsystems, Inc.
- * Portions copyright 2011-2013 ForgeRock AS
- */
-package org.opends.server.admin;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.PrintWriter;
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import javax.naming.ldap.Rdn;
-
-import org.opends.server.admin.server.ConfigurationChangeListener;
-import org.opends.server.admin.server.ServerManagementContext;
-import org.opends.server.config.ConfigException;
-import org.opends.server.types.AddressMask;
-import org.opends.server.types.ConfigChangeResult;
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.opendj.admin.server.AdministrationConnectorCfg;
-import org.forgerock.opendj.admin.server.FileBasedKeyManagerProviderCfg;
-import org.forgerock.opendj.admin.server.FileBasedTrustManagerProviderCfg;
-import org.forgerock.opendj.admin.server.KeyManagerProviderCfg;
-import org.forgerock.opendj.admin.server.LDAPConnectionHandlerCfg;
-import org.forgerock.opendj.admin.server.RootCfg;
-import org.forgerock.opendj.admin.server.TrustManagerProviderCfg;
-import org.forgerock.opendj.ldap.DN;
-import org.opends.server.types.InitializationException;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.DirectoryException;
-
-/**
- * This class is a wrapper on top of LDAPConnectionHandler to manage
- * the administration connector, which is an LDAPConnectionHandler
- * with specific (limited) configuration properties.
- */
-public final class AdministrationConnector implements
- ConfigurationChangeListener<AdministrationConnectorCfg>
-{
-
- /**
- * Default Administration Connector port.
- */
- public static final int DEFAULT_ADMINISTRATION_CONNECTOR_PORT = 4444;
-
- /**
- * Validity (in days) of the generated certificate.
- */
- public static final int ADMIN_CERT_VALIDITY = 20 * 365;
-
- // Friendly name of the administration connector
- private static final String FRIENDLY_NAME = "Administration Connector";
-
- // The tracer object for the debug logger.
- private static final DebugTracer TRACER = getTracer();
-
- private LDAPConnectionHandler adminConnectionHandler;
-
- private AdministrationConnectorCfg config; //
-
- // Predefined values for Administration Connector configuration
- //
- private static final String ADMIN_CLASS_NAME =
- "org.opends.server.protocols.ldap.LDAPConnectionHandler";
-
- private static final boolean ADMIN_ALLOW_LDAP_V2 = false;
-
- private static final boolean ADMIN_ALLOW_START_TLS = false;
-
- private static final SortedSet<AddressMask> ADMIN_ALLOWED_CLIENT =
- new TreeSet<AddressMask>();
-
- private static final SortedSet<AddressMask> ADMIN_DENIED_CLIENT =
- new TreeSet<AddressMask>();
-
- private static final boolean ADMIN_ENABLED = true;
-
- private static final boolean ADMIN_KEEP_STATS = true;
-
- private static final boolean ADMIN_USE_SSL = true;
-
- private static final int ADMIN_ACCEPT_BACKLOG = 128;
-
- private static final boolean ADMIN_ALLOW_TCP_REUSE_ADDRESS = true;
-
- private static final long ADMIN_MAX_BLOCKED_WRITE_TIME_LIMIT = 120000; // 2mn
-
- private static final int ADMIN_MAX_REQUEST_SIZE = 5000000; // 5 Mb
-
- private static final int ADMIN_WRITE_BUFFER_SIZE = 4096;
-
- private static final int ADMIN_NUM_REQUEST_HANDLERS = 1;
-
- private static final boolean ADMIN_SEND_REJECTION_NOTICE = true;
-
- private static final boolean ADMIN_USE_TCP_KEEP_ALIVE = true;
-
- private static final boolean ADMIN_USE_TCP_NO_DELAY = true;
-
- private static final SSLClientAuthPolicy ADMIN_SSL_CLIENT_AUTH_POLICY =
- SSLClientAuthPolicy.DISABLED;
-
- private static final SortedSet<String> ADMIN_SSL_CIPHER_SUITE =
- new TreeSet<String>();
-
- private static final SortedSet<String> ADMIN_SSL_PROTOCOL =
- new TreeSet<String>();
-
-
-
- /**
- * Initializes this administration connector provider based on the
- * information in the provided administration connector
- * configuration.
- *
- * @param configuration
- * The connection handler configuration that contains the
- * information to use to initialize this connection
- * handler.
- * @throws ConfigException
- * If an unrecoverable problem arises in the process of
- * performing the initialization as a result of the server
- * configuration.
- * @throws InitializationException
- * If a problem occurs during initialization that is not
- * related to the server configuration.
- */
- public void initializeAdministrationConnector(
- AdministrationConnectorCfg configuration) throws ConfigException,
- InitializationException
- {
- this.config = configuration;
-
- // Create a fake LDAP connection handler configuration
- LDAPConnectionHandlerCfg ldapConnectionHandlerCfg =
- new FakeLDAPConnectionHandlerCfg(config);
-
- // Administration Connector uses the LDAP connection handler
- // implementation
- adminConnectionHandler = new LDAPConnectionHandler(
- new SynchronousStrategy(), FRIENDLY_NAME);
- adminConnectionHandler
- .initializeConnectionHandler(ldapConnectionHandlerCfg);
- adminConnectionHandler.setAdminConnectionHandler();
-
- // Register this as a change listener.
- config.addChangeListener(this);
- }
-
-
-
- /**
- * Create an instance of the administration connector.
- */
- public AdministrationConnector()
- {
- // Do nothing.
- }
-
-
-
- /**
- * Retrieves the connection handler linked to this administration
- * connector.
- *
- * @return The connection handler linked to this administration
- * connector.
- */
- public LDAPConnectionHandler getConnectionHandler()
- {
- return adminConnectionHandler;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public boolean isConfigurationChangeAcceptable(
- AdministrationConnectorCfg configuration,
- List<LocalizableMessage> unacceptableReasons)
- {
- LDAPConnectionHandlerCfg cfg = new FakeLDAPConnectionHandlerCfg(
- configuration);
- return adminConnectionHandler.isConfigurationAcceptable(cfg,
- unacceptableReasons);
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public ConfigChangeResult applyConfigurationChange(
- AdministrationConnectorCfg configuration)
- {
- return new ConfigChangeResult(ResultCode.SUCCESS, true,
- new ArrayList<LocalizableMessage>());
- }
-
-
-
- /**
- * This private class implements a fake LDAP connection Handler
- * configuration. This allows to re-use the LDAPConnectionHandler as
- * it is.
- */
- private static class FakeLDAPConnectionHandlerCfg implements
- LDAPConnectionHandlerCfg
- {
-
- private final AdministrationConnectorCfg config;
-
-
-
- public FakeLDAPConnectionHandlerCfg(AdministrationConnectorCfg config)
- {
- this.config = config;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public Class<? extends LDAPConnectionHandlerCfg> configurationClass()
- {
- return LDAPConnectionHandlerCfg.class;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public void addLDAPChangeListener(
- ConfigurationChangeListener<LDAPConnectionHandlerCfg> listener)
- {
- // do nothing. change listener already added.
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public void removeLDAPChangeListener(
- ConfigurationChangeListener<LDAPConnectionHandlerCfg> listener)
- {
- // do nothing. change listener already added.
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public int getAcceptBacklog()
- {
- return ADMIN_ACCEPT_BACKLOG;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public boolean isAllowLDAPV2()
- {
- return ADMIN_ALLOW_LDAP_V2;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public boolean isAllowStartTLS()
- {
- return ADMIN_ALLOW_START_TLS;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public boolean isAllowTCPReuseAddress()
- {
- return ADMIN_ALLOW_TCP_REUSE_ADDRESS;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public String getJavaClass()
- {
- return ADMIN_CLASS_NAME;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public boolean isKeepStats()
- {
- return ADMIN_KEEP_STATS;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public String getKeyManagerProvider()
- {
- return config.getKeyManagerProvider();
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public DN getKeyManagerProviderDN()
- {
- return config.getKeyManagerProviderDN();
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public SortedSet<InetAddress> getListenAddress()
- {
- return config.getListenAddress();
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public int getListenPort()
- {
- return config.getListenPort();
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public long getMaxBlockedWriteTimeLimit()
- {
- return ADMIN_MAX_BLOCKED_WRITE_TIME_LIMIT;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public long getMaxRequestSize()
- {
- return ADMIN_MAX_REQUEST_SIZE;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public long getBufferSize()
- {
- return ADMIN_WRITE_BUFFER_SIZE;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public Integer getNumRequestHandlers()
- {
- return ADMIN_NUM_REQUEST_HANDLERS;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public boolean isSendRejectionNotice()
- {
- return ADMIN_SEND_REJECTION_NOTICE;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public String getSSLCertNickname()
- {
- return config.getSSLCertNickname();
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public SortedSet<String> getSSLCipherSuite()
- {
- return config.getSSLCipherSuite();
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public SSLClientAuthPolicy getSSLClientAuthPolicy()
- {
- return ADMIN_SSL_CLIENT_AUTH_POLICY;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public SortedSet<String> getSSLProtocol()
- {
- return config.getSSLProtocol();
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public String getTrustManagerProvider()
- {
- return config.getTrustManagerProvider();
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public DN getTrustManagerProviderDN()
- {
- return config.getTrustManagerProviderDN();
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public boolean isUseSSL()
- {
- return ADMIN_USE_SSL;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public boolean isUseTCPKeepAlive()
- {
- return ADMIN_USE_TCP_KEEP_ALIVE;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public boolean isUseTCPNoDelay()
- {
- return ADMIN_USE_TCP_NO_DELAY;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public void addChangeListener(
- ConfigurationChangeListener<ConnectionHandlerCfg> listener)
- {
- // do nothing. change listener already added.
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public void removeChangeListener(
- ConfigurationChangeListener<ConnectionHandlerCfg> listener)
- {
- // do nothing. change listener already added.
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public SortedSet<AddressMask> getAllowedClient()
- {
- return ADMIN_ALLOWED_CLIENT;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public SortedSet<AddressMask> getDeniedClient()
- {
- return ADMIN_DENIED_CLIENT;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public boolean isEnabled()
- {
- return ADMIN_ENABLED;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public DN dn()
- {
- return config.dn();
- }
- }
-
-
-
- /**
- * Creates a self-signed JKS certificate if needed.
- *
- * @throws InitializationException
- * If an unexpected error occurred whilst trying to create the
- * certificate.
- */
- public static void createSelfSignedCertificateIfNeeded()
- throws InitializationException
- {
- try
- {
- RootCfg root = ServerManagementContext.getInstance()
- .getRootConfiguration();
- AdministrationConnectorCfg config = root.getAdministrationConnector();
-
- // Check if certificate generation is needed
- String certAlias = config.getSSLCertNickname();
- KeyManagerProviderCfg keyMgrConfig = root.getKeyManagerProvider(config
- .getKeyManagerProvider());
- TrustManagerProviderCfg trustMgrConfig = root
- .getTrustManagerProvider(config.getTrustManagerProvider());
-
- if (hasDefaultConfigChanged(keyMgrConfig, trustMgrConfig))
- {
- // nothing to do
- return;
- }
-
- FileBasedKeyManagerProviderCfg fbKeyManagerConfig =
- (FileBasedKeyManagerProviderCfg) keyMgrConfig;
- String keystorePath = getFullPath(fbKeyManagerConfig.getKeyStoreFile());
- FileBasedTrustManagerProviderCfg fbTrustManagerConfig =
- (FileBasedTrustManagerProviderCfg) trustMgrConfig;
- String truststorePath = getFullPath(fbTrustManagerConfig
- .getTrustStoreFile());
- String pinFilePath = getFullPath(fbKeyManagerConfig.getKeyStorePinFile());
-
- // Check that either we do not have any file,
- // or we have the 3 required files (keystore, truststore, pin
- // file)
- boolean keystore = false;
- boolean truststore = false;
- boolean pinFile = false;
- int nbFiles = 0;
- if (new File(keystorePath).exists())
- {
- keystore = true;
- nbFiles++;
- }
- if (new File(truststorePath).exists())
- {
- truststore = true;
- nbFiles++;
- }
- if (new File(pinFilePath).exists())
- {
- pinFile = true;
- nbFiles++;
- }
- if (nbFiles == 3)
- {
- // nothing to do
- return;
- }
- if (nbFiles != 0)
- {
- // 1 or 2 files are missing : error
- String err = "";
- if (!keystore)
- {
- err += keystorePath + " ";
- }
- if (!truststore)
- {
- err += truststorePath + " ";
- }
- if (!pinFile)
- {
- err += pinFilePath + " ";
- }
- LocalizableMessage message = ERR_ADMIN_CERTIFICATE_GENERATION_MISSING_FILES
- .get(err);
- logError(message);
- throw new InitializationException(message);
- }
-
- // Generate a password
- String pwd = new String(SetupUtils.createSelfSignedCertificatePwd());
-
- // Generate a self-signed certificate
- CertificateManager certManager = new CertificateManager(
- getFullPath(fbKeyManagerConfig.getKeyStoreFile()), fbKeyManagerConfig
- .getKeyStoreType(), pwd);
- String hostName =
- SetupUtils.getHostNameForCertificate(DirectoryServer.getServerRoot());
- String subjectDN = "cn="
- + Rdn.escapeValue(hostName) + ",O="
- + FRIENDLY_NAME + " Self-Signed Certificate";
- certManager.generateSelfSignedCertificate(certAlias, subjectDN,
- ADMIN_CERT_VALIDITY);
-
- // Export the certificate
- String tempCertPath = getFullPath("config" + File.separator
- + "admin-cert.txt");
- SetupUtils.exportCertificate(certManager, certAlias, tempCertPath);
-
- // Create a new trust store and import the server certificate
- // into it
- CertificateManager trustManager = new CertificateManager(truststorePath,
- CertificateManager.KEY_STORE_TYPE_JKS, pwd);
- trustManager.addCertificate(certAlias, new File(tempCertPath));
-
- // Generate a password file
- if (!new File(pinFilePath).exists())
- {
- FileWriter file = new FileWriter(pinFilePath);
- PrintWriter out = new PrintWriter(file);
- out.println(pwd);
- out.flush();
- out.close();
- file.close();
- }
-
- // Change the password file permission if possible
- if (FilePermission.canSetPermissions())
- {
- try
- {
- if (!FilePermission.setPermissions(new File(pinFilePath),
- new FilePermission(0600)))
- {
- // Log a warning that the permissions were not set.
- LocalizableMessage message = WARN_ADMIN_SET_PERMISSIONS_FAILED
- .get(pinFilePath);
- ErrorLogger.logError(message);
- }
- }
- catch (DirectoryException e)
- {
- // Log a warning that the permissions were not set.
- LocalizableMessage message = WARN_ADMIN_SET_PERMISSIONS_FAILED.get(pinFilePath);
- ErrorLogger.logError(message);
- }
- }
-
- // Delete the exported certificate
- File f = new File(tempCertPath);
- f.delete();
- }
- catch (InitializationException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
- LocalizableMessage message = ERR_ADMIN_CERTIFICATE_GENERATION.get(e.getMessage());
- logError(message);
- throw new InitializationException(message);
- }
- }
-
- /**
- * Check if default configuration for administrator's key manager and trust
- * manager provider has changed.
- *
- * @param keyConfig
- * key manager provider configuration
- * @param trustConfig
- * trust manager provider configuration
- * @return true if default configuration has changed, false otherwise
- */
- private static boolean hasDefaultConfigChanged(
- KeyManagerProviderCfg keyConfig, TrustManagerProviderCfg trustConfig)
- {
- if (keyConfig.isEnabled()
- && (keyConfig instanceof FileBasedKeyManagerProviderCfg)
- && trustConfig.isEnabled()
- && (trustConfig instanceof FileBasedTrustManagerProviderCfg))
- {
- FileBasedKeyManagerProviderCfg fileKeyConfig =
- (FileBasedKeyManagerProviderCfg) keyConfig;
- boolean pinIsProvidedByFileOnly =
- (fileKeyConfig.getKeyStorePinFile() != null)
- && (fileKeyConfig.getKeyStorePin() == null)
- && (fileKeyConfig.getKeyStorePinEnvironmentVariable() == null)
- && (fileKeyConfig.getKeyStorePinProperty() == null);
- return !pinIsProvidedByFileOnly;
- }
- return true;
- }
-
- private static String getFullPath(String path)
- {
- File file = new File(path);
- if (!file.isAbsolute())
- {
- path = DirectoryServer.getInstanceRoot() + File.separator + path;
- }
-
- return path;
- }
-}
diff --git a/opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/AdministrationDataSync.java b/opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/AdministrationDataSync.java
deleted file mode 100644
index 7e72050..0000000
--- a/opendj-sdk/opendj-admin/src/main/java/org/opends/server/admin/AdministrationDataSync.java
+++ /dev/null
@@ -1,353 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- * Portions Copyright 2012 ForgeRock AS
- */
-package org.opends.server.admin;
-
-
-
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.protocols.internal.InternalClientConnection;
-import org.opends.server.protocols.internal.InternalSearchOperation;
-import org.opends.server.protocols.ldap.LDAPFilter;
-import org.opends.server.schema.DirectoryStringSyntax;
-import org.opends.server.types.Attribute;
-import org.opends.server.types.AttributeType;
-import org.opends.server.types.Attributes;
-import org.opends.server.types.ByteString;
-import org.forgerock.opendj.ldap.DN;
-import org.opends.server.types.DereferencePolicy;
-import org.opends.server.types.DirectoryException;
-import org.opends.server.types.Entry;
-import org.opends.server.types.LDAPException;
-import org.opends.server.types.Modification;
-import org.opends.server.types.ModificationType;
-import org.opends.server.types.ResultCode;
-import org.opends.server.types.SearchResultEntry;
-import org.opends.server.types.SearchScope;
-
-
-
-/**
- * Check if information found in "cn=admin data" is coherent with
- * cn=config. If and inconsistency is detected, we log a warning
- * message and update "cn=admin data"
- */
-public final class AdministrationDataSync
-{
-
- /**
- * The root connection.
- */
- private InternalClientConnection internalConnection;
-
- /**
- * The attribute name used to store the port. TODO Use the default
- * one.
- */
- private static final String LDAP_PORT = "ds-cfg-listen-port";
-
-
-
- /**
- * Create an object that will syncrhonize configuration and the
- * admin data.
- *
- * @param internalConnection
- * The root connection.
- */
- public AdministrationDataSync(InternalClientConnection internalConnection)
- {
- this.internalConnection = internalConnection;
- }
-
-
-
- /**
- * Check if information found in "cn=admin data" is coherent with
- * cn=config. If and inconsistancy is detected, we log a warning
- * message and update "cn=admin data"
- */
- public void synchronize()
- {
- // Check if the admin connector is in sync
- checkAdminConnector();
- }
-
-
-
- /**
- * Check if the admin connector is in sync. The desynchronization
- * could occurs after the upgrade from 1.0.
- */
- private void checkAdminConnector()
- {
- // Look for the server registration in "cn=admin data"
- DN serverEntryDN = searchServerEntry();
- if (serverEntryDN == null)
- {
- // Nothing to do
- return;
- }
-
- // Get the admin port
- String adminPort = getAttr("cn=Administration Connector,cn=config",
- LDAP_PORT);
- if (adminPort == null)
- {
- // best effort.
- return;
- }
-
- LinkedList<Modification> mods = new LinkedList<Modification>();
- // adminport
- String attName = "adminport";
- AttributeType attrType = DirectoryServer.getAttributeType(attName
- .toLowerCase());
- if (attrType == null)
- {
- attrType = DirectoryServer.getDefaultAttributeType(attName.toLowerCase());
- }
- mods.add(new Modification(ModificationType.REPLACE, Attributes.create(
- attrType, adminPort)));
-
- // adminEnabled
- attName = "adminEnabled";
- attrType = DirectoryServer.getAttributeType(attName.toLowerCase());
- if (attrType == null)
- {
- attrType = DirectoryServer.getDefaultAttributeType(attName.toLowerCase());
- }
- mods.add(new Modification(ModificationType.REPLACE, Attributes.create(
- attrType, "true")));
-
- // Process modification
- internalConnection.processModify(serverEntryDN, mods);
- }
-
-
-
- /**
- * Look for the DN of the local register server. Assumption: default
- * Connection Handler naming is used.
- *
- * @return The DN of the local register server or null.
- */
- private DN searchServerEntry()
- {
- DN returnDN = null;
-
- // Get the LDAP and LDAPS port
- String ldapPort = getAttr(
- "cn=LDAP Connection Handler,cn=Connection Handlers,cn=config",
- LDAP_PORT);
- String ldapsPort = getAttr(
- "cn=LDAPS Connection Handler,cn=Connection Handlers,cn=config",
- LDAP_PORT);
- boolean ldapsPortEnable = false;
- String val = getAttr(
- "cn=LDAPS Connection Handler,cn=Connection Handlers,cn=config",
- "ds-cfg-enabled");
- if (val != null)
- {
- ldapsPortEnable = val.toLowerCase().equals("true");
- }
- if ((ldapPort == null) && (ldapsPort == null))
- {
- // best effort (see assumption)
- return null;
- }
-
- // Get the IP address of the local host.
- String hostName;
- try
- {
- hostName = java.net.InetAddress.getLocalHost().getCanonicalHostName();
- }
- catch (Throwable t)
- {
- // best effort.
- return null;
- }
-
- // Look for a local server with the Ldap Port.
- String attrName = "hostname";
- AttributeType hostnameType = DirectoryServer.getAttributeType(attrName);
- if (hostnameType == null)
- {
- hostnameType = DirectoryServer.getDefaultAttributeType(attrName);
- }
- try
- {
- InternalSearchOperation op = internalConnection.processSearch(
- "cn=Servers,cn=admin data",
- SearchScope.SINGLE_LEVEL, "objectclass=*");
- if (op.getResultCode() == ResultCode.SUCCESS)
- {
- Entry entry = null;
- for (Entry currentEntry : op.getSearchEntries())
- {
- String currentHostname = currentEntry.getAttributeValue(hostnameType,
- DirectoryStringSyntax.DECODER);
- try
- {
- String currentIPAddress = java.net.InetAddress.getByName(
- currentHostname).getCanonicalHostName();
- if (currentIPAddress.equals(hostName))
- {
- // Check if one of the port match
- attrName = "ldapport";
- AttributeType portType = DirectoryServer
- .getAttributeType(attrName);
- if (portType == null)
- {
- portType = DirectoryServer.getDefaultAttributeType(attrName);
- }
- String currentport = currentEntry.getAttributeValue(portType,
- DirectoryStringSyntax.DECODER);
- if (currentport.equals(ldapPort))
- {
- entry = currentEntry;
- break;
- }
- if (ldapsPortEnable)
- {
- attrName = "ldapsport";
- portType = DirectoryServer.getAttributeType(attrName);
- if (portType == null)
- {
- portType = DirectoryServer.getDefaultAttributeType(attrName);
- }
- currentport = currentEntry.getAttributeValue(portType,
- DirectoryStringSyntax.DECODER);
- if (currentport.equals(ldapsPort))
- {
- entry = currentEntry;
- break;
- }
- }
- }
- }
- catch (Exception e)
- {
- // best effort.
- continue;
- }
- }
-
- if (entry != null)
- {
- returnDN = entry.getDN();
- }
- }
-
- }
- catch (DirectoryException e)
- {
- // never happens because the filter is always valid.
- return null;
- }
- return returnDN;
- }
-
-
-
- /**
- * Gets an attribute value from an entry.
- *
- * @param DN
- * The DN of the entry.
- * @param attrName
- * The attribute name.
- * @return The attribute value or {@code null} if the value could
- * not be retrieved.
- */
- private String getAttr(String baseDN, String attrName)
- {
- // Prepare the ldap search
- LDAPFilter filter;
- try
- {
- filter = LDAPFilter.decode("objectclass=*");
- }
- catch (LDAPException e)
- {
- // can not happen
- // best effort.
- // TODO Log an Error.
- return null;
- }
-
- LinkedHashSet<String> attributes = new LinkedHashSet<String>(1);
- attributes.add(attrName);
- InternalSearchOperation search = internalConnection.processSearch(
- ByteString.valueOf(baseDN), SearchScope.BASE_OBJECT,
- DereferencePolicy.DEREF_ALWAYS, 0, 0, false, filter, attributes);
-
- if ((search.getResultCode() != ResultCode.SUCCESS))
- {
- // can not happen
- // best effort.
- // TODO Log an Error.
- return null;
- }
-
- SearchResultEntry adminConnectorEntry = null;
-
- /*
- * Read the port from the PORT attribute
- */
- LinkedList<SearchResultEntry> result = search.getSearchEntries();
- if (!result.isEmpty())
- {
- adminConnectorEntry = result.getFirst();
- }
-
- AttributeType attrType = DirectoryServer.getAttributeType(attrName);
- if (attrType == null)
- {
- attrType = DirectoryServer.getDefaultAttributeType(attrName);
- }
-
- List<Attribute> attrs = adminConnectorEntry.getAttribute(attrType);
-
- if (attrs == null)
- {
- // can not happen
- // best effort.
- // TODO Log an Error.
- return null;
- }
-
- // Get the attribute value
- return attrs.get(0).iterator().next().toString();
- }
-
-}
diff --git a/opendj-sdk/opendj-admin/src/main/java/org/opends/server/core/DirectoryServer.java b/opendj-sdk/opendj-admin/src/main/java/org/opends/server/core/DirectoryServer.java
index f09f7d0..0e59e77 100644
--- a/opendj-sdk/opendj-admin/src/main/java/org/opends/server/core/DirectoryServer.java
+++ b/opendj-sdk/opendj-admin/src/main/java/org/opends/server/core/DirectoryServer.java
@@ -32,7 +32,7 @@
import org.opends.server.config.ConfigException;
/**
- * TODO : this is a stub
+ * TODO : this is a stub
*/
public class DirectoryServer {
@@ -56,14 +56,6 @@
throw new RuntimeException("Not implemented");
}
- public static AttributeType getAttributeType(String lowerCase) {
- throw new RuntimeException("Not implemented");
- }
-
- public static AttributeType getDefaultAttributeType(String attrName) {
- throw new RuntimeException("Not implemented");
- }
-
public static ConfigEntry getConfigEntry(DN dn) throws ConfigException {
throw new RuntimeException("Not implemented");
}
--
Gitblit v1.10.0