View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server.core.interceptor;
21  
22  
23  import org.apache.directory.server.core.DirectoryService;
24  import org.apache.directory.server.core.authn.LdapPrincipal;
25  import org.apache.directory.server.core.entry.ClonedServerEntry;
26  import org.apache.directory.server.core.filtering.EntryFilteringCursor;
27  import org.apache.directory.server.core.interceptor.context.AddContextPartitionOperationContext;
28  import org.apache.directory.server.core.interceptor.context.AddOperationContext;
29  import org.apache.directory.server.core.interceptor.context.BindOperationContext;
30  import org.apache.directory.server.core.interceptor.context.CompareOperationContext;
31  import org.apache.directory.server.core.interceptor.context.DeleteOperationContext;
32  import org.apache.directory.server.core.interceptor.context.EntryOperationContext;
33  import org.apache.directory.server.core.interceptor.context.GetMatchedNameOperationContext;
34  import org.apache.directory.server.core.interceptor.context.GetRootDSEOperationContext;
35  import org.apache.directory.server.core.interceptor.context.GetSuffixOperationContext;
36  import org.apache.directory.server.core.interceptor.context.ListOperationContext;
37  import org.apache.directory.server.core.interceptor.context.ListSuffixOperationContext;
38  import org.apache.directory.server.core.interceptor.context.LookupOperationContext;
39  import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
40  import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext;
41  import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
42  import org.apache.directory.server.core.interceptor.context.OperationContext;
43  import org.apache.directory.server.core.interceptor.context.RemoveContextPartitionOperationContext;
44  import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
45  import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
46  import org.apache.directory.server.core.interceptor.context.UnbindOperationContext;
47  import org.apache.directory.server.core.invocation.InvocationStack;
48  import org.apache.directory.shared.ldap.name.LdapDN;
49  
50  import javax.naming.Context;
51  import java.util.Iterator;
52  
53  
54  /**
55   * A easy-to-use implementation of {@link Interceptor}.  All methods are
56   * implemented to pass the flow of control to next interceptor by defaults.
57   * Please override the methods you have concern in.
58   *
59   * @org.apache.xbean.XBean
60   *
61   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
62   * @version $Rev: 662440 $, $Date: 2008-06-02 16:00:23 +0200 (Mo, 02 Jun 2008) $
63   */
64  public abstract class BaseInterceptor implements Interceptor
65  {
66      /**
67       * default interceptor name is its class, preventing accidental duplication of interceptors by naming
68       * instances differently
69       * @return (default, class name) interceptor name
70       */
71      public String getName()
72      {
73          return getClass().getName();
74      }
75      
76      /**
77       * TODO delete this since it uses static access
78       * Returns {@link LdapPrincipal} of current context.
79       * @return the authenticated principal
80       */
81      public static LdapPrincipal getPrincipal()
82      {
83          return getContext().getSession().getEffectivePrincipal();
84      }
85  
86  
87      /**
88       * TODO delete this since it uses static access
89       * Returns the current JNDI {@link Context}.
90       * @return the context on the invocation stack
91       */
92      public static OperationContext getContext()
93      {
94          return InvocationStack.getInstance().peek();
95      }
96  
97  
98      /**
99       * Creates a new instance.
100      */
101     protected BaseInterceptor()
102     {
103     }
104 
105 
106     /**
107      * This method does nothing by default.
108      * @throws Exception 
109      */
110     public void init( DirectoryService directoryService ) throws Exception
111     {
112     }
113 
114 
115     /**
116      * This method does nothing by default.
117      */
118     public void destroy()
119     {
120     }
121 
122 
123     // ------------------------------------------------------------------------
124     // Interceptor's Invoke Method
125     // ------------------------------------------------------------------------
126 
127     public void add( NextInterceptor next, AddOperationContext opContext ) throws Exception
128     {
129         next.add( opContext );
130     }
131 
132 
133     public void delete( NextInterceptor next, DeleteOperationContext opContext ) throws Exception
134     {
135         next.delete( opContext );
136     }
137 
138 
139     public LdapDN getMatchedName ( NextInterceptor next, GetMatchedNameOperationContext opContext ) throws Exception
140     {
141         return next.getMatchedName( opContext );
142     }
143 
144 
145     public ClonedServerEntry getRootDSE( NextInterceptor next, GetRootDSEOperationContext opContext ) throws Exception
146     {
147         return next.getRootDSE( opContext );
148     }
149 
150 
151     public LdapDN getSuffix( NextInterceptor next, GetSuffixOperationContext opContext ) throws Exception
152     {
153         return next.getSuffix( opContext );
154     }
155 
156 
157     public boolean hasEntry( NextInterceptor next, EntryOperationContext opContext ) throws Exception
158     {
159         return next.hasEntry( opContext );
160     }
161 
162 
163     public EntryFilteringCursor list( NextInterceptor next, ListOperationContext opContext ) throws Exception
164     {
165         return next.list( opContext );
166     }
167 
168 
169     public Iterator<String> listSuffixes ( NextInterceptor next, ListSuffixOperationContext opContext ) 
170         throws Exception
171     {
172         return next.listSuffixes( opContext );
173     }
174 
175 
176     public ClonedServerEntry lookup( NextInterceptor next, LookupOperationContext opContext ) throws Exception
177     {
178         return next.lookup( opContext );
179     }
180 
181     
182     public void modify( NextInterceptor next, ModifyOperationContext opContext ) throws Exception
183     {
184         next.modify( opContext );
185     }
186 
187 
188     public void rename( NextInterceptor next, RenameOperationContext opContext ) throws Exception
189     {
190         next.rename( opContext );
191     }
192 
193 
194     public void moveAndRename( NextInterceptor next, MoveAndRenameOperationContext opContext )
195         throws Exception
196     {
197         next.moveAndRename( opContext );
198     }
199 
200 
201     public void move( NextInterceptor next, MoveOperationContext opContext ) throws Exception
202     {
203         next.move( opContext );
204     }
205 
206 
207     public EntryFilteringCursor search( NextInterceptor next, SearchOperationContext opContext ) throws Exception
208     {
209         return next.search( opContext );
210     }
211 
212 
213     public void addContextPartition( NextInterceptor next, AddContextPartitionOperationContext opContext ) throws Exception
214     {
215         next.addContextPartition( opContext );
216     }
217 
218 
219     public void removeContextPartition( NextInterceptor next, RemoveContextPartitionOperationContext opContext ) throws Exception
220     {
221         next.removeContextPartition( opContext );
222     }
223 
224 
225     public boolean compare( NextInterceptor next, CompareOperationContext opContext ) throws Exception
226     {
227         return next.compare( opContext );
228     }
229 
230 
231     public void bind( NextInterceptor next, BindOperationContext opContext ) throws Exception
232     {
233         next.bind( opContext );
234     }
235 
236 
237     public void unbind( NextInterceptor next, UnbindOperationContext opContext ) throws Exception
238     {
239         next.unbind( opContext );
240     }
241 }