use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreModifyDnRequestDeleteOldRdn method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyDnRequestDecorator> container) throws DecoderException {
ModifyDnRequest modifyDnRequest = container.getMessage();
TLV tlv = container.getCurrentTLV();
// 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 {
modifyDnRequest.setDeleteOldRdn(BooleanDecoder.parse(value));
} catch (BooleanDecoderException bde) {
LOG.error(I18n.err(I18n.ERR_04091, 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) {
if (modifyDnRequest.getDeleteOldRdn()) {
LOG.debug(" Old Rdn attributes will be deleted");
} else {
LOG.debug(" Old Rdn attributes will be retained");
}
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreModifyDnRequestEntryName method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyDnRequestDecorator> container) throws DecoderException {
ModifyDnRequest modifyDnRequest = container.getMessage();
// Get the Value and store it in the modifyDNRequest
TLV tlv = container.getCurrentTLV();
// We have to handle the special case of a 0 length matched
// Dn
Dn entry;
if (tlv.getLength() == 0) {
// This will generate a PROTOCOL_ERROR
throw new DecoderException(I18n.err(I18n.ERR_04089));
} else {
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try {
entry = new Dn(dnStr);
} catch (LdapInvalidDnException ine) {
String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
LOG.error("{} : {}", msg, ine.getMessage());
ModifyDnResponseImpl response = new ModifyDnResponseImpl(modifyDnRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
}
modifyDnRequest.setName(entry);
}
if (IS_DEBUG) {
LOG.debug("Modifying Dn {}", entry);
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreModifyDnRequestNewRdn method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyDnRequestDecorator> container) throws DecoderException {
ModifyDnRequest modifyDnRequest = container.getMessage();
// Get the Value and store it in the modifyDNRequest
TLV tlv = container.getCurrentTLV();
// We have to handle the special case of a 0 length matched
// newDN
Rdn newRdn;
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04090);
LOG.error(msg);
ModifyDnResponseImpl response = new ModifyDnResponseImpl(modifyDnRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, modifyDnRequest.getName(), null);
} else {
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try {
Dn dn = new Dn(dnStr);
newRdn = dn.getRdn(dn.size() - 1);
} catch (LdapInvalidDnException ine) {
String msg = "Invalid new Rdn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
LOG.error("{} : {}", msg, ine.getMessage());
ModifyDnResponseImpl response = new ModifyDnResponseImpl(modifyDnRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, modifyDnRequest.getName(), ine);
}
modifyDnRequest.setNewRdn(newRdn);
}
if (IS_DEBUG) {
LOG.debug("Modifying with new Rdn {}", newRdn);
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class InitSearchRequest method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<SearchRequestDecorator> container) {
// Now, we can allocate the SearchRequest Object
TLV tlv = container.getCurrentTLV();
SearchRequest internalSearchRequest = new SearchRequestImpl();
internalSearchRequest.setMessageId(container.getMessageId());
SearchRequestDecorator searchRequest = new SearchRequestDecorator(container.getLdapCodecService(), internalSearchRequest);
searchRequest.setTlvId(tlv.getId());
container.setMessage(searchRequest);
LOG.debug("Search Request");
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreSearchRequestBaseObject method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
SearchRequestDecorator searchRequestDecorator = container.getMessage();
SearchRequest searchRequest = searchRequestDecorator.getDecorated();
TLV tlv = container.getCurrentTLV();
// We have to check that this is a correct Dn
Dn baseObject;
// root.
if (tlv.getLength() != 0) {
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try {
baseObject = new Dn(dnStr);
} catch (LdapInvalidDnException ine) {
String msg = "Invalid root Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
LOG.error("{} : {}", msg, ine.getMessage());
SearchResultDoneImpl response = new SearchResultDoneImpl(searchRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
}
} else {
baseObject = Dn.EMPTY_DN;
}
searchRequest.setBase(baseObject);
LOG.debug("Searching with root Dn : {}", baseObject);
}
Aggregations