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.interceptor;
18  
19  
20  import java.util.Iterator;
21  import java.util.Map;
22  
23  import javax.naming.Context;
24  import javax.naming.Name;
25  import javax.naming.NamingEnumeration;
26  import javax.naming.NamingException;
27  import javax.naming.directory.Attributes;
28  import javax.naming.directory.ModificationItem;
29  import javax.naming.directory.SearchControls;
30  import javax.naming.ldap.LdapContext;
31  
32  import org.apache.ldap.common.filter.ExprNode;
33  import org.apache.ldap.server.authn.LdapPrincipal;
34  import org.apache.ldap.server.configuration.ContextPartitionConfiguration;
35  import org.apache.ldap.server.configuration.InterceptorConfiguration;
36  import org.apache.ldap.server.invocation.InvocationStack;
37  import org.apache.ldap.server.jndi.ContextFactoryConfiguration;
38  import org.apache.ldap.server.jndi.ServerContext;
39  
40  
41  /***
42   * A easy-to-use implementation of {@link Interceptor}.  All methods are
43   * implemented to pass the flow of control to next interceptor by defaults.
44   * Please override the methods you have concern in.
45   *
46   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
47   * @version $Rev: 264732 $, $Date: 2005-08-30 04:04:51 -0400 (Tue, 30 Aug 2005) $
48   */
49  public abstract class BaseInterceptor implements Interceptor
50  {
51      /***
52       * Returns {@link LdapPrincipal} of current context.
53       */
54      public static LdapPrincipal getPrincipal()
55      {
56          ServerContext ctx = ( ServerContext ) getContext();
57          return ctx.getPrincipal();
58      }
59      
60      /***
61       * Returns the current JNDI {@link Context}.
62       */
63      public static LdapContext getContext()
64      {
65          return ( LdapContext ) InvocationStack.getInstance().peek().getCaller();
66      }
67  
68  
69      /***
70       * Creates a new instance.
71       */
72      protected BaseInterceptor()
73      {
74      }
75  
76  
77      /***
78       * This method does nothing by default.
79       */
80      public void init( ContextFactoryConfiguration factoryCfg, InterceptorConfiguration cfg ) throws NamingException
81      {
82      }
83  
84  
85      /***
86       * This method does nothing by default.
87       */
88      public void destroy()
89      {
90      }
91  
92  
93      // ------------------------------------------------------------------------
94      // Interceptor's Invoke Method
95      // ------------------------------------------------------------------------
96  
97      public void add( NextInterceptor next, String upName, Name normName, Attributes entry ) throws NamingException
98      {
99          next.add( upName, normName, entry );
100     }
101 
102 
103     public void delete( NextInterceptor next, Name name ) throws NamingException
104     {
105         next.delete( name );
106     }
107 
108 
109     public Name getMatchedName( NextInterceptor next, Name dn, boolean normalized ) throws NamingException
110     {
111         return next.getMatchedName( dn, normalized );
112     }
113 
114 
115     public Attributes getRootDSE( NextInterceptor next ) throws NamingException
116     {
117         return next.getRootDSE();
118     }
119 
120 
121     public Name getSuffix( NextInterceptor next, Name dn, boolean normalized ) throws NamingException
122     {
123         return next.getSuffix( dn, normalized );
124     }
125 
126 
127     public boolean hasEntry( NextInterceptor next, Name name ) throws NamingException
128     {
129         return next.hasEntry( name );
130     }
131 
132 
133     public boolean isSuffix( NextInterceptor next, Name name ) throws NamingException
134     {
135         return next.isSuffix( name );
136     }
137 
138 
139     public NamingEnumeration list( NextInterceptor next, Name base ) throws NamingException
140     {
141         return next.list( base );
142     }
143 
144 
145     public Iterator listSuffixes( NextInterceptor next, boolean normalized ) throws NamingException
146     {
147         return next.listSuffixes( normalized );
148     }
149 
150 
151     public Attributes lookup( NextInterceptor next, Name dn, String[] attrIds ) throws NamingException
152     {
153         return next.lookup( dn, attrIds );
154     }
155 
156 
157     public Attributes lookup( NextInterceptor next, Name name ) throws NamingException
158     {
159         return next.lookup( name );
160     }
161 
162 
163     public void modify( NextInterceptor next, Name name, int modOp, Attributes mods ) throws NamingException
164     {
165         next.modify( name, modOp, mods );
166     }
167 
168 
169     public void modify( NextInterceptor next, Name name, ModificationItem[] mods ) throws NamingException
170     {
171         next.modify( name, mods );
172     }
173 
174 
175     public void modifyRn( NextInterceptor next, Name name, String newRn, boolean deleteOldRn ) throws NamingException
176     {
177         next.modifyRn( name, newRn, deleteOldRn );
178     }
179 
180 
181     public void move( NextInterceptor next, Name oriChildName, Name newParentName, String newRn, boolean deleteOldRn ) throws NamingException
182     {
183         next.move( oriChildName, newParentName, newRn, deleteOldRn );
184     }
185 
186 
187     public void move( NextInterceptor next, Name oriChildName, Name newParentName ) throws NamingException
188     {
189         next.move( oriChildName, newParentName );
190     }
191 
192 
193     public NamingEnumeration search( NextInterceptor next, Name base, Map env, ExprNode filter, SearchControls searchCtls ) throws NamingException
194     {
195         return next.search( base, env, filter, searchCtls );
196     }
197 
198     public void addContextPartition( NextInterceptor next, ContextPartitionConfiguration cfg ) throws NamingException
199     {
200         next.addContextPartition( cfg );
201     }
202 
203     public void removeContextPartition( NextInterceptor next, Name suffix ) throws NamingException
204     {
205         next.removeContextPartition( suffix );
206     }
207 }