You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2011/02/16 15:37:49 UTC
svn commit: r1071268 - in
/directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api:
./ callback/
Author: pamarcelot
Date: Wed Feb 16 14:37:49 2011
New Revision: 1071268
URL: http://svn.apache.org/viewvc?rev=1071268&view=rev
Log:
Fix for DIRAPI-42 (Add additional classes and clean method arguments for SASL binds (CRAM-MD5, DIGEST-MD5, GSS-API)).
Added:
directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/CramMd5Request.java
directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/DigestMd5Request.java
directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/GssApiRequest.java
Modified:
directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java
directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/callback/SaslCallbackHandler.java
Added: directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/CramMd5Request.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/CramMd5Request.java?rev=1071268&view=auto
==============================================================================
--- directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/CramMd5Request.java (added)
+++ directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/CramMd5Request.java Wed Feb 16 14:37:49 2011
@@ -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.shared.ldap.model.constants.SupportedSaslMechanisms;
+
+
+/**
+ * Holds the data required to complete the SASL operation
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CramMd5Request extends SaslRequest
+{
+ /**
+ * TODO
+ */
+ public CramMd5Request()
+ {
+ super( SupportedSaslMechanisms.CRAM_MD5 );
+ }
+}
Added: directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/DigestMd5Request.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/DigestMd5Request.java?rev=1071268&view=auto
==============================================================================
--- directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/DigestMd5Request.java (added)
+++ directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/DigestMd5Request.java Wed Feb 16 14:37:49 2011
@@ -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.shared.ldap.model.constants.SupportedSaslMechanisms;
+
+
+/**
+ * Holds the data required to complete the SASL operation
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DigestMd5Request extends SaslRequest
+{
+ /**
+ * TODO
+ */
+ public DigestMd5Request()
+ {
+ super( SupportedSaslMechanisms.DIGEST_MD5 );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ // Overriding the visibility of the method to public
+ public void setRealmName( String realmName )
+ {
+ super.setRealmName( realmName );
+ }
+}
Added: directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/GssApiRequest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/GssApiRequest.java?rev=1071268&view=auto
==============================================================================
--- directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/GssApiRequest.java (added)
+++ directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/GssApiRequest.java Wed Feb 16 14:37:49 2011
@@ -0,0 +1,102 @@
+/*
+ * 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.shared.ldap.model.constants.SupportedSaslMechanisms;
+
+
+/**
+ * Holds the data required to complete the SASL operation
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class GssApiRequest extends SaslRequest
+{
+ /** The KDC host*/
+ protected String kdcHost;
+
+ /** The KDC port */
+ protected int kdcPort;
+
+
+ /**
+ * TODO
+ */
+ public GssApiRequest()
+ {
+ super( SupportedSaslMechanisms.CRAM_MD5 );
+ }
+
+
+ /**
+ * Gets the KDC host.
+ *
+ * @return the KDC host
+ */
+ public String getKdcHost()
+ {
+ return kdcHost;
+ }
+
+
+ /**
+ * Gets the KDC port.
+ *
+ * @return the KDC port
+ */
+ public int getKdcPort()
+ {
+ return kdcPort;
+ }
+
+
+ /**
+ * Sets the KDC host.
+ *
+ * @param kdcHost the KDC host
+ */
+ public void setKdcHost( String kdcHost )
+ {
+ this.kdcHost = kdcHost;
+ }
+
+
+ /**
+ * Sets the KDC port.
+ *
+ * @param kdcPort the KDC port
+ */
+ public void setKdcPort( int kdcPort )
+ {
+ this.kdcPort = kdcPort;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ // Overriding the visibility of the method to public
+ public void setRealmName( String realmName )
+ {
+ super.setRealmName( realmName );
+ }
+}
Modified: directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=1071268&r1=1071267&r2=1071268&view=diff
==============================================================================
--- directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java (original)
+++ directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java Wed Feb 16 14:37:49 2011
@@ -61,7 +61,6 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.codec.api.LdapCodecServiceFactory;
import org.apache.directory.shared.ldap.codec.api.MessageEncoderException;
import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
-import org.apache.directory.shared.ldap.model.constants.SupportedSaslMechanisms;
import org.apache.directory.shared.ldap.model.cursor.Cursor;
import org.apache.directory.shared.ldap.model.cursor.SearchCursor;
import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
@@ -385,7 +384,7 @@ public class LdapNetworkConnection exten
config.setLdapPort( config.getDefaultLdapPort() );
// Default to localhost if null
- if ( Strings.isEmpty(server) )
+ if ( Strings.isEmpty( server ) )
{
config.setLdapHost( "localhost" );
}
@@ -414,7 +413,7 @@ public class LdapNetworkConnection exten
config.setLdapPort( useSsl ? config.getDefaultLdapsPort() : config.getDefaultLdapPort() );
// Default to localhost if null
- if ( Strings.isEmpty(server) )
+ if ( Strings.isEmpty( server ) )
{
config.setLdapHost( "localhost" );
}
@@ -457,7 +456,7 @@ public class LdapNetworkConnection exten
config.setLdapPort( port );
// Default to localhost if null
- if ( Strings.isEmpty(server) )
+ if ( Strings.isEmpty( server ) )
{
config.setLdapHost( "localhost" );
}
@@ -913,7 +912,7 @@ public class LdapNetworkConnection exten
LOG.debug( "Bind request : {}", name );
// Create the BindRequest
- BindRequest bindRequest = createBindRequest( name, Strings.getBytesUtf8(credentials) );
+ BindRequest bindRequest = createBindRequest( name, Strings.getBytesUtf8( credentials ) );
return bind( bindRequest );
}
@@ -927,7 +926,7 @@ public class LdapNetworkConnection exten
LOG.debug( "Bind request : {}", name );
// Create the BindRequest
- BindRequest bindRequest = createBindRequest( name, Strings.getBytesUtf8(credentials) );
+ BindRequest bindRequest = createBindRequest( name, Strings.getBytesUtf8( credentials ) );
return bindAsync( bindRequest );
}
@@ -941,7 +940,7 @@ public class LdapNetworkConnection exten
LOG.debug( "Bind request : {}", name );
// Create the BindRequest
- BindRequest bindRequest = createBindRequest( name, Strings.getBytesUtf8(credentials), null );
+ BindRequest bindRequest = createBindRequest( name, Strings.getBytesUtf8( credentials ), null );
return bind( bindRequest );
}
@@ -955,7 +954,7 @@ public class LdapNetworkConnection exten
LOG.debug( "Bind request : {}", name );
// Create the BindRequest
- BindRequest bindRequest = createBindRequest( name, Strings.getBytesUtf8(credentials) );
+ BindRequest bindRequest = createBindRequest( name, Strings.getBytesUtf8( credentials ) );
return bindAsync( bindRequest );
}
@@ -1093,7 +1092,7 @@ public class LdapNetworkConnection exten
bindRequest.setName( name );
// Set the credentials
- if ( Strings.isEmpty(saslMechanism) )
+ if ( Strings.isEmpty( saslMechanism ) )
{
// Simple bind
bindRequest.setSimple( true );
@@ -1158,42 +1157,58 @@ public class LdapNetworkConnection exten
/**
- * Bind using CRAM-MD5 SASL mechanism.
+ * Bind to the server using a CramMd5Request object.
*
- * @param name the Dn of the user
- * @param credentials password of the user
- * @param authzId the authorization ID (can be null)
- * @return response of the bind operation
- * @throws LdapException if an LDAP error occurred during bind
- * @throws IOException if an IO exception occurred
- * @see #bindCramMd5(String, byte[], String, Control...)
+ * @param request The CramMd5Request POJO containing all the needed parameters
+ * @return A LdapResponse containing the result
+ * @throws LdapException if some error occurred
+ * @throws IOException if an I/O exception occurred
*/
- public BindResponse bindCramMd5( String name, String credentials, String authzId )
- throws LdapException, IOException
+ public BindResponse bind( CramMd5Request request ) throws LdapException, IOException
{
- return bindCramMd5( name, Strings.getBytesUtf8(credentials), authzId );
- }
+ if ( request == null )
+ {
+ String msg = "Cannot process a null request";
+ LOG.debug( msg );
+ throw new IllegalArgumentException( msg );
+ }
+ BindFuture bindFuture = bindAsync( request );
- /**
- * Bind using CRAM-MD5 SASL mechanism.
- *
- * @param name the Dn of the user
- * @param credentials password of the user
- * @param authzId the authorization ID (can be null)
- * @param ctrls controls to be sent with the bind request
- * @return response of the bind operation
- * @throws LdapException if an LDAP error occurred during bind
- * @throws IOException if an IO exception occurred
- */
- public BindResponse bindCramMd5( String name, byte[] credentials, String authzId, Control... ctrls )
- throws LdapException, IOException
- {
- BindFuture bindFuture = bindSasl( name, credentials, SupportedSaslMechanisms.CRAM_MD5, authzId, null, ctrls );
-
+ // Get the result from the future
try
{
- return bindFuture.get();
+ // 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 occured" );
+ 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 occured" );
+ throw new LdapException( TIME_OUT_ERROR );
}
catch ( Exception ie )
{
@@ -1208,62 +1223,73 @@ public class LdapNetworkConnection exten
/**
- * Bind using CRAM-MD5 SASL mechanism.
+ * Do an asynchronous bind, based on a CramMd5Request.
*
- * @param name the Dn of the user
- * @param credentials password of the user
- * @param authzId the authorization ID (can be null)
- * @return response of the bind operation
- * @throws LdapException if an LDAP error occurred during bind
- * @throws IOException if an IO exception occurred
- * @see #bindCramMd5(String, byte[], String, Control...)
+ * @param request The CramMd5Request 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 BindResponse bindCramMd5( String name, byte[] credentials, String authzId )
+ public BindFuture bindAsync( CramMd5Request request )
throws LdapException, IOException
{
- return bindCramMd5( name, credentials, authzId, new Control[0] );
+ return bindSasl( request );
}
/**
- * Bind using DIGEST-MD5 SASL mechanism.
+ * Bind to the server using a DigestMd5Request object.
*
- * @param name the Dn of the user
- * @param credentials password of the user
- * @param authzId the authorization ID (can be null)
- * @param realmName the SASL realm name to be used
- * @return response of the bind operation
- * @throws LdapException if an LDAP error occurred during bind
- * @throws IOException if an IO exception occurred
+ * @param request The DigestMd5Request POJO containing all the needed parameters
+ * @return A LdapResponse containing the result
+ * @throws LdapException if some error occurred
+ * @throws IOException if an I/O exception occurred
*/
- public BindResponse bindDigestMd5( String name, String credentials, String authzId, String realmName )
- throws LdapException, IOException
+ public BindResponse bind( DigestMd5Request request ) throws LdapException, IOException
{
- return bindDigestMd5( name, Strings.getBytesUtf8(credentials), authzId, realmName );
- }
-
+ if ( request == null )
+ {
+ String msg = "Cannot process a null request";
+ LOG.debug( msg );
+ throw new IllegalArgumentException( msg );
+ }
- /**
- * Bind using DIGEST-MD5 SASL mechanism.
- *
- * @param name the Dn of the user
- * @param credentials password of the user
- * @param authzId the authorization ID (can be null)
- * @param realmName the SASL realm name to be used
- * @param ctrls the LDAP controls to be used
- * @return response of the bind operation
- * @throws LdapException if an LDAP error occurred during bind
- * @throws IOException if an IO exception occurred
- */
- public BindResponse bindDigestMd5( String name, byte[] credentials, String authzId, String realmName,
- Control... ctrls ) throws LdapException, IOException
- {
- BindFuture bindFuture = bindSasl( name, credentials, SupportedSaslMechanisms.DIGEST_MD5, authzId, realmName,
- ctrls );
+ BindFuture bindFuture = bindAsync( request );
+ // Get the result from the future
try
{
- return bindFuture.get();
+ // 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 occured" );
+ 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 occured" );
+ throw new LdapException( TIME_OUT_ERROR );
}
catch ( Exception ie )
{
@@ -1278,93 +1304,120 @@ public class LdapNetworkConnection exten
/**
- * Bind using DIGEST-MD5 SASL mechanism.
+ * Do an asynchronous bind, based on a DigestMd5Request.
*
- * @param name the Dn of the user
- * @param credentials password of the user
- * @param authzId the authorization ID (can be null)
- * @param realmName the SASL realm name to be used
- * @return response of the bind operation
- * @throws LdapException if an LDAP error occurred during bind
- * @throws IOException if an IO exception occurred
- * @see #bindDigestMd5(String, byte[], String, String, Control...)
+ * @param request The DigestMd5Request 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 BindResponse bindDigestMd5( String name, byte[] credentials, String authzId, String realmName )
+ public BindFuture bindAsync( DigestMd5Request request )
throws LdapException, IOException
{
- return bindDigestMd5( name, credentials, authzId, realmName, new Control[0] );
+ return bindSasl( request );
}
/**
- * Bind to the LDAP server using GSSAPI SASL mechanism.
+ * Bind to the server using a GssApiRequest object.
*
- * @param name the Dn of the user entry
- * @param credentials the credentials of the user
- * @param realmName name of the kerberos realm in which the given user entry is present
- * @param kdcHost the host name of the KDC server
- * @param kdcPort the port of the KDC server
- * @param ctrls controls to be passed along with the bind request
- * @return response of this bind operation
- * @throws LdapException if an LDAP error occurred during bind
- * @throws IOException if an IO exception occurred
- * @see #bindGssApi(String, byte[], String, String, int, Control...)
+ * @param request The GssApiRequest POJO containing all the needed parameters
+ * @return A LdapResponse containing the result
+ * @throws LdapException if some error occurred
+ * @throws IOException if an I/O exception occurred
*/
- public BindResponse bindGssApi( String name, String credentials, String realmName, String kdcHost, int kdcPort,
- Control... ctrls )
- throws LdapException, IOException
+ public BindResponse bind( GssApiRequest request ) throws LdapException, IOException
{
- return bindGssApi( name, Strings.getBytesUtf8(credentials), realmName, kdcHost, kdcPort, ctrls );
+ 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 occured" );
+ 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 occured" );
+ throw new LdapException( TIME_OUT_ERROR );
+ }
+ catch ( Exception ie )
+ {
+ // Catch all other exceptions
+ LOG.error( NO_RESPONSE_ERROR, ie );
+ LdapException ldapException = new LdapException( NO_RESPONSE_ERROR );
+ ldapException.initCause( ie );
+
+ throw ldapException;
+ }
}
/**
- * Bind to the LDAP server using GSSAPI SASL mechanism.
+ * Do an asynchronous bind, based on a GssApiRequest.
*
- * @param name the Dn of the user entry
- * @param credentials the credentials of the user
- * @param realmName name of the kerberos realm in which the given user entry is present
- * @param kdcHost the host name of the KDC server
- * @param kdcPort the port of the KDC server
- * @param ctrls controls to be passed along with the bind request
- * @return response of this bind operation
- * @throws LdapException if an LDAP error occurred during bind
- * @throws IOException if an IO exception occurred
+ * @param request The GssApiRequest 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 BindResponse bindGssApi( String name, byte[] credentials, String realmName, String kdcHost, int kdcPort,
- Control... ctrls )
+ public BindFuture bindAsync( GssApiRequest request )
throws LdapException, IOException
{
- String krbConfPath = createKrbConfFile( realmName, kdcHost, kdcPort );
+ System.clearProperty( "java.security.krb5.conf" );
+ String krbConfPath = createKrbConfFile( request.getRealmName(), request.getKdcHost(), request.getKdcPort() );
System.setProperty( "java.security.krb5.conf", krbConfPath );
Configuration.setConfiguration( new Krb5LoginConfiguration() );
System.setProperty( "javax.security.auth.useSubjectCredsOnly", "true" );
- 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( request ) );
loginContext.login();
- // Now, bind by calling the internal bindSasl method
- BindFuture future = ( BindFuture ) Subject.doAs( loginContext.getSubject(),
+ final GssApiRequest requetFinal = request;
+
+ return ( BindFuture ) Subject.doAs( loginContext.getSubject(),
new PrivilegedExceptionAction<Object>()
{
public Object run() throws Exception
{
- return bindSasl( saslRequest );
+ return bindSasl( requetFinal );
}
} );
-
- return future.get();
}
catch ( Exception e )
{
@@ -1622,7 +1675,7 @@ public class LdapNetworkConnection exten
{
if ( message instanceof ExtendedResponse )
{
- ExtendedResponse response = (ExtendedResponse) message;
+ ExtendedResponse response = ( ExtendedResponse ) message;
if ( response.getResponseName().equals( NoticeOfDisconnect.EXTENSION_OID ) )
{
@@ -2067,7 +2120,7 @@ public class LdapNetworkConnection exten
}
else
{
- if ( modifyResponse instanceof ModifyNoDResponse)
+ if ( modifyResponse instanceof ModifyNoDResponse )
{
// A NoticeOfDisconnect : deserves a special treatment
throw new LdapException( modifyResponse.getLdapResult().getErrorMessage() );
@@ -3520,10 +3573,9 @@ public class LdapNetworkConnection exten
Control... ctrls )
throws LdapException, IOException
{
- SaslRequest saslRequest = new SaslRequest();
+ SaslRequest saslRequest = new SaslRequest( saslMech ); // TODO fix this
saslRequest.setUsername( name );
saslRequest.setCredentials( credentials );
- saslRequest.setSaslMechanism( saslMech );
saslRequest.setAuthorizationId( authzId );
saslRequest.setRealmName( realmName );
saslRequest.addAllControls( ctrls );
Modified: directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java?rev=1071268&r1=1071267&r2=1071268&view=diff
==============================================================================
--- directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java (original)
+++ directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/SaslRequest.java Wed Feb 16 14:37:49 2011
@@ -27,6 +27,7 @@ import java.util.List;
import org.apache.directory.shared.ldap.model.message.Control;
import org.apache.directory.shared.util.StringConstants;
+import org.apache.directory.shared.util.Strings;
/**
@@ -34,25 +35,33 @@ import org.apache.directory.shared.util.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
+// TODO make this class abstract
public class SaslRequest
{
+ /** The mechanism used to decode user identity */
+ protected String saslMechanism;
+
/** The list of controls */
- private List<Control> controls = new ArrayList<Control>();
+ protected List<Control> controls = new ArrayList<Control>();
/** The username */
- private String username;
+ protected String username;
/** The credentials */
- private byte[] credentials;
+ protected byte[] credentials;
- /** SASL realm name on the server */
- private String realmName;
+ /** The realm name on the server */
+ protected String realmName;
/** The authorization ID of the entity */
- private String authorizationId;
+ protected String authorizationId;
- /** The mechanism used to decode user identity */
- private String saslMechanism;
+
+ protected SaslRequest( String saslMechanism )
+ {
+ super();
+ this.saslMechanism = saslMechanism;
+ }
/**
@@ -173,11 +182,22 @@ public class SaslRequest
/**
+ * Sets the credentials.
+ *
+ * @param credentials the credentials
+ */
+ public void setCredentials( String credentials )
+ {
+ this.credentials = Strings.getBytesUtf8( credentials );
+ }
+
+
+ /**
* Sets the realm name.
*
* @param realmName The realm name
*/
- public void setRealmName( String realmName )
+ protected void setRealmName( String realmName )
{
this.realmName = realmName;
}
@@ -188,7 +208,7 @@ public class SaslRequest
*
* @param saslMechanism the SASL mechanism
*/
- public void setSaslMechanism( String saslMechanism )
+ protected void setSaslMechanism( String saslMechanism )
{
this.saslMechanism = saslMechanism;
}
Modified: directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/callback/SaslCallbackHandler.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/callback/SaslCallbackHandler.java?rev=1071268&r1=1071267&r2=1071268&view=diff
==============================================================================
--- directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/callback/SaslCallbackHandler.java (original)
+++ directory/shared/branches/m1/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/callback/SaslCallbackHandler.java Wed Feb 16 14:37:49 2011
@@ -45,7 +45,6 @@ import org.slf4j.LoggerFactory;
*/
public class SaslCallbackHandler implements CallbackHandler
{
-
/** The sasl request. */
private SaslRequest saslReq;