Foix for DIRSERVER-2145. We store the fetched entry into the BindContext
to reuse it later.
diff --git a/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/BindOperationContext.java b/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/BindOperationContext.java
index 72cc451..52eb221 100644
--- a/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/BindOperationContext.java
+++ b/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/BindOperationContext.java
@@ -22,6 +22,7 @@
import org.apache.commons.lang3.NotImplementedException;
import org.apache.directory.api.ldap.model.constants.AuthenticationLevel;
+import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapAuthenticationException;
import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
import org.apache.directory.api.ldap.model.name.Dn;
@@ -62,6 +63,9 @@
/** The IoSession if any */
private IoSession ioSession;
+
+ /** The LDAP Principal */
+ private Entry principal;
/**
@@ -288,4 +292,22 @@
{
this.ioSession = ioSession;
}
+
+
+ /**
+ * @return the principal
+ */
+ public Entry getPrincipal()
+ {
+ return principal;
+ }
+
+
+ /**
+ * @param principal the principal to set
+ */
+ public void setPrincipal( Entry principal )
+ {
+ this.principal = principal;
+ }
}
diff --git a/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/SimpleAuthenticator.java b/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/SimpleAuthenticator.java
index cd028d5..007775a 100644
--- a/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/SimpleAuthenticator.java
+++ b/interceptors/authn/src/main/java/org/apache/directory/server/core/authn/SimpleAuthenticator.java
@@ -279,13 +279,18 @@
* sub operation.
* We request all the attributes
*/
- LookupOperationContext lookupContext = new LookupOperationContext( getDirectoryService().getAdminSession(),
- bindContext.getDn(), SchemaConstants.ALL_USER_ATTRIBUTES, SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES );
-
- lookupContext.setPartition( bindContext.getPartition() );
- lookupContext.setTransaction( bindContext.getTransaction() );
-
- userEntry = getDirectoryService().getPartitionNexus().lookup( lookupContext );
+ userEntry = bindContext.getPrincipal();
+
+ if ( userEntry == null )
+ {
+ LookupOperationContext lookupContext = new LookupOperationContext( getDirectoryService().getAdminSession(),
+ bindContext.getDn(), SchemaConstants.ALL_USER_ATTRIBUTES, SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES );
+
+ lookupContext.setPartition( bindContext.getPartition() );
+ lookupContext.setTransaction( bindContext.getTransaction() );
+
+ userEntry = getDirectoryService().getPartitionNexus().lookup( lookupContext );
+ }
if ( userEntry == null )
{
diff --git a/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java b/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java
index 3e8622a..7b51648 100644
--- a/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java
+++ b/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientAddRequestTest.java
@@ -430,4 +430,37 @@
connection.close();
}
+
+
+ @Test
+ public void testAddUidWithDash() throws LdapException, IOException
+ {
+ connection.setTimeOut( 0L );
+ connection.loadSchema();
+
+ // Use the client API
+ connection.bind( "uid=admin,ou=system", "secret" );
+
+ // Add a new entry with some null values
+ Entry entry = new DefaultEntry( getLdapServer().getDirectoryService().getSchemaManager(),
+ "uid=#4869,ou=system",
+ "objectclass: top",
+ "objectclass: person",
+ "objectclass: inetOrgPerson",
+ "uid: Hi",
+ "cn: Java Duke",
+ "sn: Duke",
+ "userpassword: Password1" );
+
+ connection.add( entry );
+
+ // Now fetch the entry
+ Entry found = connection.lookup( "uid=#4869,ou=system" );
+
+ assertNotNull( found );
+ assertNotNull( found.get( "userPassword" ) );
+ assertTrue( found.contains( "uid", "Hi" ) );
+
+ connection.close();
+ }
}
diff --git a/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/BindRequestHandler.java b/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/BindRequestHandler.java
index 66ed86e..5e0f3fe 100644
--- a/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/BindRequestHandler.java
+++ b/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/request/BindRequestHandler.java
@@ -160,7 +160,8 @@
try
{
- principalEntry = directoryService.getAdminSession().lookup( bindRequest.getDn() );
+ principalEntry = directoryService.getAdminSession().lookup( bindRequest.getDn(),
+ SchemaConstants.ALL_USER_ATTRIBUTES, SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES );
}
catch ( Exception le )
{
@@ -188,6 +189,10 @@
return;
}
+ else
+ {
+ bindContext.setPrincipal( principalEntry );
+ }
// TODO - might cause issues since lookups are not returning all
// attributes right now - this is an optimization that can be