use of org.apache.directory.api.asn1.ber.tlv.BerValue 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.BerValue 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.BerValue in project directory-ldap-api by apache.
the class StoreMatchingRuleDnAttributes method action.
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
SearchRequestDecorator searchRequest = container.getMessage();
TLV tlv = container.getCurrentTLV();
// Store the value.
ExtensibleMatchFilter extensibleMatchFilter = (ExtensibleMatchFilter) searchRequest.getTerminalFilter();
// We get the value. If it's a 0, it's a FALSE. If it's
// a FF, it's a TRUE. Any other value should be an error,
// but we could relax this constraint. So if we have
// something
// which is not 0, it will be interpreted as TRUE, but we
// will generate a warning.
BerValue value = tlv.getValue();
try {
extensibleMatchFilter.setDnAttributes(BooleanDecoder.parse(value));
} catch (BooleanDecoderException bde) {
LOG.error(I18n.err(I18n.ERR_04110, Strings.dumpBytes(value.getData()), bde.getMessage()));
throw new DecoderException(bde.getMessage(), bde);
}
if (IS_DEBUG) {
LOG.debug("Dn Attributes : {}", Boolean.valueOf(extensibleMatchFilter.isDnAttributes()));
}
// unstack the filters if needed
searchRequest.unstackFilters(container);
}
use of org.apache.directory.api.asn1.ber.tlv.BerValue in project directory-ldap-api by apache.
the class StoreControlCriticality method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
TLV tlv = container.getCurrentTLV();
// Get the current control
MessageDecorator<? extends Message> message = container.getMessage();
Control control = message.getCurrentControl();
// Store the criticality
// We get the value. If it's a 0, it's a FALSE. If it's
// a FF, it's a TRUE. Any other value should be an error,
// but we could relax this constraint. So if we have
// something
// which is not 0, it will be interpreted as TRUE, but we
// will generate a warning.
BerValue value = tlv.getValue();
try {
control.setCritical(BooleanDecoder.parse(value));
} catch (BooleanDecoderException bde) {
LOG.error(I18n.err(I18n.ERR_04100_BAD_CONTROL_CRITICALITY, Strings.dumpBytes(value.getData()), bde.getMessage()));
// This will generate a PROTOCOL_ERROR
throw new DecoderException(bde.getMessage(), bde);
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("Control criticality : {}", control.isCritical());
}
}
use of org.apache.directory.api.asn1.ber.tlv.BerValue in project directory-ldap-api by apache.
the class StoreMessageId 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();
// The Length should not be null
if (tlv.getLength() == 0) {
LOG.error(I18n.err(I18n.ERR_04068));
// This will generate a PROTOCOL_ERROR
throw new DecoderException(I18n.err(I18n.ERR_04069));
}
BerValue value = tlv.getValue();
try {
int messageId = IntegerDecoder.parse(value, 0, Integer.MAX_VALUE);
container.setMessageId(messageId);
if (IS_DEBUG) {
LOG.debug("Ldap Message Id has been decoded : " + messageId);
}
} catch (IntegerDecoderException ide) {
LOG.error(I18n.err(I18n.ERR_04070, Strings.dumpBytes(value.getData()), ide.getLocalizedMessage()));
// This will generate a PROTOCOL_ERROR
throw new DecoderException(ide.getMessage(), ide);
}
}
Aggregations