use of org.apache.directory.api.ldap.model.message.DeleteRequest in project directory-ldap-api by apache.
the class QuirkySchemaTest method createFakeConnection.
private LdapConnection createFakeConnection(final String schemaFileName) {
return new LdapConnection() {
@Override
public void unBind() throws LdapException {
}
@Override
public void setTimeOut(long timeOut) {
}
@Override
public void setSchemaManager(SchemaManager schemaManager) {
}
@Override
public void setBinaryAttributeDetector(BinaryAttributeDetector binaryAttributeDetecter) {
}
@Override
public SearchCursor search(SearchRequest searchRequest) throws LdapException {
return null;
}
@Override
public EntryCursor search(String baseDn, String filter, SearchScope scope, String... attributes) throws LdapException {
return null;
}
@Override
public EntryCursor search(Dn baseDn, String filter, SearchScope scope, String... attributes) throws LdapException {
return null;
}
@Override
public void rename(Dn entryDn, Rdn newRdn, boolean deleteOldRdn) throws LdapException {
}
@Override
public void rename(String entryDn, String newRdn, boolean deleteOldRdn) throws LdapException {
}
@Override
public void rename(Dn entryDn, Rdn newRdn) throws LdapException {
}
@Override
public void rename(String entryDn, String newRdn) throws LdapException {
}
@Override
public void moveAndRename(String entryDn, String newDn, boolean deleteOldRdn) throws LdapException {
}
@Override
public void moveAndRename(Dn entryDn, Dn newDn, boolean deleteOldRdn) throws LdapException {
}
@Override
public void moveAndRename(String entryDn, String newDn) throws LdapException {
}
@Override
public void moveAndRename(Dn entryDn, Dn newDn) throws LdapException {
}
@Override
public void move(Dn entryDn, Dn newSuperiorDn) throws LdapException {
}
@Override
public void move(String entryDn, String newSuperiorDn) throws LdapException {
}
@Override
public ModifyDnResponse modifyDn(ModifyDnRequest modDnRequest) throws LdapException {
return null;
}
@Override
public ModifyResponse modify(ModifyRequest modRequest) throws LdapException {
return null;
}
@Override
public void modify(Entry entry, ModificationOperation modOp) throws LdapException {
}
@Override
public void modify(String dn, Modification... modifications) throws LdapException {
}
@Override
public void modify(Dn dn, Modification... modifications) throws LdapException {
}
@Override
public Entry lookup(String dn, Control[] controls, String... attributes) throws LdapException {
return lookup(new Dn(dn));
}
@Override
public Entry lookup(String dn, String... attributes) throws LdapException {
return lookup(new Dn(dn));
}
@Override
public Entry lookup(Dn dn, Control[] controls, String... attributes) throws LdapException {
return lookup(dn);
}
@Override
public Entry lookup(Dn dn, String... attributes) throws LdapException {
return lookup(dn);
}
@Override
public Entry lookup(String dn) throws LdapException {
return lookup(new Dn(dn));
}
@Override
public Entry lookup(Dn dn) throws LdapException {
if (dn.isRootDse()) {
Entry entry = new DefaultEntry(dn);
entry.add(SchemaConstants.SUBSCHEMA_SUBENTRY_AT, SCHEMA_DN);
return entry;
} else if (dn.toString().equals(SCHEMA_DN)) {
Entry entry = loadSchemaEntry(schemaFileName);
return entry;
} else {
throw new UnsupportedOperationException("Unexpected DN " + dn);
}
}
@Override
public void loadSchemaRelaxed() throws LdapException {
}
@Override
public void loadSchema() throws LdapException {
}
@Override
public boolean isRequestCompleted(int messageId) {
return true;
}
@Override
public boolean isControlSupported(String controlOID) throws LdapException {
return true;
}
@Override
public boolean isConnected() {
return true;
}
@Override
public boolean isAuthenticated() {
return false;
}
@Override
public List<String> getSupportedControls() throws LdapException {
return null;
}
@Override
public SchemaManager getSchemaManager() {
return null;
}
@Override
public Entry getRootDse(String... attributes) throws LdapException {
return lookup(Dn.ROOT_DSE);
}
@Override
public Entry getRootDse() throws LdapException {
return lookup(Dn.ROOT_DSE);
}
@Override
public LdapApiService getCodecService() {
return null;
}
@Override
public BinaryAttributeDetector getBinaryAttributeDetector() {
return null;
}
@Override
public ExtendedResponse extended(ExtendedRequest extendedRequest) throws LdapException {
return null;
}
@Override
public ExtendedResponse extended(Oid oid, byte[] value) throws LdapException {
return null;
}
@Override
public ExtendedResponse extended(Oid oid) throws LdapException {
return null;
}
@Override
public ExtendedResponse extended(String oid, byte[] value) throws LdapException {
return null;
}
@Override
public ExtendedResponse extended(String oid) throws LdapException {
return null;
}
@Override
public boolean exists(Dn dn) throws LdapException {
return false;
}
@Override
public boolean exists(String dn) throws LdapException {
return false;
}
@Override
public boolean doesFutureExistFor(int messageId) {
return false;
}
@Override
public DeleteResponse delete(DeleteRequest deleteRequest) throws LdapException {
return null;
}
@Override
public void delete(Dn dn) throws LdapException {
}
@Override
public void delete(String dn) throws LdapException {
}
@Override
public boolean connect() throws LdapException {
return true;
}
@Override
public CompareResponse compare(CompareRequest compareRequest) throws LdapException {
return null;
}
@Override
public boolean compare(Dn dn, String attributeName, byte[] value) throws LdapException {
return false;
}
@Override
public boolean compare(Dn dn, String attributeName, String value) throws LdapException {
return false;
}
@Override
public boolean compare(String dn, String attributeName, byte[] value) throws LdapException {
return false;
}
@Override
public boolean compare(String dn, String attributeName, String value) throws LdapException {
return false;
}
@Override
public void close() throws IOException {
}
@Override
public BindResponse bind(BindRequest bindRequest) throws LdapException {
return null;
}
@Override
public void bind(Dn name, String credentials) throws LdapException {
}
@Override
public void bind(Dn name) throws LdapException {
}
@Override
public void bind(String name, String credentials) throws LdapException {
}
@Override
public void bind(String name) throws LdapException {
}
@Override
public void bind() throws LdapException {
}
@Override
public void anonymousBind() throws LdapException {
}
@Override
public AddResponse add(AddRequest addRequest) throws LdapException {
return null;
}
@Override
public void add(Entry entry) throws LdapException {
}
@Override
public void abandon(AbandonRequest abandonRequest) {
}
@Override
public void abandon(int messageId) {
}
@Override
public boolean compare(String dn, String attributeName, Value value) throws LdapException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean compare(Dn dn, String attributeName, Value value) throws LdapException {
// TODO Auto-generated method stub
return false;
}
@Override
public BindResponse bind(SaslRequest saslRequest) throws LdapException {
// TODO Auto-generated method stub
return null;
}
};
}
use of org.apache.directory.api.ldap.model.message.DeleteRequest 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.message.DeleteRequest in project ldapchai by ldapchai.
the class ApacheLdapProviderImpl method deleteEntry.
public void deleteEntry(final String entryDN) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
getInputValidator().deleteEntry(entryDN);
try {
final DeleteRequest deleteRequest = new DeleteRequestImpl();
deleteRequest.setName(new Dn(entryDN));
final DeleteResponse response = connection.delete(deleteRequest);
processResponse(response);
} catch (LdapException e) {
throw ChaiOperationException.forErrorMessage(e.getMessage());
}
}
use of org.apache.directory.api.ldap.model.message.DeleteRequest in project directory-ldap-api by apache.
the class MessageDecorator method getDecorator.
/**
* Gets the decorator associated with a given message
*
* @param codec The LdapApiService to use
* @param decoratedMessage The message to decorate
* @return The decorator instance
*/
public static MessageDecorator<? extends Message> getDecorator(LdapApiService codec, Message decoratedMessage) {
if (decoratedMessage instanceof MessageDecorator) {
return (MessageDecorator<?>) decoratedMessage;
}
MessageDecorator<?> decorator;
switch(decoratedMessage.getType()) {
case ABANDON_REQUEST:
decorator = new AbandonRequestDecorator(codec, (AbandonRequest) decoratedMessage);
break;
case ADD_REQUEST:
decorator = new AddRequestDecorator(codec, (AddRequest) decoratedMessage);
break;
case ADD_RESPONSE:
decorator = new AddResponseDecorator(codec, (AddResponse) decoratedMessage);
break;
case BIND_REQUEST:
decorator = new BindRequestDecorator(codec, (BindRequest) decoratedMessage);
break;
case BIND_RESPONSE:
decorator = new BindResponseDecorator(codec, (BindResponse) decoratedMessage);
break;
case COMPARE_REQUEST:
decorator = new CompareRequestDecorator(codec, (CompareRequest) decoratedMessage);
break;
case COMPARE_RESPONSE:
decorator = new CompareResponseDecorator(codec, (CompareResponse) decoratedMessage);
break;
case DEL_REQUEST:
decorator = new DeleteRequestDecorator(codec, (DeleteRequest) decoratedMessage);
break;
case DEL_RESPONSE:
decorator = new DeleteResponseDecorator(codec, (DeleteResponse) decoratedMessage);
break;
case EXTENDED_REQUEST:
decorator = codec.decorate((ExtendedRequest) decoratedMessage);
break;
case EXTENDED_RESPONSE:
decorator = codec.decorate((ExtendedResponse) decoratedMessage);
break;
case INTERMEDIATE_RESPONSE:
decorator = new IntermediateResponseDecorator(codec, (IntermediateResponse) decoratedMessage);
break;
case MODIFY_REQUEST:
decorator = new ModifyRequestDecorator(codec, (ModifyRequest) decoratedMessage);
break;
case MODIFY_RESPONSE:
decorator = new ModifyResponseDecorator(codec, (ModifyResponse) decoratedMessage);
break;
case MODIFYDN_REQUEST:
decorator = new ModifyDnRequestDecorator(codec, (ModifyDnRequest) decoratedMessage);
break;
case MODIFYDN_RESPONSE:
decorator = new ModifyDnResponseDecorator(codec, (ModifyDnResponse) decoratedMessage);
break;
case SEARCH_REQUEST:
decorator = new SearchRequestDecorator(codec, (SearchRequest) decoratedMessage);
break;
case SEARCH_RESULT_DONE:
decorator = new SearchResultDoneDecorator(codec, (SearchResultDone) decoratedMessage);
break;
case SEARCH_RESULT_ENTRY:
decorator = new SearchResultEntryDecorator(codec, (SearchResultEntry) decoratedMessage);
break;
case SEARCH_RESULT_REFERENCE:
decorator = new SearchResultReferenceDecorator(codec, (SearchResultReference) decoratedMessage);
break;
case UNBIND_REQUEST:
decorator = new UnbindRequestDecorator(codec, (UnbindRequest) decoratedMessage);
break;
default:
return null;
}
Map<String, Control> controls = decoratedMessage.getControls();
if (controls != null) {
for (Control control : controls.values()) {
decorator.addControl(control);
}
}
return decorator;
}
use of org.apache.directory.api.ldap.model.message.DeleteRequest in project directory-ldap-api by apache.
the class LdapNetworkConnection method deleteTree.
/**
* deletes the entry with the given Dn, and all its children
*
* @param dn the target entry's Dn as a String
* @throws LdapException If the Dn is not valid or if the deletion failed
*/
public void deleteTree(String dn) throws LdapException {
try {
String treeDeleteOid = "1.2.840.113556.1.4.805";
Dn newDn = new Dn(dn);
if (isControlSupported(treeDeleteOid)) {
DeleteRequest deleteRequest = new DeleteRequestImpl();
deleteRequest.setName(newDn);
deleteRequest.addControl(new OpaqueControl(treeDeleteOid));
DeleteResponse deleteResponse = delete(deleteRequest);
processResponse(deleteResponse);
} else {
String msg = "The subtreeDelete control (1.2.840.113556.1.4.805) is not supported by the server\n" + " The deletion has been aborted";
LOG.error(msg);
throw new LdapException(msg);
}
} catch (LdapInvalidDnException e) {
LOG.error(e.getMessage(), e);
throw new LdapException(e.getMessage(), e);
}
}
Aggregations