opends/src/server/org/opends/server/types/DirectoryEnvironmentConfig.java
@@ -27,25 +27,21 @@ */ package org.opends.server.types; import java.io.File; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.Properties; import org.opends.quicksetup.util.Utils; import org.opends.server.api.ConfigHandler; import org.opends.server.core.DirectoryServer; import org.opends.server.extensions.ConfigFileHandler; import org.opends.quicksetup.util.Utils; import static org.opends.server.config.ConfigConstants.*; import static org.opends.messages.CoreMessages.*; import static org.opends.server.config.ConfigConstants.*; import static org.opends.server.util.ServerConstants.*; /** * This class provides a set of properties that may control various * aspects of the server environment. Note that these properties may @@ -60,8 +56,8 @@ mayInvoke=true) public final class DirectoryEnvironmentConfig { // The set of properties for the environment config. private final HashMap<String,String> configProperties; /** The set of properties for the environment config. */ private final Map<String, String> configProperties; @@ -256,33 +252,47 @@ ERR_DIRCFG_SERVER_ALREADY_RUNNING.get()); } if ((! serverRoot.exists()) || (! serverRoot.isDirectory())) if (!serverRoot.exists() || !serverRoot.isDirectory()) { throw new InitializationException( ERR_DIRCFG_INVALID_SERVER_ROOT.get( serverRoot.getAbsolutePath())); } String serverRootPath; return setPathProperty(PROPERTY_SERVER_ROOT, serverRoot); } /** * Sets a path property. * * @param propertyName * The property name to set. * @param newPath * The path to set on the property. * @return The previous property value, or {@code null} if there was none. * @throws InitializationException * If the Directory Server is already running or there is a problem * with the provided server root. */ private File setPathProperty(String propertyName, File newPath) throws InitializationException { String normalizedNewPath; try { serverRootPath = serverRoot.getCanonicalPath(); normalizedNewPath = newPath.getCanonicalPath(); } catch (Exception e) { serverRootPath = serverRoot.getAbsolutePath(); normalizedNewPath = newPath.getAbsolutePath(); } String oldRootPath = setProperty(PROPERTY_SERVER_ROOT, serverRootPath); if (oldRootPath == null) String oldPath = setProperty(propertyName, normalizedNewPath); if (oldPath != null) { return null; return new File(oldPath); } else { return new File(oldRootPath); } return null; } /** @@ -310,33 +320,14 @@ ERR_DIRCFG_SERVER_ALREADY_RUNNING.get()); } if ((! instanceRoot.exists()) || (! instanceRoot.isDirectory())) if (!instanceRoot.exists() || !instanceRoot.isDirectory()) { throw new InitializationException( ERR_DIRCFG_INVALID_SERVER_ROOT.get( instanceRoot.getAbsolutePath())); } String instanceRootPath; try { instanceRootPath = instanceRoot.getCanonicalPath(); } catch (Exception e) { instanceRootPath = instanceRoot.getAbsolutePath(); } String oldInstancePath = setProperty(PROPERTY_INSTANCE_ROOT, instanceRootPath); if (oldInstancePath == null) { return null; } else { return new File(oldInstancePath); } return setPathProperty(PROPERTY_INSTANCE_ROOT, instanceRoot); } @@ -402,33 +393,14 @@ ERR_DIRCFG_SERVER_ALREADY_RUNNING.get()); } if ((! configFile.exists()) || (! configFile.isFile())) if (!configFile.exists() || !configFile.isFile()) { throw new InitializationException( ERR_DIRCFG_INVALID_CONFIG_FILE.get( configFile.getAbsolutePath())); } String configFilePath; try { configFilePath = configFile.getCanonicalPath(); } catch (Exception e) { configFilePath = configFile.getAbsolutePath(); } String oldConfigFilePath = setProperty(PROPERTY_CONFIG_FILE, configFilePath); if (oldConfigFilePath == null) { return null; } else { return new File(oldConfigFilePath); } return setPathProperty(PROPERTY_CONFIG_FILE, configFile); } @@ -491,7 +463,7 @@ ERR_DIRCFG_SERVER_ALREADY_RUNNING.get()); } if (! (ConfigHandler.class.isAssignableFrom(configClass))) if (!ConfigHandler.class.isAssignableFrom(configClass)) { throw new InitializationException( ERR_DIRCFG_INVALID_CONFIG_CLASS.get( @@ -535,13 +507,22 @@ */ public boolean useLastKnownGoodConfiguration() { String useLastKnownGoodStr = getProperty(PROPERTY_USE_LAST_KNOWN_GOOD_CONFIG); return useLastKnownGoodStr != null && useLastKnownGoodStr.equalsIgnoreCase("true"); return isPropertyTrue(PROPERTY_USE_LAST_KNOWN_GOOD_CONFIG); } /** * Indicates whether the property value is set and equal to "true" for the * supplied property name. * * @param propertyName * the name of the property to be checked * @return {@code true} if the property is set and the property value is * <code>"true"</code>, {@code false} otherwise . */ private boolean isPropertyTrue(String propertyName) { return "true".equalsIgnoreCase(getProperty(propertyName)); } /** * Specifies whether the Directory Server should attempt to start @@ -565,17 +546,8 @@ boolean useLastKnownGoodConfiguration) throws InitializationException { if (DirectoryServer.isRunning()) { throw new InitializationException( ERR_DIRCFG_SERVER_ALREADY_RUNNING.get()); } String oldUseLastKnownGoodStr = setProperty(PROPERTY_USE_LAST_KNOWN_GOOD_CONFIG, String.valueOf(useLastKnownGoodConfiguration)); return oldUseLastKnownGoodStr != null && oldUseLastKnownGoodStr.equalsIgnoreCase("true"); return setBooleanProperty(PROPERTY_USE_LAST_KNOWN_GOOD_CONFIG, useLastKnownGoodConfiguration); } @@ -593,8 +565,8 @@ { String maintainArchiveStr = getProperty(PROPERTY_MAINTAIN_CONFIG_ARCHIVE); return maintainArchiveStr == null || (!maintainArchiveStr.equalsIgnoreCase("false")); return maintainArchiveStr == null || !"false".equalsIgnoreCase(maintainArchiveStr); } @@ -627,8 +599,7 @@ String oldMaintainStr = setProperty(PROPERTY_MAINTAIN_CONFIG_ARCHIVE, String.valueOf(maintainConfigArchive)); return oldMaintainStr == null || (!oldMaintainStr.equalsIgnoreCase("false")); return oldMaintainStr == null || !"false".equalsIgnoreCase(oldMaintainStr); } @@ -793,34 +764,14 @@ ERR_DIRCFG_SERVER_ALREADY_RUNNING.get()); } if ((! schemaDirectory.exists()) || (! schemaDirectory.isDirectory())) if (!schemaDirectory.exists() || !schemaDirectory.isDirectory()) { throw new InitializationException( ERR_DIRCFG_INVALID_SCHEMA_DIRECTORY.get( schemaDirectory.getAbsolutePath())); } String schemaDirectoryPath; try { schemaDirectoryPath = schemaDirectory.getCanonicalPath(); } catch (Exception e) { schemaDirectoryPath = schemaDirectory.getAbsolutePath(); } String oldSchemaDir = setProperty(PROPERTY_SCHEMA_DIRECTORY, schemaDirectoryPath); if (oldSchemaDir == null) { return null; } else { return new File(oldSchemaDir); } return setPathProperty(PROPERTY_SCHEMA_DIRECTORY, schemaDirectory); } @@ -905,26 +856,7 @@ } } String lockDirectoryPath; try { lockDirectoryPath = lockDirectory.getCanonicalPath(); } catch (Exception e) { lockDirectoryPath = lockDirectory.getAbsolutePath(); } String oldLockDir = setProperty(PROPERTY_LOCK_DIRECTORY, lockDirectoryPath); if (oldLockDir == null) { return null; } else { return new File(oldLockDir); } return setPathProperty(PROPERTY_LOCK_DIRECTORY, lockDirectory); } @@ -939,9 +871,7 @@ */ public boolean disableConnectionHandlers() { String disableStr = getProperty(PROPERTY_DISABLE_CONNECTION_HANDLERS); return disableStr != null && disableStr.equalsIgnoreCase("true"); return isPropertyTrue(PROPERTY_DISABLE_CONNECTION_HANDLERS); } /** @@ -955,9 +885,7 @@ */ public boolean disableSynchronization() { String disableStr = getProperty(PROPERTY_DISABLE_SYNCHRONIZATION); return disableStr != null && disableStr.equalsIgnoreCase("true"); return isPropertyTrue(PROPERTY_DISABLE_SYNCHRONIZATION); } /** @@ -971,9 +899,7 @@ */ public boolean disableAdminDataSynchronization() { String disableStr = getProperty(PROPERTY_DISABLE_ADMIN_DATA_SYNCHRONIZATION); return disableStr != null && disableStr.equalsIgnoreCase("true"); return isPropertyTrue(PROPERTY_DISABLE_ADMIN_DATA_SYNCHRONIZATION); } /** @@ -997,20 +923,36 @@ boolean disableConnectionHandlers) throws InitializationException { return setBooleanProperty(PROPERTY_DISABLE_CONNECTION_HANDLERS, disableConnectionHandlers); } /** * Sets a boolean property. * * @param propertyName * the property name to set * @param newValue * the new value to set for the property * @return The previous setting for this configuration option. If no previous * value was specified, then {@code false} will be returned. * @throws InitializationException * If the Directory Server is already running or there is a problem * with the provided server root. */ private boolean setBooleanProperty(String propertyName, boolean newValue) throws InitializationException { if (DirectoryServer.isRunning()) { throw new InitializationException( ERR_DIRCFG_SERVER_ALREADY_RUNNING.get()); } String oldDisableStr = setProperty(PROPERTY_DISABLE_CONNECTION_HANDLERS, String.valueOf(disableConnectionHandlers)); return oldDisableStr != null && oldDisableStr.equalsIgnoreCase("true"); final String oldValue = setProperty(propertyName, String.valueOf(newValue)); return "true".equalsIgnoreCase(oldValue); } /** * Indicates whether all threads created by the Directory Server * should be created as daemon threads. @@ -1021,9 +963,7 @@ */ public boolean forceDaemonThreads() { String forceDaemonStr = getProperty(PROPERTY_FORCE_DAEMON_THREADS); return forceDaemonStr != null && forceDaemonStr.equalsIgnoreCase("true"); return isPropertyTrue(PROPERTY_FORCE_DAEMON_THREADS); } @@ -1046,17 +986,8 @@ public boolean setForceDaemonThreads(boolean forceDaemonThreads) throws InitializationException { if (DirectoryServer.isRunning()) { throw new InitializationException( ERR_DIRCFG_SERVER_ALREADY_RUNNING.get()); } String oldForceDaemonStr = setProperty(PROPERTY_FORCE_DAEMON_THREADS, String.valueOf(forceDaemonThreads)); return oldForceDaemonStr != null && oldForceDaemonStr.equalsIgnoreCase("true"); return setBooleanProperty(PROPERTY_FORCE_DAEMON_THREADS, forceDaemonThreads); } @@ -1071,8 +1002,7 @@ */ public boolean disableExec() { String disableStr = getProperty(PROPERTY_DISABLE_EXEC); return disableStr != null && disableStr.equalsIgnoreCase("true"); return isPropertyTrue(PROPERTY_DISABLE_EXEC); } @@ -1096,15 +1026,7 @@ public boolean setDisableExec(boolean disableExec) throws InitializationException { if (DirectoryServer.isRunning()) { throw new InitializationException( ERR_DIRCFG_SERVER_ALREADY_RUNNING.get()); } String oldDisableStr = setProperty(PROPERTY_DISABLE_EXEC, String.valueOf(disableExec)); return oldDisableStr != null && oldDisableStr.equalsIgnoreCase("true"); return setBooleanProperty(PROPERTY_DISABLE_EXEC, disableExec); } @@ -1353,4 +1275,3 @@ } } } opends/tests/unit-tests-testng/src/server/org/opends/server/authorization/dseecompat/AciTestCase.java
@@ -23,41 +23,14 @@ * * * Copyright 2008-2009 Sun Microsystems, Inc. * Portions Copyright 2013 ForgeRock AS */ package org.opends.server.authorization.dseecompat; import org.opends.server.DirectoryServerTestCase; import org.opends.server.TestCaseUtils; import org.opends.server.config.ConfigConstants; import org.opends.server.core.DirectoryServer; import org.opends.server.protocols.internal.InternalClientConnection; import org.opends.server.protocols.ldap.LDAPResultCode; import org.opends.server.tools.LDAPModify; import org.opends.server.tools.LDAPSearch; import org.opends.server.tools.LDAPDelete; import org.opends.server.tools.LDAPPasswordModify; import org.opends.server.types.Attribute; import org.opends.server.types.DN; import org.opends.server.types.Entry; import org.opends.server.types.Modification; import org.opends.server.types.ModificationType; import org.opends.server.types.ResultCode; import static org.opends.server.util.ServerConstants.EOL; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.testng.Assert; import org.testng.Reporter; import static org.opends.server.util.ServerConstants.*; import java.io.*; import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.HashMap; import java.util.ArrayList; import java.util.*; import javax.naming.NamingException; import javax.naming.NoPermissionException; @@ -66,13 +39,29 @@ import javax.naming.directory.InitialDirContext; import javax.naming.directory.ModificationItem; import org.opends.server.DirectoryServerTestCase; import org.opends.server.TestCaseUtils; import org.opends.server.config.ConfigConstants; import org.opends.server.core.DirectoryServer; import org.opends.server.protocols.internal.InternalClientConnection; import org.opends.server.protocols.ldap.LDAPResultCode; import org.opends.server.tools.LDAPDelete; import org.opends.server.tools.LDAPModify; import org.opends.server.tools.LDAPPasswordModify; import org.opends.server.tools.LDAPSearch; import org.opends.server.types.*; import org.testng.Assert; import org.testng.Reporter; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @SuppressWarnings("javadoc") @Test(groups = {"precommit", "dseecompat"}, sequential = true) public abstract class AciTestCase extends DirectoryServerTestCase { private Attribute globalACIAttribute = null; @BeforeClass public void aciTestCaseSetup() throws Exception { @@ -182,7 +171,7 @@ protected String pwdModify(String bindDn, String bindPassword, String newPassword, String noOpControl, String pwdPolicyControl, int rc) { String pwdPolicyControl, int expectedRc) { ArrayList<String> argList=new ArrayList<String>(20); argList.add("-h"); @@ -210,7 +199,7 @@ int ret= LDAPPasswordModify.mainPasswordModify(argList.toArray(args), false, oStream, oStream); Assert.assertEquals(rc, ret, "Returned error: " + oStream.toString()); Assert.assertEquals(expectedRc, ret, "Returned error: " + oStream); return oStream.toString(); } @@ -247,7 +236,7 @@ oStream.reset(); int retVal = LDAPSearch.mainSearch(argList.toArray(args), false, oStream, oStream); Assert.assertEquals(0, retVal, "Returned error: " + oStream.toString()); Assert.assertEquals(0, retVal, "Returned error: " + oStream); return oStream.toString(); } @@ -257,9 +246,9 @@ String[] attrList, String base, String filter ,String attr, boolean pwdPolicy, boolean reportAuthzID, int rc) { int expectedRc) { return _LDAPSearchParams(bindDn, bindPassword, proxyDN, authzid, attrList, base, filter, attr, pwdPolicy, reportAuthzID, rc); base, filter, attr, pwdPolicy, reportAuthzID, expectedRc); } protected String LDAPSearchParams(String bindDn, String bindPassword, @@ -273,8 +262,9 @@ private String _LDAPSearchParams(String bindDn, String bindPassword, String proxyDN, String authzid, String[] attrList, String base, String filter ,String attr, boolean pwdPolicy, boolean reportAuthzID, int rc) { ArrayList<String> argList=new ArrayList<String>(20); boolean pwdPolicy, boolean reportAuthzID, int expectedRc) { List<String> argList = new ArrayList<String>(20); argList.add("-h"); argList.add("127.0.0.1"); argList.add("-p"); @@ -318,18 +308,21 @@ oStream.reset(); int retVal = LDAPSearch.mainSearch(argList.toArray(args), false, oStream, oStream); Assert.assertEquals(retVal, rc, "Returned error: " + oStream.toString()); Assert.assertEquals(retVal, expectedRc, "Returned error: " + oStream); return oStream.toString(); } protected void LDIFAdd(String ldif, String bindDn, String bindPassword, String controlStr, int rc) throws Exception { _LDIFModify(ldif, bindDn, bindPassword, controlStr, true, rc, false); String controlStr, int expectedRc) throws Exception { _LDIFModify(ldif, bindDn, bindPassword, controlStr, true, expectedRc, false); } protected void LDIFModify(String ldif, String bindDn, String bindPassword, String controlStr, int rc) throws Exception { _LDIFModify(ldif, bindDn, bindPassword, controlStr, false, rc, false); String controlStr, int expectedRc) throws Exception { _LDIFModify(ldif, bindDn, bindPassword, controlStr, false, expectedRc, false); } protected void LDIFModify(String ldif, String bindDn, String bindPassword) @@ -350,13 +343,15 @@ } protected void LDIFDelete(String dn, String bindDn, String bindPassword, String controlStr, int rc) { _LDIFDelete(dn, bindDn, bindPassword, controlStr, rc); String controlStr, int expectedRc) { _LDIFDelete(dn, bindDn, bindPassword, controlStr, expectedRc); } private void _LDIFDelete(String dn, String bindDn, String bindPassword, String controlStr, int rc) { ArrayList<String> argList=new ArrayList<String>(20); String controlStr, int expectedRc) { List<String> argList = new ArrayList<String>(20); argList.add("-h"); argList.add("127.0.0.1"); argList.add("-p"); @@ -371,20 +366,21 @@ } argList.add(dn); String[] args = new String[argList.size()]; ldapDelete(argList.toArray(args), rc); ldapDelete(argList.toArray(args), expectedRc); } private void ldapDelete(String[] args, int rc) { private void ldapDelete(String[] args, int expectedRc) { oStream.reset(); int retVal = LDAPDelete.mainDelete(args, false, oStream, oStream); Assert.assertEquals(rc, retVal, "Returned error: " + oStream.toString()); Assert.assertEquals(expectedRc, retVal, "Returned error: " + oStream); } private void _LDIFModify(String ldif, String bindDn, String bindPassword, String controlStr, boolean add, int rc, boolean useAdminPort) throws Exception { String controlStr, boolean add, int expectedRc, boolean useAdminPort) throws Exception { File tempFile = getTemporaryLdifFile(); TestCaseUtils.writeFile(tempFile, ldif); ArrayList<String> argList=new ArrayList<String>(20); @@ -412,11 +408,12 @@ argList.add("-f"); argList.add(tempFile.getAbsolutePath()); String[] args = new String[argList.size()]; ldapModify(argList.toArray(args), rc); ldapModify(argList.toArray(args), expectedRc); } protected void JNDIModify(Hashtable<?, ?> env, String name, String attr, String val, int rc) { protected void JNDIModify(Hashtable<?, ?> env, String name, String attr, String val, int expectedRc) { try { DirContext ctx = new InitialDirContext(env); ModificationItem[] mods = new ModificationItem[1 ]; @@ -425,20 +422,22 @@ ctx.modifyAttributes(name, mods); ctx.close(); } catch (NoPermissionException npe) { Assert.assertEquals(LDAPResultCode.INSUFFICIENT_ACCESS_RIGHTS, rc, "Returned error: " + npe.getMessage()); Assert.assertEquals(LDAPResultCode.INSUFFICIENT_ACCESS_RIGHTS, expectedRc, "Returned error: " + npe.getMessage()); return; } catch (NamingException ex) { Assert.assertEquals(-1, rc, "Returned error: " + ex.getMessage()); Assert.assertEquals(-1, expectedRc, "Returned error: " + ex.getMessage()); } Assert.assertEquals(LDAPResultCode.SUCCESS, rc, ""); Assert.assertEquals(LDAPResultCode.SUCCESS, expectedRc, ""); } private void ldapModify(String[] args, int rc) { private void ldapModify(String[] args, int expectedRc) { oStream.reset(); int retVal =LDAPModify.mainModify(args, false, oStream, oStream); if(rc != -1) Assert.assertEquals(rc, retVal, "Returned error: " + oStream.toString()); if (expectedRc != -1) Assert.assertEquals(expectedRc, retVal, "Returned error: " + oStream); } protected void deleteAttrFromEntry(String dn, String attr) throws Exception { @@ -485,8 +484,7 @@ return ldif.toString(); } protected static String makeAddEntryLDIF(String dn, String ... lines) { protected static String makeAddEntryLDIF(String dn, String ... lines) { StringBuilder ldif = new StringBuilder(); ldif.append("dn: ").append(dn).append(EOL); ldif.append("changetype: add").append(EOL); opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/DbHandlerTest.java
@@ -23,7 +23,7 @@ * * * Copyright 2006-2010 Sun Microsystems, Inc. * Portions Copyright 2011 ForgeRock AS * Portions Copyright 2011-2013 ForgeRock AS */ package org.opends.server.replication.server; @@ -37,14 +37,15 @@ import org.opends.server.replication.common.ChangeNumberGenerator; import org.opends.server.replication.protocol.DeleteMsg; import org.testng.annotations.Test; import static org.testng.Assert.*; import static org.opends.server.TestCaseUtils.*; import static org.opends.server.loggers.debug.DebugLogger.debugEnabled; import static org.opends.server.loggers.debug.DebugLogger.getTracer; import static org.opends.server.loggers.debug.DebugLogger.*; import static org.testng.Assert.*; /** * Test the dbHandler class */ @SuppressWarnings("javadoc") public class DbHandlerTest extends ReplicationTestCase { // The tracer object for the debug logger @@ -279,7 +280,7 @@ } } /* /** * Test the feature of clearing a dbHandler used by a replication server. * The clear feature is used when a replication server receives a request * to reset the generationId of a given domain. @@ -368,7 +369,6 @@ /** * Test the logic that manages counter records in the DbHandler in order to * optimize the counting of record in the replication changelog db. * @throws Exception */ @Test(enabled=true, groups = { "opendj-256" }) void testDbCounts() throws Exception @@ -403,6 +403,7 @@ // After a purge. // After shutdowning/closing and reopening the db. testDBCount(40, 10); // FIXME next line is the one failing with the stacktrace above testDBCount(4000, 1000); }