1 package net.sf.provisioner.requests;
2
3 import javax.naming.NamingException;
4 import javax.naming.directory.DirContext;
5
6 import net.sf.provisioner.config.ConfigRequest;
7 import net.sf.provisioner.config.LDAPNetworkElement;
8 import net.sf.provisioner.responses.Response;
9
10 import org.jdom.Document;
11
12
13
14
15
16
17 public class LDAPDeleteRequest extends LDAPRequest {
18
19 public LDAPDeleteRequest(ConfigRequest request, Document opParameters) {
20 super(request,opParameters);
21 }
22
23 @Override
24 public Response sendRequest() throws Exception {
25 DirContext context = ((LDAPNetworkElement) this.ne).findRootContext();
26
27 try {
28 if (logger.isTraceEnabled()) {
29 logger.trace(
30 String.format(
31 "sending LDAP delete request for dn '%s'",
32 getDistinguishedName()
33 )
34 );
35 }
36 context.unbind(getDistinguishedName());
37
38 Response response = new Response();
39 response.result =
40 response.errorStr = "Deleted attribute " + getDistinguishedName();
41 response.retry = false;
42 response.successfull = true;
43 return response;
44
45 } catch (NamingException e) {
46 Response response = new Response();
47 response.result = "Failed to delete attribute.";
48
49 Throwable t = e.getRootCause();
50 if (t != null) {
51
52 response.errorStr = t.getMessage();
53 } else {
54
55 response.errorStr = e.getExplanation();
56 }
57
58 response.retry = false;
59 response.successfull = false;
60 return response;
61 } finally {
62 context.close();
63 }
64 }
65 }