org.apache.directory.api.ldap.codec.decorators
Class BindRequestDecorator

java.lang.Object
  extended by org.apache.directory.api.ldap.codec.api.MessageDecorator<M>
      extended by org.apache.directory.api.ldap.codec.decorators.RequestDecorator<M>
          extended by org.apache.directory.api.ldap.codec.decorators.ResultResponseRequestDecorator<M,R>
              extended by org.apache.directory.api.ldap.codec.decorators.SingleReplyRequestDecorator<BindRequest,BindResponse>
                  extended by org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator
All Implemented Interfaces:
Decorator<BindRequest>, AbandonableRequest, BindRequest, Message, Request, ResultResponseRequest<BindResponse>, SingleReplyRequest<BindResponse>

public class BindRequestDecorator
extends SingleReplyRequestDecorator<BindRequest,BindResponse>
implements BindRequest

A decorator for the BindRequest message

Author:
Apache Directory Project

Field Summary
 
Fields inherited from class org.apache.directory.api.ldap.codec.api.MessageDecorator
messageLength
 
Fields inherited from interface org.apache.directory.api.ldap.model.message.BindRequest
RESP_TYPE, TYPE
 
Constructor Summary
BindRequestDecorator(LdapApiService codec, BindRequest decoratedMessage)
          Makes a BindRequest a MessageDecorator.
 
Method Summary
 BindRequest addAllControls(Control[] controls)
          Adds an array of controls to this Message.
 BindRequest addControl(Control control)
          Adds a control to this Message.
 int computeLength()
          Compute the BindRequest length BindRequest :
 ByteBuffer encode(ByteBuffer buffer)
          Encode the BindRequest message to a PDU.
 int getBindRequestLength()
           
 byte[] getCredentials()
          Gets the simple credentials associated with a simple authentication attempt or null if this request uses SASL authentication mechanisms.
 Dn getDn()
          Gets the DN of the subject in this authentication request.
 String getName()
          Gets the name of the subject in this authentication request.
 int getSaslCredentialsLength()
           
 String getSaslMechanism()
          Gets the SASL mechanism String associated with this BindRequest if the bind operation is using SASL.
 int getSaslMechanismLength()
           
 boolean getSimple()
          Checks to see if the authentication mechanism is simple and not SASL based.
 boolean getVersion3()
          Gets whether or not the Ldap v3 protocol is used.
 boolean isSimple()
          Checks to see if the authentication mechanism is simple and not SASL based.
 boolean isVersion3()
          Checks to see if the Ldap v3 protocol is used.
 BindRequest removeControl(Control control)
          Deletes a control removing it from this Message.
 void setBindRequestLength(int bindRequestLength)
          Stores the encoded length for the BindRequest
 BindRequest setCredentials(byte[] credentials)
          Sets the simple credentials associated with a simple authentication attempt.
 BindRequest setCredentials(String credentials)
          Sets the simple credentials associated with a simple authentication attempt.
 BindRequest setDn(Dn dn)
          Sets the DN of the subject in this authentication request.
 BindRequest setMessageId(int messageId)
          Sets the Message ID for this request
 BindRequest setName(String name)
          Sets the name of the subject in this authentication request.
 void setSaslCredentialsLength(int saslCredentialsLength)
          Stores the encoded length for the SaslCredentials
 BindRequest setSaslMechanism(String saslMechanism)
          Sets the SASL mechanism String associated with this BindRequest if the bind operation is using SASL.
 void setSaslMechanismLength(int saslMechanismLength)
          Stores the encoded length for the Mechanism
 BindRequest setSimple(boolean isSimple)
          Sets the authentication mechanism to simple or to SASL based authentication.
 BindRequest setVersion3(boolean isVersion3)
          Sets whether or not the LDAP v3 or v2 protocol is used.
 
Methods inherited from class org.apache.directory.api.ldap.codec.decorators.SingleReplyRequestDecorator
abandon, addAbandonListener, getResponseType, isAbandoned
 
Methods inherited from class org.apache.directory.api.ldap.codec.decorators.ResultResponseRequestDecorator
getResultResponse, hasResponse
 
Methods inherited from class org.apache.directory.api.ldap.codec.api.MessageDecorator
get, getCodecService, getControl, getControls, getControlsLength, getCurrentControl, getDecorated, getDecorator, getMessageId, getMessageLength, getType, hasControl, put, setControlsLength, setMessageLength, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.directory.api.ldap.model.message.SingleReplyRequest
getResponseType
 
Methods inherited from interface org.apache.directory.api.ldap.model.message.ResultResponseRequest
getResultResponse
 
Methods inherited from interface org.apache.directory.api.ldap.model.message.Request
hasResponse
 
Methods inherited from interface org.apache.directory.api.ldap.model.message.Message
get, getControl, getControls, getMessageId, getType, hasControl, put
 
