View Javadoc
1   /*
2    * Copyright (c) 2002-2025, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.portal.service.rbac;
35  
36  import java.util.ArrayList;
37  import java.util.Arrays;
38  import java.util.Collection;
39  import java.util.Collections;
40  import java.util.List;
41  import java.util.Objects;
42  
43  import org.junit.Test;
44  
45  import fr.paris.lutece.api.user.User;
46  import fr.paris.lutece.portal.business.rbac.RBAC;
47  import fr.paris.lutece.portal.business.rbac.RBACHome;
48  import fr.paris.lutece.test.LuteceTestCase;
49  import fr.paris.lutece.util.ReferenceList;
50  
51  public class RBACServiceTest extends LuteceTestCase
52  {
53      private final static class TestResource implements RBACResource
54      {
55  
56          @Override
57          public int hashCode( )
58          {
59              return Objects.hash( _strResourceId, _strResourceType );
60          }
61  
62          @Override
63          public boolean equals( Object obj )
64          {
65              if ( this == obj )
66                  return true;
67              if ( obj == null )
68                  return false;
69              if ( getClass( ) != obj.getClass( ) )
70                  return false;
71              TestResource other = ( TestResource ) obj;
72              return Objects.equals( _strResourceId, other._strResourceId )
73                      && Objects.equals( _strResourceType, other._strResourceType );
74          }
75  
76          private final String _strResourceType;
77          private final String _strResourceId;
78  
79          TestResource( String strResourcetype, String strResourceId )
80          {
81              _strResourceType = strResourcetype;
82              _strResourceId = strResourceId;
83          }
84  
85          @Override
86          public String getResourceTypeCode( )
87          {
88              return _strResourceType;
89          }
90  
91          @Override
92          public String getResourceId( )
93          {
94              return _strResourceId;
95          }
96  
97      }
98  
99      private static final String[ ][ ] data = { { "JUNITROLE1", "JUNITTYPE1", "JUNITID1", "JUNITPERM1" },
100             { "JUNITROLE2", "JUNITTYPE2", "*", "JUNITPERM2" }, { "JUNITROLE3", "JUNITTYPE3", "JUNITID3", "*" },
101             { "JUNITROLE4", "JUNITTYPE4", "JUNITID4", "*" }, { "JUNITROLE5", "JUNITTYPE4", "JUNITID5", "*" },
102             { "JUNITROLE6", "JUNITTYPE6", "*", "JUNITPERM6" }, { "JUNITROLE6", "JUNITTYPE6", "*", "JUNITPERM6_BIS" },
103             { "JUNITROLE7", "JUNITTYPE6", "*", "JUNITPERM6_TER" }, };
104 
105     private Collection<RBAC> rbacs;
106 
107     @Override
108     protected void setUp( ) throws Exception
109     {
110         super.setUp( );
111         rbacs = new ArrayList<>( );
112         for ( String[ ] rbacData : data )
113         {
114             RBAC rbac = new RBAC( );
115             rbac.setRoleKey( rbacData[ 0 ] );
116             rbac.setResourceTypeKey( rbacData[ 1 ] );
117             rbac.setResourceId( rbacData[ 2 ] );
118             rbac.setPermissionKey( rbacData[ 3 ] );
119             RBACHome.create( rbac );
120             rbacs.add( rbac );
121         }
122     }
123 
124     @Override
125     protected void tearDown( ) throws Exception
126     {
127         for ( RBAC rbac : rbacs )
128         {
129             try
130             {
131                 RBACHome.remove( rbac.getRBACId( ) );
132             }
133             catch ( Exception e )
134             {
135                 System.err.println( "Failed to teardown RBAC " + rbac.getRBACId( ) + " ( " + e.getMessage( ) + ")" );
136             }
137         }
138         super.tearDown( );
139     }
140 
141     @Test
142     public void testGetAuthorizedCollectionEmpty( )
143     {
144         List<TestResource> resources = Collections.emptyList( );
145         User user = new TestUser( "JUNITROLE1" );
146         Collection<TestResource> authorized = RBACService.getAuthorizedCollection( resources, "JUNITPERM1", user );
147         assertEquals( 0, authorized.size( ) );
148     }
149 
150     @Test
151     public void testGetAuthorizedCollectionNoUser( )
152     {
153         TestResource testResource = new TestResource( "JUNITTYPE1", "JUNITID1" );
154         List<TestResource> resources = Arrays.asList( testResource );
155         Collection<TestResource> authorized = RBACService.getAuthorizedCollection( resources, "JUNITPERM1",
156                 ( User ) null );
157         assertEquals( 0, authorized.size( ) );
158     }
159 
160     @Test
161     public void testGetAuthorizedCollection( )
162     {
163         TestResource testResource = new TestResource( "JUNITTYPE1", "JUNITID1" );
164         List<TestResource> resources = Arrays.asList( testResource );
165         User user = new TestUser( "JUNITROLE1" );
166         Collection<TestResource> authorized = RBACService.getAuthorizedCollection( resources, "JUNITPERM1", user );
167         assertEquals( 1, authorized.size( ) );
168         assertTrue( authorized.contains( testResource ) );
169     }
170 
171     @Test
172     public void testGetAuthorizedCollectionNoRole( )
173     {
174         TestResource testResource = new TestResource( "JUNITTYPE1", "JUNITID1" );
175         List<TestResource> resources = Arrays.asList( testResource );
176         User user = new TestUser( );
177         Collection<TestResource> authorized = RBACService.getAuthorizedCollection( resources, "JUNITPERM1", user );
178         assertEquals( 0, authorized.size( ) );
179     }
180 
181     @Test
182     public void testGetAuthorizedCollectionWrongType( )
183     {
184         TestResource testResource = new TestResource( "JUNITTYPE1_WRONG", "JUNITID1" );
185         List<TestResource> resources = Arrays.asList( testResource );
186         User user = new TestUser( "JUNITROLE1" );
187         Collection<TestResource> authorized = RBACService.getAuthorizedCollection( resources, "JUNITPERM1", user );
188         assertEquals( 0, authorized.size( ) );
189     }
190 
191     @Test
192     public void testGetAuthorizedCollectionWrongPerm( )
193     {
194         TestResource testResource = new TestResource( "JUNITTYPE1", "JUNITID1" );
195         List<TestResource> resources = Arrays.asList( testResource );
196         User user = new TestUser( "JUNITROLE1" );
197         Collection<TestResource> authorized = RBACService.getAuthorizedCollection( resources, "JUNITPERM1_WRONG",
198                 user );
199         assertEquals( 0, authorized.size( ) );
200     }
201 
202     @Test
203     public void testGetAuthorizedCollectionWrongRole( )
204     {
205         TestResource testResource = new TestResource( "JUNITTYPE1", "JUNITID1" );
206         List<TestResource> resources = Arrays.asList( testResource );
207         User user = new TestUser( "JUNITROLE1_WRONG" );
208         Collection<TestResource> authorized = RBACService.getAuthorizedCollection( resources, "JUNITPERM1", user );
209         assertEquals( 0, authorized.size( ) );
210     }
211 
212     @Test
213     public void testGetAuthorizedCollectionWrongResourceId( )
214     {
215         TestResource testResource = new TestResource( "JUNITTYPE1", "JUNITID1_WRONG" );
216         List<TestResource> resources = Arrays.asList( testResource );
217         User user = new TestUser( "JUNITROLE1" );
218         Collection<TestResource> authorized = RBACService.getAuthorizedCollection( resources, "JUNITPERM1", user );
219         assertEquals( 0, authorized.size( ) );
220     }
221 
222     @Test
223     public void testGetAuthorizedCollectionWildcardId( )
224     {
225         TestResource testResource = new TestResource( "JUNITTYPE2", "JUNITID2" );
226         TestResource testResource2 = new TestResource( "JUNITTYPE2", "JUNITID2_BIS" );
227         List<TestResource> resources = Arrays.asList( testResource, testResource2 );
228         User user = new TestUser( "JUNITROLE2" );
229         Collection<TestResource> authorized = RBACService.getAuthorizedCollection( resources, "JUNITPERM2", user );
230         assertEquals( 2, authorized.size( ) );
231         assertTrue( authorized.contains( testResource ) );
232         assertTrue( authorized.contains( testResource2 ) );
233     }
234 
235     @Test
236     public void testGetAuthorizedCollectionWildcardPerm( )
237     {
238         TestResource testResource = new TestResource( "JUNITTYPE3", "JUNITID3" );
239         List<TestResource> resources = Arrays.asList( testResource );
240         User user = new TestUser( "JUNITROLE3" );
241         Arrays.asList( "JUNITPERM3", "JUNITPERM3BIS", "JUNITPERM3TER" ).forEach( perm -> {
242             Collection<TestResource> authorized = RBACService.getAuthorizedCollection( resources, perm, user );
243             assertEquals( 1, authorized.size( ) );
244             assertTrue( authorized.contains( testResource ) );
245         } );
246     }
247 
248     @Test
249     public void testGetAuthorizedCollectionMultipleRoles( )
250     {
251         TestResource testResource = new TestResource( "JUNITTYPE1", "JUNITID1" );
252         TestResource testResource2 = new TestResource( "JUNITTYPE2", "JUNITID3" );
253         TestResource testResource3 = new TestResource( "JUNITTYPE3", "JUNITID3" );
254         List<TestResource> resources = Arrays.asList( testResource, testResource2, testResource3 );
255         User user = new TestUser( "JUNITROLE1", "JUNITROLE3" );
256         Collection<TestResource> authorized = RBACService.getAuthorizedCollection( resources, "JUNITPERM1", user );
257         assertEquals( 2, authorized.size( ) );
258         assertTrue( authorized.contains( testResource ) );
259         assertTrue( authorized.contains( testResource3 ) );
260     }
261 
262     @Test
263     public void testGetAuthorizedReferenceListEmpty( )
264     {
265         ReferenceList refList = new ReferenceList( );
266         User user = new TestUser( "JUNITROLE1" );
267         ReferenceList authorized = RBACService.getAuthorizedReferenceList( refList, "JUNITTYPE1", "JUNITPERM1", user );
268         assertEquals( 0, authorized.size( ) );
269     }
270 
271     @Test
272     public void testGetAuthorizedReferenceListNoUser( )
273     {
274         ReferenceList refList = new ReferenceList( );
275         refList.addItem( "JUNITID1", "JUNITID1" );
276         ReferenceList authorized = RBACService.getAuthorizedReferenceList( refList, "JUNITTYPE1", "JUNITPERM1",
277                 ( User ) null );
278         assertEquals( 0, authorized.size( ) );
279     }
280 
281     @Test
282     public void testGetAuthorizedReferenceList( )
283     {
284         ReferenceList refList = new ReferenceList( );
285         refList.addItem( "JUNITID1", "JUNITID1" );
286         User user = new TestUser( "JUNITROLE1" );
287         ReferenceList authorized = RBACService.getAuthorizedReferenceList( refList, "JUNITTYPE1", "JUNITPERM1", user );
288         assertEquals( 1, authorized.size( ) );
289         assertEquals( "JUNITID1", authorized.get( 0 ).getCode( ) );
290     }
291 
292     @Test
293     public void testGetAuthorizedReferenceListNoRole( )
294     {
295         ReferenceList refList = new ReferenceList( );
296         refList.addItem( "JUNITID1", "JUNITID1" );
297         User user = new TestUser( );
298         ReferenceList authorized = RBACService.getAuthorizedReferenceList( refList, "JUNITTYPE1", "JUNITPERM1", user );
299         assertEquals( 0, authorized.size( ) );
300     }
301 
302     @Test
303     public void testGetAuthorizedReferenceListWrongType( )
304     {
305         ReferenceList refList = new ReferenceList( );
306         refList.addItem( "JUNITID1", "JUNITID1" );
307         User user = new TestUser( "JUNITROLE1" );
308         ReferenceList authorized = RBACService.getAuthorizedReferenceList( refList, "JUNITTYPE1_WRONG", "JUNITPERM1",
309                 user );
310         assertEquals( 0, authorized.size( ) );
311     }
312 
313     @Test
314     public void testGetAuthorizedReferenceListWrongPerm( )
315     {
316         ReferenceList refList = new ReferenceList( );
317         refList.addItem( "JUNITID1", "JUNITID1" );
318         User user = new TestUser( "JUNITROLE1" );
319         ReferenceList authorized = RBACService.getAuthorizedReferenceList( refList, "JUNITTYPE1", "JUNITPERM1_WRONG",
320                 user );
321         assertEquals( 0, authorized.size( ) );
322     }
323 
324     @Test
325     public void testGetAuthorizedReferenceListWrongRole( )
326     {
327         ReferenceList refList = new ReferenceList( );
328         refList.addItem( "JUNITID1", "JUNITID1" );
329         User user = new TestUser( "JUNITROLE1_WRONG" );
330         ReferenceList authorized = RBACService.getAuthorizedReferenceList( refList, "JUNITTYPE1", "JUNITPERM1", user );
331         assertEquals( 0, authorized.size( ) );
332     }
333 
334     @Test
335     public void testGetAuthorizedReferenceListWrongResourceId( )
336     {
337         ReferenceList refList = new ReferenceList( );
338         refList.addItem( "JUNITID1_WRONG", "JUNITID1_WRONG" );
339         User user = new TestUser( "JUNITROLE1" );
340         ReferenceList authorized = RBACService.getAuthorizedReferenceList( refList, "JUNITTYPE1", "JUNITPERM1", user );
341         assertEquals( 0, authorized.size( ) );
342     }
343 
344     @Test
345     public void testGetAuthorizedReferenceListWildcardId( )
346     {
347         ReferenceList refList = new ReferenceList( );
348         refList.addItem( "JUNITID2", "JUNITID2" );
349         refList.addItem( "JUNITID2_BIS", "JUNITID2_BIS" );
350         User user = new TestUser( "JUNITROLE2" );
351         ReferenceList authorized = RBACService.getAuthorizedReferenceList( refList, "JUNITTYPE2", "JUNITPERM2", user );
352         assertEquals( 2, authorized.size( ) );
353         assertTrue( authorized.stream( ).anyMatch( refItem -> "JUNITID2".equals( refItem.getCode( ) ) ) );
354         assertTrue( authorized.stream( ).anyMatch( refItem -> "JUNITID2_BIS".equals( refItem.getCode( ) ) ) );
355     }
356 
357     @Test
358     public void testGetAuthorizedReferenceListWildcardPerm( )
359     {
360         ReferenceList refList = new ReferenceList( );
361         refList.addItem( "JUNITID3", "JUNITID3" );
362         User user = new TestUser( "JUNITROLE3" );
363         Arrays.asList( "JUNITPERM3", "JUNITPERM3BIS", "JUNITPERM3TER" ).forEach( perm -> {
364             ReferenceList authorized = RBACService.getAuthorizedReferenceList( refList, "JUNITTYPE3", perm, user );
365             assertEquals( 1, authorized.size( ) );
366             assertEquals( "JUNITID3", authorized.get( 0 ).getCode( ) );
367         } );
368     }
369 
370     @Test
371     public void testGetAuthorizedReferenceListMultipleRoles( )
372     {
373         ReferenceList refList = new ReferenceList( );
374         refList.addItem( "JUNITID4", "JUNITID4" );
375         refList.addItem( "JUNITID5", "JUNITID5" );
376         refList.addItem( "JUNITID6", "JUNITID6" );
377         User user = new TestUser( "JUNITROLE4", "JUNITROLE5" );
378         ReferenceList authorized = RBACService.getAuthorizedReferenceList( refList, "JUNITTYPE4", "JUNITPERM4", user );
379         assertEquals( 2, authorized.size( ) );
380         assertTrue( authorized.stream( ).anyMatch( refItem -> "JUNITID4".equals( refItem.getCode( ) ) ) );
381         assertTrue( authorized.stream( ).anyMatch( refItem -> "JUNITID5".equals( refItem.getCode( ) ) ) );
382     }
383 
384     @Test
385     public void testGetAuthorizedActionsCollection( )
386     {
387         TestRBACActionc/TestRBACAction.html#TestRBACAction">TestRBACAction testAction = new TestRBACAction( "JUNITPERM1" );
388         List<RBACAction> actions = Arrays.asList( testAction );
389         TestResource testResource = new TestResource( "JUNITTYPE1", "JUNITID1" );
390         User user = new TestUser( "JUNITROLE1" );
391         Collection<RBACAction> authorized = RBACService.getAuthorizedActionsCollection( actions, testResource, user );
392         assertEquals( 1, authorized.size( ) );
393         assertTrue(
394                 authorized.stream( ).map( RBACAction::getPermission ).allMatch( perm -> "JUNITPERM1".equals( perm ) ) );
395     }
396 
397     @Test
398     public void testGetAuthorizedActionsCollectionWrondResourceId( )
399     {
400         TestRBACActionc/TestRBACAction.html#TestRBACAction">TestRBACAction testAction = new TestRBACAction( "JUNITPERM1" );
401         List<RBACAction> actions = Arrays.asList( testAction );
402         TestResource testResource = new TestResource( "JUNITTYPE1", "JUNITID1_WRONG" );
403         User user = new TestUser( "JUNITROLE1" );
404         Collection<RBACAction> authorized = RBACService.getAuthorizedActionsCollection( actions, testResource, user );
405         assertEquals( 0, authorized.size( ) );
406     }
407 
408     @Test
409     public void testGetAuthorizedActionsCollectionWrondResourceType( )
410     {
411         TestRBACActionc/TestRBACAction.html#TestRBACAction">TestRBACAction testAction = new TestRBACAction( "JUNITPERM1" );
412         List<RBACAction> actions = Arrays.asList( testAction );
413         TestResource testResource = new TestResource( "JUNITTYPE1_WRONG", "JUNITID1" );
414         User user = new TestUser( "JUNITROLE1" );
415         Collection<RBACAction> authorized = RBACService.getAuthorizedActionsCollection( actions, testResource, user );
416         assertEquals( 0, authorized.size( ) );
417     }
418 
419     @Test
420     public void testGetAuthorizedActionsCollectionEmptyCollection( )
421     {
422         TestResource testResource = new TestResource( "JUNITTYPE1", "JUNITID1" );
423         User user = new TestUser( "JUNITROLE1" );
424         Collection<RBACAction> authorized = RBACService.getAuthorizedActionsCollection( Collections.emptyList( ),
425                 testResource, user );
426         assertEquals( 0, authorized.size( ) );
427     }
428 
429     @Test
430     public void testGetAuthorizedActionsCollectionNoPermOnResource( )
431     {
432         TestRBACActionc/TestRBACAction.html#TestRBACAction">TestRBACAction testAction = new TestRBACAction( "JUNITPERM1" );
433         List<RBACAction> actions = Arrays.asList( testAction );
434         TestResource testResource = new TestResource( "JUNITTYPE1", "JUNITID2" );
435         User user = new TestUser( "JUNITROLE1" );
436         Collection<RBACAction> authorized = RBACService.getAuthorizedActionsCollection( actions, testResource, user );
437         assertEquals( 0, authorized.size( ) );
438     }
439 
440     @Test
441     public void testGetAuthorizedActionsCollectionNoRole( )
442     {
443         TestRBACActionc/TestRBACAction.html#TestRBACAction">TestRBACAction testAction = new TestRBACAction( "JUNITPERM1" );
444         List<RBACAction> actions = Arrays.asList( testAction );
445         TestResource testResource = new TestResource( "JUNITTYPE1", "JUNITID1" );
446         User user = new TestUser( );
447         Collection<RBACAction> authorized = RBACService.getAuthorizedActionsCollection( actions, testResource, user );
448         assertEquals( 0, authorized.size( ) );
449     }
450 
451     @Test
452     public void testGetAuthorizedActionsCollectionWildcardPermission( )
453     {
454         TestRBACActionc/TestRBACAction.html#TestRBACAction">TestRBACAction testAction = new TestRBACAction( "JUNITPERM1" );
455         TestRBACAction/TestRBACAction.html#TestRBACAction">TestRBACAction testAction2 = new TestRBACAction( "JUNITPERM1_BIS" );
456         List<RBACAction> actions = Arrays.asList( testAction, testAction2 );
457         TestResource testResource = new TestResource( "JUNITTYPE3", "JUNITID3" );
458         User user = new TestUser( "JUNITROLE3" );
459         Collection<RBACAction> authorized = RBACService.getAuthorizedActionsCollection( actions, testResource, user );
460         assertEquals( 2, authorized.size( ) );
461         assertTrue(
462                 authorized.stream( ).map( RBACAction::getPermission ).anyMatch( perm -> "JUNITPERM1".equals( perm ) ) );
463         assertTrue( authorized.stream( ).map( RBACAction::getPermission )
464                 .anyMatch( perm -> "JUNITPERM1_BIS".equals( perm ) ) );
465     }
466 
467     @Test
468     public void testGetAuthorizedActionsCollectionMultiplePermission( )
469     {
470         TestRBACActionc/TestRBACAction.html#TestRBACAction">TestRBACAction testAction = new TestRBACAction( "JUNITPERM6" );
471         TestRBACAction/TestRBACAction.html#TestRBACAction">TestRBACAction testAction2 = new TestRBACAction( "JUNITPERM6_BIS" );
472         TestRBACAction/TestRBACAction.html#TestRBACAction">TestRBACAction testAction3 = new TestRBACAction( "JUNITPERM6_TER" );
473         List<RBACAction> actions = Arrays.asList( testAction, testAction2, testAction3 );
474         TestResource testResource = new TestResource( "JUNITTYPE6", "JUNITID6" );
475         User user = new TestUser( "JUNITROLE6" );
476         Collection<RBACAction> authorized = RBACService.getAuthorizedActionsCollection( actions, testResource, user );
477         assertEquals( 2, authorized.size( ) );
478         assertTrue(
479                 authorized.stream( ).map( RBACAction::getPermission ).anyMatch( perm -> "JUNITPERM6".equals( perm ) ) );
480         assertTrue( authorized.stream( ).map( RBACAction::getPermission )
481                 .anyMatch( perm -> "JUNITPERM6_BIS".equals( perm ) ) );
482     }
483 
484     @Test
485     public void testGetAuthorizedActionsCollectionMultipleRoles( )
486     {
487         TestRBACActionc/TestRBACAction.html#TestRBACAction">TestRBACAction testAction = new TestRBACAction( "JUNITPERM6" );
488         TestRBACAction/TestRBACAction.html#TestRBACAction">TestRBACAction testAction2 = new TestRBACAction( "JUNITPERM6_BIS" );
489         TestRBACAction/TestRBACAction.html#TestRBACAction">TestRBACAction testAction3 = new TestRBACAction( "JUNITPERM6_TER" );
490         TestRBACAction/TestRBACAction.html#TestRBACAction">TestRBACAction testAction4 = new TestRBACAction( "JUNITPERM6_QUATER" );
491         List<RBACAction> actions = Arrays.asList( testAction, testAction2, testAction3, testAction4 );
492         TestResource testResource = new TestResource( "JUNITTYPE6", "JUNITID6" );
493         User user = new TestUser( "JUNITROLE6", "JUNITROLE7" );
494         Collection<RBACAction> authorized = RBACService.getAuthorizedActionsCollection( actions, testResource, user );
495         assertEquals( 3, authorized.size( ) );
496         assertTrue(
497                 authorized.stream( ).map( RBACAction::getPermission ).anyMatch( perm -> "JUNITPERM6".equals( perm ) ) );
498         assertTrue( authorized.stream( ).map( RBACAction::getPermission )
499                 .anyMatch( perm -> "JUNITPERM6_BIS".equals( perm ) ) );
500         assertTrue( authorized.stream( ).map( RBACAction::getPermission )
501                 .anyMatch( perm -> "JUNITPERM6_TER".equals( perm ) ) );
502     }
503 
504     @Test
505     public void testGetAuthorizedActionsCollectionWildcardId( )
506     {
507         TestRBACActionc/TestRBACAction.html#TestRBACAction">TestRBACAction testAction = new TestRBACAction( "JUNITPERM2" );
508         List<RBACAction> actions = Arrays.asList( testAction );
509         Arrays.asList( "JUNITID2", "JUNITID2_BIS", "JUNITID2_TER" ).forEach( id -> {
510             TestResource testResource = new TestResource( "JUNITTYPE2", id );
511             User user = new TestUser( "JUNITROLE2" );
512             Collection<RBACAction> authorized = RBACService.getAuthorizedActionsCollection( actions, testResource,
513                     user );
514             assertEquals( 1, authorized.size( ) );
515             assertTrue( authorized.stream( ).map( RBACAction::getPermission )
516                     .allMatch( perm -> "JUNITPERM2".equals( perm ) ) );
517         } );
518     }
519 
520 }