public interface SaslClient
A protocol library such as one for LDAP gets an instance of this class in order to perform authentication defined by a specific SASL mechanism. Invoking methods on the SaslClient instance process challenges and create responses according to the SASL mechanism implemented by the SaslClient. As the authentication proceeds, the instance encapsulates the state of a SASL client's authentication exchange.
Here's an example of how an LDAP library might use a SaslClient. It first gets an instance of a SaslClient:
It can then proceed to use the client for authentication. For example, an LDAP library might use the client as follows:SaslClient sc = Sasl.createSaslClient(mechanisms, authorizationId, protocol, serverName, props, callbackHandler);
Note that the call to createInitialResponse() is optional. Protocols such as IMAP4 do not invoke it but instead only use evaluateChallenge(), possibly with an empty challenge. It is the responsibility of the SaslClient implementation for a mechanism to take this into account so that it behaves properly regardless of whether createInitialResponse() is called.InputStream is = ldap.getInputStream(); OutputStream os = ldap.getOutputStream(); byte[] toServer = sc.createInitialResponse(); LdapResult res = ldap.sendBindRequest(dn, sc.getName(), toServer); while (!sc.isComplete() && res.status == SASL_BIND_IN_PROGRESS) { toServer = sc.evaluateChallenge(res.getBytesFromServer()); if (toServer != null) { res = ldap.sendBindRequest(dn, sc.getName(), toServer); } } if (sc.isComplete() && res.status == SUCCESS) { // Get the input and output streams; may be unchanged is = sc.getInputStream( is ); os = sc.getOutputStream( os ); // Use these streams from now on ldap.setInputStream( is ); ldap.setOutputStream( os ); }
Sasl
,
SaslClientFactory
Modifier and Type | Method and Description |
---|---|
byte[] |
createInitialResponse()
Retrieves the initial response.
|
byte[] |
evaluateChallenge(byte[] challenge)
Evaluates the challenge data and generates a response.
|
java.io.InputStream |
getInputStream(java.io.InputStream is)
Retrieves an input stream for the session.
|
java.lang.String |
getMechanismName()
Returns the IANA-registered mechanism name of this SASL client.
|
java.io.OutputStream |
getOutputStream(java.io.OutputStream os)
Retrieves an output stream for the session.
|
boolean |
isComplete()
Determines whether the authentication exchange has completed.
|
java.lang.String getMechanismName()
byte[] createInitialResponse() throws SaslException
SaslException
- If an error occurred while creating
the initial response.byte[] evaluateChallenge(byte[] challenge) throws SaslException
challenge
- The non-null challenge sent from the server.SaslException
- If an error occurred while processing
the challenge or generating a response.boolean isComplete()
java.io.InputStream getInputStream(java.io.InputStream is) throws java.io.IOException
is
- The original input stream for reading from the server.java.io.IOException
- If the authentication exchange has not completed
or an error occurred while getting the stream.java.io.OutputStream getOutputStream(java.io.OutputStream os) throws java.io.IOException
os
- The original output stream for writing to the server.java.io.IOException
- If the authentication exchange has not completed
or an error occurred while getting the stream.