use of org.apache.directory.api.ldap.model.message.BindRequest in project directory-ldap-api by apache.
the class StoreVersion method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<BindRequestDecorator> container) throws DecoderException {
BindRequest bindRequestMessage = container.getMessage();
// The current TLV should be a integer between 1 and 127
// We get it and store it in Version
TLV tlv = container.getCurrentTLV();
BerValue value = tlv.getValue();
try {
int version = IntegerDecoder.parse(value, 1, 127);
if (IS_DEBUG) {
LOG.debug("Ldap version ", Integer.valueOf(version));
}
bindRequestMessage.setVersion3(version == 3);
} catch (IntegerDecoderException ide) {
LOG.error(I18n.err(I18n.ERR_04078, Strings.dumpBytes(value.getData()), ide.getMessage()));
// This will generate a PROTOCOL_ERROR
throw new DecoderException(ide.getMessage(), ide);
}
}
use of org.apache.directory.api.ldap.model.message.BindRequest in project directory-fortress-core by apache.
the class LdapDataProvider method bind.
/**
* Calls the PoolMgr to perform an LDAP bind for a user/password combination. This function is valid
* if and only if the user entity is a member of the USERS data set.
*
* @param connection connection to ldap server.
* @param szUserDn contains the LDAP dn to the user entry in String format.
* @param password contains the password in clear text.
* @return bindResponse contains the result of the operation.
* @throws LdapException in the event of LDAP error.
*/
protected BindResponse bind(LdapConnection connection, String szUserDn, String password) throws LdapException {
COUNTERS.incrementBind();
Dn userDn = new Dn(szUserDn);
BindRequest bindReq = new BindRequestImpl();
bindReq.setDn(userDn);
bindReq.setCredentials(password);
bindReq.addControl(PP_REQ_CTRL);
return connection.bind(bindReq);
}
use of org.apache.directory.api.ldap.model.message.BindRequest in project directory-ldap-api by apache.
the class MessageDecorator method getDecorator.
/**
* Gets the decorator associated with a given message
*
* @param codec The LdapApiService to use
* @param decoratedMessage The message to decorate
* @return The decorator instance
*/
public static MessageDecorator<? extends Message> getDecorator(LdapApiService codec, Message decoratedMessage) {
if (decoratedMessage instanceof MessageDecorator) {
return (MessageDecorator<?>) decoratedMessage;
}
MessageDecorator<?> decorator;
switch(decoratedMessage.getType()) {
case ABANDON_REQUEST:
decorator = new AbandonRequestDecorator(codec, (AbandonRequest) decoratedMessage);
break;
case ADD_REQUEST:
decorator = new AddRequestDecorator(codec, (AddRequest) decoratedMessage);
break;
case ADD_RESPONSE:
decorator = new AddResponseDecorator(codec, (AddResponse) decoratedMessage);
break;
case BIND_REQUEST:
decorator = new BindRequestDecorator(codec, (BindRequest) decoratedMessage);
break;
case BIND_RESPONSE:
decorator = new BindResponseDecorator(codec, (BindResponse) decoratedMessage);
break;
case COMPARE_REQUEST:
decorator = new CompareRequestDecorator(codec, (CompareRequest) decoratedMessage);
break;
case COMPARE_RESPONSE:
decorator = new CompareResponseDecorator(codec, (CompareResponse) decoratedMessage);
break;
case DEL_REQUEST:
decorator = new DeleteRequestDecorator(codec, (DeleteRequest) decoratedMessage);
break;
case DEL_RESPONSE:
decorator = new DeleteResponseDecorator(codec, (DeleteResponse) decoratedMessage);
break;
case EXTENDED_REQUEST:
decorator = codec.decorate((ExtendedRequest) decoratedMessage);
break;
case EXTENDED_RESPONSE:
decorator = codec.decorate((ExtendedResponse) decoratedMessage);
break;
case INTERMEDIATE_RESPONSE:
decorator = new IntermediateResponseDecorator(codec, (IntermediateResponse) decoratedMessage);
break;
case MODIFY_REQUEST:
decorator = new ModifyRequestDecorator(codec, (ModifyRequest) decoratedMessage);
break;
case MODIFY_RESPONSE:
decorator = new ModifyResponseDecorator(codec, (ModifyResponse) decoratedMessage);
break;
case MODIFYDN_REQUEST:
decorator = new ModifyDnRequestDecorator(codec, (ModifyDnRequest) decoratedMessage);
break;
case MODIFYDN_RESPONSE:
decorator = new ModifyDnResponseDecorator(codec, (ModifyDnResponse) decoratedMessage);
break;
case SEARCH_REQUEST:
decorator = new SearchRequestDecorator(codec, (SearchRequest) decoratedMessage);
break;
case SEARCH_RESULT_DONE:
decorator = new SearchResultDoneDecorator(codec, (SearchResultDone) decoratedMessage);
break;
case SEARCH_RESULT_ENTRY:
decorator = new SearchResultEntryDecorator(codec, (SearchResultEntry) decoratedMessage);
break;
case SEARCH_RESULT_REFERENCE:
decorator = new SearchResultReferenceDecorator(codec, (SearchResultReference) decoratedMessage);
break;
case UNBIND_REQUEST:
decorator = new UnbindRequestDecorator(codec, (UnbindRequest) decoratedMessage);
break;
default:
return null;
}
Map<String, Control> controls = decoratedMessage.getControls();
if (controls != null) {
for (Control control : controls.values()) {
decorator.addControl(control);
}
}
return decorator;
}
use of org.apache.directory.api.ldap.model.message.BindRequest in project directory-ldap-api by apache.
the class StoreName method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<BindRequestDecorator> container) throws DecoderException {
BindRequest bindRequestMessage = container.getMessage();
// Get the Value and store it in the BindRequest
TLV tlv = container.getCurrentTLV();
// We have to handle the special case of a 0 length name
if (tlv.getLength() == 0) {
bindRequestMessage.setName("");
} else {
byte[] nameBytes = tlv.getValue().getData();
String nameStr = Strings.utf8ToString(nameBytes);
bindRequestMessage.setName(nameStr);
}
if (IS_DEBUG) {
LOG.debug(" The Bind name is {}", bindRequestMessage.getName());
}
}
use of org.apache.directory.api.ldap.model.message.BindRequest in project directory-ldap-api by apache.
the class StoreSaslCredentials method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<BindRequestDecorator> container) throws DecoderException {
BindRequest bindRequestMessage = container.getMessage();
// Get the Value and store it in the BindRequest
TLV tlv = container.getCurrentTLV();
// credentials
if (tlv.getLength() == 0) {
bindRequestMessage.setCredentials(Strings.EMPTY_BYTES);
} else {
bindRequestMessage.setCredentials(tlv.getValue().getData());
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("The credentials are : {}", Strings.dumpBytes(bindRequestMessage.getCredentials()));
}
}
Aggregations