You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by sm...@apache.org on 2021/06/24 17:13:28 UTC
[directory-fortress-core] branch FC-238 updated: Got the
RelaxControl working again. Also parameterized the max and block connection
pool settings in properties
This is an automated email from the ASF dual-hosted git repository.
smckinney pushed a commit to branch FC-238
in repository https://gitbox.apache.org/repos/asf/directory-fortress-core.git
The following commit(s) were added to refs/heads/FC-238 by this push:
new 32d7dc1 Got the RelaxControl working again. Also parameterized the max and block connection pool settings in properties
32d7dc1 is described below
commit 32d7dc13f840408d1381d41267f9fa3acd84a041
Author: Shawn McKinney <sm...@symas.com>
AuthorDate: Thu Jun 24 12:13:22 2021 -0500
Got the RelaxControl working again. Also parameterized the max and block connection pool settings in properties
---
build-config.xml | 6 ++
build.properties.example | 6 ++
config/bootstrap/fortress.properties.src | 11 ++++
config/fortress.properties.src | 6 ++
slapd.properties.example | 6 ++
.../apache/directory/fortress/core/GlobalIds.java | 9 ++-
.../fortress/core/ldap/LdapConnectionProvider.java | 35 ++++++-----
.../fortress/core/ldap/LdapDataProvider.java | 2 -
.../fortress/core/ldap/RelaxControlDecorator.java | 34 ----------
.../fortress/core/ldap/RelaxControlFactory.java | 73 ++++++++--------------
10 files changed, 89 insertions(+), 99 deletions(-)
diff --git a/build-config.xml b/build-config.xml
index cf60447..933a5d7 100644
--- a/build-config.xml
+++ b/build-config.xml
@@ -311,6 +311,9 @@
<replace file="${dst.bootstrap.conf}" token="@USR_MAX_CONN@" value="${user.max.conn}"/>
<replace file="${dst.bootstrap.conf}" token="@VALIDATE_CONN_IDLE@" value="${all.validate.conn.idle}"/>
<replace file="${dst.bootstrap.conf}" token="@VALIDATE_CONN_BORROW@" value="${all.validate.conn.borrow}"/>
+ <replace file="${dst.bootstrap.conf}" token="@MAX_CONN_BLOCK@" value="${all.max.conn.block}"/>
+ <replace file="${dst.bootstrap.conf}" token="@MAX_CONN_BLOCK_TIME@" value="${all.max.conn.block.time}"/>
+ <replace file="${dst.bootstrap.conf}" token="@REGISTER_RELAX_CONTROL@" value="${temp.enable.relax.control}"/>
<replace file="${dst.bootstrap.conf}" token="@CFG_CRYPTO_PROP@" value="${crypto.prop}"/>
<replace file="${dst.bootstrap.conf}" token="@SERVER_TYPE@" value="${ldap.server.type}"/>
<replace file="${dst.bootstrap.conf}" token="@ROLE_OCCUPANTS@" value="${role.occupants}"/>
@@ -350,6 +353,9 @@
<replace file="${dst.remote.conf}" token="@USR_MIN_CONN@" value="${user.min.conn}"/>
<replace file="${dst.remote.conf}" token="@VALIDATE_CONN_IDLE@" value="${all.validate.conn.idle}"/>
<replace file="${dst.remote.conf}" token="@VALIDATE_CONN_BORROW@" value="${all.validate.conn.borrow}"/>
+ <replace file="${dst.remote.conf}" token="@MAX_CONN_BLOCK@" value="${all.max.conn.block}"/>
+ <replace file="${dst.remote.conf}" token="@MAX_CONN_BLOCK_TIME@" value="${all.max.conn.block.time}"/>
+ <replace file="${dst.remote.conf}" token="@REGISTER_RELAX_CONTROL@" value="${temp.enable.relax.control}"/>
<replace file="${dst.remote.conf}" token="@USR_MAX_CONN@" value="${user.max.conn}"/>
<replace file="${dst.remote.conf}" token="@CFG_CRYPTO_PROP@" value="${crypto.prop}"/>
<replace file="${dst.remote.conf}" token="@ENABLE_REST@" value="${enable.mgr.impl.rest}"/>
diff --git a/build.properties.example b/build.properties.example
index 8e280db..268ebeb 100644
--- a/build.properties.example
+++ b/build.properties.example
@@ -118,6 +118,12 @@ user.max.conn=10
all.validate.conn.borrow=false
# Applies to all pools, connection validated when idle with dummy ldapsearch. (default is false)
all.validate.conn.idle=false
+# Applies to all pools, when all connections are exhausted will block. (default is true)
+all.max.conn.block=true
+# Applies to all pools, when all connections are exhausted will block for this many milliseconds. (default is 5000)
+all.max.conn.block.time=5000
+# Set to true if using API 2.0.2 and need relax control (default is false):
+temp.enable.relax.control=false
########################################################################
# 3. GROUP OBJECT CLASS DEFINITIONS
diff --git a/config/bootstrap/fortress.properties.src b/config/bootstrap/fortress.properties.src
index d0c4f7b..883f964 100755
--- a/config/bootstrap/fortress.properties.src
+++ b/config/bootstrap/fortress.properties.src
@@ -52,6 +52,17 @@ log.admin.pw=@CFG_LOG_ROOT_PW@
min.log.conn=@LOG_MIN_CONN@
max.log.conn=@LOG_MAX_CONN@
+# Applies to all pools, connection validated on retrieval with dummy ldapsearch. (default is false)
+validate.conn.borrow=@VALIDATE_CONN_BORROW@
+# Applies to all pools, connection validated when idle with dummy ldapsearch. (default is false)
+validate.conn.idle=@VALIDATE_CONN_IDLE@
+# Applies to all pools, when all connections are exhausted will block. (default is true)
+max.conn.block=@MAX_CONN_BLOCK@
+# Applies to all pools, when all connections are exhausted will block for this many milliseconds. (default is 5000)
+max.conn.block.time=@MAX_CONN_BLOCK_TIME@
+# Set to true if using API 2.0.2 and need relax control (default is false):
+enable.relax.control.registration=@REGISTER_RELAX_CONTROL@
+
validate.conn.borrow=@VALIDATE_CONN_BORROW@
validate.conn.idle=@VALIDATE_CONN_IDLE@
diff --git a/config/fortress.properties.src b/config/fortress.properties.src
index c8b6eb5..9996ec0 100755
--- a/config/fortress.properties.src
+++ b/config/fortress.properties.src
@@ -62,6 +62,12 @@ max.user.conn=@USR_MAX_CONN@
validate.conn.borrow=@VALIDATE_CONN_BORROW@
# Applies to all pools, connection validated when idle with dummy ldapsearch. (default is false)
validate.conn.idle=@VALIDATE_CONN_IDLE@
+# Applies to all pools, when all connections are exhausted will block. (default is true)
+max.conn.block=@MAX_CONN_BLOCK@
+# Applies to all pools, when all connections are exhausted will block for this many milliseconds. (default is 5000)
+max.conn.block.time=@MAX_CONN_BLOCK_TIME@
+# Set to true if using API 2.0.2 and need relax control (default is false):
+enable.relax.control.registration=@REGISTER_RELAX_CONTROL@
# These credentials are used for read/write access to all nodes under slapd access log suffix:
log.admin.user=@LOG_ROOT_DN@
diff --git a/slapd.properties.example b/slapd.properties.example
index 1a3b5e4..c3e1baa 100644
--- a/slapd.properties.example
+++ b/slapd.properties.example
@@ -76,6 +76,12 @@ log.max.conn=3
all.validate.conn.borrow=false
# Applies to all pools, connection validated when idle with dummy ldapsearch. (default is false)
all.validate.conn.idle=false
+# Applies to all pools, when all connections are exhausted will block. (default is true)
+all.max.conn.block=true
+# Applies to all pools, when all connections are exhausted will block for this many milliseconds. (default is 5000)
+all.max.conn.block.time=5000
+# Set to true if using API 2.0.2 and need relax control (default is false):
+temp.enable.relax.control=false
#These are passwords used for LDAP audit log service accounts:
# Audit Pool:
diff --git a/src/main/java/org/apache/directory/fortress/core/GlobalIds.java b/src/main/java/org/apache/directory/fortress/core/GlobalIds.java
index fee7aaa..7d6f727 100755
--- a/src/main/java/org/apache/directory/fortress/core/GlobalIds.java
+++ b/src/main/java/org/apache/directory/fortress/core/GlobalIds.java
@@ -463,7 +463,14 @@ public final class GlobalIds
* Applies to all pools, connection validated when idle with dummy ldapsearch.
*/
public static final String TEST_ON_IDLE = "validate.conn.idle";
-
+ /**
+ * Applies to all pools, when all connections are exhausted will block. (default is true)
+ */
+ public static final String IS_MAX_CONN_BLOCK = "max.conn.block";
+ /**
+ * Applies to all pools, when all connections are exhausted will block for this many milliseconds. (default is 5000)
+ */
+ public static final String MAX_CONN_BLOCK_TIME = "max.conn.block.time";
// Used for TLS/SSL client-side configs:
public static final String ENABLE_LDAP_SSL = "enable.ldap.ssl";
public static final String ENABLE_LDAP_STARTTLS = "enable.ldap.starttls";
diff --git a/src/main/java/org/apache/directory/fortress/core/ldap/LdapConnectionProvider.java b/src/main/java/org/apache/directory/fortress/core/ldap/LdapConnectionProvider.java
index dfb18bd..cb0184a 100644
--- a/src/main/java/org/apache/directory/fortress/core/ldap/LdapConnectionProvider.java
+++ b/src/main/java/org/apache/directory/fortress/core/ldap/LdapConnectionProvider.java
@@ -23,11 +23,11 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
-import org.apache.commons.pool.PoolableObjectFactory;
-import org.apache.commons.pool.impl.GenericObjectPool;
import org.apache.commons.pool2.PooledObjectFactory;
+import org.apache.directory.api.ldap.codec.api.ControlFactory;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.codec.api.LdapApiServiceFactory;
+import org.apache.directory.api.ldap.codec.osgi.DefaultLdapCodecService;
import org.apache.directory.api.ldap.codec.standalone.StandaloneLdapApiService;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.fortress.core.CfgRuntimeException;
@@ -35,10 +35,7 @@ import org.apache.directory.fortress.core.GlobalErrIds;
import org.apache.directory.fortress.core.GlobalIds;
import org.apache.directory.fortress.core.util.Config;
import org.apache.directory.fortress.core.util.EncryptUtil;
-import org.apache.directory.ldap.client.api.LdapConnection;
-import org.apache.directory.ldap.client.api.LdapConnectionConfig;
-import org.apache.directory.ldap.client.api.LdapConnectionPool;
-import org.apache.directory.ldap.client.api.ValidatingPoolableLdapConnectionFactory;
+import org.apache.directory.ldap.client.api.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -128,6 +125,8 @@ public class LdapConnectionProvider
int logmax = Config.getInstance().getInt( GlobalIds.LDAP_LOG_POOL_MAX, 10 );
boolean testOnBorrow = Config.getInstance().getBoolean( GlobalIds.TEST_ON_BORROW, false );
boolean testWhileIdle = Config.getInstance().getBoolean( GlobalIds.TEST_ON_IDLE, false );
+ boolean isBlockOnMaxConnection = Config.getInstance().getBoolean( GlobalIds.IS_MAX_CONN_BLOCK, true );
+ int maxConnBlockTime = Config.getInstance().getInt( GlobalIds.MAX_CONN_BLOCK_TIME, 5000 );
int timeBetweenEvictionRunMillis = Config.getInstance().getInt( GlobalIds.LDAP_ADMIN_POOL_EVICT_RUN_MILLIS, 1000 * 60 * 30 );
int logTimeBetweenEvictionRunMillis = Config.getInstance().getInt( GlobalIds.LDAP_LOG_POOL_EVICT_RUN_MILLIS, 1000 * 60 * 30 );
@@ -165,8 +164,16 @@ public class LdapConnectionProvider
{
adminPw = Config.getInstance().getProperty( GlobalIds.LDAP_ADMIN_POOL_PW, true );
}
-
config.setCredentials( adminPw );
+
+ // Register Relax Control:
+ if ( Config.getInstance().getBoolean( "enable.relax.control.registration", false ) )
+ {
+ ControlFactory<RelaxControl> relaxControlFactory = new RelaxControlFactory( new DefaultLdapCodecService() );
+ (new LdapNetworkConnection()).getCodecService().registerRequestControl(relaxControlFactory);
+ LOG.info( "Register RelaxControl" );
+ }
+
// TODO: FIXME #4
/*
try
@@ -199,8 +206,8 @@ public class LdapConnectionProvider
adminPool = new LdapConnectionPool( poolFactory );
adminPool.setTestOnBorrow( testOnBorrow );
adminPool.setMaxTotal( max );
- adminPool.setBlockWhenExhausted( true );
- adminPool.setMaxWaitMillis( 5000 );
+ adminPool.setBlockWhenExhausted( isBlockOnMaxConnection );
+ adminPool.setMaxWaitMillis( maxConnBlockTime );
adminPool.setMinIdle( min );
adminPool.setMaxIdle( -1 );
adminPool.setTestWhileIdle( testWhileIdle );
@@ -210,8 +217,8 @@ public class LdapConnectionProvider
userPool = new LdapConnectionPool( poolFactory );
userPool.setTestOnBorrow( testOnBorrow );
userPool.setMaxTotal( max );
- userPool.setBlockWhenExhausted( true );
- userPool.setMaxWaitMillis( 5000 );
+ userPool.setBlockWhenExhausted( isBlockOnMaxConnection );
+ userPool.setMaxWaitMillis( maxConnBlockTime );
userPool.setMinIdle( min );
userPool.setMaxIdle( -1 );
userPool.setTestWhileIdle( testWhileIdle );
@@ -254,9 +261,9 @@ public class LdapConnectionProvider
poolFactory = new ValidatingPoolableLdapConnectionFactory( logConfig );
logPool = new LdapConnectionPool( poolFactory );
logPool.setTestOnBorrow( testOnBorrow );
- logPool.setMaxTotal( max );
- logPool.setBlockWhenExhausted( true );
- logPool.setMaxWaitMillis( 5000 );
+ logPool.setMaxTotal( logmax );
+ logPool.setBlockWhenExhausted( isBlockOnMaxConnection );
+ logPool.setMaxWaitMillis( maxConnBlockTime );
logPool.setMinIdle( logmin );
logPool.setTestWhileIdle( testWhileIdle );
logPool.setTimeBetweenEvictionRunsMillis( logTimeBetweenEvictionRunMillis );
diff --git a/src/main/java/org/apache/directory/fortress/core/ldap/LdapDataProvider.java b/src/main/java/org/apache/directory/fortress/core/ldap/LdapDataProvider.java
index 4ce8d9f..925417c 100644
--- a/src/main/java/org/apache/directory/fortress/core/ldap/LdapDataProvider.java
+++ b/src/main/java/org/apache/directory/fortress/core/ldap/LdapDataProvider.java
@@ -272,7 +272,6 @@ public abstract class LdapDataProvider
}
AddRequest addRequest = new AddRequestImpl();
addRequest.setEntry( entry );
- // TODO: FIXME #2
if ( setRelaxControl )
{
addRequest.addControl( new RelaxControlImpl() );
@@ -350,7 +349,6 @@ public abstract class LdapDataProvider
{
modRequest.addModification( mod );
}
- // TODO: FIXME #2
if ( setRelaxControl )
{
modRequest.addControl( new RelaxControlImpl() );
diff --git a/src/main/java/org/apache/directory/fortress/core/ldap/RelaxControlDecorator.java b/src/main/java/org/apache/directory/fortress/core/ldap/RelaxControlDecorator.java
deleted file mode 100644
index 70ef78f..0000000
--- a/src/main/java/org/apache/directory/fortress/core/ldap/RelaxControlDecorator.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.apache.directory.fortress.core.ldap;
-
-
-import org.apache.directory.api.asn1.Asn1Object;
-import org.apache.directory.api.asn1.DecoderException;
-import org.apache.directory.api.asn1.EncoderException;
-import org.apache.directory.api.ldap.codec.api.ControlDecorator;
-import org.apache.directory.api.ldap.codec.api.LdapApiService;
-
-import java.nio.ByteBuffer;
-
-
-public class RelaxControlDecorator extends ControlDecorator<RelaxControl> implements RelaxControl
-{
- public RelaxControlDecorator(LdapApiService codec, RelaxControl control)
- {
- super(codec, control);
- }
-
- public int computeLength()
- {
- return 0;
- }
-
- public Asn1Object decode(byte[] controlBytes) throws DecoderException
- {
- return this;
- }
-
- public ByteBuffer encode(ByteBuffer buffer) throws EncoderException
- {
- return buffer;
- }
-}
diff --git a/src/main/java/org/apache/directory/fortress/core/ldap/RelaxControlFactory.java b/src/main/java/org/apache/directory/fortress/core/ldap/RelaxControlFactory.java
index a241393..c8cef82 100644
--- a/src/main/java/org/apache/directory/fortress/core/ldap/RelaxControlFactory.java
+++ b/src/main/java/org/apache/directory/fortress/core/ldap/RelaxControlFactory.java
@@ -1,34 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
package org.apache.directory.fortress.core.ldap;
-import org.apache.directory.api.asn1.DecoderException;
-import org.apache.directory.api.asn1.util.Asn1Buffer;
-import org.apache.directory.api.ldap.codec.api.CodecControl;
-import org.apache.directory.api.ldap.codec.api.ControlContainer;
-import org.apache.directory.api.ldap.codec.api.ControlFactory;
+import org.apache.directory.api.ldap.codec.api.AbstractControlFactory;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
-import org.apache.directory.api.ldap.model.message.Control;
-
-/**
- * A codec {@link ControlFactory} implementation for {@link RelaxControl} controls.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-public class RelaxControlFactory implements ControlFactory<RelaxControl>
+public class RelaxControlFactory extends AbstractControlFactory<RelaxControl>
{
- /** The LDAP codec responsible for encoding and decoding Cascade Controls */
- private LdapApiService codec;
-
-
/**
- * Creates a new instance of TransactionSpecificationFactory.
+ * Creates a new instance of ManageDsaITFactory.
*
* @param codec The LDAP codec
*/
public RelaxControlFactory( LdapApiService codec )
{
- this.codec = codec;
+ super( codec, RelaxControl.OID );
}
@@ -36,35 +40,8 @@ public class RelaxControlFactory implements ControlFactory<RelaxControl>
* {@inheritDoc}
*/
@Override
- public String getOid()
+ public RelaxControl newControl()
{
- return RelaxControl.OID;
+ return new RelaxControlImpl();
}
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public CodecControl<RelaxControl> newControl()
- {
- return new RelaxControlDecorator( codec, new RelaxControlImpl() );
- }
-
-
- public void encodeValue(Asn1Buffer var1, Control var2)
- {
-
- }
-
- public void decodeValue(ControlContainer var1, Control var2, byte[] var3) throws DecoderException
- {
-
- }
-
- public void decodeValue(Control var1, byte[] var2) throws DecoderException
- {
-
- }
-
}