opendj3-server-dev/src/server/org/opends/server/api/AuthenticationPolicyFactory.java
@@ -33,6 +33,7 @@ import org.forgerock.i18n.LocalizableMessage; import org.opends.server.admin.std.server.AuthenticationPolicyCfg; import org.opends.server.config.ConfigException; import org.opends.server.core.ServerContext; import org.opends.server.types.InitializationException; @@ -82,4 +83,14 @@ */ boolean isConfigurationAcceptable(T configuration, List<LocalizableMessage> unacceptableReasons); /** * Sets the server context. * * @param serverContext * The server context. */ void setServerContext(final ServerContext serverContext); } opendj3-server-dev/src/server/org/opends/server/core/AttributeSyntaxConfigManager.java
@@ -73,13 +73,17 @@ // attribute syntaxes. private ConcurrentHashMap<DN,AttributeSyntax> syntaxes; private final ServerContext serverContext; /** * Creates a new instance of this attribute syntax config manager. * * @param serverContext * The server context, that contains the schema. */ public AttributeSyntaxConfigManager() public AttributeSyntaxConfigManager(final ServerContext serverContext) { this.serverContext = serverContext; syntaxes = new ConcurrentHashMap<DN,AttributeSyntax>(); } @@ -130,7 +134,7 @@ try { DirectoryServer.registerAttributeSyntax(syntax, false); serverContext.getSchema().registerSyntax(syntax, false); syntaxes.put(syntaxConfiguration.dn(), syntax); } catch (DirectoryException de) @@ -207,7 +211,7 @@ try { DirectoryServer.registerAttributeSyntax(syntax, false); serverContext.getSchema().registerSyntax(syntax, false); syntaxes.put(configuration.dn(), syntax); } catch (DirectoryException de) @@ -282,7 +286,7 @@ AttributeSyntax syntax = syntaxes.remove(configuration.dn()); if (syntax != null) { DirectoryServer.deregisterAttributeSyntax(syntax); serverContext.getSchema().deregisterSyntax(syntax); syntax.finalizeSyntax(); } @@ -363,7 +367,7 @@ { if (existingSyntax != null) { DirectoryServer.deregisterAttributeSyntax(existingSyntax); serverContext.getSchema().deregisterSyntax(existingSyntax); AttributeSyntax syntax = syntaxes.remove(configuration.dn()); if (syntax != null) @@ -399,7 +403,7 @@ try { DirectoryServer.registerAttributeSyntax(syntax, false); serverContext.getSchema().registerSyntax(syntax, false); syntaxes.put(configuration.dn(), syntax); } catch (DirectoryException de) opendj3-server-dev/src/server/org/opends/server/core/DirectoryServer.java
@@ -756,6 +756,13 @@ return DirectoryServer.getServerRoot(); } /** {@inheritDoc} */ @Override public Schema getSchema() { return directoryServer.schema; } } @@ -1607,6 +1614,7 @@ defaultBooleanSyntax = initAndRegister(new BooleanSyntax()); defaultStringSyntax = initAndRegister(new DirectoryStringSyntax()); defaultSyntax = defaultStringSyntax; schema.registerDefaultSyntax(defaultSyntax); defaultDNSyntax = initAndRegister(new DistinguishedNameSyntax()); initAndRegister(new IA5StringSyntax()); defaultIntegerSyntax = initAndRegister(new IntegerSyntax()); @@ -1623,7 +1631,7 @@ try { syntax.initializeSyntax(null); registerAttributeSyntax(syntax, true); directoryServer.schema.registerSyntax(syntax, true); } catch (Exception e) { @@ -1761,7 +1769,7 @@ { // Create the schema configuration manager, and initialize the schema from // the configuration. schemaConfigManager = new SchemaConfigManager(); schemaConfigManager = new SchemaConfigManager(serverContext); schema = schemaConfigManager.getSchema(); schemaConfigManager.initializeMatchingRules(); @@ -2658,7 +2666,7 @@ // Initialize all the authentication policies. authenticationPolicyConfigManager = new PasswordPolicyConfigManager(); authenticationPolicyConfigManager = new PasswordPolicyConfigManager(serverContext); authenticationPolicyConfigManager.initializeAuthenticationPolicies(); } @@ -3805,69 +3813,6 @@ return directoryServer.schema.getSyntaxSet(); } /** * Retrieves the requested attribute syntax. * * @param oid The OID of the syntax to retrieve. * @param allowDefault Indicates whether to return the default attribute * syntax if the requested syntax is unknown. * * @return The requested attribute syntax, the default syntax if the * requested syntax is unknown and the caller has indicated that the * default is acceptable, or <CODE>null</CODE> otherwise. */ public static AttributeSyntax getAttributeSyntax(String oid, boolean allowDefault) { AttributeSyntax syntax = directoryServer.schema.getSyntax(oid); if (syntax == null && allowDefault) { return getDefaultAttributeSyntax(); } return syntax; } /** * Registers the provided attribute syntax with the Directory Server. * * @param syntax The attribute syntax to register with the * Directory Server. * @param overwriteExisting Indicates whether to overwrite an existing * mapping if there are any conflicts (i.e., * another attribute syntax with the same OID or * name). * * @throws DirectoryException If a conflict is encountered and the * <CODE>overwriteExisting</CODE> flag is set to * <CODE>false</CODE> */ public static void registerAttributeSyntax(AttributeSyntax syntax, boolean overwriteExisting) throws DirectoryException { directoryServer.schema.registerSyntax(syntax, overwriteExisting); } /** * Deregisters the provided attribute syntax with the Directory Server. * * @param syntax The attribute syntax to deregister with the Directory * Server. */ public static void deregisterAttributeSyntax(AttributeSyntax syntax) { directoryServer.schema.deregisterSyntax(syntax); } /** * Retrieves the default attribute syntax that should be used for attributes * that are not defined in the server schema. opendj3-server-dev/src/server/org/opends/server/core/PasswordPolicyConfigManager.java
@@ -66,14 +66,17 @@ { private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); private final ServerContext serverContext; /** * Creates a new instance of this password policy config manager. * * @param serverContext * The server context. */ public PasswordPolicyConfigManager() public PasswordPolicyConfigManager(ServerContext serverContext) { // Nothing to do. this.serverContext = serverContext; } @@ -441,7 +444,7 @@ // Creates and registers the provided authentication policy // configuration. private static void createAuthenticationPolicy( private void createAuthenticationPolicy( AuthenticationPolicyCfg policyConfiguration) throws ConfigException, InitializationException { @@ -469,6 +472,7 @@ { theClass = pd.loadClass(className, AuthenticationPolicyFactory.class); factory = (AuthenticationPolicyFactory<?>) theClass.newInstance(); factory.setServerContext(serverContext); } catch (Exception e) { @@ -522,7 +526,7 @@ // Determines whether or not the new authentication policy configuration's // implementation class is acceptable. private static boolean isAuthenticationPolicyConfigurationAcceptable( private boolean isAuthenticationPolicyConfigurationAcceptable( AuthenticationPolicyCfg policyConfiguration, List<LocalizableMessage> unacceptableReasons) { @@ -552,6 +556,7 @@ theClass = pd.loadClass(className, AuthenticationPolicyFactory.class); factory = (AuthenticationPolicyFactory<?>) theClass.newInstance(); factory.setServerContext(serverContext); // Determine the initialization method to use: it must take a // single parameter which is the exact type of the configuration opendj3-server-dev/src/server/org/opends/server/core/PasswordPolicyFactory.java
@@ -103,7 +103,7 @@ // passwords. private long requireChangeByTime; private final ServerContext serverContext; /** * {@inheritDoc} @@ -124,7 +124,7 @@ ArrayList<LocalizableMessage> messages = new ArrayList<LocalizableMessage>(); try { updateConfiguration(configuration, this); updateConfiguration(configuration, true); return new ConfigChangeResult(ResultCode.SUCCESS, false, messages); } catch (ConfigException ce) @@ -158,7 +158,7 @@ { try { updateConfiguration(configuration, null); updateConfiguration(configuration, false); } catch (ConfigException ce) { @@ -192,10 +192,11 @@ * Creates a new password policy based on the configuration contained in the * provided configuration entry. Any parameters not included in the provided * configuration entry will be assigned server-wide default values. * * @param serverContext TODO * @param configuration * The configuration with the information to use to initialize this * password policy. * * @throws ConfigException * If the provided entry does not contain a valid password policy * configuration. @@ -203,16 +204,17 @@ * If an error occurs while initializing the password policy that * is not related to the server configuration. */ private PasswordPolicyImpl(PasswordPolicyCfg configuration) private PasswordPolicyImpl(ServerContext serverContext, PasswordPolicyCfg configuration) throws ConfigException, InitializationException { updateConfiguration(configuration, this); this.serverContext = serverContext; updateConfiguration(configuration, true); } private static void updateConfiguration(PasswordPolicyCfg configuration, PasswordPolicyImpl policy) throws ConfigException, private void updateConfiguration(PasswordPolicyCfg configuration, boolean applyChanges) throws ConfigException, InitializationException { final DN configEntryDN = configuration.dn(); @@ -333,8 +335,8 @@ { ByteString valueString = ByteString.valueOf(requireChangeBy); GeneralizedTimeSyntax syntax = (GeneralizedTimeSyntax) DirectoryServer .getAttributeSyntax(SYNTAX_GENERALIZED_TIME_OID, false); GeneralizedTimeSyntax syntax = (GeneralizedTimeSyntax) serverContext.getSchema().getSyntax(SYNTAX_GENERALIZED_TIME_OID, false); if (syntax == null) { @@ -428,16 +430,16 @@ // If we've got this far then the configuration is good and we can commit // the changes if required. if (policy != null) if (applyChanges) { policy.configuration = configuration; policy.authPasswordSyntax = authPasswordSyntax; policy.defaultStorageSchemes = defaultStorageSchemes; policy.deprecatedStorageSchemes = deprecatedStorageSchemes; policy.notificationHandlers = notificationHandlers; policy.passwordGenerator = passwordGenerator; policy.passwordValidators = passwordValidators; policy.requireChangeByTime = requireChangeByTime; this.configuration = configuration; this.authPasswordSyntax = authPasswordSyntax; this.defaultStorageSchemes = defaultStorageSchemes; this.deprecatedStorageSchemes = deprecatedStorageSchemes; this.notificationHandlers = notificationHandlers; this.passwordGenerator = passwordGenerator; this.passwordValidators = passwordValidators; this.requireChangeByTime = requireChangeByTime; } } @@ -1148,7 +1150,7 @@ } private ServerContext serverContext; /** * Default constructor instantiated from authentication policy config manager. @@ -1158,7 +1160,16 @@ // Nothing to do . } /** * Sets the server context. * * @param serverContext * The server context. */ @Override public void setServerContext(final ServerContext serverContext) { this.serverContext = serverContext; } /** * {@inheritDoc} @@ -1168,7 +1179,7 @@ final PasswordPolicyCfg configuration) throws ConfigException, InitializationException { PasswordPolicyImpl policy = new PasswordPolicyImpl(configuration); PasswordPolicyImpl policy = new PasswordPolicyImpl(serverContext, configuration); configuration.addPasswordPolicyChangeListener(policy); return policy; } @@ -1185,7 +1196,7 @@ { try { new PasswordPolicyImpl(configuration); new PasswordPolicyImpl(null, configuration); } catch (final ConfigException ce) { opendj3-server-dev/src/server/org/opends/server/core/SchemaConfigManager.java
@@ -64,11 +64,17 @@ /** The schema that has been parsed from the server configuration. */ private Schema schema; private final ServerContext serverContext; /** * Creates a new instance of this schema config manager. * * @param serverContext * The server context. */ public SchemaConfigManager() public SchemaConfigManager(ServerContext serverContext) { this.serverContext = serverContext; schema = new Schema(); } @@ -147,7 +153,7 @@ throws ConfigException, InitializationException { AttributeSyntaxConfigManager syntaxConfigManager = new AttributeSyntaxConfigManager(); new AttributeSyntaxConfigManager(serverContext); syntaxConfigManager.initializeAttributeSyntaxes(); } opendj3-server-dev/src/server/org/opends/server/core/ServerContext.java
@@ -25,6 +25,8 @@ */ package org.opends.server.core; import org.opends.server.types.Schema; /** * Context for the server, giving access to global properties of the server. */ @@ -45,4 +47,11 @@ */ public String getServerRoot(); /** * Returns the schema of the server. * * @return the schema */ public Schema getSchema(); } opendj3-server-dev/src/server/org/opends/server/extensions/LDAPPassThroughAuthenticationPolicyFactory.java
@@ -50,6 +50,7 @@ import org.opends.server.config.ConfigException; import org.opends.server.core.DirectoryServer; import org.opends.server.core.ModifyOperation; import org.opends.server.core.ServerContext; import org.opends.server.protocols.internal.InternalClientConnection; import org.opends.server.protocols.ldap.*; import org.opends.server.schema.GeneralizedTimeSyntax; @@ -2162,6 +2163,8 @@ // The provider which should be used by policies to create LDAP connections. private final Provider provider; private ServerContext serverContext; /** * The default LDAP connection factory provider. */ @@ -2390,7 +2393,16 @@ this(DEFAULT_PROVIDER); } /** * Sets the server context. * * @param serverContext * The server context. */ @Override public void setServerContext(ServerContext serverContext) { this.serverContext = serverContext; } /** * Package private constructor allowing unit tests to provide mock connection opendj3-server-dev/src/server/org/opends/server/schema/MatchingRuleSyntax.java
@@ -546,8 +546,7 @@ // See if the server recognizes that syntax. If not, then log a // warning. syntax = DirectoryServer.getAttributeSyntax(oidBuffer.toString(), false); syntax = DirectoryServer.getSchema().getSyntax(oidBuffer.toString(), false); if (syntax == null) { logger.error(ERR_ATTR_SYNTAX_MR_UNKNOWN_SYNTAX, valueStr, oidBuffer); opendj3-server-dev/src/server/org/opends/server/schema/ObjectIdentifierFirstComponentEqualityMatchingRule.java
@@ -276,10 +276,10 @@ } } AttributeSyntax syntax1 = DirectoryServer.getAttributeSyntax(oid, false); AttributeSyntax syntax1 = DirectoryServer.getSchema().getSyntax(oid, false); if (syntax1 != null) { AttributeSyntax syntax2 = DirectoryServer.getAttributeSyntax(value2String, AttributeSyntax syntax2 = DirectoryServer.getSchema().getSyntax(value2String, false); if (syntax2 == null) { opendj3-server-dev/src/server/org/opends/server/types/DirectoryConfig.java
@@ -418,29 +418,6 @@ return DirectoryServer.getAttributeSyntaxes(); } /** * Retrieves the requested attribute syntax. * * @param oid The OID of the syntax to retrieve. * @param allowDefault Indicates whether to return the default * attribute syntax if the requested syntax is * unknown. * * @return The requested attribute syntax, the default syntax if * the requested syntax is unknown and the caller has * indicated that the default is acceptable, or * <CODE>null</CODE> otherwise. */ public static AttributeSyntax getAttributeSyntax(String oid, boolean allowDefault) { return DirectoryServer.getAttributeSyntax(oid, allowDefault); } /** * Retrieves the default attribute syntax that should be used for * attributes that are not defined in the server schema. opendj3-server-dev/src/server/org/opends/server/types/Schema.java
@@ -39,6 +39,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.forgerock.i18n.LocalizableMessage; import org.opends.server.admin.std.server.DirectoryStringAttributeSyntaxCfg; import org.forgerock.i18n.slf4j.LocalizedLogger; import org.forgerock.opendj.ldap.ByteString; import org.forgerock.opendj.ldap.ModificationType; @@ -119,6 +120,11 @@ private ConcurrentHashMap<String,AttributeSyntax<?>> syntaxes; /** * The default attribute syntax to use for attributes with no defined syntax. */ private AttributeSyntax<DirectoryStringAttributeSyntaxCfg> defaultSyntax; /** * The entire set of matching rules for this schema, mapped between the * lowercase names and OID for the definition and the matching rule itself. */ @@ -836,7 +842,28 @@ return syntaxes.containsKey(lowerName); } /** * Retrieves the requested attribute syntax. * * @param oid * The OID of the syntax to retrieve. * @param allowDefault * Indicates whether to return the default attribute syntax if the * requested syntax is unknown. * @return The requested attribute syntax, the default syntax if the requested * syntax is unknown and the caller has indicated that the default is * acceptable, or <CODE>null</CODE> otherwise. */ public AttributeSyntax getSyntax(String oid, boolean allowDefault) { AttributeSyntax syntax = getSyntax(oid); if (syntax == null && allowDefault) { return getDefaultSyntax(); } return syntax; } /** * Retrieves the attribute syntax definition with the OID. @@ -852,6 +879,32 @@ return syntaxes.get(lowerName); } /** * Retrieves the default attribute syntax that should be used for attributes * that are not defined in the server schema. * * @return The default attribute syntax that should be used for attributes * that are not defined in the server schema. */ public AttributeSyntax getDefaultSyntax() { return defaultSyntax; } /** * Registers the defaut syntax for this schema. * * @param defaultSyntax * The defautl syntax to use. */ public void registerDefaultSyntax( AttributeSyntax<DirectoryStringAttributeSyntaxCfg> defaultSyntax) { this.defaultSyntax = defaultSyntax; } /** opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/AttributeTypeSyntaxTest.java
@@ -159,7 +159,7 @@ // server. AttributeTypeSyntax attrTypeSyntax = (AttributeTypeSyntax) DirectoryServer.getAttributeSyntax("1.3.6.1.4.1.1466.115.121.1.3", false); DirectoryServer.getSchema().getSyntax("1.3.6.1.4.1.1466.115.121.1.3", false); assertNotNull(attrTypeSyntax); opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/ConfigurableAttributeSyntaxTest.java
@@ -115,7 +115,7 @@ config.getEntry()); TelephoneNumberSyntax syntax = (TelephoneNumberSyntax) DirectoryServer.getAttributeSyntax(oid, false); (TelephoneNumberSyntax) DirectoryServer.getSchema().getSyntax(oid, false); // apply the configuration. ArrayList<LocalizableMessage> unacceptableReasons = new ArrayList<LocalizableMessage>();