use of org.apache.directory.api.ldap.model.name.Dn 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);
}
use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.
the class InitDelRequest method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<DeleteRequestDecorator> container) throws DecoderException {
// Create the DeleteRequest LdapMessage instance and store it in the container
DeleteRequest internaldelRequest = new DeleteRequestImpl();
internaldelRequest.setMessageId(container.getMessageId());
DeleteRequestDecorator delRequest = new DeleteRequestDecorator(container.getLdapCodecService(), internaldelRequest);
container.setMessage(delRequest);
// And store the Dn into it
// Get the Value and store it in the DelRequest
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_04073));
} else {
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try {
entry = new Dn(dnStr);
} catch (LdapInvalidDnException ine) {
String msg = I18n.err(I18n.ERR_04074, dnStr, Strings.dumpBytes(dnBytes), ine.getLocalizedMessage());
LOG.error(msg);
DeleteResponseImpl response = new DeleteResponseImpl(delRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
}
delRequest.setName(entry);
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("Deleting Dn {}", entry);
}
}
use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.
the class DnComparator method compare.
/**
* {@inheritDoc}
*/
@Override
public int compare(Object obj0, Object obj1) {
if ((obj0 instanceof String) && (obj1 instanceof String)) {
return compare((String) obj0, (String) obj1);
}
Dn dn0 = null;
Dn dn1 = null;
try {
dn0 = getDn(obj0);
dn1 = getDn(obj1);
} catch (LdapException e) {
// -- what do we do here ?
return -1;
}
int dn0Size = dn0.getRdns().size();
int dn1Size = dn1.getRdns().size();
// when both DNs are equal checking isAncestorOf() returns true
if (dn0.equals(dn1)) {
return 0;
} else if (dn0Size > dn1Size) {
return -1;
} else if (dn1Size > dn0Size) {
return 1;
}
for (int i = dn0Size - 1; i >= 0; i--) {
int comp = dn0.getRdn(i).compareTo(dn1.getRdn(i));
if (comp != 0) {
return comp;
}
}
return 0;
}
use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.
the class ParsedDnComparator method getDn.
private Dn getDn(Object obj) throws LdapInvalidDnException {
Dn dn;
if (obj instanceof Dn) {
dn = (Dn) obj;
dn = dn.isSchemaAware() ? dn : new Dn(schemaManager, dn);
} else if (obj instanceof String) {
dn = new Dn(schemaManager, (String) obj);
} else {
throw new IllegalStateException(I18n.err(I18n.ERR_13720_CANNOT_HANDLE_DN_COMPARISONS, obj == null ? null : obj.getClass()));
}
return dn;
}
use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.
the class TriggerSpecificationParserTest method testMultipleSPCalls.
@Test
public void testMultipleSPCalls() throws Exception {
TriggerSpecification triggerSpecification = null;
String spec = "AFTER Delete " + "CALL \"BackupUtilities.backupDeletedEntry\" ($ldapContext \"ou=Backup,ou=System\", $name, $deletedEntry); " + "CALL \"BackupUtilities.recreateDeletedEntry\" ($name, $deletedEntry);";
triggerSpecification = parser.parse(spec);
assertNotNull(triggerSpecification);
assertEquals(triggerSpecification.getActionTime(), ActionTime.AFTER);
assertEquals(triggerSpecification.getLdapOperation(), LdapOperation.DELETE);
List<SPSpec> spSpecs = triggerSpecification.getSPSpecs();
assertTrue(spSpecs != null);
assertTrue(spSpecs.size() == 2);
SPSpec firstSpec = spSpecs.get(0);
assertEquals(firstSpec.getName(), "BackupUtilities.backupDeletedEntry");
assertEquals(firstSpec.getOptions().size(), 0);
assertEquals(firstSpec.getParameters().size(), 3);
assertTrue(firstSpec.getParameters().contains(StoredProcedureParameter.Delete_NAME.instance()));
assertTrue(firstSpec.getParameters().contains(StoredProcedureParameter.Delete_DELETED_ENTRY.instance()));
assertTrue(firstSpec.getParameters().contains(StoredProcedureParameter.Generic_LDAP_CONTEXT.instance(new Dn("ou=Backup,ou=System"))));
SPSpec secondSpec = spSpecs.get(1);
assertEquals(secondSpec.getName(), "BackupUtilities.recreateDeletedEntry");
assertEquals(secondSpec.getOptions().size(), 0);
assertEquals(secondSpec.getParameters().size(), 2);
assertTrue(secondSpec.getParameters().contains(StoredProcedureParameter.Delete_NAME.instance()));
assertTrue(secondSpec.getParameters().contains(StoredProcedureParameter.Delete_DELETED_ENTRY.instance()));
}
Aggregations