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 2013/04/05 19:41:53 UTC
svn commit: r1465061 - in
/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api:
LdapConnection.java LdapNetworkConnection.java SaslPlainRequest.java
Author: elecharny
Date: Fri Apr 5 17:41:53 2013
New Revision: 1465061
URL: http://svn.apache.org/r1465061
Log:
Added the SASL PLAIN bind
Added:
directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslPlainRequest.java
Modified:
directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java?rev=1465061&r1=1465060&r2=1465061&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java Fri Apr 5 17:41:53 2013
@@ -189,6 +189,31 @@ public interface LdapConnection
/**
+ * SASL PLAIN Bind on a server.
+ *
+ * @param authcid The Authentication identity
+ * @param credentials The password. It can't be null
+ * @return The BindResponse LdapResponse
+ * @throws {@link LdapException} if some error occurred
+ * @throws IOException if an I/O exception occurred
+ */
+ // Not yet available on the CoreConnection
+ //BindResponse bindSaslPlain( String authcid, String credentials ) throws LdapException, IOException;
+
+ /**
+ * SASL PLAIN Bind on a server.
+ *
+ * @param authzid The Authorization identity
+ * @param authcid The Authentication identity
+ * @param credentials The password. It can't be null
+ * @return The BindResponse LdapResponse
+ * @throws {@link LdapException} if some error occurred
+ * @throws IOException if an I/O exception occurred
+ */
+ // Not yet available on the CoreConnection
+ //BindResponse bindSaslPlain( String authzid, String authcid, String credentials ) throws LdapException, IOException;
+
+ /**
* Unauthenticated authentication Bind on a server.
*
* @param name The name we use to authenticate the user. It must be a
@@ -814,17 +839,17 @@ public interface LdapConnection
* @return true if there is a non-null future exists, false otherwise
*/
boolean doesFutureExistFor( int messageId );
-
-
+
+
/**
* @return the object responsible for the detection of binary attributes
*/
BinaryAttributeDetector getBinaryAttributeDetector();
-
-
+
+
/**
* Sets the object responsible for the detection of binary attributes
* @return
*/
- void setBinaryAttributeDetector( BinaryAttributeDetector binaryAttributeDetecter);
+ void setBinaryAttributeDetector( BinaryAttributeDetector binaryAttributeDetecter );
}
\ No newline at end of file
Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=1465061&r1=1465060&r2=1465061&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java Fri Apr 5 17:41:53 2013
@@ -1184,6 +1184,89 @@ public class LdapNetworkConnection exten
/**
+ * SASL PLAIN Bind on a server.
+ *
+ * @param authcid The Authentication identity
+ * @param credentials The password. It can't be null
+ * @return The BindResponse LdapResponse
+ * @throws {@link LdapException} if some error occurred
+ * @throws IOException if an I/O exception occurred
+ */
+ public BindResponse bindSaslPlain( String authcid, String credentials ) throws LdapException, IOException
+ {
+ return bindSaslPlain( null, authcid, credentials );
+ }
+
+
+ /**
+ * SASL PLAIN Bind on a server.
+ *
+ * @param authzid The Authorization identity
+ * @param authcid The Authentication identity
+ * @param credentials The password. It can't be null
+ * @return The BindResponse LdapResponse
+ * @throws {@link LdapException} if some error occurred
+ * @throws IOException if an I/O exception occurred
+ */
+ public BindResponse bindSaslPlain( String authzid, String authcid, String credentials ) throws LdapException,
+ IOException
+ {
+ LOG.debug( "SASL PLAIN Bind request" );
+
+ // Create the BindRequest
+ SaslPlainRequest saslRequest = new SaslPlainRequest();
+ saslRequest.setAuthorizationId( authzid );
+ saslRequest.setUsername( authcid );
+ saslRequest.setCredentials( credentials );
+
+ BindFuture bindFuture = bindAsync( saslRequest );
+
+ // Get the result from the future
+ try
+ {
+ // Read the response, waiting for it if not available immediately
+ // Get the response, blocking
+ BindResponse bindResponse = bindFuture.get( timeout, TimeUnit.MILLISECONDS );
+
+ if ( bindResponse == null )
+ {
+ // We didn't received anything : this is an error
+ LOG.error( "Bind failed : timeout occurred" );
+ throw new LdapException( TIME_OUT_ERROR );
+ }
+
+ if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
+ {
+ authenticated.set( true );
+
+ // Everything is fine, return the response
+ LOG.debug( "Bind successful : {}", bindResponse );
+ }
+ else
+ {
+ // We have had an error
+ LOG.debug( "Bind failed : {}", bindResponse );
+ }
+
+ return bindResponse;
+ }
+ catch ( TimeoutException te )
+ {
+ // We didn't received anything : this is an error
+ LOG.error( "Bind failed : timeout occurred" );
+ throw new LdapException( TIME_OUT_ERROR, te );
+ }
+ catch ( Exception ie )
+ {
+ // Catch all other exceptions
+ LOG.error( NO_RESPONSE_ERROR, ie );
+
+ throw new LdapException( NO_RESPONSE_ERROR, ie );
+ }
+ }
+
+
+ /**
* Bind to the server using a CramMd5Request object.
*
* @param request The CramMd5Request POJO containing all the needed parameters
@@ -1263,6 +1346,21 @@ public class LdapNetworkConnection exten
/**
+ * Do an asynchronous bind, based on a SaslPlainRequest.
+ *
+ * @param request The SaslPlainRequest POJO containing all the needed parameters
+ * @return The bind operation's future
+ * @throws LdapException if some error occurred
+ * @throws IOException if an I/O exception occurred
+ */
+ public BindFuture bindAsync( SaslPlainRequest request )
+ throws LdapException, IOException
+ {
+ return bindSasl( request );
+ }
+
+
+ /**
* Bind to the server using a DigestMd5Request object.
*
* @param request The DigestMd5Request POJO containing all the needed parameters
@@ -3666,8 +3764,9 @@ public class LdapNetworkConnection exten
// If the session has not been establish, or is closed, we get out immediately
checkSession();
- BindRequest bindRequest = createBindRequest( ( String ) null, null, saslRequest.getSaslMechanism(), saslRequest
- .getControls() );
+ BindRequest bindRequest = createBindRequest( ( String ) null, null,
+ saslRequest.getSaslMechanism(), saslRequest
+ .getControls() );
// Update the messageId
int newId = messageId.incrementAndGet();
Added: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslPlainRequest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslPlainRequest.java?rev=1465061&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslPlainRequest.java (added)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslPlainRequest.java Fri Apr 5 17:41:53 2013
@@ -0,0 +1,41 @@
+/*
+ * 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.ldap.client.api;
+
+
+import org.apache.directory.api.ldap.model.constants.SupportedSaslMechanisms;
+
+
+/**
+ * Holds the data required to complete the SASL PLAIN operation
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SaslPlainRequest extends SaslRequest
+{
+ /**
+ * Creates a new instance of CramMd5Request.
+ */
+ public SaslPlainRequest()
+ {
+ super( SupportedSaslMechanisms.PLAIN );
+ }
+}