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 2017/11/28 22:56:59 UTC
[directory-ldap-api] 03/03: Added support for SASL EXTERNAL
(DIRAPI-105)
This is an automated email from the ASF dual-hosted git repository.
elecharny pushed a commit to branch shared-value
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git
commit c5192d9feb1ef0563a4690bf40b0fac7374e788d
Author: Emmanuel Lécharny <el...@symas.com>
AuthorDate: Tue Nov 28 23:49:34 2017 +0100
Added support for SASL EXTERNAL (DIRAPI-105)
---
.../ldap/client/api/LdapNetworkConnection.java | 57 ++++++++++++++++++++++
.../ldap/client/api/SaslExternalRequest.java | 51 +++++++++++++++++++
2 files changed, 108 insertions(+)
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 8f9d138..e43a8f2 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
@@ -1707,6 +1707,63 @@ public class LdapNetworkConnection extends AbstractLdapConnection implements Lda
/**
+ * Bind to the server using a SaslExternalRequest object.
+ *
+ * @param request The SaslExternalRequest POJO containing all the needed parameters
+ * @return A LdapResponse containing the result
+ * @throws LdapException if some error occurred
+ */
+ public BindResponse bind( SaslExternalRequest request ) throws LdapException
+ {
+ if ( request == null )
+ {
+ String msg = "Cannot process a null request";
+ LOG.debug( msg );
+ throw new IllegalArgumentException( msg );
+ }
+
+ BindFuture bindFuture = bindAsync( request );
+
+ // 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 ( Exception ie )
+ {
+ // Catch all other exceptions
+ LOG.error( NO_RESPONSE_ERROR, ie );
+
+ throw new LdapException( NO_RESPONSE_ERROR, ie );
+ }
+ }
+
+
+ /**
* Do an asynchronous bind, based on a GssApiRequest.
*
* @param request The GssApiRequest POJO containing all the needed parameters
diff --git a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslExternalRequest.java b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslExternalRequest.java
new file mode 100644
index 0000000..c438d47
--- /dev/null
+++ b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/SaslExternalRequest.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.ldap.client.api;
+
+
+import org.apache.directory.api.ldap.model.constants.SupportedSaslMechanisms;
+
+
+/**
+ * Holds the data required to complete the EXTERNAL SASL operation
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SaslExternalRequest extends AbstractSaslRequest
+{
+ /**
+ * Creates a new instance of SaslExternalRequest.
+ */
+ public SaslExternalRequest()
+ {
+ super( SupportedSaslMechanisms.EXTERNAL );
+ }
+
+
+ /**
+ * Creates a new instance of SaslExternalRequest.
+ */
+ public SaslExternalRequest( String authzId )
+ {
+ super( SupportedSaslMechanisms.EXTERNAL );
+ this.authorizationId = authzId;
+ }
+}
--
To stop receiving notification emails like this one, please contact
"commits@directory.apache.org" <co...@directory.apache.org>.