use of org.apache.directory.api.asn1.util.Oid in project directory-ldap-api by apache.
the class BerValue method encode.
/**
* Encode an OID value
*
* @param buffer The PDU in which the value will be put
* @param oid The OID to be encoded
* @throws EncoderException if the PDU in which the value should be encoded is
* two small
*/
public static void encode(ByteBuffer buffer, Oid oid) throws EncoderException {
if (buffer == null) {
throw new EncoderException(I18n.err(I18n.ERR_01300_CANNOT_PUT_PDU_IN_NULL_BUFFER));
}
try {
buffer.put(UniversalTag.OCTET_STRING.getValue());
buffer.put(TLV.getBytes(oid.getEncodedLength()));
if (oid.getEncodedLength() != 0) {
oid.writeBytesTo(buffer);
}
} catch (BufferOverflowException boe) {
throw new EncoderException(I18n.err(I18n.ERR_01301_PDU_BUFFER_SIZE_TOO_SMALL), boe);
}
}
use of org.apache.directory.api.asn1.util.Oid in project directory-ldap-api by apache.
the class AddControl method action.
/**
* {@inheritDoc}
*/
public void action(ControlsContainer container) throws DecoderException {
TLV tlv = container.getCurrentTLV();
// We have to handle the special case of a 0 length OID
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04097_NULL_CONTROL_OID);
LOG.error(msg);
// This will generate a PROTOCOL_ERROR
throw new DecoderException(msg);
}
byte[] value = tlv.getValue().getData();
String oidValue = Strings.asciiBytesToString(value);
// The OID is encoded as a String, not an Object Id
if (!Oid.isOid(oidValue)) {
String msg = I18n.err(I18n.ERR_04098_INVALID_CONTROL_OID, oidValue);
LOG.error(msg);
// This will generate a PROTOCOL_ERROR
throw new DecoderException(msg);
}
CodecControl<?> control = container.getLdapCodecService().newControl(oidValue);
container.setCurrentControl(control);
container.addControl(control);
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("Control OID : {}", oidValue);
}
}
use of org.apache.directory.api.asn1.util.Oid in project directory-ldap-api by apache.
the class StoreExtendedResponseName method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ExtendedResponseDecorator<?>> container) throws DecoderException {
// We can allocate the ExtendedResponse Object
ExtendedResponse extendedResponse;
// Get the Value and store it in the ExtendedResponse
TLV tlv = container.getCurrentTLV();
// OID
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04017);
LOG.error(msg);
throw new DecoderException(msg);
} else {
String responseName = Oid.fromString(Strings.asciiBytesToString(tlv.getValue().getData())).toString();
extendedResponse = LdapApiServiceFactory.getSingleton().newExtendedResponse(responseName, container.getMessageId(), null);
((ExtendedResponseDecorator<?>) extendedResponse).setLdapResult((LdapResultDecorator) (container.getMessage().getLdapResult()));
container.setMessage(LdapApiServiceFactory.getSingleton().decorate(extendedResponse));
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("OID read : {}", extendedResponse.getResponseName());
}
}
use of org.apache.directory.api.asn1.util.Oid in project directory-ldap-api by apache.
the class StoreIntermediateResponseName method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<IntermediateResponseDecorator<?>> container) throws DecoderException {
// We can get the IntermediateResponse Object
IntermediateResponse intermediateResponse = container.getMessage();
// Get the Value and store it in the IntermediateResponse
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[] responseNameBytes = tlv.getValue().getData();
String oidStr = Strings.utf8ToString(responseNameBytes);
if (Oid.isOid(oidStr)) {
Oid.isOid(oidStr);
intermediateResponse.setResponseName(oidStr);
} else {
String msg = "The Intermediate Response name is not a valid OID : " + Strings.utf8ToString(responseNameBytes) + " (" + Strings.dumpBytes(responseNameBytes) + ") is invalid";
LOG.error("{} : {}", msg, oidStr);
// Rethrow the exception, we will get a PROTOCOL_ERROR
throw new DecoderException(msg);
}
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("OID read : {}", intermediateResponse.getResponseName());
}
}
use of org.apache.directory.api.asn1.util.Oid 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());
}
}
Aggregations