@@ -59,8 +59,8 @@ public void indexPattern_simple_inclusive() throws Exception {
59
59
FieldPrivileges subject = createSubject (roleConfig );
60
60
61
61
FieldPrivileges .FlsRule rule = subject .getRestriction (ctx ("fls_role_1" ), "index_a1" );
62
- assertTrue ("included_field_a should be allowed" , rule .isAllowed ("included_field_a" ));
63
- assertFalse ("Fields other than included_field_a should be not allowed" , rule .isAllowed ("other_field" ));
62
+ assertTrue ("included_field_a should be allowed" , rule .isAllowedAssumingParentsAreAllowed ("included_field_a" ));
63
+ assertFalse ("Fields other than included_field_a should be not allowed" , rule .isAllowedAssumingParentsAreAllowed ("other_field" ));
64
64
}
65
65
66
66
@ Test
@@ -72,8 +72,8 @@ public void indexPattern_simple_exclusive() throws Exception {
72
72
FieldPrivileges subject = createSubject (roleConfig );
73
73
74
74
FieldPrivileges .FlsRule rule = subject .getRestriction (ctx ("fls_role_1" ), "index_a1" );
75
- assertFalse ("excluded_field_a should be not allowed" , rule .isAllowed ("excluded_field_a" ));
76
- assertTrue ("Fields other than included_field_a should be allowed" , rule .isAllowed ("other_field" ));
75
+ assertFalse ("excluded_field_a should be not allowed" , rule .isAllowedAssumingParentsAreAllowed ("excluded_field_a" ));
76
+ assertTrue ("Fields other than included_field_a should be allowed" , rule .isAllowedAssumingParentsAreAllowed ("other_field" ));
77
77
}
78
78
79
79
@ Test
@@ -86,11 +86,11 @@ public void indexPattern_joined_inclusive() throws Exception {
86
86
FieldPrivileges subject = createSubject (roleConfig );
87
87
88
88
FieldPrivileges .FlsRule rule = subject .getRestriction (ctx ("fls_role_1" , "fls_role_2" ), "index_a1" );
89
- assertTrue ("included_field_a should be allowed" , rule .isAllowed ("included_field_a" ));
90
- assertTrue ("included_field_a1_foo should be allowed" , rule .isAllowed ("included_field_a1_foo" ));
89
+ assertTrue ("included_field_a should be allowed" , rule .isAllowedAssumingParentsAreAllowed ("included_field_a" ));
90
+ assertTrue ("included_field_a1_foo should be allowed" , rule .isAllowedAssumingParentsAreAllowed ("included_field_a1_foo" ));
91
91
assertFalse (
92
92
"Fields other than included_field_a and included_field_a1_foo should be not allowed" ,
93
- rule .isAllowed ("other_field" )
93
+ rule .isAllowedAssumingParentsAreAllowed ("other_field" )
94
94
);
95
95
}
96
96
@@ -104,9 +104,12 @@ public void indexPattern_joined_exclusive() throws Exception {
104
104
FieldPrivileges subject = createSubject (roleConfig );
105
105
106
106
FieldPrivileges .FlsRule rule = subject .getRestriction (ctx ("fls_role_1" , "fls_role_2" ), "index_a1" );
107
- assertFalse ("excluded_field_a should be not allowed" , rule .isAllowed ("excluded_field_a" ));
108
- assertFalse ("excluded_field_a1_foo should be not allowed" , rule .isAllowed ("excluded_field_a1_foo" ));
109
- assertTrue ("Fields other than included_field_a and included_field_a1_foo should be allowed" , rule .isAllowed ("other_field" ));
107
+ assertFalse ("excluded_field_a should be not allowed" , rule .isAllowedAssumingParentsAreAllowed ("excluded_field_a" ));
108
+ assertFalse ("excluded_field_a1_foo should be not allowed" , rule .isAllowedAssumingParentsAreAllowed ("excluded_field_a1_foo" ));
109
+ assertTrue (
110
+ "Fields other than included_field_a and included_field_a1_foo should be allowed" ,
111
+ rule .isAllowedAssumingParentsAreAllowed ("other_field" )
112
+ );
110
113
}
111
114
112
115
@ Test
@@ -119,8 +122,8 @@ public void indexPattern_unrestricted_inclusive() throws Exception {
119
122
FieldPrivileges subject = createSubject (roleConfig );
120
123
121
124
FieldPrivileges .FlsRule rule = subject .getRestriction (ctx ("fls_role_1" , "non_fls_role" ), "index_a1" );
122
- assertTrue ("included_field_a should be allowed" , rule .isAllowed ("included_field_a" ));
123
- assertTrue ("other_field should be allowed" , rule .isAllowed ("other_field" ));
125
+ assertTrue ("included_field_a should be allowed" , rule .isAllowedAssumingParentsAreAllowed ("included_field_a" ));
126
+ assertTrue ("other_field should be allowed" , rule .isAllowedAssumingParentsAreAllowed ("other_field" ));
124
127
}
125
128
126
129
@ Test
@@ -133,8 +136,8 @@ public void indexPattern_unrestricted_exclusive() throws Exception {
133
136
FieldPrivileges subject = createSubject (roleConfig );
134
137
135
138
FieldPrivileges .FlsRule rule = subject .getRestriction (ctx ("fls_role_1" , "non_fls_role" ), "index_a1" );
136
- assertTrue ("excluded_field_a should be allowed" , rule .isAllowed ("excluded_field_a" ));
137
- assertTrue ("other_field should be allowed" , rule .isAllowed ("other_field" ));
139
+ assertTrue ("excluded_field_a should be allowed" , rule .isAllowedAssumingParentsAreAllowed ("excluded_field_a" ));
140
+ assertTrue ("other_field should be allowed" , rule .isAllowedAssumingParentsAreAllowed ("other_field" ));
138
141
}
139
142
140
143
static SecurityDynamicConfiguration <RoleV7 > roleConfig (TestSecurityConfig .Role ... roles ) {
@@ -168,8 +171,13 @@ public static class FlsRule {
168
171
public void simple_inclusive () throws Exception {
169
172
FieldPrivileges .FlsRule flsRule = FieldPrivileges .FlsRule .of ("field_inclusive" );
170
173
assertFalse ("FLS rule field_inclusive should be restricted" , flsRule .isUnrestricted ());
171
- assertTrue ("field_inclusive is allowed" , flsRule .isAllowed ("field_inclusive" ));
172
- assertFalse ("other_field is not allowed" , flsRule .isAllowed ("other_field" ));
174
+
175
+ assertTrue ("field_inclusive is allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("field_inclusive" ));
176
+ assertTrue ("field_inclusive is allowed" , flsRule .isAllowedRecursive ("field_inclusive" ));
177
+
178
+ assertFalse ("other_field is not allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("other_field" ));
179
+ assertFalse ("other_field is not allowed" , flsRule .isAllowedRecursive ("other_field" ));
180
+
173
181
assertEquals ("FLS:[field_inclusive]" , flsRule .toString ());
174
182
assertEquals (Arrays .asList ("field_inclusive" ), flsRule .getSource ());
175
183
}
@@ -178,26 +186,40 @@ public void simple_inclusive() throws Exception {
178
186
public void simple_exclusive () throws Exception {
179
187
FieldPrivileges .FlsRule flsRule = FieldPrivileges .FlsRule .of ("~field_exclusive" );
180
188
assertFalse ("FLS rule field_exclusive should be restricted" , flsRule .isUnrestricted ());
181
- assertFalse ("field_exclusive is not allowed" , flsRule .isAllowed ("field_exclusive" ));
182
- assertTrue ("other_field is allowed" , flsRule .isAllowed ("other_field" ));
189
+
190
+ assertFalse ("field_exclusive is not allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("field_exclusive" ));
191
+ assertFalse ("field_exclusive is not allowed" , flsRule .isAllowedRecursive ("field_exclusive" ));
192
+
193
+ assertTrue ("other_field is allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("other_field" ));
194
+ assertTrue ("other_field is allowed" , flsRule .isAllowedRecursive ("other_field" ));
183
195
}
184
196
185
197
@ Test
186
198
public void multi_inclusive () throws Exception {
187
199
FieldPrivileges .FlsRule flsRule = FieldPrivileges .FlsRule .of ("field_inclusive_1" , "field_inclusive_2" );
188
200
assertFalse ("FLS rule should be restricted" , flsRule .isUnrestricted ());
189
- assertTrue ("field_inclusive_1 is allowed" , flsRule .isAllowed ("field_inclusive_1" ));
190
- assertTrue ("field_inclusive_2 is allowed" , flsRule .isAllowed ("field_inclusive_2" ));
191
- assertFalse ("other_field is not allowed" , flsRule .isAllowed ("other_field" ));
201
+
202
+ assertTrue ("field_inclusive_1 is allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("field_inclusive_1" ));
203
+ assertTrue ("field_inclusive_2 is allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("field_inclusive_2" ));
204
+ assertTrue ("field_inclusive_1 is allowed" , flsRule .isAllowedRecursive ("field_inclusive_1" ));
205
+ assertTrue ("field_inclusive_2 is allowed" , flsRule .isAllowedRecursive ("field_inclusive_2" ));
206
+
207
+ assertFalse ("other_field is not allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("other_field" ));
208
+ assertFalse ("other_field is not allowed" , flsRule .isAllowedRecursive ("other_field" ));
192
209
}
193
210
194
211
@ Test
195
212
public void multi_exclusive () throws Exception {
196
213
FieldPrivileges .FlsRule flsRule = FieldPrivileges .FlsRule .of ("~field_exclusive_1" , "~field_exclusive_2" );
197
214
assertFalse ("FLS rule should be restricted" , flsRule .isUnrestricted ());
198
- assertFalse ("field_exclusive_1 is not allowed" , flsRule .isAllowed ("field_exclusive_1" ));
199
- assertFalse ("field_exclusive_1 is not allowed" , flsRule .isAllowed ("field_exclusive_2" ));
200
- assertTrue ("other_field is allowed" , flsRule .isAllowed ("other_field" ));
215
+
216
+ assertFalse ("field_exclusive_1 is not allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("field_exclusive_1" ));
217
+ assertFalse ("field_exclusive_2 is not allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("field_exclusive_2" ));
218
+ assertFalse ("field_exclusive_1 is not allowed" , flsRule .isAllowedRecursive ("field_exclusive_1" ));
219
+ assertFalse ("field_exclusive_2 is not allowed" , flsRule .isAllowedRecursive ("field_exclusive_2" ));
220
+
221
+ assertTrue ("other_field is allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("other_field" ));
222
+ assertTrue ("other_field is allowed" , flsRule .isAllowedRecursive ("other_field" ));
201
223
}
202
224
203
225
@ Test
@@ -207,35 +229,51 @@ public void multi_mixed() throws Exception {
207
229
// The behavior is undocumented - if there are exclusions and inclusions, only exclusions are regarded.
208
230
// It might make sense to re-think this behavior.
209
231
assertFalse ("FLS rule should be restricted" , flsRule .isUnrestricted ());
210
- assertFalse ("field_exclusive_1 is not allowed" , flsRule .isAllowed ("field_exclusive_1" ));
211
- assertTrue ("other_field is allowed" , flsRule .isAllowed ("other_field" ));
232
+ assertFalse ("field_exclusive_1 is not allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("field_exclusive_1" ));
233
+ assertTrue ("other_field is allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("other_field" ));
212
234
}
213
235
214
236
@ Test
215
237
public void nested_inclusive () throws Exception {
216
238
FieldPrivileges .FlsRule flsRule = FieldPrivileges .FlsRule .of ("a.b.c" );
217
239
assertFalse ("FLS rule should be restricted" , flsRule .isUnrestricted ());
218
- assertTrue ("a.b.c is allowed" , flsRule .isAllowed ("a.b.c" ));
219
- assertFalse ("a.b is not allowed for non-objects" , flsRule .isAllowed ("a.b" ));
220
- assertTrue ("a.b is not allowed for objects" , flsRule .isObjectAllowed ("a.b" ));
221
- assertFalse ("other_field is not allowed" , flsRule .isAllowed ("other_field" ));
222
- assertFalse ("a.b.other_field is not allowed" , flsRule .isAllowed ("a.b.other_field" ));
240
+
241
+ assertTrue ("a.b.c is allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("a.b.c" ));
242
+ assertTrue ("a.b.c is allowed" , flsRule .isAllowedRecursive ("a.b.c" ));
243
+
244
+ assertFalse ("a.b is not allowed for non-objects" , flsRule .isAllowedAssumingParentsAreAllowed ("a.b" ));
245
+ assertTrue ("a.b is not allowed for objects" , flsRule .isObjectAllowedAssumingParentsAreAllowed ("a.b" ));
246
+ assertFalse ("a.b is not allowed recursively" , flsRule .isAllowedRecursive ("a.b" ));
247
+
248
+ assertFalse ("other_field is not allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("other_field" ));
249
+ assertFalse ("other_field is not allowed" , flsRule .isAllowedRecursive ("other_field" ));
250
+
251
+ assertFalse ("a.b.other_field is not allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("a.b.other_field" ));
252
+ assertFalse ("a.b.other_field is not allowed" , flsRule .isAllowedRecursive ("a.b.other_field" ));
253
+
254
+ assertTrue ("a.b.c.d is allowed" , flsRule .isAllowedRecursive ("a.b.c.d" ));
223
255
}
224
256
225
257
@ Test
226
258
public void nested_exclusive () throws Exception {
227
259
FieldPrivileges .FlsRule flsRule = FieldPrivileges .FlsRule .of ("~a.b.c" );
228
260
assertFalse ("FLS rule should be restricted" , flsRule .isUnrestricted ());
229
- assertFalse ("a.b.c is not allowed" , flsRule .isAllowed ("a.b.c" ));
230
- assertTrue ("a.b is allowed" , flsRule .isAllowed ("a.b" ));
231
- assertTrue ("a.b is allowed for objects" , flsRule .isObjectAllowed ("a.b" ));
261
+
262
+ assertFalse ("a.b.c is not allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("a.b.c" ));
263
+ assertFalse ("a.b.c is not allowed" , flsRule .isAllowedRecursive ("a.b.c" ));
264
+
265
+ assertTrue ("a.b is allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("a.b" ));
266
+ assertTrue ("a.b is allowed for objects" , flsRule .isObjectAllowedAssumingParentsAreAllowed ("a.b" ));
267
+ assertTrue ("a.b is allowed recursively" , flsRule .isAllowedAssumingParentsAreAllowed ("a.b" ));
268
+
269
+ assertFalse ("a.b.c.d is not allowed" , flsRule .isAllowedRecursive ("a.b.c.d" ));
232
270
}
233
271
234
272
@ Test
235
273
public void wildcard_inclusive () throws Exception {
236
274
FieldPrivileges .FlsRule flsRule = FieldPrivileges .FlsRule .of ("*" );
237
275
assertTrue ("FLS rule * is unrestricted" , flsRule .isUnrestricted ());
238
- assertTrue ("anything is allowed" , flsRule .isAllowed ("anything" ));
276
+ assertTrue ("anything is allowed" , flsRule .isAllowedAssumingParentsAreAllowed ("anything" ));
239
277
assertEquals ("FLS:*" , flsRule .toString ());
240
278
}
241
279
0 commit comments