View Javadoc

1   /*
2    *   Copyright 2004 The Apache Software Foundation
3    *
4    *   Licensed under the Apache License, Version 2.0 (the "License");
5    *   you may not use this file except in compliance with the License.
6    *   You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *   Unless required by applicable law or agreed to in writing, software
11   *   distributed under the License is distributed on an "AS IS" BASIS,
12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *   See the License for the specific language governing permissions and
14   *   limitations under the License.
15   *
16   */
17  package org.apache.ldap.server.jndi;
18  
19  
20  import org.apache.ldap.common.NotImplementedException;
21  import org.apache.ldap.server.PartitionNexus;
22  import org.apache.ldap.server.authn.LdapPrincipal;
23  
24  import javax.naming.Name;
25  import javax.naming.NamingException;
26  import javax.naming.ldap.Control;
27  import javax.naming.ldap.ExtendedRequest;
28  import javax.naming.ldap.ExtendedResponse;
29  import javax.naming.ldap.LdapContext;
30  import java.util.Hashtable;
31  
32  
33  /***
34   * An Eve implementation of a JNDI LdapContext.
35   *
36   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
37   * @version $Rev: 159259 $
38   */
39  public class ServerLdapContext extends ServerDirContext implements LdapContext
40  {
41      private static final Control[] EMPTY_CONTROLS = new Control[0];
42      private Control[] requestControls = EMPTY_CONTROLS;
43      private Control[] responseControls = EMPTY_CONTROLS;
44      private Control[] connectControls = EMPTY_CONTROLS;
45  
46  
47      /***
48       * Creates an instance of an ServerLdapContext.
49       *
50       * @param nexusProxy the proxy to a partition nexus
51       * @param env the JNDI environment parameters
52       * @throws NamingException the context cannot be created
53       */
54      public ServerLdapContext( PartitionNexus nexusProxy, Hashtable env ) throws NamingException
55      {
56          super( nexusProxy, env );
57      }
58  
59  
60      /***
61       * Creates a new ServerDirContext with a distinguished name which is used to
62       * set the PROVIDER_URL to the distinguished name for this context.
63       *
64       * @param principal the directory user principal that is propagated
65       * @param nexusProxy the intercepting proxy to the nexus
66       * @param env the environment properties used by this context
67       * @param dn the distinguished name of this context
68       */
69      ServerLdapContext( LdapPrincipal principal, PartitionNexus nexusProxy, Hashtable env, Name dn )
70      {
71          super( principal, nexusProxy, env, dn );
72      }
73  
74  
75      /***
76       * @see javax.naming.ldap.LdapContext#extendedOperation(
77       * javax.naming.ldap.ExtendedRequest)
78       */
79      public ExtendedResponse extendedOperation( ExtendedRequest request )
80      {
81          throw new NotImplementedException();
82      }
83  
84  
85      /***
86       * @see javax.naming.ldap.LdapContext#newInstance(
87       * javax.naming.ldap.Control[])
88       */
89      public LdapContext newInstance( Control[] requestControls )
90          throws NamingException
91      {
92          ServerLdapContext ctx = new ServerLdapContext( getPrincipal(), getNexusProxy(),
93                  getEnvironment(), getDn() );
94          ctx.setRequestControls( requestControls );
95          return ctx;
96      }
97  
98  
99      /***
100      * @see javax.naming.ldap.LdapContext#reconnect(javax.naming.ldap.Control[])
101      */
102     public void reconnect( Control[] connCtls ) throws NamingException
103     {
104         this.connectControls = connCtls;
105     }
106 
107 
108     /***
109      * @see javax.naming.ldap.LdapContext#getConnectControls()
110      */
111     public Control[] getConnectControls() throws NamingException
112     {
113         return this.connectControls;
114     }
115 
116 
117     /***
118      * @see javax.naming.ldap.LdapContext#setRequestControls(
119      * javax.naming.ldap.Control[])
120      */
121     public void setRequestControls( Control[] requestControls )
122         throws NamingException
123     {
124         this.requestControls = requestControls;
125     }
126 
127 
128     /***
129      * @see javax.naming.ldap.LdapContext#getRequestControls()
130      */
131     public Control[] getRequestControls() throws NamingException
132     {
133         return requestControls;
134     }
135 
136 
137     /***
138      * @see javax.naming.ldap.LdapContext#getResponseControls()
139      */
140     public Control[] getResponseControls() throws NamingException
141     {
142         return responseControls;
143     }
144 }