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.authz.support;
21  
22  
23  import java.util.Collection;
24  import java.util.Iterator;
25  
26  import org.apache.directory.api.ldap.aci.ACITuple;
27  import org.apache.directory.api.ldap.aci.MicroOperation;
28  import org.apache.directory.api.ldap.model.entry.Entry;
29  import org.apache.directory.api.ldap.model.exception.LdapException;
30  
31  
32  /**
33   * An {@link ACITupleFilter} that discard tuples which doesn't contain any
34   * related {@link MicroOperation}s. (18.8.3.4, X.501) 
35   *
36   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
37   *
38   */
39  public class MicroOperationFilter implements ACITupleFilter
40  {
41      /**
42       * {@inheritDoc}
43       */
44      @Override
45      public Collection<ACITuple> filter( AciContext aciContext, OperationScope scope, Entry userEntry )
46          throws LdapException
47      {
48          if ( aciContext.getAciTuples().isEmpty() )
49          {
50              return aciContext.getAciTuples();
51          }
52  
53          for ( Iterator<ACITuple> i = aciContext.getAciTuples().iterator(); i.hasNext(); )
54          {
55              ACITuple tuple = i.next();
56  
57              /*
58               * The ACITuple must contain all the MicroOperations specified within the
59               * microOperations argument.  Just matching a single microOperation is not
60               * enough.  All must be matched to retain the ACITuple.
61               */
62  
63              boolean retain = true;
64  
65              for ( MicroOperation microOp : aciContext.getMicroOperations() )
66              {
67                  if ( !tuple.getMicroOperations().contains( microOp ) )
68                  {
69                      retain = false;
70                      break;
71                  }
72              }
73  
74              if ( !retain )
75              {
76                  i.remove();
77              }
78          }
79  
80          return aciContext.getAciTuples();
81      }
82  
83  }