You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2023/02/14 03:10:24 UTC
[directory-ldap-api] branch master updated: o Added a Default DN factory and used it. o Added a Cache for DN to avoid parsing them again and again when they are the same
This is an automated email from the ASF dual-hosted git repository.
elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git
The following commit(s) were added to refs/heads/master by this push:
new b1230085f o Added a Default DN factory and used it. o Added a Cache for DN to avoid parsing them again and again when they are the same
b1230085f is described below
commit b1230085ff33b15649196f40f8d2035feed4c803
Author: emmanuel lecharny <el...@apache.org>
AuthorDate: Tue Feb 14 04:10:19 2023 +0100
o Added a Default DN factory and used it.
o Added a Cache for DN to avoid parsing them again and again when they
are the same
---
.../directory/api/osgi/ApiLdapNetMinaOsgiTest.java | 2 +-
.../ldap/client/api/LdapNetworkConnection.java | 12 +-
.../codec/actions/ldapResult/StoreMatchedDN.java | 12 +-
.../request/add/StoreAddRequestEntryName.java | 14 +-
.../compare/StoreCompareRequestEntryName.java | 16 ++-
.../codec/actions/request/del/InitDelRequest.java | 16 ++-
.../modify/StoreModifyRequestObjectName.java | 12 +-
.../modifydn/StoreModifyDnRequestEntryName.java | 16 ++-
.../modifydn/StoreModifyDnRequestNewRdn.java | 16 ++-
.../modifydn/StoreModifyDnRequestNewSuperior.java | 14 +-
.../search/StoreSearchRequestBaseObject.java | 14 +-
.../entry/StoreSearchResultEntryObjectName.java | 14 +-
.../api/ldap/codec/api/LdapApiService.java | 15 ++
.../api/ldap/codec/api/LdapMessageContainer.java | 22 +++
.../ldap/codec/osgi/DefaultLdapCodecService.java | 25 +++-
ldap/model/pom.xml | 6 +
.../api/ldap/model/name/DefaultDnFactory.java | 160 +++++++++++++++++++++
.../directory/api/ldap/model/name/DnFactory.java | 51 +++++++
.../directory/api/ldap/model/url/LdapUrlTest.java | 1 -
.../protocol/mina/LdapProtocolCodecFactory.java | 2 +-
.../codec/protocol/mina/LdapProtocolDecoder.java | 9 +-
pom.xml | 17 +++
22 files changed, 445 insertions(+), 21 deletions(-)
diff --git a/integ-osgi/src/test/java/org/apache/directory/api/osgi/ApiLdapNetMinaOsgiTest.java b/integ-osgi/src/test/java/org/apache/directory/api/osgi/ApiLdapNetMinaOsgiTest.java
index b286a194d..d25470fdb 100644
--- a/integ-osgi/src/test/java/org/apache/directory/api/osgi/ApiLdapNetMinaOsgiTest.java
+++ b/integ-osgi/src/test/java/org/apache/directory/api/osgi/ApiLdapNetMinaOsgiTest.java
@@ -49,7 +49,7 @@ public class ApiLdapNetMinaOsgiTest extends ApiOsgiTestBase
@Override
protected void useBundleClasses() throws Exception
{
- new LdapProtocolDecoder();
+ new LdapProtocolDecoder( null );
new LdapProtocolEncoder();
}
diff --git a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
index 1c664e45a..e581163b8 100644
--- a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
+++ b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
@@ -143,6 +143,7 @@ import org.apache.directory.api.ldap.model.message.extended.ModifyDnNoDResponse;
import org.apache.directory.api.ldap.model.message.extended.ModifyNoDResponse;
import org.apache.directory.api.ldap.model.message.extended.NoticeOfDisconnect;
import org.apache.directory.api.ldap.model.message.extended.SearchNoDResponse;
+import org.apache.directory.api.ldap.model.name.DefaultDnFactory;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.name.Rdn;
import org.apache.directory.api.ldap.model.schema.AttributeType;
@@ -4584,9 +4585,14 @@ public class LdapNetworkConnection extends AbstractLdapConnection implements Lda
schemaManager = tmp;
// Change the container's BinaryDetector
- ioSession.setAttribute( LdapDecoder.MESSAGE_CONTAINER_ATTR,
+ LdapMessageContainer<Message> ldapMessageContainer =
new LdapMessageContainer<>( codec,
- new SchemaBinaryAttributeDetector( schemaManager ) ) );
+ new SchemaBinaryAttributeDetector( schemaManager ) );
+
+ // Associate a DnFactory to the container
+ ldapMessageContainer.setDnFactory( new DefaultDnFactory( schemaManager, 1000 ) );
+
+ ioSession.setAttribute( LdapDecoder.MESSAGE_CONTAINER_ATTR, ldapMessageContainer );
}
catch ( LdapException le )
@@ -4835,6 +4841,8 @@ public class LdapNetworkConnection extends AbstractLdapConnection implements Lda
LdapMessageContainer<Message> ldapMessageContainer =
new LdapMessageContainer<>(
codec, config.getBinaryAttributeDetector() );
+
+ ldapMessageContainer.setDnFactory( new DefaultDnFactory( schemaManager, 1000 ) );
session.setAttribute( LdapDecoder.MESSAGE_CONTAINER_ATTR, ldapMessageContainer );
}
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/ldapResult/StoreMatchedDN.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/ldapResult/StoreMatchedDN.java
index 8e23da4a8..011e3eb95 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/ldapResult/StoreMatchedDN.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/ldapResult/StoreMatchedDN.java
@@ -30,6 +30,7 @@ import org.apache.directory.api.ldap.model.message.LdapResult;
import org.apache.directory.api.ldap.model.message.Message;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.name.DnFactory;
import org.apache.directory.api.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -97,7 +98,16 @@ public class StoreMatchedDN extends GrammarAction<LdapMessageContainer<Message>>
try
{
- matchedDn = new Dn( dnStr );
+ DnFactory dnFactory = container.getDnFactory();
+
+ if ( dnFactory == null )
+ {
+ matchedDn = new Dn( dnStr );
+ }
+ else
+ {
+ matchedDn = dnFactory.create( dnStr );
+ }
}
catch ( LdapInvalidDnException ine )
{
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/add/StoreAddRequestEntryName.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/add/StoreAddRequestEntryName.java
index 26fc1324b..92396c137 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/add/StoreAddRequestEntryName.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/add/StoreAddRequestEntryName.java
@@ -31,6 +31,7 @@ import org.apache.directory.api.ldap.model.message.AddRequest;
import org.apache.directory.api.ldap.model.message.AddResponseImpl;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.name.DnFactory;
import org.apache.directory.api.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -90,7 +91,18 @@ public class StoreAddRequestEntryName extends GrammarAction<LdapMessageContainer
try
{
- Dn entryDn = new Dn( dnStr );
+ DnFactory dnFactory = container.getDnFactory();
+ Dn entryDn;
+
+ if ( dnFactory == null )
+ {
+ entryDn = new Dn( dnStr );
+ }
+ else
+ {
+ entryDn = dnFactory.create( dnStr );
+ }
+
addRequest.setEntryDn( entryDn );
}
catch ( LdapInvalidDnException ine )
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/compare/StoreCompareRequestEntryName.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/compare/StoreCompareRequestEntryName.java
index 67dd5f0ef..28d44438c 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/compare/StoreCompareRequestEntryName.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/compare/StoreCompareRequestEntryName.java
@@ -31,6 +31,7 @@ import org.apache.directory.api.ldap.model.message.CompareRequest;
import org.apache.directory.api.ldap.model.message.CompareResponseImpl;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.name.DnFactory;
import org.apache.directory.api.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -83,8 +84,19 @@ public class StoreCompareRequestEntryName extends GrammarAction<LdapMessageConta
try
{
- Dn entry = new Dn( dnStr );
- compareRequest.setName( entry );
+ DnFactory dnFactory = container.getDnFactory();
+ Dn entryDn;
+
+ if ( dnFactory == null )
+ {
+ entryDn = new Dn( dnStr );
+ }
+ else
+ {
+ entryDn = dnFactory.create( dnStr );
+ }
+
+ compareRequest.setName( entryDn );
}
catch ( LdapInvalidDnException ine )
{
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/del/InitDelRequest.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/del/InitDelRequest.java
index f1bb4e420..e77a28f06 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/del/InitDelRequest.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/del/InitDelRequest.java
@@ -32,6 +32,7 @@ import org.apache.directory.api.ldap.model.message.DeleteRequestImpl;
import org.apache.directory.api.ldap.model.message.DeleteResponseImpl;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.name.DnFactory;
import org.apache.directory.api.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -89,8 +90,19 @@ public class InitDelRequest extends GrammarAction<LdapMessageContainer<DeleteReq
try
{
- Dn entry = new Dn( dnStr );
- delRequest.setName( entry );
+ DnFactory dnFactory = container.getDnFactory();
+ Dn entryDn;
+
+ if ( dnFactory == null )
+ {
+ entryDn = new Dn( dnStr );
+ }
+ else
+ {
+ entryDn = dnFactory.create( dnStr );
+ }
+
+ delRequest.setName( entryDn );
}
catch ( LdapInvalidDnException ine )
{
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modify/StoreModifyRequestObjectName.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modify/StoreModifyRequestObjectName.java
index be35d61d8..22eff8565 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modify/StoreModifyRequestObjectName.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modify/StoreModifyRequestObjectName.java
@@ -31,6 +31,7 @@ import org.apache.directory.api.ldap.model.message.ModifyRequest;
import org.apache.directory.api.ldap.model.message.ModifyResponseImpl;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.name.DnFactory;
import org.apache.directory.api.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -83,7 +84,16 @@ public class StoreModifyRequestObjectName extends GrammarAction<LdapMessageConta
try
{
- object = new Dn( dnStr );
+ DnFactory dnFactory = container.getDnFactory();
+
+ if ( dnFactory == null )
+ {
+ object = new Dn( dnStr );
+ }
+ else
+ {
+ object = dnFactory.create( dnStr );
+ }
}
catch ( LdapInvalidDnException ine )
{
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modifydn/StoreModifyDnRequestEntryName.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modifydn/StoreModifyDnRequestEntryName.java
index dbf989a75..343634bf5 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modifydn/StoreModifyDnRequestEntryName.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modifydn/StoreModifyDnRequestEntryName.java
@@ -31,6 +31,7 @@ import org.apache.directory.api.ldap.model.message.ModifyDnRequest;
import org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.name.DnFactory;
import org.apache.directory.api.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -83,8 +84,19 @@ public class StoreModifyDnRequestEntryName extends GrammarAction<LdapMessageCont
try
{
- Dn entry = new Dn( dnStr );
- modifyDnRequest.setName( entry );
+ DnFactory dnFactory = container.getDnFactory();
+ Dn entryDn;
+
+ if ( dnFactory == null )
+ {
+ entryDn = new Dn( dnStr );
+ }
+ else
+ {
+ entryDn = dnFactory.create( dnStr );
+ }
+
+ modifyDnRequest.setName( entryDn );
}
catch ( LdapInvalidDnException ine )
{
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modifydn/StoreModifyDnRequestNewRdn.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modifydn/StoreModifyDnRequestNewRdn.java
index cef5085e6..313608cf6 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modifydn/StoreModifyDnRequestNewRdn.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modifydn/StoreModifyDnRequestNewRdn.java
@@ -31,6 +31,7 @@ import org.apache.directory.api.ldap.model.message.ModifyDnRequest;
import org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.name.DnFactory;
import org.apache.directory.api.ldap.model.name.Rdn;
import org.apache.directory.api.util.Strings;
import org.slf4j.Logger;
@@ -92,8 +93,19 @@ public class StoreModifyDnRequestNewRdn extends GrammarAction<LdapMessageContain
try
{
- Dn dn = new Dn( dnStr );
- Rdn newRdn = dn.getRdn( dn.size() - 1 );
+ DnFactory dnFactory = container.getDnFactory();
+ Dn entryDn;
+
+ if ( dnFactory == null )
+ {
+ entryDn = new Dn( dnStr );
+ }
+ else
+ {
+ entryDn = dnFactory.create( dnStr );
+ }
+
+ Rdn newRdn = entryDn.getRdn( entryDn.size() - 1 );
modifyDnRequest.setNewRdn( newRdn );
}
catch ( LdapInvalidDnException ine )
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modifydn/StoreModifyDnRequestNewSuperior.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modifydn/StoreModifyDnRequestNewSuperior.java
index 0bed922e8..156179255 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modifydn/StoreModifyDnRequestNewSuperior.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/modifydn/StoreModifyDnRequestNewSuperior.java
@@ -31,6 +31,7 @@ import org.apache.directory.api.ldap.model.message.ModifyDnRequest;
import org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.name.DnFactory;
import org.apache.directory.api.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -97,7 +98,18 @@ public class StoreModifyDnRequestNewSuperior extends GrammarAction<LdapMessageCo
try
{
- Dn newSuperior = new Dn( dnStr );
+ DnFactory dnFactory = container.getDnFactory();
+ Dn newSuperior;
+
+ if ( dnFactory == null )
+ {
+ newSuperior = new Dn( dnStr );
+ }
+ else
+ {
+ newSuperior = dnFactory.create( dnStr );
+ }
+
modifyDnRequest.setNewSuperior( newSuperior );
}
catch ( LdapInvalidDnException ine )
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/search/StoreSearchRequestBaseObject.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/search/StoreSearchRequestBaseObject.java
index 3357fe69e..839ff9df5 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/search/StoreSearchRequestBaseObject.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/request/search/StoreSearchRequestBaseObject.java
@@ -31,6 +31,7 @@ import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
import org.apache.directory.api.ldap.model.message.SearchRequest;
import org.apache.directory.api.ldap.model.message.SearchResultDoneImpl;
import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.name.DnFactory;
import org.apache.directory.api.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -81,7 +82,18 @@ public class StoreSearchRequestBaseObject extends GrammarAction<LdapMessageConta
try
{
- Dn baseObject = new Dn( dnStr );
+ DnFactory dnFactory = container.getDnFactory();
+ Dn baseObject;
+
+ if ( dnFactory == null )
+ {
+ baseObject = new Dn( dnStr );
+ }
+ else
+ {
+ baseObject = new Dn( dnStr ); //dnFactory.create( dnStr );
+ }
+
searchRequest.setBase( baseObject );
}
catch ( LdapInvalidDnException ine )
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/response/search/entry/StoreSearchResultEntryObjectName.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/response/search/entry/StoreSearchResultEntryObjectName.java
index a91b851dd..e4bb29ba9 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/response/search/entry/StoreSearchResultEntryObjectName.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/actions/response/search/entry/StoreSearchResultEntryObjectName.java
@@ -28,6 +28,7 @@ import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
import org.apache.directory.api.ldap.model.message.SearchResultEntry;
import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.name.DnFactory;
import org.apache.directory.api.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -79,7 +80,18 @@ public class StoreSearchResultEntryObjectName extends GrammarAction<LdapMessageC
try
{
- Dn objectName = new Dn( dnStr );
+ DnFactory dnFactory = container.getDnFactory();
+ Dn objectName;
+
+ if ( dnFactory == null )
+ {
+ objectName = new Dn( dnStr );
+ }
+ else
+ {
+ objectName = dnFactory.create( dnStr );
+ }
+
searchResultEntry.setObjectName( objectName );
}
catch ( LdapInvalidDnException ine )
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapApiService.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapApiService.java
index 1856cac81..42d55802b 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapApiService.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapApiService.java
@@ -28,6 +28,7 @@ import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.message.ExtendedRequest;
import org.apache.directory.api.ldap.model.message.ExtendedResponse;
+import org.apache.directory.api.ldap.model.name.DnFactory;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
@@ -356,4 +357,18 @@ public interface LdapApiService
* none had been set earlier.
*/
ProtocolCodecFactory registerProtocolCodecFactory( ProtocolCodecFactory factory );
+
+
+ /**
+ * Associate a DnFactory to the service
+ * @param dnfactory The DnFactory instance
+ */
+ void setDnfactory( DnFactory dnfactory );
+
+
+ /**
+ * Get the DN Factory
+ * @return The DnFactory instance
+ */
+ DnFactory getDnFactory();
}
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapMessageContainer.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapMessageContainer.java
index de514b419..b005761d7 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapMessageContainer.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapMessageContainer.java
@@ -35,6 +35,7 @@ import org.apache.directory.api.ldap.model.message.ExtendedResponse;
import org.apache.directory.api.ldap.model.message.LdapResult;
import org.apache.directory.api.ldap.model.message.Message;
import org.apache.directory.api.ldap.model.message.ResultResponse;
+import org.apache.directory.api.ldap.model.name.DnFactory;
/**
@@ -63,6 +64,9 @@ public class LdapMessageContainer<E extends Message> extends AbstractContainer
/** The current control factory, if any */
private ControlFactory<?> controlFactory;
+ /** The DN Factory used to speed up Ldap Message DN decoding */
+ private DnFactory dnFactory;
+
/** The current Intermediate response factory */
private IntermediateOperationFactory intermediateFactory;
@@ -539,4 +543,22 @@ public class LdapMessageContainer<E extends Message> extends AbstractContainer
{
this.extendedFactory = extendedFactory;
}
+
+
+ /**
+ * @return the dnFactory
+ */
+ public DnFactory getDnFactory()
+ {
+ return dnFactory;
+ }
+
+
+ /**
+ * @param dnFactory the dnFactory to set
+ */
+ public void setDnFactory( DnFactory dnFactory )
+ {
+ this.dnFactory = dnFactory;
+ }
}
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/osgi/DefaultLdapCodecService.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/osgi/DefaultLdapCodecService.java
index 257a90b61..aeac46e4e 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/osgi/DefaultLdapCodecService.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/osgi/DefaultLdapCodecService.java
@@ -48,8 +48,8 @@ import org.apache.directory.api.ldap.codec.controls.sort.SortRequestFactory;
import org.apache.directory.api.ldap.codec.controls.sort.SortResponseFactory;
import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.message.ExtendedRequest;
-import org.apache.directory.api.ldap.model.message.OpaqueExtendedRequest;
import org.apache.directory.api.ldap.model.message.ExtendedResponse;
+import org.apache.directory.api.ldap.model.message.OpaqueExtendedRequest;
import org.apache.directory.api.ldap.model.message.controls.Cascade;
import org.apache.directory.api.ldap.model.message.controls.EntryChange;
import org.apache.directory.api.ldap.model.message.controls.ManageDsaIT;
@@ -60,6 +60,7 @@ import org.apache.directory.api.ldap.model.message.controls.ProxiedAuthz;
import org.apache.directory.api.ldap.model.message.controls.SortRequest;
import org.apache.directory.api.ldap.model.message.controls.SortResponse;
import org.apache.directory.api.ldap.model.message.controls.Subentries;
+import org.apache.directory.api.ldap.model.name.DnFactory;
import org.apache.directory.api.util.Strings;
import org.apache.directory.api.util.exception.NotImplementedException;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
@@ -95,6 +96,9 @@ public class DefaultLdapCodecService implements LdapApiService
/** The registered ProtocolCodecFactory */
private ProtocolCodecFactory protocolCodecFactory;
+
+ /** The DN Factory */
+ private DnFactory dnFactory;
/**
@@ -759,4 +763,23 @@ public class DefaultLdapCodecService implements LdapApiService
return sb.toString();
}
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setDnfactory( DnFactory dnfactory )
+ {
+ this.dnFactory = dnfactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public DnFactory getDnFactory()
+ {
+ return dnFactory;
+ }
}
diff --git a/ldap/model/pom.xml b/ldap/model/pom.xml
index 4f3a8cba9..8f645c0f4 100644
--- a/ldap/model/pom.xml
+++ b/ldap/model/pom.xml
@@ -97,6 +97,11 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>com.github.ben-manes.caffeine</groupId>
+ <artifactId>caffeine</artifactId>
+ </dependency>
</dependencies>
<build>
@@ -194,6 +199,7 @@
<Import-Package>
antlr;version=${antlr.version},
antlr.collections.impl;version=${antlr.version},
+ com.github.benmanes.caffeine.cache;bundle-version=${caffeine.version},
javax.crypto,
javax.crypto.spec,
javax.naming,
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/DefaultDnFactory.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/DefaultDnFactory.java
new file mode 100644
index 000000000..aa0383a6c
--- /dev/null
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/DefaultDnFactory.java
@@ -0,0 +1,160 @@
+/*
+ * 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
+ *
+ * http://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.api.ldap.model.name;
+
+
+import java.time.Duration;
+
+import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+
+
+/**
+ * The default Dn factory implementation.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DefaultDnFactory implements DnFactory
+{
+ private static final Logger LOG = LoggerFactory.getLogger( DefaultDnFactory.class );
+
+ /** The cache for DNs */
+ private Cache<String, Dn> dnCache;
+
+ /** The schema manager */
+ private SchemaManager schemaManager;
+
+ /** Flag to enable stats */
+ private boolean enableStats = false;
+
+ // stat counters
+ private int hitCount = 0;
+ private int missCount = 0;
+
+
+ /**
+ * Instantiates a new default Dn factory.
+ *
+ * @param schemaManager The SchemaManager instance
+ * @param cacheSize The cache size used to store DNs
+ */
+ public DefaultDnFactory( SchemaManager schemaManager, int cacheSize )
+ {
+ this.schemaManager = schemaManager;
+ this.dnCache = Caffeine.newBuilder().maximumSize( cacheSize ).expireAfterAccess( Duration.ofMinutes( 10L ) )
+ .build();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Dn create( String dn ) throws LdapInvalidDnException
+ {
+ if ( dn == null )
+ {
+ return null;
+ }
+
+ if ( dn.trim().length() == 0 )
+ {
+ return Dn.ROOT_DSE;
+ }
+
+ Dn cachedDn = null;
+
+ // read the explanation at the above DN_CACHE variable declaration
+ // for the reason for performing this check
+ if ( dnCache != null )
+ {
+ cachedDn = dnCache.getIfPresent( dn );
+ }
+
+ if ( cachedDn == null )
+ {
+ LOG.debug( "Dn {} not found in the cache, creating", dn );
+
+ cachedDn = new Dn( schemaManager, dn );
+
+ if ( dnCache != null )
+ {
+ dnCache.put( dn, cachedDn );
+ }
+
+ if ( enableStats )
+ {
+ missCount++;
+ }
+ }
+ else
+ {
+ if ( enableStats )
+ {
+ hitCount++;
+ }
+ }
+
+ LOG.debug( "Dn {} found in the cache", dn );
+
+ if ( enableStats )
+ {
+ LOG.debug( "Dn cache hit - {} , miss - {} and is normalized = {}", hitCount, missCount, cachedDn.isSchemaAware() );
+ }
+
+ return cachedDn;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Dn create( String... upRdns ) throws LdapInvalidDnException
+ {
+ StringBuilder sb = new StringBuilder();
+ boolean isFirst = true;
+
+ for ( String s : upRdns )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( ',' );
+ }
+
+ sb.append( s );
+ }
+
+ String dn = sb.toString();
+
+ return create( dn );
+ }
+
+}
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/DnFactory.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/DnFactory.java
new file mode 100644
index 000000000..8ed23ec58
--- /dev/null
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/DnFactory.java
@@ -0,0 +1,51 @@
+/*
+ * 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
+ *
+ * http://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.api.ldap.model.name;
+
+
+import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
+
+
+/**
+ * A factory for DNs, with a cache.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface DnFactory
+{
+ /**
+ * Creates a Dn from user provided RDNs.
+ *
+ * @param upRdns the user provided RDNs
+ * @return the created Dn
+ * @throws LdapInvalidDnException if one of the strings isn't a valid Rdn
+ */
+ Dn create( String... upRdns ) throws LdapInvalidDnException;
+
+
+ /**
+ * Creates a Dn form a user provided Dn.
+ *
+ * @param upDn the user provided Dn
+ * @return the created Dn
+ * @throws LdapInvalidDnException if the string isn't a valid Dn
+ */
+ Dn create( String upDn ) throws LdapInvalidDnException;
+}
\ No newline at end of file
diff --git a/ldap/model/src/test/java/org/apache/directory/api/ldap/model/url/LdapUrlTest.java b/ldap/model/src/test/java/org/apache/directory/api/ldap/model/url/LdapUrlTest.java
index 45ec63fd9..62d1ac440 100644
--- a/ldap/model/src/test/java/org/apache/directory/api/ldap/model/url/LdapUrlTest.java
+++ b/ldap/model/src/test/java/org/apache/directory/api/ldap/model/url/LdapUrlTest.java
@@ -36,7 +36,6 @@ import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
import org.apache.directory.api.ldap.model.exception.LdapURLEncodingException;
import org.apache.directory.api.ldap.model.message.SearchScope;
import org.apache.directory.api.ldap.model.name.Dn;
-import org.apache.directory.api.ldap.model.url.LdapUrl;
import org.apache.directory.api.ldap.model.url.LdapUrl.Extension;
import org.junit.jupiter.api.Test;
diff --git a/ldap/net/mina/src/main/java/org/apache/directory/api/ldap/codec/protocol/mina/LdapProtocolCodecFactory.java b/ldap/net/mina/src/main/java/org/apache/directory/api/ldap/codec/protocol/mina/LdapProtocolCodecFactory.java
index 1fcdc45a2..399c9a7e4 100644
--- a/ldap/net/mina/src/main/java/org/apache/directory/api/ldap/codec/protocol/mina/LdapProtocolCodecFactory.java
+++ b/ldap/net/mina/src/main/java/org/apache/directory/api/ldap/codec/protocol/mina/LdapProtocolCodecFactory.java
@@ -59,7 +59,7 @@ public class LdapProtocolCodecFactory implements ProtocolCodecFactory
*/
public LdapProtocolCodecFactory( LdapApiService ldapApiService )
{
- ldapDecoder = new LdapProtocolDecoder();
+ ldapDecoder = new LdapProtocolDecoder( ldapApiService );
ldapEncoder = new LdapProtocolEncoder( ldapApiService );
}
diff --git a/ldap/net/mina/src/main/java/org/apache/directory/api/ldap/codec/protocol/mina/LdapProtocolDecoder.java b/ldap/net/mina/src/main/java/org/apache/directory/api/ldap/codec/protocol/mina/LdapProtocolDecoder.java
index 71b6417d1..fc985f44a 100644
--- a/ldap/net/mina/src/main/java/org/apache/directory/api/ldap/codec/protocol/mina/LdapProtocolDecoder.java
+++ b/ldap/net/mina/src/main/java/org/apache/directory/api/ldap/codec/protocol/mina/LdapProtocolDecoder.java
@@ -28,6 +28,7 @@ import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.ber.Asn1Decoder;
import org.apache.directory.api.asn1.ber.tlv.TLVStateEnum;
import org.apache.directory.api.i18n.I18n;
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.codec.api.LdapDecoder;
import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
import org.apache.directory.api.ldap.codec.api.ResponseCarryingException;
@@ -54,11 +55,15 @@ public class LdapProtocolDecoder implements ProtocolDecoder
/** The logger */
private static final Logger CODEC_LOG = LoggerFactory.getLogger( Loggers.CODEC_LOG.getName() );
+ /** The LDAP API Service instance */
+ private LdapApiService ldapApiService;
+
/**
* Creates a new instance of LdapProtocolEncoder.
*/
- public LdapProtocolDecoder()
+ public LdapProtocolDecoder( LdapApiService ldapApiService )
{
+ this.ldapApiService = ldapApiService;
}
@@ -79,6 +84,8 @@ public class LdapProtocolDecoder implements ProtocolDecoder
messageContainer.setMaxPDUSize( maxPDUSize );
}
+
+ messageContainer.setDnFactory( ldapApiService.getDnFactory() );
List<Message> decodedMessages = new ArrayList<>();
ByteBuffer buf = in.buf();
diff --git a/pom.xml b/pom.xml
index 385db35bf..60b84ca79 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,6 +62,7 @@
<!-- Set versions for depending jars -->
<antlr.version>2.7.7</antlr.version>
+ <caffeine.version>2.9.3</caffeine.version>
<commons.codec.version>1.15</commons.codec.version>
<commons.collections.version>4.4</commons.collections.version>
<commons.lang.version>3.12.0</commons.lang.version>
@@ -658,6 +659,22 @@
<artifactId>xml-apis</artifactId>
<version>${xml.apis.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>com.github.ben-manes.caffeine</groupId>
+ <artifactId>caffeine</artifactId>
+ <version>${caffeine.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.google.errorprone</groupId>
+ <artifactId>error_prone_annotations</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.checkerframework</groupId>
+ <artifactId>checker-qual</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
</dependencyManagement>