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 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.authn.LdapPrincipal;
31  import org.apache.ldap.server.partition.ContextPartitionNexus;
32  
33  
34  /***
35   * An implementation of a JNDI LdapContext.
36   *
37   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38   * @version $Rev: 264732 $
39   */
40  public class ServerLdapContext extends ServerDirContext implements LdapContext
41  {
42      private static final Control[] EMPTY_CONTROLS = new Control[0];
43      private Control[] requestControls = EMPTY_CONTROLS;
44      private Control[] responseControls = EMPTY_CONTROLS;
45      private Control[] connectControls = EMPTY_CONTROLS;
46  
47  
48      /***
49       * Creates an instance of an ServerLdapContext.
50       *
51       * @param service the parent service that manages this context
52       * @param env the JNDI environment parameters
53       * @throws NamingException the context cannot be created
54       */
55      public ServerLdapContext( ContextFactoryService service, Hashtable env ) throws NamingException
56      {
57          super( service, env );
58      }
59  
60  
61      /***
62       * Creates a new ServerDirContext with a distinguished name which is used to
63       * set the PROVIDER_URL to the distinguished name for this context.
64       *
65       * @param principal the directory user principal that is propagated
66       * @param nexusProxy the intercepting proxy to the nexus
67       * @param env the environment properties used by this context
68       * @param dn the distinguished name of this context
69       */
70      ServerLdapContext( LdapPrincipal principal, ContextPartitionNexus nexusProxy, Hashtable env, Name dn )
71      {
72          super( principal, nexusProxy, env, dn );
73      }
74  
75  
76      /***
77       * @see javax.naming.ldap.LdapContext#extendedOperation(
78       * javax.naming.ldap.ExtendedRequest)
79       */
80      public ExtendedResponse extendedOperation( ExtendedRequest request )
81      {
82          throw new NotImplementedException();
83      }
84  
85  
86      /***
87       * @see javax.naming.ldap.LdapContext#newInstance(
88       * javax.naming.ldap.Control[])
89       */
90      public LdapContext newInstance( Control[] requestControls )
91          throws NamingException
92      {
93          ServerLdapContext ctx = new ServerLdapContext( getPrincipal(), getNexusProxy(),
94                  getEnvironment(), getDn() );
95          ctx.setRequestControls( requestControls );
96          return ctx;
97      }
98  
99  
100     /***
101      * @see javax.naming.ldap.LdapContext#reconnect(javax.naming.ldap.Control[])
102      */
103     public void reconnect( Control[] connCtls ) throws NamingException
104     {
105         this.connectControls = connCtls;
106     }
107 
108 
109     /***
110      * @see javax.naming.ldap.LdapContext#getConnectControls()
111      */
112     public Control[] getConnectControls() throws NamingException
113     {
114         return this.connectControls;
115     }
116 
117 
118     /***
119      * @see javax.naming.ldap.LdapContext#setRequestControls(
120      * javax.naming.ldap.Control[])
121      */
122     public void setRequestControls( Control[] requestControls )
123         throws NamingException
124     {
125         this.requestControls = requestControls;
126     }
127 
128 
129     /***
130      * @see javax.naming.ldap.LdapContext#getRequestControls()
131      */
132     public Control[] getRequestControls() throws NamingException
133     {
134         return requestControls;
135     }
136 
137 
138     /***
139      * @see javax.naming.ldap.LdapContext#getResponseControls()
140      */
141     public Control[] getResponseControls() throws NamingException
142     {
143         return responseControls;
144     }
145 }