1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.aci;
21
22
23 import java.util.Collection;
24 import java.util.HashSet;
25 import java.util.Set;
26
27 import org.apache.directory.api.i18n.I18n;
28 import org.apache.directory.api.ldap.model.constants.AuthenticationLevel;
29
30
31
32
33
34
35
36
37
38 public abstract class ACIItem
39 {
40
41 private String identificationTag;
42
43
44 private int precedence = 0;
45
46
47 private AuthenticationLevel authenticationLevel;
48
49
50
51
52
53
54
55
56
57 protected ACIItem( String identificationTag, int precedence, AuthenticationLevel authenticationLevel )
58 {
59 if ( identificationTag == null )
60 {
61 throw new IllegalArgumentException( I18n.err( I18n.ERR_04001_NULL_IDENTIFICATION_TAG ) );
62 }
63
64 if ( ( precedence < 0 ) || ( precedence > 255 ) )
65 {
66 throw new IllegalArgumentException( I18n.err( I18n.ERR_04002_BAD_PRECENDENCE, precedence ) );
67 }
68
69 if ( authenticationLevel == null )
70 {
71 throw new IllegalArgumentException( I18n.err( I18n.ERR_04003_NULL_AUTHENTICATION_LEVEL ) );
72 }
73
74 this.identificationTag = identificationTag;
75 this.precedence = precedence;
76 this.authenticationLevel = authenticationLevel;
77 }
78
79
80
81
82
83
84
85 public String getIdentificationTag()
86 {
87 return identificationTag;
88 }
89
90
91
92
93
94
95
96 public int getPrecedence()
97 {
98 return precedence;
99 }
100
101
102
103
104
105
106
107 public AuthenticationLevel getAuthenticationLevel()
108 {
109 return authenticationLevel;
110 }
111
112
113
114
115
116
117
118 public abstract Collection<ACITuple> toTuples();
119
120
121
122
123
124
125
126
127 protected static Collection<MicroOperation> toMicroOperations( Collection<GrantAndDenial> grantsAndDenials )
128 {
129 Set<MicroOperation> microOps = new HashSet<>();
130
131 for ( GrantAndDenial grantAndDenial : grantsAndDenials )
132 {
133 microOps.add( grantAndDenial.getMicroOperation() );
134 }
135
136 return microOps;
137 }
138
139
140
141
142
143 @Override
144 public String toString()
145 {
146 StringBuilder buf = new StringBuilder();
147
148
149 buf.append( "identificationTag \"" );
150 buf.append( getIdentificationTag() );
151
152
153 buf.append( "\", precedence " );
154 buf.append( getPrecedence() );
155
156
157 buf.append( ", authenticationLevel " );
158 buf.append( getAuthenticationLevel().getName() );
159
160 return buf.toString();
161 }
162 }