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 2010/10/30 04:10:44 UTC
svn commit: r1028970 - in /directory:
apacheds/branches/apacheds-config/ldap-client-test/
apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/
apacheds/branches/apacheds-config/ldap-client-test/src/te...
Author: elecharny
Date: Sat Oct 30 02:10:44 2010
New Revision: 1028970
URL: http://svn.apache.org/viewvc?rev=1028970&view=rev
Log:
Merged the trunk modifications into the branch
Added:
directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/SearchCursorImpl.java
- copied unchanged from r1028957, directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/SearchCursorImpl.java
Modified:
directory/apacheds/branches/apacheds-config/ldap-client-test/ (props changed)
directory/apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java
directory/apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/bind/SimpleBindRequestTest.java
directory/apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
directory/apacheds/branches/apacheds-config/service/ (props changed)
directory/apacheds/branches/apacheds-config/test-framework/ (props changed)
directory/apacheds/branches/apacheds-config/wrapper/ (props changed)
directory/apacheds/branches/apacheds-config/xdbm-partition/ (props changed)
directory/apacheds/branches/apacheds-config/xdbm-tools/ (props changed)
directory/shared/branches/shared-config/ldap-client-api/ (props changed)
directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/Krb5LoginConfiguration.java (props changed)
directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionConfig.java
directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java
directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/callback/SaslCallbackHandler.java
Propchange: directory/apacheds/branches/apacheds-config/ldap-client-test/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Sat Oct 30 02:10:44 2010
@@ -0,0 +1,6 @@
+/directory/apacheds/branches/apacheds-codec-merge/ldap-client-test:982369-987590
+/directory/apacheds/branches/apacheds-replication/ldap-client-test:749790-764110
+/directory/apacheds/branches/apacheds-schema/ldap-client-test:806623-896441
+/directory/apacheds/branches/apacheds-subtree/ldap-client-test:965203-965686
+/directory/apacheds/branches/xdbm-refactoring/ldap-client-test:945827-946347
+/directory/apacheds/trunk/ldap-client-test:1023440-1028957
Modified: directory/apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java?rev=1028970&r1=1028969&r2=1028970&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java (original)
+++ directory/apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java Sat Oct 30 02:10:44 2010
@@ -153,6 +153,7 @@ public class LdapSSLConnectionTest exten
try
{
connection = new LdapNetworkConnection( tlsConfig );
+ connection.connect();
connection.startTls();
BindResponse bindResponse = connection.bind( "uid=admin,ou=system", "secret" );
@@ -171,6 +172,7 @@ public class LdapSSLConnectionTest exten
public void testGetSupportedControlsWithStartTLS() throws Exception
{
LdapNetworkConnection connection = new LdapNetworkConnection( tlsConfig );
+ connection.connect();
connection.startTls();
DN dn = new DN( "uid=admin,ou=system" );
Modified: directory/apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/bind/SimpleBindRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/bind/SimpleBindRequestTest.java?rev=1028970&r1=1028969&r2=1028970&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/bind/SimpleBindRequestTest.java (original)
+++ directory/apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/bind/SimpleBindRequestTest.java Sat Oct 30 02:10:44 2010
@@ -448,4 +448,26 @@ public class SimpleBindRequestTest exten
assertEquals( 2, bindResponse.getMessageId() );
assertTrue( connection.isAuthenticated() );
}
+
+
+ /**
+ * DIRSERVER-1548
+ */
+ @Test
+ public void testSimpleBindInvalidFwdByValidOnSameCon() throws Exception
+ {
+ connection.setTimeOut( Integer.MAX_VALUE );
+ BindResponse response = connection.bind( "uid=admin,ou=system", "wrongpwd" );
+ LdapResult ldapResult = response.getLdapResult();
+ assertEquals( ResultCodeEnum.INVALID_CREDENTIALS, ldapResult.getResultCode() );
+ assertEquals( 1, response.getMessageId() );
+ assertFalse( connection.isAuthenticated() );
+
+ response = connection.bind( "uid=admin,ou=system", "secret" );
+ ldapResult = response.getLdapResult();
+ assertEquals( ResultCodeEnum.SUCCESS, ldapResult.getResultCode() );
+ assertEquals( 2, response.getMessageId() );
+ assertTrue( connection.isAuthenticated() );
+ }
+
}
Modified: directory/apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java?rev=1028970&r1=1028969&r2=1028970&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java (original)
+++ directory/apacheds/branches/apacheds-config/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java Sat Oct 30 02:10:44 2010
@@ -29,7 +29,6 @@ import java.util.concurrent.TimeUnit;
import org.apache.directory.ldap.client.api.LdapAsyncConnection;
import org.apache.directory.ldap.client.api.LdapNetworkConnection;
-import org.apache.directory.ldap.client.api.SearchCursor;
import org.apache.directory.ldap.client.api.future.SearchFuture;
import org.apache.directory.server.annotations.CreateLdapServer;
import org.apache.directory.server.annotations.CreateTransport;
@@ -37,6 +36,7 @@ import org.apache.directory.server.core.
import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
import org.apache.directory.server.core.integ.FrameworkRunner;
import org.apache.directory.shared.ldap.cursor.Cursor;
+import org.apache.directory.shared.ldap.cursor.SearchCursor;
import org.apache.directory.shared.ldap.entry.Entry;
import org.apache.directory.shared.ldap.exception.LdapException;
import org.apache.directory.shared.ldap.filter.SearchScope;
@@ -67,12 +67,19 @@ import org.junit.runner.RunWith;
"cn: user1",
// alias to the above entry
- "dn: cn=user1-alias,ou=users,ou=system", "objectClass: alias", "objectClass: top",
- "objectClass: extensibleObject", "aliasedObjectName: cn=user1,ou=users,ou=system", "cn: user1-alias",
+ "dn: cn=user1-alias,ou=users,ou=system",
+ "objectClass: alias",
+ "objectClass: top",
+ "objectClass: extensibleObject",
+ "aliasedObjectName: cn=user1,ou=users,ou=system",
+ "cn: user1-alias",
// Another user
- "dn: cn=elecharny,ou=users,ou=system", "objectClass: person", "objectClass: top",
- "sn:: RW1tYW51ZWwgTMOpY2hhcm55", "cn: elecharny"
+ "dn: cn=elecharny,ou=users,ou=system",
+ "objectClass: person",
+ "objectClass: top",
+ "sn:: RW1tYW51ZWwgTMOpY2hhcm55",
+ "cn: elecharny"
})
public class ClientSearchRequestTest extends AbstractLdapTestUnit
@@ -112,7 +119,8 @@ public class ClientSearchRequestTest ext
@Test
public void testSearch() throws Exception
{
- SearchCursor cursor = ( SearchCursor ) connection.search( "ou=system", "(objectclass=*)", SearchScope.ONELEVEL,
+ SearchCursor cursor = connection.search( "ou=system", "(objectclass=*)",
+ SearchScope.ONELEVEL,
"*", "+" );
int count = 0;
while ( cursor.next() )
@@ -132,7 +140,7 @@ public class ClientSearchRequestTest ext
@Test
public void testSearchEquality() throws Exception
{
- Cursor<Response> cursor = connection.search( "ou=system", "(objectclass=organizationalUnit)",
+ SearchCursor cursor = connection.search( "ou=system", "(objectclass=organizationalUnit)",
SearchScope.ONELEVEL, "*", "+" );
int count = 0;
while ( cursor.next() )
Propchange: directory/apacheds/branches/apacheds-config/service/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 30 02:10:44 2010
@@ -3,3 +3,4 @@
/directory/apacheds/branches/apacheds-schema/service:806623-896441
/directory/apacheds/branches/apacheds-subtree/service:965203-965686
/directory/apacheds/branches/xdbm-refactoring/service:945827-946347
+/directory/apacheds/trunk/service:1023440-1028957
Propchange: directory/apacheds/branches/apacheds-config/test-framework/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 30 02:10:44 2010
@@ -5,3 +5,4 @@
/directory/apacheds/branches/apacheds-schema/test-framework:806623-893782
/directory/apacheds/branches/apacheds-subtree/test-framework:965203-965686
/directory/apacheds/branches/xdbm-refactoring/test-framework:945827-946347
+/directory/apacheds/trunk/test-framework:1023440-1028957
Propchange: directory/apacheds/branches/apacheds-config/wrapper/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 30 02:10:44 2010
@@ -3,3 +3,4 @@
/directory/apacheds/branches/apacheds-schema/wrapper:806623-896441
/directory/apacheds/branches/apacheds-subtree/wrapper:965203-965686
/directory/apacheds/branches/xdbm-refactoring/wrapper:945827-946347
+/directory/apacheds/trunk/wrapper:1023440-1028957
Propchange: directory/apacheds/branches/apacheds-config/xdbm-partition/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 30 02:10:44 2010
@@ -1,2 +1,3 @@
/directory/apacheds/branches/apacheds-codec-merge/xdbm-partition:982369-987590
/directory/apacheds/branches/apacheds-dnfactory-experiment/xdbm-partition:980138-980938
+/directory/apacheds/trunk/xdbm-partition:1023440-1028957
Propchange: directory/apacheds/branches/apacheds-config/xdbm-tools/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 30 02:10:44 2010
@@ -1,2 +1,3 @@
/directory/apacheds/branches/apacheds-codec-merge/xdbm-tools:982369-987590
/directory/apacheds/branches/apacheds-dnfactory-experiment/xdbm-tools:980138-980938
+/directory/apacheds/trunk/xdbm-tools:1023440-1028957
Propchange: directory/shared/branches/shared-config/ldap-client-api/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Sat Oct 30 02:10:44 2010
@@ -0,0 +1,6 @@
+/directory/shared/branches/shared-codec-merge/ldap-client-api:982370-987558
+/directory/shared/branches/shared-replication/ldap-client-api:749791-764113
+/directory/shared/branches/shared-schema/ldap-client-api:806622-896441
+/directory/shared/branches/shared-subtree/ldap-client-api:965208-965686
+/directory/shared/branches/xdbm-refactoring/ldap-client-api:945830-946347
+/directory/shared/trunk/ldap-client-api:1023442-1028957
Propchange: directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/Krb5LoginConfiguration.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 30 02:10:44 2010
@@ -1,2 +1,3 @@
/directory/apacheds/branches/apacheds-codec-merge/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/jaas/Krb5LoginConfiguration.java:982369-987590
/directory/apacheds/branches/apacheds-dnfactory-experiment/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/jaas/Krb5LoginConfiguration.java:980138-980936
+/directory/shared/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/Krb5LoginConfiguration.java:1023442-1028957
Modified: directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java?rev=1028970&r1=1028969&r2=1028970&view=diff
==============================================================================
--- directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java (original)
+++ directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java Sat Oct 30 02:10:44 2010
@@ -24,7 +24,7 @@ import java.io.IOException;
import java.util.List;
import org.apache.directory.shared.asn1.primitives.OID;
-import org.apache.directory.shared.ldap.cursor.Cursor;
+import org.apache.directory.shared.ldap.cursor.SearchCursor;
import org.apache.directory.shared.ldap.entry.Entry;
import org.apache.directory.shared.ldap.entry.Modification;
import org.apache.directory.shared.ldap.entry.ModificationOperation;
@@ -46,7 +46,6 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.message.ModifyDnResponse;
import org.apache.directory.shared.ldap.message.ModifyRequest;
import org.apache.directory.shared.ldap.message.ModifyResponse;
-import org.apache.directory.shared.ldap.message.Response;
import org.apache.directory.shared.ldap.message.SearchRequest;
import org.apache.directory.shared.ldap.name.DN;
import org.apache.directory.shared.ldap.name.RDN;
@@ -204,10 +203,10 @@ public interface LdapConnection
* @param filter The filter to use for this search. It can't be empty
* @param scope The search scope : OBJECT, ONELEVEL or SUBTREE
* @param attributes The attributes to use for this search
- * @return A cursor on the result.
+ * @return A search cursor on the result.
* @throws LdapException if some error occurred
*/
- Cursor<Response> search( DN baseDn, String filter, SearchScope scope, String... attributes )
+ SearchCursor search( DN baseDn, String filter, SearchScope scope, String... attributes )
throws LdapException;
@@ -227,10 +226,10 @@ public interface LdapConnection
* @param filter The filter to use for this search. It can't be empty
* @param scope The search scope : OBJECT, ONELEVEL or SUBTREE
* @param attributes The attributes to use for this search
- * @return A cursor on the result.
+ * @return A search cursor on the result.
* @throws LdapException if some error occurred
*/
- Cursor<Response> search( String baseDn, String filter, SearchScope scope, String... attributes )
+ SearchCursor search( String baseDn, String filter, SearchScope scope, String... attributes )
throws LdapException;
@@ -238,10 +237,10 @@ public interface LdapConnection
* Performs search in a synchronous mode.
*
* @param searchRequest The search configuration
- * @return A {@link Cursor} containing Entries and References
+ * @return a search cursor on the result.
* @throws LdapException if some error occurred
*/
- Cursor<Response> search( SearchRequest searchRequest ) throws LdapException;
+ SearchCursor search( SearchRequest searchRequest ) throws LdapException;
//------------------------ The LDAP operations ------------------------//
@@ -702,8 +701,8 @@ public interface LdapConnection
/**
- * Loads the default schema that is bundled in the API.
- *
+ * Loads all the default schemas that are bundled with the API.<br><br>
+ * <b>Note:</b> This method enables <b>all</b> schemas prior to loading
* @throws LdapException in case of problems while loading the schema
*/
void loadSchema() throws LdapException;
Modified: directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionConfig.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionConfig.java?rev=1028970&r1=1028969&r2=1028970&view=diff
==============================================================================
--- directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionConfig.java (original)
+++ directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionConfig.java Sat Oct 30 02:10:44 2010
@@ -21,10 +21,17 @@
package org.apache.directory.ldap.client.api;
+import java.security.KeyStore;
import java.security.SecureRandom;
import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import javax.net.ssl.X509TrustManager;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -82,7 +89,45 @@ public class LdapConnectionConfig
/** name of the protocol used for creating SSL context, default value is "TLS" */
private String sslProtocol = DEFAULT_SSL_PROTOCOL;
+ private static final Logger LOG = LoggerFactory.getLogger( LdapConnectionConfig.class );
+
+ public LdapConnectionConfig()
+ {
+ setDefaultTrustManager();
+ }
+
+
+ /**
+ * sets the default trust manager based on the SunX509 trustManagement algorithm
+ */
+ private void setDefaultTrustManager()
+ {
+ String trustMgmtAlgo = "SunX509";
+
+ try
+ {
+ TrustManagerFactory tmFactory = TrustManagerFactory.getInstance( trustMgmtAlgo );
+ tmFactory.init( KeyStore.getInstance( KeyStore.getDefaultType() ) );
+ TrustManager factoryTrustManagers[] = tmFactory.getTrustManagers();
+
+ for ( int i = 0; i < factoryTrustManagers.length; i++ )
+ {
+ if ( factoryTrustManagers[i] instanceof X509TrustManager )
+ {
+ trustManagers = new TrustManager[] { factoryTrustManagers[i] };
+ LOG.debug( "found X509TrustManager {}", factoryTrustManagers[i] );
+ break;
+ }
+ }
+ }
+ catch( Exception e )
+ {
+ LOG.warn( "couldn't find any default X509 TrustManager with algorithm {}", trustMgmtAlgo );
+ }
+ }
+
+
/**
* Checks if SSL (ldaps://) is used.
*
Modified: directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=1028970&r1=1028969&r2=1028970&view=diff
==============================================================================
--- directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java (original)
+++ directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java Sat Oct 30 02:10:44 2010
@@ -65,6 +65,7 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.constants.SupportedSaslMechanisms;
import org.apache.directory.shared.ldap.cursor.Cursor;
+import org.apache.directory.shared.ldap.cursor.SearchCursor;
import org.apache.directory.shared.ldap.entry.DefaultEntry;
import org.apache.directory.shared.ldap.entry.Entry;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
@@ -172,7 +173,7 @@ public class LdapNetworkConnection exten
private long timeout = LdapConnectionConfig.DEFAULT_TIMEOUT;
/** configuration object for the connection */
- private LdapConnectionConfig config = new LdapConnectionConfig();
+ private LdapConnectionConfig config;
/** The connector open with the remote server */
private IoConnector connector;
@@ -329,6 +330,7 @@ public class LdapNetworkConnection exten
*/
public LdapNetworkConnection()
{
+ config = new LdapConnectionConfig();
config.setUseSsl( false );
config.setLdapPort( config.getDefaultLdapPort() );
config.setLdapHost( config.getDefaultLdapHost() );
@@ -358,6 +360,7 @@ public class LdapNetworkConnection exten
*/
public LdapNetworkConnection( boolean useSsl )
{
+ config = new LdapConnectionConfig();
config.setUseSsl( useSsl );
config.setLdapPort( useSsl ? config.getDefaultLdapsPort() : config.getDefaultLdapPort() );
config.setLdapHost( config.getDefaultLdapHost() );
@@ -374,6 +377,7 @@ public class LdapNetworkConnection exten
*/
public LdapNetworkConnection( String server )
{
+ config = new LdapConnectionConfig();
config.setUseSsl( false );
config.setLdapPort( config.getDefaultLdapPort() );
@@ -402,6 +406,7 @@ public class LdapNetworkConnection exten
*/
public LdapNetworkConnection( String server, boolean useSsl )
{
+ config = new LdapConnectionConfig();
config.setUseSsl( useSsl );
config.setLdapPort( useSsl ? config.getDefaultLdapsPort() : config.getDefaultLdapPort() );
@@ -444,6 +449,7 @@ public class LdapNetworkConnection exten
*/
public LdapNetworkConnection( String server, int port, boolean useSsl )
{
+ config = new LdapConnectionConfig();
config.setUseSsl( useSsl );
config.setLdapPort( port );
@@ -619,7 +625,7 @@ public class LdapNetworkConnection exten
}
// And close the connector if it has been created locally
- if ( localConnector )
+ if ( localConnector && ( connector != null ) )
{
// Release the connector
connector.dispose();
@@ -1132,29 +1138,22 @@ public class LdapNetworkConnection exten
// If the session has not been establish, or is closed, we get out immediately
checkSession();
- if ( bindRequest.isSimple() )
- {
- // Update the messageId
- int newId = messageId.incrementAndGet();
- bindRequest.setMessageId( newId );
+ // Update the messageId
+ int newId = messageId.incrementAndGet();
+ bindRequest.setMessageId( newId );
- LOG.debug( "-----------------------------------------------------------------" );
- LOG.debug( "Sending request \n{}", bindRequest );
+ LOG.debug( "-----------------------------------------------------------------" );
+ LOG.debug( "Sending request \n{}", bindRequest );
- // Create a future for this Bind operation
- BindFuture bindFuture = new BindFuture( this, newId );
+ // Create a future for this Bind operation
+ BindFuture bindFuture = new BindFuture( this, newId );
- addToFutureMap( newId, bindFuture );
+ addToFutureMap( newId, bindFuture );
- writeBindRequest( bindRequest );
+ writeBindRequest( bindRequest );
- // Ok, done return the future
- return bindFuture;
- }
- else
- {
- return bindSasl( new SaslRequest( bindRequest ) );
- }
+ // Ok, done return the future
+ return bindFuture;
}
@@ -1311,13 +1310,14 @@ public class LdapNetworkConnection exten
* @throws IOException if an IO exception occurred
* @see #bindGssApi(String, byte[], String, String, int, Control...)
*/
- public BindResponse bindGssApi( String name, String credentials, String realmName, String kdcHost, int kdcPort, Control... ctrls )
- throws LdapException, IOException
+ public BindResponse bindGssApi( String name, String credentials, String realmName, String kdcHost, int kdcPort,
+ Control... ctrls )
+ throws LdapException, IOException
{
return bindGssApi( name, StringTools.getBytesUtf8( credentials ), realmName, kdcHost, kdcPort, ctrls );
}
-
-
+
+
/**
* Bind to the LDAP server using GSSAPI SASL mechanism.
*
@@ -1331,34 +1331,38 @@ public class LdapNetworkConnection exten
* @throws LdapException if an LDAP error occurred during bind
* @throws IOException if an IO exception occurred
*/
- public BindResponse bindGssApi( String name, byte[] credentials, String realmName, String kdcHost, int kdcPort, Control... ctrls )
+ public BindResponse bindGssApi( String name, byte[] credentials, String realmName, String kdcHost, int kdcPort,
+ Control... ctrls )
throws LdapException, IOException
{
- BindRequest bindRequest = createBindRequest( name, credentials, SupportedSaslMechanisms.GSSAPI, ctrls );
-
String krbConfPath = createKrbConfFile( realmName, kdcHost, kdcPort );
System.setProperty( "java.security.krb5.conf", krbConfPath );
Configuration.setConfiguration( new Krb5LoginConfiguration() );
System.setProperty( "javax.security.auth.useSubjectCredsOnly", "true" );
- final SaslRequest saslRequest = new SaslRequest( bindRequest );
+ final SaslRequest saslRequest = new SaslRequest();
+ saslRequest.setUsername( name );
+ saslRequest.setCredentials( credentials );
+ saslRequest.setSaslMechanism( SupportedSaslMechanisms.GSSAPI );
+ saslRequest.setRealmName( realmName );
+ saslRequest.addAllControls( ctrls );
try
{
LoginContext loginContext = new LoginContext( "ldapnetworkconnection",
- new SaslCallbackHandler( saslRequest ) );
+ new SaslCallbackHandler( saslRequest ) );
loginContext.login();
// Now, bind by calling the internal bindSasl method
BindFuture future = ( BindFuture ) Subject.doAs( loginContext.getSubject(),
- new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- return bindSasl( saslRequest );
- }
- } );
+ new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ return bindSasl( saslRequest );
+ }
+ } );
return future.get();
}
@@ -1372,7 +1376,7 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public Cursor<Response> search( DN baseDn, String filter, SearchScope scope, String... attributes )
+ public SearchCursor search( DN baseDn, String filter, SearchScope scope, String... attributes )
throws LdapException
{
if ( baseDn == null )
@@ -1398,7 +1402,7 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public Cursor<Response> search( String baseDn, String filter, SearchScope scope, String... attributes )
+ public SearchCursor search( String baseDn, String filter, SearchScope scope, String... attributes )
throws LdapException
{
return search( new DN( baseDn ), filter, scope, attributes );
@@ -1486,7 +1490,7 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public Cursor<Response> search( SearchRequest searchRequest ) throws LdapException
+ public SearchCursor search( SearchRequest searchRequest ) throws LdapException
{
if ( searchRequest == null )
{
@@ -1499,7 +1503,7 @@ public class LdapNetworkConnection exten
long timeout = getTimeout( searchRequest.getTimeLimit() );
- return new SearchCursor( searchFuture, timeout, TimeUnit.MILLISECONDS );
+ return new SearchCursorImpl( searchFuture, timeout, TimeUnit.MILLISECONDS );
}
@@ -1525,7 +1529,7 @@ public class LdapNetworkConnection exten
LOG.debug( "Sending Unbind request \n{}", unbindRequest );
// Send the request to the server
- // Use this for logging instead: WriteFuture unbindFuture = ldapSession.write( unbindRequest );
+ // Use this for logging instead: WriteFuture unbindFuture = ldapSession.write( unbindRequest );
ldapSession.write( unbindRequest );
//LOG.debug( "waiting for unbindFuture" );
@@ -1592,6 +1596,8 @@ public class LdapNetworkConnection exten
*/
public void exceptionCaught( IoSession session, Throwable cause ) throws Exception
{
+ LOG.warn( cause.getMessage(), cause );
+
if ( cause instanceof ProtocolEncoderException )
{
Throwable realCause = ( ( ProtocolEncoderException ) cause ).getCause();
@@ -3145,8 +3151,8 @@ public class LdapNetworkConnection exten
throw new LdapException( e );
}
}
-
-
+
+
/**
* loads schema using the specified schema loader
*
@@ -3159,13 +3165,6 @@ public class LdapNetworkConnection exten
{
SchemaManager tmp = new DefaultSchemaManager( loader );
- // we enable all the schemas so that need not check with server for enabled schemas
- Collection<Schema> schemas = tmp.getLoader().getAllSchemas();
- for ( Schema s : schemas )
- {
- //s.enable();
- }
-
tmp.loadAllEnabled();
if ( !tmp.getErrors().isEmpty() )
@@ -3174,7 +3173,7 @@ public class LdapNetworkConnection exten
LOG.error( msg + " {}", schemaManager.getErrors() );
throw new LdapException( msg );
}
-
+
schemaManager = tmp;
}
catch ( LdapException le )
@@ -3417,8 +3416,6 @@ public class LdapNetworkConnection exten
{
try
{
- connect();
-
checkSession();
ExtendedResponse resp = extended( START_TLS_REQ_OID );
@@ -3484,13 +3481,15 @@ public class LdapNetworkConnection exten
Control... ctrls )
throws LdapException, IOException
{
- BindRequest bindReq = createBindRequest( name, credentials, saslMech, ctrls );
-
- SaslRequest saslReq = new SaslRequest( bindReq );
- saslReq.setRealmName( realmName );
- saslReq.setAuthorizationId( authzId );
+ SaslRequest saslRequest = new SaslRequest();
+ saslRequest.setUsername( name );
+ saslRequest.setCredentials( credentials );
+ saslRequest.setSaslMechanism( saslMech );
+ saslRequest.setAuthorizationId( authzId );
+ saslRequest.setRealmName( realmName );
+ saslRequest.addAllControls( ctrls );
- return bindSasl( saslReq );
+ return bindSasl( saslRequest );
}
@@ -3510,7 +3509,8 @@ public class LdapNetworkConnection exten
// If the session has not been establish, or is closed, we get out immediately
checkSession();
- BindRequest bindRequest = saslRequest.getBindRequest();
+ BindRequest bindRequest = createBindRequest( ( String ) null, null, saslRequest.getSaslMechanism(), saslRequest
+ .getControls() );
// Update the messageId
int newId = messageId.incrementAndGet();
@@ -3537,7 +3537,7 @@ public class LdapNetworkConnection exten
saslRequest.getAuthorizationId(),
"ldap",
config.getLdapHost(),
- saslRequest.getSaslMechProps(),
+ null,
new SaslCallbackHandler( saslRequest ) );
// If the SaslClient wasn't created, that means we can't create the SASL client
Modified: directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java?rev=1028970&r1=1028969&r2=1028970&view=diff
==============================================================================
--- directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java (original)
+++ directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java Sat Oct 30 02:10:44 2010
@@ -21,10 +21,11 @@
package org.apache.directory.ldap.client.api;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
-import org.apache.directory.shared.ldap.message.BindRequest;
+import org.apache.directory.shared.ldap.message.control.Control;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -35,61 +36,91 @@ import org.apache.directory.shared.ldap.
*/
public class SaslRequest
{
- /** the bind request */
- private BindRequest bindRequest;
+ /** The list of controls */
+ private List<Control> controls = new ArrayList<Control>();
- /** the sasl mechaism's properties */
- private Map<String, String> saslMechProps = new HashMap<String, String>();
+ /** The username */
+ private String username;
+
+ /** The credentials */
+ private byte[] credentials;
/** SASL realm name on the server */
private String realmName;
- /** the authorization ID of the entity */
+ /** The authorization ID of the entity */
private String authorizationId;
+ /** The mechanism used to decode user identity */
+ private String saslMechanism;
+
/**
- * Creates a new instance of SaslRequest.
+ * Adds the given controls.
*
- * @param bindRequest The included BindRequest
+ * @param controls the controls
*/
- protected SaslRequest( BindRequest bindRequest )
+ public void addAllControls( Control[] controls )
{
- this.bindRequest = bindRequest;
+ this.controls.addAll( Arrays.asList( controls ) );
}
/**
- * @return The interned BindRequest
+ * Adds the given control.
+ *
+ * @param control the control
*/
- public BindRequest getBindRequest()
+ public void addControl( Control control )
{
- return bindRequest;
+ this.controls.add( control );
}
/**
- * @return The supported SASL mechanisms
+ * Gets the authorization ID.
+ *
+ * @return the authorization ID
*/
- public Map<String, String> getSaslMechProps()
+ public String getAuthorizationId()
{
- return saslMechProps;
+ return authorizationId;
}
/**
- * Set the supported SASL mechanisms
+ * Gets the controls.
*
- * @param saslMechProps The list of supported mechanisms
+ * @return the controls
*/
- public void setSaslMechProps( Map<String, String> saslMechProps )
+ public Control[] getControls()
{
- this.saslMechProps = saslMechProps;
+ return controls.toArray( new Control[0] );
}
/**
- * @return The realm name
+ * Gets the crendentials
+ *
+ * @return the credentials
+ */
+ public byte[] getCredentials()
+ {
+ if ( credentials != null )
+ {
+ return credentials;
+ }
+ else
+ {
+ return StringTools.EMPTY_BYTES;
+ }
+ }
+
+
+ /**
+ * Gets realm name.
+ *
+ * @return the realm name
*/
public String getRealmName()
{
@@ -98,21 +129,24 @@ public class SaslRequest
/**
- * Set the realm Name
- * @param realmName The realm name
+ * Gets the SASL mechanism.
+ *
+ * @return the SASL mechanism
*/
- public void setRealmName( String realmName )
+ public String getSaslMechanism()
{
- this.realmName = realmName;
+ return saslMechanism;
}
/**
- * @return The authorization Id
+ * Gets the username.
+ *
+ * @return the username
*/
- public String getAuthorizationId()
+ public String getUsername()
{
- return authorizationId;
+ return username;
}
@@ -128,30 +162,45 @@ public class SaslRequest
/**
- * Sets the interned BindRequest
+ * Sets the credentials.
*
- * @param bindRequest The interned BindRequest
+ * @param credentials the credentials
*/
- public void setBindRequest( BindRequest bindRequest )
+ public void setCredentials( byte[] credentials )
{
- this.bindRequest = bindRequest;
+ this.credentials = credentials;
}
/**
- * @return the credentials
+ * Sets the realm name.
+ *
+ * @param realmName The realm name
*/
- public byte[] getCredentials()
+ public void setRealmName( String realmName )
{
- byte[] credentials = bindRequest.getCredentials();
+ this.realmName = realmName;
+ }
- if ( credentials != null )
- {
- return credentials;
- }
- else
- {
- return StringTools.EMPTY_BYTES;
- }
+
+ /**
+ * Sets the SASL mechanism
+ *
+ * @param saslMechanism the SASL mechanism
+ */
+ public void setSaslMechanism( String saslMechanism )
+ {
+ this.saslMechanism = saslMechanism;
+ }
+
+
+ /**
+ * Sets the username.
+ *
+ * @param username the username
+ */
+ public void setUsername( String username )
+ {
+ this.username = username;
}
}
Modified: directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/callback/SaslCallbackHandler.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/callback/SaslCallbackHandler.java?rev=1028970&r1=1028969&r2=1028970&view=diff
==============================================================================
--- directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/callback/SaslCallbackHandler.java (original)
+++ directory/shared/branches/shared-config/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/callback/SaslCallbackHandler.java Sat Oct 30 02:10:44 2010
@@ -73,19 +73,17 @@ public class SaslCallbackHandler impleme
{
NameCallback ncb = ( NameCallback ) cb;
- String name = saslReq.getBindRequest().getName().getRdn().getUpValue().getString();
+ String name = saslReq.getUsername();
LOG.debug( "sending name {} in the NameCallback", name );
-
ncb.setName( name );
}
-
else if ( cb instanceof PasswordCallback )
{
PasswordCallback pcb = ( PasswordCallback ) cb;
+
LOG.debug( "sending credentials in the PasswordCallback" );
pcb.setPassword( StringTools.utf8ToString( saslReq.getCredentials() ).toCharArray() );
}
-
else if ( cb instanceof RealmCallback )
{
RealmCallback rcb = ( RealmCallback ) cb;