use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class InitAddResponse method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<AddResponseDecorator> container) throws DecoderException {
// Now, we can allocate the AddResponse Object
AddResponseDecorator addResponse = new AddResponseDecorator(container.getLdapCodecService(), new AddResponseImpl(container.getMessageId()));
container.setMessage(addResponse);
// We will check that the request is not null
TLV tlv = container.getCurrentTLV();
int expectedLength = tlv.getLength();
if (expectedLength == 0) {
String msg = I18n.err(I18n.ERR_04088);
LOG.error(msg);
throw new DecoderException(msg);
}
LOG.debug("Add Response");
}
use of org.apache.directory.api.asn1.ber.tlv.TLV 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.ber.tlv.TLV 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.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreSearchResultEntryObjectName method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<SearchResultEntryDecorator> container) throws DecoderException {
SearchResultEntryDecorator searchResultEntry = container.getMessage();
TLV tlv = container.getCurrentTLV();
Dn objectName = Dn.EMPTY_DN;
// Store the value.
if (tlv.getLength() == 0) {
searchResultEntry.setObjectName(objectName);
} else {
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try {
objectName = new Dn(dnStr);
} catch (LdapInvalidDnException ine) {
// This is for the client side. We will never decode LdapResult on the server
String msg = "The Dn " + Strings.dumpBytes(dnBytes) + "is invalid : " + ine.getMessage();
LOG.error("{} : {}", msg, ine.getMessage());
throw new DecoderException(msg, ine);
}
searchResultEntry.setObjectName(objectName);
}
if (IS_DEBUG) {
LOG.debug("Search Result Entry Dn found : {}", searchResultEntry.getObjectName());
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreReference method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<SearchResultReferenceDecorator> container) throws DecoderException {
SearchResultReference searchResultReference = container.getMessage();
// Get the Value and store it in the BindRequest
TLV tlv = container.getCurrentTLV();
// Get the referral, or create it if not existing
Referral referral = searchResultReference.getReferral();
if (referral == null) {
referral = new ReferralImpl();
searchResultReference.setReferral(referral);
}
// We have to handle the special case of a 0 length list of referrals
LdapUrl url = LdapUrl.EMPTY_URL;
if (tlv.getLength() == 0) {
referral.addLdapUrl("");
} else {
String urlStr = Strings.utf8ToString(tlv.getValue().getData());
try {
url = new LdapUrl(urlStr);
referral.addLdapUrl(urlStr);
} catch (LdapURLEncodingException luee) {
LOG.error(I18n.err(I18n.ERR_04021, urlStr, luee.getMessage()));
throw new DecoderException(I18n.err(I18n.ERR_04016, luee.getMessage()), luee);
}
}
if (IS_DEBUG) {
LOG.debug("Search reference URL found : {}", url);
}
// We can have an END transition
container.setGrammarEndAllowed(true);
}
Aggregations