use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreExtendedRequestName method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ExtendedRequestDecorator<?>> container) throws DecoderException {
ExtendedRequest req;
// Get the Value and store it in the ExtendedRequest
TLV tlv = container.getCurrentTLV();
// OID
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04095);
LOG.error(msg);
// This will generate a PROTOCOL_ERROR
throw new DecoderException(msg);
} else {
byte[] requestNameBytes = tlv.getValue().getData();
try {
String requestName = Strings.utf8ToString(requestNameBytes);
if (!Oid.isOid(requestName)) {
String msg = "The Request name is not a valid OID : " + Strings.utf8ToString(requestNameBytes) + " (" + Strings.dumpBytes(requestNameBytes) + ") is invalid";
LOG.error(msg);
// throw an exception, we will get a PROTOCOL_ERROR
throw new DecoderException(msg);
}
req = LdapApiServiceFactory.getSingleton().newExtendedRequest(requestName, null);
req.setMessageId(container.getMessageId());
container.setMessage(LdapApiServiceFactory.getSingleton().decorate(req));
} catch (DecoderException de) {
String msg = "The Request name is not a valid OID : " + Strings.utf8ToString(requestNameBytes) + " (" + Strings.dumpBytes(requestNameBytes) + ") is invalid";
LOG.error("{} : {}", msg, de.getMessage());
// Rethrow the exception, we will get a PROTOCOL_ERROR
throw de;
}
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("OID read : {}", req.getRequestName());
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class InitAttributeVals method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyRequestDecorator> container) {
TLV tlv = container.getCurrentTLV();
// If the length is null, we store an empty value
if (tlv.getLength() == 0) {
LOG.debug("No vals for this attribute");
}
// We can have an END transition
container.setGrammarEndAllowed(true);
LOG.debug("Some vals are to be decoded");
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreModifyRequestObjectName method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyRequestDecorator> container) throws DecoderException {
ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
ModifyRequest modifyRequest = modifyRequestDecorator.getDecorated();
TLV tlv = container.getCurrentTLV();
Dn object = Dn.EMPTY_DN;
// Store the value.
if (tlv.getLength() == 0) {
(modifyRequestDecorator.getDecorated()).setName(object);
} else {
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try {
object = new Dn(dnStr);
} catch (LdapInvalidDnException ine) {
String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
LOG.error("{} : {}", msg, ine.getMessage());
ModifyResponseImpl response = new ModifyResponseImpl(modifyRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
}
modifyRequest.setName(object);
}
if (IS_DEBUG) {
LOG.debug("Modification of Dn {}", modifyRequest.getName());
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreOperationType method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyRequestDecorator> container) throws DecoderException {
ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
TLV tlv = container.getCurrentTLV();
// Decode the operation type
int operation = 0;
try {
operation = IntegerDecoder.parse(tlv.getValue(), 0, 2);
} catch (IntegerDecoderException ide) {
String msg = I18n.err(I18n.ERR_04082, Strings.dumpBytes(tlv.getValue().getData()));
LOG.error(msg);
// This will generate a PROTOCOL_ERROR
throw new DecoderException(msg, ide);
}
// Store the current operation.
modifyRequestDecorator.setCurrentOperation(operation);
if (IS_DEBUG) {
switch(operation) {
case LdapCodecConstants.OPERATION_ADD:
LOG.debug("Modification operation : ADD");
break;
case LdapCodecConstants.OPERATION_DELETE:
LOG.debug("Modification operation : DELETE");
break;
case LdapCodecConstants.OPERATION_REPLACE:
LOG.debug("Modification operation : REPLACE");
break;
default:
LOG.debug("Modification operation : UNKNOWN");
}
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV 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());
}
}
Aggregations