Methods inherited from interface org.apache.directory.api.ldap.model.message.AbandonableRequest
abandon, addAbandonListener, isAbandoned
 

Constructor Detail

BindRequestDecorator

public BindRequestDecorator(LdapApiService codec,
                            BindRequest decoratedMessage)
Makes a BindRequest a MessageDecorator.

Parameters:
decoratedMessage - the decorated BindRequests.
Method Detail

setBindRequestLength

public void setBindRequestLength(int bindRequestLength)
Stores the encoded length for the BindRequest

Parameters:
bindRequestLength - The encoded length

getBindRequestLength

public int getBindRequestLength()
Returns:
The encoded BindRequest's length

setSaslCredentialsLength

public void setSaslCredentialsLength(int saslCredentialsLength)
Stores the encoded length for the SaslCredentials

Parameters:
saslCredentialsLength - The encoded length

getSaslCredentialsLength

public int getSaslCredentialsLength()
Returns:
The encoded SaslCredentials's length

setSaslMechanismLength

public void setSaslMechanismLength(int saslMechanismLength)
Stores the encoded length for the Mechanism

Parameters:
saslMechanismLength - The encoded length

getSaslMechanismLength

public int getSaslMechanismLength()
Returns:
The encoded SaslMechanism's length

setMessageId

public BindRequest setMessageId(int messageId)
Sets the Message ID for this request

Specified by:
setMessageId in interface BindRequest
Specified by:
setMessageId in interface Message
Overrides:
setMessageId in class MessageDecorator<BindRequest>
Parameters:
messageId - The message Id
Returns:
A Message reference

addControl

public BindRequest addControl(Control control)
                       throws MessageException
Adds a control to this Message.

Specified by:
addControl in interface BindRequest
Specified by:
addControl in interface Message
Overrides:
addControl in class MessageDecorator<BindRequest>
Parameters:
control - the control to add.
Returns:
A Message reference
Throws:
MessageException - if controls cannot be added to this Message or the control is not known etc.

addAllControls

public BindRequest addAllControls(Control[] controls)
                           throws MessageException
Adds an array of controls to this Message.

Specified by:
addAllControls in interface BindRequest
Specified by:
addAllControls in interface Message
Overrides:
addAllControls in class MessageDecorator<BindRequest>
Parameters:
controls - the controls to add.
Returns:
A Message reference
Throws:
MessageException - if controls cannot be added to this Message or they are not known etc.

removeControl

public BindRequest removeControl(Control control)
                          throws MessageException
Deletes a control removing it from this Message.

Specified by:
removeControl in interface BindRequest
Specified by:
removeControl in interface Message
Overrides:
removeControl in class MessageDecorator<BindRequest>
Parameters:
control - the control to remove.
Returns:
A Message reference
Throws:
MessageException - if controls cannot be added to this Message or the control is not known etc.

isSimple

public boolean isSimple()
Checks to see if the authentication mechanism is simple and not SASL based.

Specified by:
isSimple in interface BindRequest
Returns:
true if the mechanism is simple false if it is SASL based.

getSimple

public boolean getSimple()
Checks to see if the authentication mechanism is simple and not SASL based.

Specified by:
getSimple in interface BindRequest
Returns:
true if the mechanism is simple false if it is SASL based.

setSimple

public BindRequest setSimple(boolean isSimple)
Sets the authentication mechanism to simple or to SASL based authentication.

Specified by:
setSimple in interface BindRequest
Parameters:
isSimple - true if authentication is simple, false otherwise.
Returns:
The BindRequest instance

getCredentials

public byte[] getCredentials()
Gets the simple credentials associated with a simple authentication attempt or null if this request uses SASL authentication mechanisms.

Specified by:
getCredentials in interface BindRequest
Returns:
null if the mechanism is SASL, or the credentials if it is simple.

setCredentials

public BindRequest setCredentials(String credentials)
Sets the simple credentials associated with a simple authentication attempt. Ignored if this request uses SASL authentication mechanisms.

Specified by:
setCredentials in interface BindRequest
Parameters:
credentials - the credentials if authentication is simple
Returns:
The BindRequest instance

setCredentials

public BindRequest setCredentials(byte[] credentials)
Sets the simple credentials associated with a simple authentication attempt. Ignored if this request uses SASL authentication mechanisms.

Specified by:
setCredentials in interface BindRequest
Parameters:
credentials - the credentials if authentication is simple
Returns:
The BindRequest instance

getName

public String getName()
Gets the name of the subject in this authentication request. This field may take on a null value (a zero length string) for the purposes of anonymous binds, when authentication has been performed at a lower layer, or when using SASL credentials with a mechanism that includes the name in the credentials.

