This project has retired. For details please refer to its Attic page.
ArchivaRbacManager xref
View Javadoc
1   package org.apache.archiva.web.security;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   * http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import org.apache.archiva.admin.model.RepositoryAdminException;
22  import org.apache.archiva.admin.model.runtime.RedbackRuntimeConfigurationAdmin;
23  import org.apache.archiva.components.cache.Cache;
24  import org.apache.archiva.redback.rbac.AbstractRBACManager;
25  import org.apache.archiva.redback.rbac.Operation;
26  import org.apache.archiva.redback.rbac.Permission;
27  import org.apache.archiva.redback.rbac.RBACManager;
28  import org.apache.archiva.redback.rbac.RbacManagerException;
29  import org.apache.archiva.redback.rbac.RbacObjectInvalidException;
30  import org.apache.archiva.redback.rbac.RbacObjectNotFoundException;
31  import org.apache.archiva.redback.rbac.Resource;
32  import org.apache.archiva.redback.rbac.Role;
33  import org.apache.archiva.redback.rbac.UserAssignment;
34  import org.apache.commons.lang3.StringUtils;
35  import org.springframework.context.ApplicationContext;
36  import org.springframework.stereotype.Service;
37  
38  import javax.inject.Inject;
39  import javax.inject.Named;
40  import java.util.ArrayList;
41  import java.util.Collection;
42  import java.util.HashMap;
43  import java.util.LinkedHashMap;
44  import java.util.List;
45  import java.util.Map;
46  import java.util.Set;
47  
48  /**
49   * @author Olivier Lamy
50   * @since 1.4-M4
51   */
52  @Service( "rbacManager#archiva" )
53  public class ArchivaRbacManager
54      extends AbstractRBACManager
55      implements RBACManager
56  {
57  
58      private Map<String, RBACManager> rbacManagersPerId;
59  
60      @Inject
61      private ApplicationContext applicationContext;
62  
63      @Inject
64      private RedbackRuntimeConfigurationAdmin redbackRuntimeConfigurationAdmin;
65  
66      @Inject
67      @Named( value = "cache#operations" )
68      private Cache<String, Operation> operationsCache;
69  
70      @Inject
71      @Named( value = "cache#permissions" )
72      private Cache<String, Permission> permissionsCache;
73  
74      @Inject
75      @Named( value = "cache#resources" )
76      private Cache<String, Resource> resourcesCache;
77  
78      @Inject
79      @Named( value = "cache#roles" )
80      private Cache<String, Role> rolesCache;
81  
82      @Inject
83      @Named( value = "cache#userAssignments" )
84      private Cache<String, UserAssignment> userAssignmentsCache;
85  
86      @Inject
87      @Named( value = "cache#userPermissions" )
88      private Cache<String, Map<String, List<Permission>>> userPermissionsCache;
89  
90      @Inject
91      @Named( value = "cache#effectiveRoleSet" )
92      private Cache<String, Set<Role>> effectiveRoleSetCache;
93  
94      @Override
95      public void initialize()
96      {
97          try
98          {
99              List<String> rbacManagerIds =
100                 redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getRbacManagerImpls();
101 
102             clearCaches();
103 
104             if ( rbacManagerIds.isEmpty() )
105             {
106                 rbacManagerIds.add( RedbackRuntimeConfigurationAdmin.DEFAULT_RBAC_MANAGER_IMPL );
107             }
108 
109             log.info( "use rbacManagerIds: '{}'", rbacManagerIds );
110 
111             this.rbacManagersPerId = new LinkedHashMap<>( rbacManagerIds.size() );
112 
113             for ( String id : rbacManagerIds )
114             {
115                 if ( StringUtils.equalsIgnoreCase( "jdo", id ))
116                 {
117                     id = RedbackRuntimeConfigurationAdmin.DEFAULT_RBAC_MANAGER_IMPL;
118                 }
119                 RBACManager rbacManager = applicationContext.getBean( "rbacManager#" + id, RBACManager.class );
120                 rbacManagersPerId.put( id, rbacManager );
121             }
122 
123         }
124         catch ( RepositoryAdminException e )
125         {
126 
127             log.error( e.getMessage(), e );
128             throw new RuntimeException( e.getMessage(), e );
129         }
130     }
131 
132     private void clearCaches() {
133         resourcesCache.clear();
134         operationsCache.clear();
135         permissionsCache.clear();
136         rolesCache.clear();
137         userAssignmentsCache.clear();
138         userPermissionsCache.clear();
139         effectiveRoleSetCache.clear();
140     }
141 
142     protected RBACManager getRbacManagerForWrite()
143     {
144         for ( RBACManager rbacManager : this.rbacManagersPerId.values() )
145         {
146             if ( !rbacManager.isReadOnly() )
147             {
148                 log.debug("Writable Rbac manager {}", rbacManager.getDescriptionKey());
149                 return rbacManager;
150             }
151         }
152         return this.rbacManagersPerId.isEmpty() ? applicationContext.getBean(
153             "rbacManager#" + RedbackRuntimeConfigurationAdmin.DEFAULT_RBAC_MANAGER_IMPL, RBACManager.class ) //
154             : this.rbacManagersPerId.values().iterator().next();
155     }
156 
157     @Override
158     public Role createRole( String name )
159     {
160         return getRbacManagerForWrite().createRole( name );
161     }
162 
163     @Override
164     public Role saveRole( Role role )
165         throws RbacObjectInvalidException, RbacManagerException
166     {
167         Exception lastException = null;
168         boolean allFailed = true;
169         for ( RBACManager rbacManager : rbacManagersPerId.values() )
170         {
171             try
172             {
173                 if ( !rbacManager.isReadOnly() )
174                 {
175                     role = rbacManager.saveRole( role );
176                     allFailed = false;
177                 }
178             }
179             catch ( Exception e )
180             {
181                 lastException = e;
182             }
183         }
184         if ( lastException != null && allFailed )
185         {
186             throw new RbacManagerException( lastException.getMessage(), lastException );
187         }
188         return role;
189     }
190 
191     @Override
192     public void saveRoles( Collection<Role> roles )
193         throws RbacObjectInvalidException, RbacManagerException
194     {
195         Exception lastException = null;
196         boolean allFailed = true;
197         for ( RBACManager rbacManager : rbacManagersPerId.values() )
198         {
199             try
200             {
201                 if ( !rbacManager.isReadOnly() )
202                 {
203                     rbacManager.saveRoles( roles );
204                     allFailed = false;
205                 }
206             }
207             catch ( Exception e )
208             {
209                 lastException = e;
210             }
211         }
212         if ( lastException != null && allFailed )
213         {
214             throw new RbacManagerException( lastException.getMessage(), lastException );
215         }
216     }
217 
218     @Override
219     public Role getRole( String roleName )
220         throws RbacObjectNotFoundException, RbacManagerException
221     {
222 
223         Role el = rolesCache.get( roleName );
224         if ( el != null )
225         {
226             return el;
227         }
228 
229         Exception lastException = null;
230         for ( RBACManager rbacManager : rbacManagersPerId.values() )
231         {
232             try
233             {
234                 Role role = rbacManager.getRole( roleName );
235                 if ( role != null )
236                 {
237                     rolesCache.put( role.getName(), role );
238                     return role;
239                 }
240             }
241             catch ( Exception e )
242             {
243                 lastException = e;
244             }
245         }
246         log.debug( "cannot find role for name: ‘{}", roleName );
247         if ( lastException != null )
248         {
249             throw new RbacManagerException( lastException.getMessage(), lastException );
250         }
251         return null;
252     }
253 
254     @Override
255     public List<Role> getAllRoles()
256         throws RbacManagerException
257     {
258         Map<String, Role> allRoles = new HashMap<>();
259         boolean allFailed = true;
260         Exception lastException = null;
261         for ( RBACManager rbacManager : rbacManagersPerId.values() )
262         {
263             try
264             {
265                 List<? extends Role> roles = rbacManager.getAllRoles();
266                 for ( Role role : roles )
267                 {
268                     allRoles.put( role.getName(), role );
269                 }
270                 allFailed = false;
271             }
272             catch ( Exception e )
273             {
274                 lastException = e;
275             }
276         }
277 
278         if ( lastException != null && allFailed )
279         {
280             throw new RbacManagerException( lastException.getMessage(), lastException );
281         }
282 
283         return new ArrayList<>( allRoles.values() );
284     }
285 
286     @Override
287     public void removeRole( Role role )
288         throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException
289     {
290         boolean allFailed = true;
291         Exception lastException = null;
292         for ( RBACManager rbacManager : rbacManagersPerId.values() )
293         {
294             try
295             {
296                 rbacManager.removeRole( role );
297                 rolesCache.remove( role.getName() );
298                 allFailed = false;
299             }
300             catch ( Exception e )
301             {
302                 lastException = e;
303             }
304         }
305 
306         if ( lastException != null && allFailed )
307         {
308             throw new RbacManagerException( lastException.getMessage(), lastException );
309         }
310     }
311 
312     @Override
313     public Permission createPermission( String name )
314         throws RbacManagerException
315     {
316         return getRbacManagerForWrite().createPermission( name );
317     }
318 
319     @Override
320     public Permission createPermission( String name, String operationName, String resourceIdentifier )
321         throws RbacManagerException
322     {
323         return getRbacManagerForWrite().createPermission( name, operationName, resourceIdentifier );
324     }
325 
326     @Override
327     public Permission savePermission( Permission permission )
328         throws RbacObjectInvalidException, RbacManagerException
329     {
330         boolean allFailed = true;
331         Exception lastException = null;
332         for ( RBACManager rbacManager : rbacManagersPerId.values() )
333         {
334             try
335             {
336                 if ( rbacManager.isReadOnly() )
337                 {
338                     permission = rbacManager.savePermission( permission );
339                     allFailed = false;
340                 }
341             }
342             catch ( Exception e )
343             {
344                 lastException = e;
345             }
346         }
347 
348         if ( lastException != null && allFailed )
349         {
350             throw new RbacManagerException( lastException.getMessage(), lastException );
351         }
352 
353         return permission;
354     }
355 
356     @Override
357     public Permission getPermission( String permissionName )
358         throws RbacObjectNotFoundException, RbacManagerException
359     {
360 
361         Permission el = permissionsCache.get( permissionName );
362         if ( el != null )
363         {
364             return el;
365         }
366 
367         Exception lastException = null;
368         for ( RBACManager rbacManager : rbacManagersPerId.values() )
369         {
370             try
371             {
372                 Permission p = rbacManager.getPermission( permissionName );
373                 if ( p != null )
374                 {
375                     permissionsCache.put( permissionName, p );
376                     return p;
377                 }
378             }
379             catch ( Exception e )
380             {
381                 lastException = e;
382             }
383         }
384 
385         if ( lastException != null )
386         {
387             throw new RbacManagerException( lastException.getMessage(), lastException );
388         }
389         return null;
390     }
391 
392     @Override
393     public List<Permission> getAllPermissions()
394         throws RbacManagerException
395     {
396         Map<String, Permission> allPermissions = new HashMap<>();
397         boolean allFailed = true;
398         Exception lastException = null;
399         for ( RBACManager rbacManager : rbacManagersPerId.values() )
400         {
401             try
402             {
403                 List<? extends Permission> permissions = rbacManager.getAllPermissions();
404                 for ( Permission p : permissions )
405                 {
406                     allPermissions.put( p.getName(), p );
407                 }
408                 allFailed = false;
409             }
410             catch ( Exception e )
411             {
412                 lastException = e;
413             }
414         }
415 
416         if ( lastException != null && allFailed )
417         {
418             throw new RbacManagerException( lastException.getMessage(), lastException );
419         }
420         return new ArrayList<>( allPermissions.values() );
421     }
422 
423     @Override
424     public void removePermission( Permission permission )
425         throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException
426     {
427         boolean allFailed = true;
428         Exception lastException = null;
429         for ( RBACManager rbacManager : rbacManagersPerId.values() )
430         {
431             try
432             {
433                 rbacManager.removePermission( permission );
434                 permissionsCache.remove( permission.getName() );
435                 allFailed = false;
436             }
437             catch ( Exception e )
438             {
439                 lastException = e;
440             }
441         }
442 
443         if ( lastException != null && allFailed )
444         {
445             throw new RbacManagerException( lastException.getMessage(), lastException );
446         }
447     }
448 
449     @Override
450     public Operation createOperation( String name )
451         throws RbacManagerException
452     {
453         return getRbacManagerForWrite().createOperation( name );
454     }
455 
456     @Override
457     public Operation saveOperation( Operation operation )
458         throws RbacObjectInvalidException, RbacManagerException
459     {
460         boolean allFailed = true;
461         Exception lastException = null;
462         for ( RBACManager rbacManager : rbacManagersPerId.values() )
463         {
464             try
465             {
466                 if ( !rbacManager.isReadOnly() )
467                 {
468                     operation = rbacManager.saveOperation( operation );
469                     allFailed = false;
470                 }
471             }
472             catch ( Exception e )
473             {
474                 lastException = e;
475             }
476         }
477 
478         if ( lastException != null && allFailed )
479         {
480             throw new RbacManagerException( lastException.getMessage(), lastException );
481         }
482         return operation;
483     }
484 
485     @Override
486     public Operation getOperation( String operationName )
487         throws RbacObjectNotFoundException, RbacManagerException
488     {
489 
490         Operation el = operationsCache.get( operationName );
491         if ( el != null )
492         {
493             return el;
494         }
495 
496         Exception lastException = null;
497         for ( RBACManager rbacManager : rbacManagersPerId.values() )
498         {
499             try
500             {
501                 Operation o = rbacManager.getOperation( operationName );
502                 if ( o != null )
503                 {
504                     operationsCache.put( operationName, o );
505                     return o;
506                 }
507             }
508             catch ( Exception e )
509             {
510                 lastException = e;
511             }
512         }
513 
514         if ( lastException != null )
515         {
516             throw new RbacManagerException( lastException.getMessage(), lastException );
517         }
518         return null;
519     }
520 
521     @Override
522     public List<Operation> getAllOperations()
523         throws RbacManagerException
524     {
525         Map<String, Operation> allOperations = new HashMap<>();
526         boolean allFailed = true;
527         Exception lastException = null;
528         for ( RBACManager rbacManager : rbacManagersPerId.values() )
529         {
530             try
531             {
532                 List<? extends Operation> operations = rbacManager.getAllOperations();
533                 for ( Operation o : operations )
534                 {
535                     allOperations.put( o.getName(), o );
536                 }
537                 allFailed = false;
538             }
539             catch ( Exception e )
540             {
541                 lastException = e;
542             }
543         }
544 
545         if ( lastException != null && allFailed )
546         {
547             throw new RbacManagerException( lastException.getMessage(), lastException );
548         }
549         return new ArrayList<>( allOperations.values() );
550     }
551 
552     @Override
553     public void removeOperation( Operation operation )
554         throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException
555     {
556         boolean allFailed = true;
557         Exception lastException = null;
558         for ( RBACManager rbacManager : rbacManagersPerId.values() )
559         {
560             try
561             {
562                 rbacManager.removeOperation( operation );
563                 operationsCache.remove( operation.getName() );
564                 allFailed = false;
565             }
566             catch ( Exception e )
567             {
568                 lastException = e;
569             }
570         }
571 
572         if ( lastException != null && allFailed )
573         {
574             throw new RbacManagerException( lastException.getMessage(), lastException );
575         }
576     }
577 
578     @Override
579     public Resource createResource( String identifier )
580         throws RbacManagerException
581     {
582         return getRbacManagerForWrite().createResource( identifier );
583     }
584 
585     @Override
586     public Resource saveResource( Resource resource )
587         throws RbacObjectInvalidException, RbacManagerException
588     {
589         boolean allFailed = true;
590         Exception lastException = null;
591         for ( RBACManager rbacManager : rbacManagersPerId.values() )
592         {
593             try
594             {
595                 if ( !rbacManager.isReadOnly() )
596                 {
597                     resource = rbacManager.saveResource( resource );
598                     allFailed = false;
599                 }
600             }
601             catch ( Exception e )
602             {
603                 lastException = e;
604             }
605         }
606 
607         if ( lastException != null && allFailed )
608         {
609             throw new RbacManagerException( lastException.getMessage(), lastException );
610         }
611         return resource;
612     }
613 
614     @Override
615     public Resource getResource( String resourceIdentifier )
616         throws RbacObjectNotFoundException, RbacManagerException
617     {
618 
619         Resource el = resourcesCache.get( resourceIdentifier );
620         if ( el != null )
621         {
622             return el;
623         }
624 
625         Exception lastException = null;
626         for ( RBACManager rbacManager : rbacManagersPerId.values() )
627         {
628             try
629             {
630                 Resource r = rbacManager.getResource( resourceIdentifier );
631                 if ( r != null )
632                 {
633                     resourcesCache.put( resourceIdentifier, r );
634                     return r;
635                 }
636             }
637             catch ( Exception e )
638             {
639                 lastException = e;
640             }
641         }
642 
643         if ( lastException != null )
644         {
645             throw new RbacManagerException( lastException.getMessage(), lastException );
646         }
647         return null;
648     }
649 
650     @Override
651     public List<Resource> getAllResources()
652         throws RbacManagerException
653     {
654         Map<String, Resource> allResources = new HashMap<>();
655         boolean allFailed = true;
656         Exception lastException = null;
657         for ( RBACManager rbacManager : rbacManagersPerId.values() )
658         {
659             try
660             {
661                 List<? extends Resource> resources = rbacManager.getAllResources();
662                 for ( Resource r : resources )
663                 {
664                     allResources.put( r.getIdentifier(), r );
665                 }
666                 allFailed = false;
667             }
668             catch ( Exception e )
669             {
670                 lastException = e;
671             }
672         }
673 
674         if ( lastException != null && allFailed )
675         {
676             throw new RbacManagerException( lastException.getMessage(), lastException );
677         }
678         return new ArrayList<>( allResources.values() );
679     }
680 
681     @Override
682     public void removeResource( Resource resource )
683         throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException
684     {
685         boolean allFailed = true;
686         Exception lastException = null;
687         for ( RBACManager rbacManager : rbacManagersPerId.values() )
688         {
689             try
690             {
691                 rbacManager.removeResource( resource );
692                 resourcesCache.remove( resource.getIdentifier() );
693                 allFailed = false;
694             }
695             catch ( Exception e )
696             {
697                 lastException = e;
698             }
699         }
700 
701         if ( lastException != null && allFailed )
702         {
703             throw new RbacManagerException( lastException.getMessage(), lastException );
704         }
705     }
706 
707     @Override
708     public UserAssignment createUserAssignment( String principal )
709         throws RbacManagerException
710     {
711         return getRbacManagerForWrite().createUserAssignment( principal );
712     }
713 
714     @Override
715     public UserAssignment saveUserAssignment( UserAssignment userAssignment )
716         throws RbacObjectInvalidException, RbacManagerException
717     {
718         boolean allFailed = true;
719         Exception lastException = null;
720         for ( RBACManager rbacManager : rbacManagersPerId.values() )
721         {
722             try
723             {
724                 if ( !rbacManager.isReadOnly() )
725                 {
726                     userAssignment = rbacManager.saveUserAssignment( userAssignment );
727                     allFailed = false;
728                 }
729             }
730             catch ( Exception e )
731             {
732                 lastException = e;
733             }
734         }
735 
736         if ( lastException != null && allFailed )
737         {
738             throw new RbacManagerException( lastException.getMessage(), lastException );
739         }
740         return userAssignment;
741     }
742 
743     @Override
744     public UserAssignment getUserAssignment( String principal )
745         throws RbacObjectNotFoundException, RbacManagerException
746     {
747         UserAssignment el = userAssignmentsCache.get( principal );
748         if ( el != null )
749         {
750             return el;
751         }
752         UserAssignment ua = null;
753         Exception lastException = null;
754         for ( RBACManager rbacManager : rbacManagersPerId.values() )
755         {
756             try
757             {
758                 if ( ua == null )
759                 {
760                     ua = rbacManager.getUserAssignment( principal );
761                 }
762                 else
763                 {
764                     UserAssignment userAssignment = rbacManager.getUserAssignment( principal );
765                     if ( userAssignment != null )
766                     {
767                         for ( String roleName : userAssignment.getRoleNames() )
768                         {
769                             ua.addRoleName( roleName );
770                         }
771                     }
772                 }
773             }
774             catch ( Exception e )
775             {
776                 lastException = e;
777             }
778         }
779 
780         if ( ua != null )
781         {
782             userAssignmentsCache.put( principal, ua );
783             return ua;
784         }
785 
786         if ( lastException != null )
787         {
788             throw new RbacManagerException( lastException.getMessage(), lastException );
789         }
790         return null;
791     }
792 
793     @Override
794     public boolean userAssignmentExists( String principal )
795     {
796 
797         for ( RBACManager rbacManager : rbacManagersPerId.values() )
798         {
799             try
800             {
801                 boolean exists = rbacManager.userAssignmentExists( principal );
802                 if ( exists )
803                 {
804                     return true;
805                 }
806             }
807             catch ( Exception e )
808             {
809                 // no op
810             }
811         }
812 
813         return false;
814     }
815 
816     @Override
817     public boolean userAssignmentExists( UserAssignment assignment )
818     {
819         for ( RBACManager rbacManager : rbacManagersPerId.values() )
820         {
821             try
822             {
823                 boolean exists = rbacManager.userAssignmentExists( assignment );
824                 if ( exists )
825                 {
826                     return true;
827                 }
828             }
829             catch ( Exception e )
830             {
831                 // no op
832             }
833         }
834 
835         return false;
836     }
837 
838     @Override
839     public List<UserAssignment> getAllUserAssignments()
840         throws RbacManagerException
841     {
842         Map<String, UserAssignment> allUserAssignments = new HashMap<>();
843         boolean allFailed = true;
844         Exception lastException = null;
845         for ( RBACManager rbacManager : rbacManagersPerId.values() )
846         {
847             try
848             {
849                 List<? extends UserAssignment> userAssignments = rbacManager.getAllUserAssignments();
850                 for ( UserAssignment ua : userAssignments )
851                 {
852                     UserAssignment userAssignment = allUserAssignments.get( ua.getPrincipal() );
853                     if ( userAssignment != null )
854                     {
855                         for ( String roleName : ua.getRoleNames() )
856                         {
857                             userAssignment.addRoleName( roleName );
858                         }
859                     }
860                     allUserAssignments.put( ua.getPrincipal(), ua );
861                 }
862                 allFailed = false;
863             }
864             catch ( Exception e )
865             {
866                 lastException = e;
867             }
868         }
869 
870         if ( lastException != null && allFailed )
871         {
872             throw new RbacManagerException( lastException.getMessage(), lastException );
873         }
874         return new ArrayList<>( allUserAssignments.values() );
875     }
876 
877     @Override
878     public List<UserAssignment> getUserAssignmentsForRoles( Collection<String> roleNames )
879         throws RbacManagerException
880     {
881         List<UserAssignment> allUserAssignments = new ArrayList<>();
882         boolean allFailed = true;
883         Exception lastException = null;
884         for ( RBACManager rbacManager : rbacManagersPerId.values() )
885         {
886             try
887             {
888                 List<? extends UserAssignment> userAssignments = rbacManager.getUserAssignmentsForRoles( roleNames );
889 
890                 allUserAssignments.addAll( userAssignments );
891 
892                 allFailed = false;
893             }
894             catch ( Exception e )
895             {
896                 lastException = e;
897             }
898         }
899 
900         if ( lastException != null && allFailed )
901         {
902             throw new RbacManagerException( lastException.getMessage(), lastException );
903         }
904         return allUserAssignments;
905     }
906 
907     @Override
908     public void removeUserAssignment( UserAssignment userAssignment )
909         throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException
910     {
911         boolean allFailed = true;
912         Exception lastException = null;
913         for ( RBACManager rbacManager : rbacManagersPerId.values() )
914         {
915             try
916             {
917                 rbacManager.removeUserAssignment( userAssignment );
918                 userAssignmentsCache.remove( userAssignment.getPrincipal() );
919                 allFailed = false;
920             }
921             catch ( Exception e )
922             {
923                 lastException = e;
924             }
925         }
926 
927         if ( lastException != null && allFailed )
928         {
929             throw new RbacManagerException( lastException.getMessage(), lastException );
930         }
931     }
932 
933     @Override
934     public boolean roleExists( String name )
935         throws RbacManagerException
936     {
937         Role r = rolesCache.get( name );
938         if ( r != null )
939         {
940             return true;
941         }
942 
943         boolean allFailed = true;
944         Exception lastException = null;
945         for ( RBACManager rbacManager : rbacManagersPerId.values() )
946         {
947             try
948             {
949                 boolean exists = rbacManager.roleExists( name );
950                 if ( exists )
951                 {
952                     return true;
953                 }
954             }
955             catch ( Exception e )
956             {
957                 lastException = e;
958             }
959         }
960 
961         if ( lastException != null && allFailed )
962         {
963             throw new RbacManagerException( lastException.getMessage(), lastException );
964         }
965         return false;
966     }
967 
968     @Override
969     public boolean roleExists( Role role )
970         throws RbacManagerException
971     {
972         return roleExists( role.getName() );
973     }
974 
975     @Override
976     public void eraseDatabase()
977     {
978         log.warn( "eraseDatabase not implemented" );
979     }
980 
981     @Override
982     public boolean isFinalImplementation()
983     {
984         return false;
985     }
986 
987     @Override
988     public String getDescriptionKey()
989     {
990         return "archiva.redback.rbacmanager.archiva";
991     }
992 
993     @Override
994     public boolean isReadOnly()
995     {
996         return false;
997     }
998 }