View Javadoc

1   /*
2    *   @(#) $Id: MicroOperationFilter.java 326050 2005-10-18 08:19:14Z akarasulu $
3    *   
4    *   Copyright 2004 The Apache Software Foundation
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   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, software
13   *   distributed under the License is distributed on an "AS IS" BASIS,
14   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *   See the License for the specific language governing permissions and
16   *   limitations under the License.
17   *
18   */
19  package org.apache.ldap.server.authz.support;
20  
21  import java.util.Collection;
22  import java.util.Iterator;
23  
24  import javax.naming.Name;
25  import javax.naming.NamingException;
26  import javax.naming.directory.Attributes;
27  
28  import org.apache.ldap.common.aci.ACITuple;
29  import org.apache.ldap.common.aci.AuthenticationLevel;
30  import org.apache.ldap.common.aci.MicroOperation;
31  import org.apache.ldap.server.partition.DirectoryPartitionNexusProxy;
32  
33  
34  /***
35   * An {@link ACITupleFilter} that discard tuples which doesn't contain any
36   * related {@link MicroOperation}s. (18.8.3.4, X.501) 
37   *
38   * @author The Apache Directory Project
39   * @version $Rev: 326050 $, $Date: 2005-10-18 04:19:14 -0400 (Tue, 18 Oct 2005) $
40   *
41   */
42  public class MicroOperationFilter implements ACITupleFilter
43  {
44      public Collection filter( Collection tuples, OperationScope scope, DirectoryPartitionNexusProxy proxy,
45                                Collection userGroupNames, Name userName, Attributes userEntry,
46                                AuthenticationLevel authenticationLevel, Name entryName, String attrId,
47                                Object attrValue, Attributes entry, Collection microOperations )
48              throws NamingException
49      {
50          if( tuples.size() == 0 )
51          {
52              return tuples;
53          }
54  
55          for( Iterator i = tuples.iterator(); i.hasNext(); )
56          {
57              ACITuple tuple = ( ACITuple ) i.next();
58  
59              /*
60               * The ACITuple must contain all the MicroOperations specified within the
61               * microOperations argument.  Just matching a single microOperation is not
62               * enough.  All must be matched to retain the ACITuple.
63               */
64  
65              boolean retain = true;
66              for( Iterator j = microOperations.iterator(); j.hasNext(); )
67              {
68                  MicroOperation microOp = ( MicroOperation ) j.next();
69                  if( ! tuple.getMicroOperations().contains( microOp ) )
70                  {
71                      retain = false;
72                      break;
73                  }
74              }
75  
76              if( !retain )
77              {
78                  i.remove();
79              }
80          }
81  
82          return tuples;
83      }
84  
85  }