1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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.model.entry.Entry;
28 import org.apache.directory.api.ldap.model.exception.LdapException;
29
30
31
32
33
34
35
36
37 public class HighestPrecedenceFilter implements ACITupleFilter
38 {
39
40
41
42 @Override
43 public Collection<ACITuple> filter( AciContext aciContext, OperationScope scope, Entry userEntry )
44 throws LdapException
45 {
46 ACI_LOG.debug( "Filtering HighestPrecedence..." );
47
48 if ( aciContext.getAciTuples().size() <= 1 )
49 {
50 ACI_LOG.debug( "HighestPrecedence : nothing to do" );
51 return aciContext.getAciTuples();
52 }
53
54 int maxPrecedence = -1;
55
56
57 for ( ACITuple tuple : aciContext.getAciTuples() )
58 {
59 if ( ( tuple.getPrecedence() != null ) && ( tuple.getPrecedence() > maxPrecedence ) )
60 {
61 maxPrecedence = tuple.getPrecedence();
62 }
63 }
64
65
66 for ( Iterator<ACITuple> i = aciContext.getAciTuples().iterator(); i.hasNext(); )
67 {
68 ACITuple tuple = i.next();
69
70 if ( ( tuple.getPrecedence() != null ) && ( tuple.getPrecedence() != maxPrecedence ) )
71 {
72 i.remove();
73 }
74 }
75
76 return aciContext.getAciTuples();
77 }
78 }