Specified by:
getName in interface BindRequest
Returns:
the name of the authenticating user.

setName

public BindRequest setName(String name)
Sets the name of the subject in this authentication request. This field may take on a null value (or a zero length string) for the purposes of anonymous binds, when authentication has been performed at a lower layer, or when using SASL credentials with a mechanism that includes the name in the credentials.

Specified by:
setName in interface BindRequest
Parameters:
name - the name of the authenticating user - leave null for anonymous user.
Returns:
The BindRequest instance

getDn

public Dn getDn()
Gets the DN of the subject in this authentication request. This field may take on a null value (a zero length string) for the purposes of anonymous binds, when authentication has been performed at a lower layer, or when using SASL credentials with a mechanism that includes the DN in the credentials.

Specified by:
getDn in interface BindRequest
Returns:
the DN of the authenticating user.

setDn

public BindRequest setDn(Dn dn)
Sets the DN of the subject in this authentication request. This field may take on a null value (or a zero length string) for the purposes of anonymous binds, when authentication has been performed at a lower layer, or when using SASL credentials with a mechanism that includes the DN in the credentials.

Specified by:
setDn in interface BindRequest
Parameters:
dn - the DN of the authenticating user - leave null for anonymous user.
Returns:
The BindRequest instance

isVersion3

public boolean isVersion3()
Checks to see if the Ldap v3 protocol is used. Normally this would extract a version number from the bind request sent by the client indicating the version of the protocol to be used in this protocol session. The integer is either a 2 or a 3 at the moment. We thought it was better to just check if the protocol used is 3 or not rather than use an type-safe enumeration type for a binary value. If an LDAPv4 comes out then we shall convert the return type to a type safe enumeration.

Specified by:
isVersion3 in interface BindRequest
Returns:
true if client using version 3 false if it is version 2.

getVersion3

public boolean getVersion3()
Gets whether or not the Ldap v3 protocol is used. Normally this would extract a version number from the bind request sent by the client indicating the version of the protocol to be used in this protocol session. The integer is either a 2 or a 3 at the moment. We thought it was better to just check if the protocol used is 3 or not rather than use an type-safe enumeration type for a binary value. If an LDAPv4 comes out then we shall convert the return type to a type safe enumeration.

Specified by:
getVersion3 in interface BindRequest
Returns:
true if client using version 3 false if it is version 2.

setVersion3

public BindRequest setVersion3(boolean isVersion3)
Sets whether or not the LDAP v3 or v2 protocol is used. Normally this would extract a version number from the bind request sent by the client indicating the version of the protocol to be used in this protocol session. The integer is either a 2 or a 3 at the moment. We thought it was better to just check if the protocol used is 3 or not rather than use an type-safe enumeration type for a binary value. If an LDAPv4 comes out then we shall convert the return type to a type safe enumeration.

Specified by:
setVersion3 in interface BindRequest
Parameters:
isVersion3 - if true the client will be exhibiting version 3 bind behavior, If false is used version 2 behavior will be exhibited.
Returns:
The BindRequest instance

getSaslMechanism

public String getSaslMechanism()
Gets the SASL mechanism String associated with this BindRequest if the bind operation is using SASL.

Specified by:
getSaslMechanism in interface BindRequest
Returns:
the SASL mechanism or null if the bind operation is simple

setSaslMechanism

public BindRequest setSaslMechanism(String saslMechanism)
Sets the SASL mechanism String associated with this BindRequest if the bind operation is using SASL.

Specified by:
setSaslMechanism in interface BindRequest
Parameters:
saslMechanism - the SASL mechanism
Returns:
The BindRequest instance

computeLength

public int computeLength()
Compute the BindRequest length BindRequest :
 0x60 L1
   |
   +--> 0x02 0x01 (1..127) version
   +--> 0x04 L2 name
   +--> authentication
 
 L2 = Length(name)
 L3/4 = Length(authentication)
 Length(BindRequest) = Length(0x60) + Length(L1) + L1 + Length(0x02) + 1 + 1 +
      Length(0x04) + Length(L2) + L2 + Length(authentication)
 

Specified by:
computeLength in interface Decorator<BindRequest>
Returns:
The object's computed length

encode

public ByteBuffer encode(ByteBuffer buffer)
                  throws EncoderException
Encode the BindRequest message to a PDU. BindRequest :
 0x60 LL
   0x02 LL version         0x80 LL simple
   0x04 LL name           /
   authentication.encode()
                          \ 0x83 LL mechanism [0x04 LL credential]
 

Specified by:
encode in interface Decorator<BindRequest>
Parameters:
buffer - The buffer where to put the PDU
Returns:
The PDU.
Throws:
EncoderException - if the buffer can't be encoded


Copyright © 2003-2013 The Apache Software Foundation. All Rights Reserved.