use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreSearchRequestAttributeDesc method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
SearchRequestDecorator searchRequestDecorator = container.getMessage();
TLV tlv = container.getCurrentTLV();
String attributeDescription = null;
if (tlv.getLength() != 0) {
attributeDescription = Strings.utf8ToString(tlv.getValue().getData());
// If the attributeDescription is empty, we won't add it
if (!Strings.isEmpty(attributeDescription.trim())) {
searchRequestDecorator.getDecorated().addAttributes(attributeDescription);
}
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("Decoded Attribute Description : {}", attributeDescription);
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreSearchRequestScope method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
SearchRequest searchRequest = container.getMessage().getDecorated();
TLV tlv = container.getCurrentTLV();
// We have to check that this is a correct scope
BerValue value = tlv.getValue();
int scope = 0;
try {
scope = IntegerDecoder.parse(value, LdapCodecConstants.SCOPE_BASE_OBJECT, LdapCodecConstants.SCOPE_WHOLE_SUBTREE);
} catch (IntegerDecoderException ide) {
String msg = I18n.err(I18n.ERR_04101, value.toString());
LOG.error(msg);
throw new DecoderException(msg, ide);
}
searchRequest.setScope(SearchScope.getSearchScope(scope));
if (IS_DEBUG) {
switch(scope) {
case LdapCodecConstants.SCOPE_BASE_OBJECT:
LOG.debug("Searching within BASE_OBJECT scope ");
break;
case LdapCodecConstants.SCOPE_SINGLE_LEVEL:
LOG.debug("Searching within SINGLE_LEVEL scope ");
break;
case LdapCodecConstants.SCOPE_WHOLE_SUBTREE:
LOG.debug("Searching within WHOLE_SUBTREE scope ");
break;
default:
LOG.debug("Searching within UNKNOWN scope ");
}
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreResultCode method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
// The current TLV should be a integer
// We get it and store it in MessageId
TLV tlv = container.getCurrentTLV();
BerValue value = tlv.getValue();
ResultCodeEnum resultCode = ResultCodeEnum.SUCCESS;
try {
resultCode = ResultCodeEnum.getResultCode(IntegerDecoder.parse(value, 0, ResultCodeEnum.E_SYNC_REFRESH_REQUIRED.getResultCode()));
} catch (IntegerDecoderException ide) {
LOG.error(I18n.err(I18n.ERR_04018, Strings.dumpBytes(value.getData()), ide.getMessage()));
throw new DecoderException(ide.getMessage(), ide);
}
if (IS_DEBUG) {
LOG.debug("The result code is set to " + resultCode);
}
ResultResponse response = (ResultResponse) container.getMessage();
LdapResult ldapResult = response.getLdapResult();
ldapResult.setResultCode(resultCode);
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class AddAttributeValue method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<AddRequestDecorator> container) {
AddRequestDecorator addRequest = container.getMessage();
TLV tlv = container.getCurrentTLV();
// Store the value. It can't be null
Object value = null;
try {
if (tlv.getLength() == 0) {
addRequest.addAttributeValue("");
} else {
if (container.isBinary(addRequest.getCurrentAttributeType())) {
value = tlv.getValue().getData();
if (IS_DEBUG) {
LOG.debug("Adding value {}", Strings.dumpBytes((byte[]) value));
}
addRequest.addAttributeValue((byte[]) value);
} else {
value = Strings.utf8ToString(tlv.getValue().getData());
if (IS_DEBUG) {
LOG.debug("Adding value {}" + value);
}
addRequest.addAttributeValue((String) value);
}
}
} catch (LdapException le) {
// Just swallow the exception, it can't occur here
}
// We can have an END transition
container.setGrammarEndAllowed(true);
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class InitSaslBind method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<BindRequestDecorator> container) throws DecoderException {
BindRequest bindRequestMessage = container.getMessage();
TLV tlv = container.getCurrentTLV();
// We will check that the sasl is not null
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04079);
LOG.error(msg);
BindResponseImpl response = new BindResponseImpl(bindRequestMessage.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_CREDENTIALS, bindRequestMessage.getDn(), null);
}
bindRequestMessage.setSimple(false);
if (IS_DEBUG) {
LOG.debug("The SaslCredential has been created");
}
}
Aggregations