1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.jndi;
18
19
20 import java.util.Hashtable;
21
22 import javax.naming.Name;
23 import javax.naming.NamingException;
24 import javax.naming.ldap.Control;
25 import javax.naming.ldap.ExtendedRequest;
26 import javax.naming.ldap.ExtendedResponse;
27 import javax.naming.ldap.LdapContext;
28
29 import org.apache.ldap.common.NotImplementedException;
30 import org.apache.ldap.server.DirectoryService;
31 import org.apache.ldap.server.authn.LdapPrincipal;
32 import org.apache.ldap.server.partition.DirectoryPartitionNexus;
33
34
35 /***
36 * An implementation of a JNDI LdapContext.
37 *
38 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
39 * @version $Rev: 307234 $
40 */
41 public class ServerLdapContext extends ServerDirContext implements LdapContext
42 {
43 private static final Control[] EMPTY_CONTROLS = new Control[0];
44 private Control[] requestControls = EMPTY_CONTROLS;
45 private Control[] responseControls = EMPTY_CONTROLS;
46 private Control[] connectControls = EMPTY_CONTROLS;
47
48
49 /***
50 * Creates an instance of an ServerLdapContext.
51 *
52 * @param service the parent service that manages this context
53 * @param env the JNDI environment parameters
54 * @throws NamingException the context cannot be created
55 */
56 public ServerLdapContext( DirectoryService service, Hashtable env ) throws NamingException
57 {
58 super( service, env );
59 }
60
61
62 /***
63 * Creates a new ServerDirContext with a distinguished name which is used to
64 * set the PROVIDER_URL to the distinguished name for this context.
65 *
66 * @param principal the directory user principal that is propagated
67 * @param nexusProxy the intercepting proxy to the nexus
68 * @param env the environment properties used by this context
69 * @param dn the distinguished name of this context
70 */
71 ServerLdapContext( LdapPrincipal principal, DirectoryPartitionNexus nexusProxy, Hashtable env, Name dn )
72 {
73 super( principal, nexusProxy, env, dn );
74 }
75
76
77 /***
78 * @see javax.naming.ldap.LdapContext#extendedOperation(
79 * javax.naming.ldap.ExtendedRequest)
80 */
81 public ExtendedResponse extendedOperation( ExtendedRequest request )
82 {
83 throw new NotImplementedException();
84 }
85
86
87 /***
88 * @see javax.naming.ldap.LdapContext#newInstance(
89 * javax.naming.ldap.Control[])
90 */
91 public LdapContext newInstance( Control[] requestControls )
92 throws NamingException
93 {
94 ServerLdapContext ctx = new ServerLdapContext( getPrincipal(), getNexusProxy(),
95 getEnvironment(), getDn() );
96 ctx.setRequestControls( requestControls );
97 return ctx;
98 }
99
100
101 /***
102 * @see javax.naming.ldap.LdapContext#reconnect(javax.naming.ldap.Control[])
103 */
104 public void reconnect( Control[] connCtls ) throws NamingException
105 {
106 this.connectControls = connCtls;
107 }
108
109
110 /***
111 * @see javax.naming.ldap.LdapContext#getConnectControls()
112 */
113 public Control[] getConnectControls() throws NamingException
114 {
115 return this.connectControls;
116 }
117
118
119 /***
120 * @see javax.naming.ldap.LdapContext#setRequestControls(
121 * javax.naming.ldap.Control[])
122 */
123 public void setRequestControls( Control[] requestControls )
124 throws NamingException
125 {
126 this.requestControls = requestControls;
127 }
128
129
130 /***
131 * @see javax.naming.ldap.LdapContext#getRequestControls()
132 */
133 public Control[] getRequestControls() throws NamingException
134 {
135 return requestControls;
136 }
137
138
139 /***
140 * @see javax.naming.ldap.LdapContext#getResponseControls()
141 */
142 public Control[] getResponseControls() throws NamingException
143 {
144 return responseControls;
145 }
146
147
148
149
150
151
152
153 /***
154 * Explicitly exposes an LDAP compare operation which JNDI does not
155 * directly provide. All normalization and schema checking etcetera
156 * is handled by this call.
157 *
158 * @param name the name of the entri
159 * @param oid the name or object identifier for the attribute to compare
160 * @param value the value to compare the attribute to
161 * @return true if the entry has the value for the attribute, false otherwise
162 * @throws NamingException if the backing store cannot be accessed, or
163 * permission is not allowed for this operation or the oid is not recognized,
164 * or the attribute is not present in the entry ... you get the picture.
165 */
166 public boolean compare( Name name, String oid, Object value ) throws NamingException
167 {
168 return super.getNexusProxy().compare( name, oid, value );
169 }
170 }