diff --git a/redback-authorization/redback-authorization-providers/redback-authorization-rbac/src/main/java/org/apache/archiva/redback/authorization/rbac/RbacAuthorizer.java b/redback-authorization/redback-authorization-providers/redback-authorization-rbac/src/main/java/org/apache/archiva/redback/authorization/rbac/RbacAuthorizer.java index 33dde907..888c5084 100644 --- a/redback-authorization/redback-authorization-providers/redback-authorization-rbac/src/main/java/org/apache/archiva/redback/authorization/rbac/RbacAuthorizer.java +++ b/redback-authorization/redback-authorization-providers/redback-authorization-rbac/src/main/java/org/apache/archiva/redback/authorization/rbac/RbacAuthorizer.java @@ -87,7 +87,7 @@ public class RbacAuthorizer if ( principal != null ) { // Set permissions = manager.getAssignedPermissions( principal.toString(), operation ); - Map> permissionMap = manager.getAssignedPermissionMap( principal ); + Map> permissionMap = manager.getAssignedPermissionMap( principal ); if ( permissionMap.keySet().contains( operation ) ) { @@ -116,7 +116,7 @@ public class RbacAuthorizer if ( !guest.isLocked() ) { // Set permissions = manager.getAssignedPermissions( principal.toString(), operation ); - Map> permissionMap = manager.getAssignedPermissionMap( guest.getUsername() ); + Map> permissionMap = manager.getAssignedPermissionMap( guest.getUsername() ); if ( permissionMap.keySet().contains( operation ) ) { diff --git a/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java b/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java index c8920c6a..77c44de5 100644 --- a/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java +++ b/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java @@ -254,8 +254,8 @@ public class DataManagementTest dataManagementTool.restoreRBACDatabase( manager, targetDirectory ); - List roles = manager.getAllRoles(); - List assignments = manager.getAllUserAssignments(); + List roles = manager.getAllRoles(); + List assignments = manager.getAllUserAssignments(); assertEquals( 4, roles.size() ); assertEquals( 2, assignments.size() ); assertEquals( 6, manager.getAllOperations().size() ); diff --git a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/LockedAdminEnvironmentCheck.java b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/LockedAdminEnvironmentCheck.java index 8d05e68a..35806375 100644 --- a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/LockedAdminEnvironmentCheck.java +++ b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/LockedAdminEnvironmentCheck.java @@ -76,7 +76,7 @@ public class LockedAdminEnvironmentCheck List roles = new ArrayList(); roles.add( RedbackRoleConstants.SYSTEM_ADMINISTRATOR_ROLE ); - List systemAdminstrators; + List systemAdminstrators; try { systemAdminstrators = rbacManager.getUserAssignmentsForRoles( roles ); diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultRoleManagementService.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultRoleManagementService.java index ee3fbb04..9ad643b6 100644 --- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultRoleManagementService.java +++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultRoleManagementService.java @@ -253,7 +253,7 @@ public class DefaultRoleManagementService } try { - List roles = + List roles = filterAssignableRoles( rbacManager.getEffectivelyAssignedRoles( username ) ); List effectivelyAssignedRoles = new ArrayList( roles.size() ); @@ -312,7 +312,7 @@ public class DefaultRoleManagementService { try { - List roles = rbacManager.getAllRoles(); + List roles = rbacManager.getAllRoles(); if ( roles == null ) { @@ -341,7 +341,7 @@ public class DefaultRoleManagementService { try { - List roles = rbacManager.getAllRoles(); + List roles = rbacManager.getAllRoles(); if ( roles == null ) { @@ -365,8 +365,8 @@ public class DefaultRoleManagementService } } - private List filterAssignableRoles( - Collection roles ) + private List filterAssignableRoles( + Collection roles ) { List assignableRoles = new ArrayList( roles.size() ); @@ -388,13 +388,13 @@ public class DefaultRoleManagementService org.apache.archiva.redback.rbac.Role rbacRole = rbacManager.getRole( roleName ); Role role = new Role( rbacRole ); - Map parentRoles = rbacManager.getParentRoles( rbacRole ); + Map parentRoles = rbacManager.getParentRoles( rbacRole ); for ( String parentRoleName : parentRoles.keySet() ) { role.getParentRoleNames().add( parentRoleName ); } - List userAssignments = rbacManager.getUserAssignmentsForRoles( Arrays.asList( roleName ) ); + List userAssignments = rbacManager.getUserAssignmentsForRoles( Arrays.asList( roleName ) ); if ( userAssignments != null ) { @@ -414,7 +414,7 @@ public class DefaultRoleManagementService if ( !role.getParentRoleNames().isEmpty() ) { - List userParentAssignments = + List userParentAssignments = rbacManager.getUserAssignmentsForRoles( parentRoles.keySet() ); if ( userParentAssignments != null ) { @@ -614,7 +614,7 @@ public class DefaultRoleManagementService rbacManager.saveUserAssignment( assignment ); } - List allRoles = + List allRoles = filterRolesForCurrentUserAccess( rbacManager.getAllRoles() ); List modelApplications = roleManager.getModel().getApplications(); @@ -628,7 +628,7 @@ public class DefaultRoleManagementService applicationRoles.setDescription( modelApplication.getDescription() ); applicationRoles.setName( modelApplication.getId() ); - Collection appRoles = + Collection appRoles = filterApplicationRoles( modelApplication, allRoles, modelApplication.getTemplates() ); List roleNames = new ArrayList( toRoleNames( appRoles ) ); @@ -750,7 +750,7 @@ public class DefaultRoleManagementService //---------------------------------------------------------------- private org.apache.archiva.redback.rbac.Role isInList( String roleName, - Collection roles ) + Collection roles ) { for ( org.apache.archiva.redback.rbac.Role role : roles ) { @@ -762,8 +762,8 @@ public class DefaultRoleManagementService return null; } - private Collection filterApplicationRoles( ModelApplication application, - List allRoles, + private Collection filterApplicationRoles( ModelApplication application, + List allRoles, List applicationTemplates ) { Set applicationRoles = @@ -810,7 +810,7 @@ public class DefaultRoleManagementService return false; } - private List toRoleNames( Collection roles ) + private List toRoleNames( Collection roles ) { List names = new ArrayList( roles.size() ); @@ -847,7 +847,7 @@ public class DefaultRoleManagementService } private Set discoverResources( List applicationTemplates, - Collection roles ) + Collection roles ) { Set resources = new HashSet(); for ( ModelTemplate modelTemplate : applicationTemplates ) @@ -876,8 +876,8 @@ public class DefaultRoleManagementService * @throws RedbackServiceException * */ - protected List filterRolesForCurrentUserAccess( - List roleList ) + protected List filterRolesForCurrentUserAccess( + List roleList ) throws RedbackServiceException { RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get(); @@ -892,12 +892,12 @@ public class DefaultRoleManagementService new ArrayList(); try { - Map> assignedPermissionMap = rbacManager.getAssignedPermissionMap( currentUser ); + Map> assignedPermissionMap = rbacManager.getAssignedPermissionMap( currentUser ); List resourceGrants = new ArrayList(); if ( assignedPermissionMap.containsKey( RedbackRoleConstants.USER_MANAGEMENT_ROLE_GRANT_OPERATION ) ) { - List roleGrantPermissions = + List roleGrantPermissions = assignedPermissionMap.get( RedbackRoleConstants.USER_MANAGEMENT_ROLE_GRANT_OPERATION ); for ( Permission permission : roleGrantPermissions ) diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java index d85ad416..8759da44 100644 --- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java +++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java @@ -842,7 +842,7 @@ public class DefaultUserService { try { - Set permissions = + Set permissions = rbacManager.getAssignedPermissions( userName ); // FIXME return guest permissions !! List userPermissions = new ArrayList( permissions.size() ); diff --git a/redback-rbac/redback-rbac-model/src/main/java/org/apache/archiva/redback/rbac/AbstractRBACManager.java b/redback-rbac/redback-rbac-model/src/main/java/org/apache/archiva/redback/rbac/AbstractRBACManager.java index 537ad167..eaba5ced 100644 --- a/redback-rbac/redback-rbac-model/src/main/java/org/apache/archiva/redback/rbac/AbstractRBACManager.java +++ b/redback-rbac/redback-rbac-model/src/main/java/org/apache/archiva/redback/rbac/AbstractRBACManager.java @@ -30,6 +30,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; /** * AbstractRBACManager @@ -45,18 +47,21 @@ public abstract class AbstractRBACManager private Resource globalResource; + @Override @PostConstruct public void initialize() { //no op } + @Override public boolean isFinalImplementation() { return false; } + @Override public void addListener( RBACManagerListener listener ) { if ( !listeners.contains( listener ) ) @@ -65,6 +70,7 @@ public abstract class AbstractRBACManager } } + @Override public void removeListener( RBACManagerListener listener ) { listeners.remove( listener ); @@ -179,36 +185,42 @@ public abstract class AbstractRBACManager } } + @Override public void removeRole( String roleName ) throws RbacObjectNotFoundException, RbacManagerException { removeRole( getRole( roleName ) ); } + @Override public void removePermission( String permissionName ) throws RbacObjectNotFoundException, RbacManagerException { removePermission( getPermission( permissionName ) ); } + @Override public void removeOperation( String operationName ) throws RbacObjectNotFoundException, RbacManagerException { removeOperation( getOperation( operationName ) ); } + @Override public void removeResource( String resourceIdentifier ) throws RbacObjectNotFoundException, RbacManagerException { removeResource( getResource( resourceIdentifier ) ); } + @Override public void removeUserAssignment( String principal ) throws RbacObjectNotFoundException, RbacManagerException { removeUserAssignment( getUserAssignment( principal ) ); } + @Override public boolean resourceExists( Resource resource ) { try @@ -221,6 +233,7 @@ public abstract class AbstractRBACManager } } + @Override public boolean resourceExists( String identifier ) { try @@ -241,6 +254,7 @@ public abstract class AbstractRBACManager return false; } + @Override public boolean operationExists( Operation operation ) { try @@ -253,6 +267,7 @@ public abstract class AbstractRBACManager } } + @Override public boolean operationExists( String name ) { try @@ -273,6 +288,7 @@ public abstract class AbstractRBACManager return false; } + @Override public boolean permissionExists( Permission permission ) { try @@ -285,6 +301,7 @@ public abstract class AbstractRBACManager } } + @Override public boolean permissionExists( String name ) { try @@ -305,6 +322,7 @@ public abstract class AbstractRBACManager return false; } + @Override public boolean roleExists( Role role ) throws RbacManagerException { @@ -318,6 +336,7 @@ public abstract class AbstractRBACManager } } + @Override public boolean roleExists( String name ) throws RbacManagerException { @@ -339,6 +358,7 @@ public abstract class AbstractRBACManager return false; } + @Override public boolean userAssignmentExists( String principal ) { try @@ -359,6 +379,7 @@ public abstract class AbstractRBACManager return false; } + @Override public boolean userAssignmentExists( UserAssignment assignment ) { try @@ -380,7 +401,8 @@ public abstract class AbstractRBACManager * @throws RbacObjectNotFoundException * @throws RbacManagerException */ - public Set getAssignedPermissions( String principal ) + @Override + public Set getAssignedPermissions( String principal ) throws RbacObjectNotFoundException, RbacManagerException { @@ -426,33 +448,18 @@ public abstract class AbstractRBACManager * @throws RbacObjectNotFoundException * @throws RbacManagerException */ - public Map> getAssignedPermissionMap( String principal ) + @Override + public Map> getAssignedPermissionMap( String principal ) throws RbacObjectNotFoundException, RbacManagerException { return getPermissionMapByOperation( getAssignedPermissions( principal ) ); } - private Map> getPermissionMapByOperation( Collection permissions ) + private Map> getPermissionMapByOperation( Collection permissions ) { - Map> userPermMap = new HashMap>(); - - for ( Permission permission : permissions ) - { - List permList = userPermMap.get( permission.getOperation().getName() ); - - if ( permList != null ) - { - permList.add( permission ); - } - else - { - List newPermList = new ArrayList( permissions.size() ); - newPermList.add( permission ); - userPermMap.put( permission.getOperation().getName(), newPermList ); - } - } - - return userPermMap; + Map> tList = new HashMap<>( ); + tList.putAll( permissions.stream().collect( Collectors.groupingBy( p -> p.getOperation( ).getName( ) ) ) ); + return tList; } private void gatherUniquePermissions( Role role, Collection coll ) @@ -471,8 +478,8 @@ public abstract class AbstractRBACManager if ( role.hasChildRoles() ) { - Map childRoles = getChildRoles( role ); - Iterator it = childRoles.values().iterator(); + Map childRoles = getChildRoles( role ); + Iterator it = childRoles.values().iterator(); while ( it.hasNext() ) { Role child = it.next(); @@ -481,6 +488,7 @@ public abstract class AbstractRBACManager } } + @Override public List getAllAssignableRoles() throws RbacManagerException, RbacObjectNotFoundException { @@ -509,6 +517,7 @@ public abstract class AbstractRBACManager * @throws RbacObjectNotFoundException * @throws RbacManagerException */ + @Override public Collection getAssignedRoles( String principal ) throws RbacObjectNotFoundException, RbacManagerException { @@ -526,6 +535,7 @@ public abstract class AbstractRBACManager * @throws RbacObjectNotFoundException * @throws RbacManagerException */ + @Override public Collection getAssignedRoles( UserAssignment ua ) throws RbacObjectNotFoundException, RbacManagerException { @@ -604,6 +614,7 @@ public abstract class AbstractRBACManager } } + @Override public Collection getEffectivelyAssignedRoles( String principal ) throws RbacObjectNotFoundException, RbacManagerException { @@ -653,6 +664,7 @@ public abstract class AbstractRBACManager * @throws RbacManagerException * @throws RbacObjectNotFoundException */ + @Override public Collection getEffectivelyUnassignedRoles( String principal ) throws RbacManagerException, RbacObjectNotFoundException { @@ -672,6 +684,7 @@ public abstract class AbstractRBACManager * @throws RbacManagerException * @throws RbacObjectNotFoundException */ + @Override public Collection getUnassignedRoles( String principal ) throws RbacManagerException, RbacObjectNotFoundException { @@ -684,6 +697,7 @@ public abstract class AbstractRBACManager return CollectionUtils.subtract( allRoles, assignedRoles ); } + @Override public Resource getGlobalResource() throws RbacManagerException { @@ -696,6 +710,7 @@ public abstract class AbstractRBACManager return globalResource; } + @Override public void addChildRole( Role role, Role childRole ) throws RbacObjectInvalidException, RbacManagerException { @@ -703,7 +718,8 @@ public abstract class AbstractRBACManager role.addChildRoleName( childRole.getName() ); } - public Map getChildRoles( Role role ) + @Override + public Map getChildRoles( Role role ) throws RbacManagerException { Map childRoles = new HashMap(); @@ -759,7 +775,8 @@ public abstract class AbstractRBACManager return childRoles; } - public Map getParentRoles( Role role ) + @Override + public Map getParentRoles( Role role ) throws RbacManagerException { Map parentRoles = new HashMap(); @@ -768,7 +785,7 @@ public abstract class AbstractRBACManager { if ( !r.getName().equals( role.getName() ) ) { - Set effectiveRoles = getEffectiveRoles( r ); + Set effectiveRoles = getEffectiveRoles( r ); for ( Role currentRole : effectiveRoles ) { if ( currentRole.getName().equals( role.getName() ) ) @@ -784,7 +801,8 @@ public abstract class AbstractRBACManager return parentRoles; } - public Set getEffectiveRoles( Role role ) + @Override + public Set getEffectiveRoles( Role role ) throws RbacObjectNotFoundException, RbacManagerException { Set roleSet = new HashSet(); @@ -793,7 +811,8 @@ public abstract class AbstractRBACManager return roleSet; } - public Map getRoles( Collection roleNames ) + @Override + public Map getRoles( Collection roleNames ) throws RbacObjectNotFoundException, RbacManagerException { Map roleMap = new HashMap(); diff --git a/redback-rbac/redback-rbac-model/src/main/java/org/apache/archiva/redback/rbac/RBACManager.java b/redback-rbac/redback-rbac-model/src/main/java/org/apache/archiva/redback/rbac/RBACManager.java index 34cdcdf8..9299cb08 100644 --- a/redback-rbac/redback-rbac-model/src/main/java/org/apache/archiva/redback/rbac/RBACManager.java +++ b/redback-rbac/redback-rbac-model/src/main/java/org/apache/archiva/redback/rbac/RBACManager.java @@ -81,28 +81,28 @@ public interface RBACManager Role getRole( String roleName ) throws RbacObjectNotFoundException, RbacManagerException; - Map getRoles( Collection roleNames ) + Map getRoles( Collection roleNames ) throws RbacObjectNotFoundException, RbacManagerException; void addChildRole( Role role, Role childRole ) throws RbacObjectInvalidException, RbacManagerException; - Map getChildRoles( Role role ) + Map getChildRoles( Role role ) throws RbacManagerException; - Map getParentRoles( Role role ) + Map getParentRoles( Role role ) throws RbacManagerException; /** * Method getRoles */ - List getAllRoles() + List getAllRoles() throws RbacManagerException; /** * Method getEffectiveRoles */ - Set getEffectiveRoles( Role role ) + Set getEffectiveRoles( Role role ) throws RbacObjectNotFoundException, RbacManagerException; /** @@ -169,7 +169,7 @@ public interface RBACManager Permission getPermission( String permissionName ) throws RbacObjectNotFoundException, RbacManagerException; - List getAllPermissions() + List getAllPermissions() throws RbacManagerException; void removePermission( Permission permission ) @@ -213,7 +213,7 @@ public interface RBACManager Operation getOperation( String operationName ) throws RbacObjectNotFoundException, RbacManagerException; - List getAllOperations() + List getAllOperations() throws RbacManagerException; void removeOperation( Operation operation ) @@ -249,7 +249,7 @@ public interface RBACManager Resource getResource( String resourceIdentifier ) throws RbacObjectNotFoundException, RbacManagerException; - List getAllResources() + List getAllResources() throws RbacManagerException; void removeResource( Resource resource ) @@ -293,13 +293,13 @@ public interface RBACManager /** * Method getAssignments */ - List getAllUserAssignments() + List getAllUserAssignments() throws RbacManagerException; /** * Method getUserAssignmentsForRoless */ - List getUserAssignmentsForRoles( Collection roleNames ) + List getUserAssignmentsForRoles( Collection roleNames ) throws RbacManagerException; /** @@ -333,7 +333,7 @@ public interface RBACManager * @throws RbacObjectNotFoundException * @throws RbacManagerException */ - Collection getAssignedRoles( String principal ) + Collection getAssignedRoles( String principal ) throws RbacObjectNotFoundException, RbacManagerException; /** @@ -342,7 +342,7 @@ public interface RBACManager * @param userAssignment * @return Collection of {@link Role} objects for the provided UserAssignment. */ - Collection getAssignedRoles( UserAssignment userAssignment ) + Collection getAssignedRoles( UserAssignment userAssignment ) throws RbacObjectNotFoundException, RbacManagerException; /** @@ -354,7 +354,7 @@ public interface RBACManager * @throws RbacManagerException * @throws RbacObjectNotFoundException */ - Collection getEffectivelyUnassignedRoles( String principal ) + Collection getEffectivelyUnassignedRoles( String principal ) throws RbacManagerException, RbacObjectNotFoundException; /** @@ -365,7 +365,7 @@ public interface RBACManager * @throws RbacObjectNotFoundException * @throws RbacManagerException */ - Collection getEffectivelyAssignedRoles( String principal ) + Collection getEffectivelyAssignedRoles( String principal ) throws RbacObjectNotFoundException, RbacManagerException; /** @@ -376,7 +376,7 @@ public interface RBACManager * @throws RbacManagerException * @throws RbacObjectNotFoundException */ - Collection getUnassignedRoles( String principal ) + Collection getUnassignedRoles( String principal ) throws RbacManagerException, RbacObjectNotFoundException; /** @@ -388,7 +388,7 @@ public interface RBACManager * @throws RbacObjectNotFoundException * @throws RbacManagerException */ - Set getAssignedPermissions( String principal ) + Set getAssignedPermissions( String principal ) throws RbacObjectNotFoundException, RbacManagerException; /** @@ -399,7 +399,7 @@ public interface RBACManager * @throws RbacObjectNotFoundException * @throws RbacManagerException */ - Map> getAssignedPermissionMap( String principal ) + Map> getAssignedPermissionMap( String principal ) throws RbacObjectNotFoundException, RbacManagerException; /** @@ -409,7 +409,7 @@ public interface RBACManager * @throws RbacManagerException * @throws RbacObjectNotFoundException */ - List getAllAssignableRoles() + List getAllAssignableRoles() throws RbacManagerException, RbacObjectNotFoundException; /** diff --git a/redback-rbac/redback-rbac-model/src/main/java/org/apache/archiva/redback/rbac/Role.java b/redback-rbac/redback-rbac-model/src/main/java/org/apache/archiva/redback/rbac/Role.java index d1f293e1..3e2405e8 100644 --- a/redback-rbac/redback-rbac-model/src/main/java/org/apache/archiva/redback/rbac/Role.java +++ b/redback-rbac/redback-rbac-model/src/main/java/org/apache/archiva/redback/rbac/Role.java @@ -77,7 +77,7 @@ public interface Role /** * Method getPermissions */ - List getPermissions(); + List getPermissions(); /** * true if this role is available to be assigned to a user diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/main/java/org/apache/archiva/redback/rbac/cached/CachedRbacManager.java b/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/main/java/org/apache/archiva/redback/rbac/cached/CachedRbacManager.java index 61c62eee..cbcb9b87 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/main/java/org/apache/archiva/redback/rbac/cached/CachedRbacManager.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/main/java/org/apache/archiva/redback/rbac/cached/CachedRbacManager.java @@ -79,17 +79,19 @@ public class CachedRbacManager @Inject @Named( value = "cache#userPermissions" ) - private Cache>> userPermissionsCache; + private Cache>> userPermissionsCache; @Inject @Named( value = "cache#effectiveRoleSet" ) - private Cache> effectiveRoleSetCache; + private Cache> effectiveRoleSetCache; + @Override public void initialize() { // no op } + @Override public void addChildRole( Role role, Role childRole ) throws RbacObjectInvalidException, RbacManagerException { @@ -104,11 +106,13 @@ public class CachedRbacManager } } + @Override public void addListener( RBACManagerListener listener ) { this.rbacImpl.addListener( listener ); } + @Override public Operation createOperation( String name ) throws RbacManagerException { @@ -116,6 +120,7 @@ public class CachedRbacManager return this.rbacImpl.createOperation( name ); } + @Override public Permission createPermission( String name ) throws RbacManagerException { @@ -123,6 +128,7 @@ public class CachedRbacManager return this.rbacImpl.createPermission( name ); } + @Override public Permission createPermission( String name, String operationName, String resourceIdentifier ) throws RbacManagerException { @@ -130,6 +136,7 @@ public class CachedRbacManager return this.rbacImpl.createPermission( name, operationName, resourceIdentifier ); } + @Override public Resource createResource( String identifier ) throws RbacManagerException { @@ -137,12 +144,14 @@ public class CachedRbacManager return this.rbacImpl.createResource( identifier ); } + @Override public Role createRole( String name ) { rolesCache.remove( name ); return this.rbacImpl.createRole( name ); } + @Override public UserAssignment createUserAssignment( String principal ) throws RbacManagerException { @@ -150,6 +159,7 @@ public class CachedRbacManager return this.rbacImpl.createUserAssignment( principal ); } + @Override public void eraseDatabase() { try @@ -166,42 +176,48 @@ public class CachedRbacManager /** * @see org.apache.archiva.redback.rbac.RBACManager#getAllAssignableRoles() */ - public List getAllAssignableRoles() + @Override + public List getAllAssignableRoles() throws RbacManagerException, RbacObjectNotFoundException { log.debug( "NOT CACHED - .getAllAssignableRoles()" ); return this.rbacImpl.getAllAssignableRoles(); } - public List getAllOperations() + @Override + public List getAllOperations() throws RbacManagerException { log.debug( "NOT CACHED - .getAllOperations()" ); return this.rbacImpl.getAllOperations(); } - public List getAllPermissions() + @Override + public List getAllPermissions() throws RbacManagerException { log.debug( "NOT CACHED - .getAllPermissions()" ); return this.rbacImpl.getAllPermissions(); } - public List getAllResources() + @Override + public List getAllResources() throws RbacManagerException { log.debug( "NOT CACHED - .getAllResources()" ); return this.rbacImpl.getAllResources(); } - public List getAllRoles() + @Override + public List getAllRoles() throws RbacManagerException { log.debug( "NOT CACHED - .getAllRoles()" ); return this.rbacImpl.getAllRoles(); } - public List getAllUserAssignments() + @Override + public List getAllUserAssignments() throws RbacManagerException { log.debug( "NOT CACHED - .getAllUserAssignments()" ); @@ -211,11 +227,12 @@ public class CachedRbacManager /** * @see org.apache.archiva.redback.rbac.RBACManager#getAssignedPermissionMap(java.lang.String) */ + @Override @SuppressWarnings( "unchecked" ) - public Map> getAssignedPermissionMap( String principal ) + public Map> getAssignedPermissionMap( String principal ) throws RbacObjectNotFoundException, RbacManagerException { - Map> el = userPermissionsCache.get( principal ); + Map> el = userPermissionsCache.get( principal ); if ( el != null ) { @@ -224,66 +241,74 @@ public class CachedRbacManager } log.debug( "building user permission map" ); - Map> userPermMap = this.rbacImpl.getAssignedPermissionMap( principal ); + Map> userPermMap = this.rbacImpl.getAssignedPermissionMap( principal ); userPermissionsCache.put( principal, userPermMap ); return userPermMap; } - public Set getAssignedPermissions( String principal ) + @Override + public Set getAssignedPermissions( String principal ) throws RbacObjectNotFoundException, RbacManagerException { log.debug( "NOT CACHED - .getAssignedPermissions(String)" ); return this.rbacImpl.getAssignedPermissions( principal ); } - public Collection getAssignedRoles( String principal ) + @Override + public Collection getAssignedRoles( String principal ) throws RbacObjectNotFoundException, RbacManagerException { log.debug( "NOT CACHED - .getAssignedRoles(String)" ); return this.rbacImpl.getAssignedRoles( principal ); } - public Collection getAssignedRoles( UserAssignment userAssignment ) + @Override + public Collection getAssignedRoles( UserAssignment userAssignment ) throws RbacObjectNotFoundException, RbacManagerException { log.debug( "NOT CACHED - .getAssignedRoles(UserAssignment)" ); return this.rbacImpl.getAssignedRoles( userAssignment ); } - public Map getChildRoles( Role role ) + @Override + public Map getChildRoles( Role role ) throws RbacManagerException { log.debug( "NOT CACHED - .getChildRoles(Role)" ); return this.rbacImpl.getChildRoles( role ); } - public Map getParentRoles( Role role ) + @Override + public Map getParentRoles( Role role ) throws RbacManagerException { log.debug( "NOT CACHED - .getParentRoles(Role)" ); return this.rbacImpl.getParentRoles( role ); } - public Collection getEffectivelyAssignedRoles( String principal ) + @Override + public Collection getEffectivelyAssignedRoles( String principal ) throws RbacObjectNotFoundException, RbacManagerException { log.debug( "NOT CACHED - .getEffectivelyAssignedRoles(String)" ); return this.rbacImpl.getEffectivelyAssignedRoles( principal ); } - public Collection getEffectivelyUnassignedRoles( String principal ) + @Override + public Collection getEffectivelyUnassignedRoles( String principal ) throws RbacManagerException, RbacObjectNotFoundException { log.debug( "NOT CACHED - .getEffectivelyUnassignedRoles(String)" ); return this.rbacImpl.getEffectivelyUnassignedRoles( principal ); } + @Override @SuppressWarnings( "unchecked" ) - public Set getEffectiveRoles( Role role ) + public Set getEffectiveRoles( Role role ) throws RbacObjectNotFoundException, RbacManagerException { - Set el = effectiveRoleSetCache.get( role.getName() ); + Set el = effectiveRoleSetCache.get( role.getName() ); if ( el != null ) { @@ -293,12 +318,13 @@ public class CachedRbacManager else { log.debug( "building effective role set" ); - Set effectiveRoleSet = this.rbacImpl.getEffectiveRoles( role ); + Set effectiveRoleSet = this.rbacImpl.getEffectiveRoles( role ); effectiveRoleSetCache.put( role.getName(), effectiveRoleSet ); return effectiveRoleSet; } } + @Override public Resource getGlobalResource() throws RbacManagerException { @@ -307,6 +333,7 @@ public class CachedRbacManager return this.rbacImpl.getGlobalResource(); } + @Override public Operation getOperation( String operationName ) throws RbacObjectNotFoundException, RbacManagerException { @@ -323,6 +350,7 @@ public class CachedRbacManager } } + @Override public Permission getPermission( String permissionName ) throws RbacObjectNotFoundException, RbacManagerException { @@ -339,6 +367,7 @@ public class CachedRbacManager } } + @Override public Resource getResource( String resourceIdentifier ) throws RbacObjectNotFoundException, RbacManagerException { @@ -355,6 +384,7 @@ public class CachedRbacManager } } + @Override public Role getRole( String roleName ) throws RbacObjectNotFoundException, RbacManagerException { @@ -371,20 +401,23 @@ public class CachedRbacManager } } - public Map getRoles( Collection roleNames ) + @Override + public Map getRoles( Collection roleNames ) throws RbacObjectNotFoundException, RbacManagerException { log.debug( "NOT CACHED - .getRoles(Collection)" ); return this.rbacImpl.getRoles( roleNames ); } - public Collection getUnassignedRoles( String principal ) + @Override + public Collection getUnassignedRoles( String principal ) throws RbacManagerException, RbacObjectNotFoundException { log.debug( "NOT CACHED - .getUnassignedRoles(String)" ); return this.rbacImpl.getUnassignedRoles( principal ); } + @Override public UserAssignment getUserAssignment( String principal ) throws RbacObjectNotFoundException, RbacManagerException { @@ -401,13 +434,15 @@ public class CachedRbacManager } } - public List getUserAssignmentsForRoles( Collection roleNames ) + @Override + public List getUserAssignmentsForRoles( Collection roleNames ) throws RbacManagerException { log.debug( "NOT CACHED - .getUserAssignmentsForRoles(Collection)" ); return this.rbacImpl.getUserAssignmentsForRoles( roleNames ); } + @Override public boolean operationExists( Operation operation ) { if ( operation == null ) @@ -423,6 +458,7 @@ public class CachedRbacManager return this.rbacImpl.operationExists( operation ); } + @Override public boolean operationExists( String name ) { if ( operationsCache.hasKey( name ) ) @@ -433,6 +469,7 @@ public class CachedRbacManager return this.rbacImpl.operationExists( name ); } + @Override public boolean permissionExists( Permission permission ) { if ( permission == null ) @@ -448,6 +485,7 @@ public class CachedRbacManager return this.rbacImpl.permissionExists( permission ); } + @Override public boolean permissionExists( String name ) { if ( permissionsCache.hasKey( name ) ) @@ -458,6 +496,7 @@ public class CachedRbacManager return this.rbacImpl.permissionExists( name ); } + @Override public void rbacInit( boolean freshdb ) { if ( rbacImpl instanceof RBACManagerListener ) @@ -473,6 +512,7 @@ public class CachedRbacManager this.userPermissionsCache.clear(); } + @Override public void rbacPermissionRemoved( Permission permission ) { if ( rbacImpl instanceof RBACManagerListener ) @@ -483,6 +523,7 @@ public class CachedRbacManager invalidateCachedPermission( permission ); } + @Override public void rbacPermissionSaved( Permission permission ) { if ( rbacImpl instanceof RBACManagerListener ) @@ -493,6 +534,7 @@ public class CachedRbacManager invalidateCachedPermission( permission ); } + @Override public void rbacRoleRemoved( Role role ) { if ( rbacImpl instanceof RBACManagerListener ) @@ -503,6 +545,7 @@ public class CachedRbacManager invalidateCachedRole( role ); } + @Override public void rbacRoleSaved( Role role ) { if ( rbacImpl instanceof RBACManagerListener ) @@ -513,6 +556,7 @@ public class CachedRbacManager invalidateCachedRole( role ); } + @Override public void rbacUserAssignmentRemoved( UserAssignment userAssignment ) { if ( rbacImpl instanceof RBACManagerListener ) @@ -523,6 +567,7 @@ public class CachedRbacManager invalidateCachedUserAssignment( userAssignment ); } + @Override public void rbacUserAssignmentSaved( UserAssignment userAssignment ) { if ( rbacImpl instanceof RBACManagerListener ) @@ -533,11 +578,13 @@ public class CachedRbacManager invalidateCachedUserAssignment( userAssignment ); } + @Override public void removeListener( RBACManagerListener listener ) { this.rbacImpl.removeListener( listener ); } + @Override public void removeOperation( Operation operation ) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { @@ -545,6 +592,7 @@ public class CachedRbacManager this.rbacImpl.removeOperation( operation ); } + @Override public void removeOperation( String operationName ) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { @@ -552,6 +600,7 @@ public class CachedRbacManager this.rbacImpl.removeOperation( operationName ); } + @Override public void removePermission( Permission permission ) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { @@ -559,6 +608,7 @@ public class CachedRbacManager this.rbacImpl.removePermission( permission ); } + @Override public void removePermission( String permissionName ) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { @@ -566,6 +616,7 @@ public class CachedRbacManager this.rbacImpl.removePermission( permissionName ); } + @Override public void removeResource( Resource resource ) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { @@ -573,6 +624,7 @@ public class CachedRbacManager this.rbacImpl.removeResource( resource ); } + @Override public void removeResource( String resourceIdentifier ) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { @@ -580,6 +632,7 @@ public class CachedRbacManager this.rbacImpl.removeResource( resourceIdentifier ); } + @Override public void removeRole( Role role ) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { @@ -587,6 +640,7 @@ public class CachedRbacManager this.rbacImpl.removeRole( role ); } + @Override public void removeRole( String roleName ) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { @@ -594,6 +648,7 @@ public class CachedRbacManager this.rbacImpl.removeRole( roleName ); } + @Override public void removeUserAssignment( String principal ) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { @@ -601,6 +656,7 @@ public class CachedRbacManager this.rbacImpl.removeUserAssignment( principal ); } + @Override public void removeUserAssignment( UserAssignment userAssignment ) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { @@ -608,6 +664,7 @@ public class CachedRbacManager this.rbacImpl.removeUserAssignment( userAssignment ); } + @Override public boolean resourceExists( Resource resource ) { if ( resourcesCache.hasKey( resource.getIdentifier() ) ) @@ -618,6 +675,7 @@ public class CachedRbacManager return this.rbacImpl.resourceExists( resource ); } + @Override public boolean resourceExists( String identifier ) { if ( resourcesCache.hasKey( identifier ) ) @@ -628,6 +686,7 @@ public class CachedRbacManager return this.rbacImpl.resourceExists( identifier ); } + @Override public boolean roleExists( Role role ) throws RbacManagerException { @@ -639,6 +698,7 @@ public class CachedRbacManager return this.rbacImpl.roleExists( role ); } + @Override public boolean roleExists( String name ) throws RbacManagerException { @@ -650,6 +710,7 @@ public class CachedRbacManager return this.rbacImpl.roleExists( name ); } + @Override public Operation saveOperation( Operation operation ) throws RbacObjectInvalidException, RbacManagerException { @@ -657,6 +718,7 @@ public class CachedRbacManager return this.rbacImpl.saveOperation( operation ); } + @Override public Permission savePermission( Permission permission ) throws RbacObjectInvalidException, RbacManagerException { @@ -664,6 +726,7 @@ public class CachedRbacManager return this.rbacImpl.savePermission( permission ); } + @Override public Resource saveResource( Resource resource ) throws RbacObjectInvalidException, RbacManagerException { @@ -671,6 +734,7 @@ public class CachedRbacManager return this.rbacImpl.saveResource( resource ); } + @Override public synchronized Role saveRole( Role role ) throws RbacObjectInvalidException, RbacManagerException { @@ -697,6 +761,7 @@ public class CachedRbacManager return this.rbacImpl.saveRole( role ); } + @Override public synchronized void saveRoles( Collection roles ) throws RbacObjectInvalidException, RbacManagerException { @@ -719,6 +784,7 @@ public class CachedRbacManager this.rbacImpl.saveRoles( roles ); } + @Override public UserAssignment saveUserAssignment( UserAssignment userAssignment ) throws RbacObjectInvalidException, RbacManagerException { @@ -726,6 +792,7 @@ public class CachedRbacManager return this.rbacImpl.saveUserAssignment( userAssignment ); } + @Override public boolean userAssignmentExists( String principal ) { if ( userAssignmentsCache.hasKey( principal ) ) @@ -736,6 +803,7 @@ public class CachedRbacManager return this.rbacImpl.userAssignmentExists( principal ); } + @Override public boolean userAssignmentExists( UserAssignment assignment ) { if ( userAssignmentsCache.hasKey( assignment.getPrincipal() ) ) @@ -803,72 +871,77 @@ public class CachedRbacManager userPermissionsCache.clear(); } - public Cache getOperationsCache() + public Cache getOperationsCache() { return operationsCache; } - public void setOperationsCache( Cache operationsCache ) + @SuppressWarnings( "unchecked" ) + public void setOperationsCache( Cache operationsCache ) { - this.operationsCache = operationsCache; + this.operationsCache = (Cache) operationsCache; } - public Cache getPermissionsCache() + public Cache getPermissionsCache() { return permissionsCache; } - public void setPermissionsCache( Cache permissionsCache ) + @SuppressWarnings( "unchecked" ) + public void setPermissionsCache( Cache permissionsCache ) { - this.permissionsCache = permissionsCache; + this.permissionsCache = (Cache) permissionsCache; } - public Cache getResourcesCache() + public Cache getResourcesCache() { return resourcesCache; } - public void setResourcesCache( Cache resourcesCache ) + @SuppressWarnings( "unchecked" ) + public void setResourcesCache( Cache resourcesCache ) { - this.resourcesCache = resourcesCache; + this.resourcesCache = (Cache) resourcesCache; } - public Cache getRolesCache() + public Cache getRolesCache() { return rolesCache; } - public void setRolesCache( Cache rolesCache ) + @SuppressWarnings( "unchecked" ) + public void setRolesCache( Cache rolesCache ) { - this.rolesCache = rolesCache; + this.rolesCache = (Cache) rolesCache; } - public Cache getUserAssignmentsCache() + public Cache getUserAssignmentsCache() { return userAssignmentsCache; } - public void setUserAssignmentsCache( Cache userAssignmentsCache ) + @SuppressWarnings( "unchecked" ) + public void setUserAssignmentsCache( Cache userAssignmentsCache ) { - this.userAssignmentsCache = userAssignmentsCache; + this.userAssignmentsCache = (Cache) userAssignmentsCache; } - public Cache getUserPermissionsCache() + public Cache>> getUserPermissionsCache() { return userPermissionsCache; } - public void setUserPermissionsCache( Cache userPermissionsCache ) + public void setUserPermissionsCache( Cache>> userPermissionsCache ) { this.userPermissionsCache = userPermissionsCache; } - public Cache getEffectiveRoleSetCache() + public Cache> getEffectiveRoleSetCache() { return effectiveRoleSetCache; } - public void setEffectiveRoleSetCache( Cache effectiveRoleSetCache ) + public void setEffectiveRoleSetCache( Cache> effectiveRoleSetCache ) { this.effectiveRoleSetCache = effectiveRoleSetCache; } @@ -884,16 +957,19 @@ public class CachedRbacManager } + @Override public boolean isFinalImplementation() { return false; } + @Override public String getDescriptionKey() { return "archiva.redback.rbacmanager.cached"; } + @Override public boolean isReadOnly() { return false; diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java index 02b2ce7d..726c151e 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java @@ -76,13 +76,13 @@ public class JpaRbacManager extends AbstractRBACManager { @Transactional @Override - public Map> getAssignedPermissionMap(String principal) throws RbacManagerException { + public Map> getAssignedPermissionMap(String principal) throws RbacManagerException { return super.getAssignedPermissionMap(principal); } @Transactional @Override - public Map getChildRoles(Role role) throws RbacManagerException { + public Map getChildRoles(Role role) throws RbacManagerException { return super.getChildRoles(role); } @@ -102,7 +102,7 @@ public class JpaRbacManager extends AbstractRBACManager { } final EntityManager em = getEm(); - List merged = new ArrayList(); + List merged = new ArrayList<>( ); for (Role role : roles ) { RBACObjectAssertions.assertValid(role); merged.add(em.merge(role)); @@ -129,9 +129,9 @@ public class JpaRbacManager extends AbstractRBACManager { } @Override - public List getAllRoles() throws RbacManagerException { + public List getAllRoles() throws RbacManagerException { final EntityManager em = getEm(); - Query q = em.createQuery("SELECT r FROM JpaRole r"); + TypedQuery q = em.createQuery("SELECT r FROM JpaRole r", JpaRole.class); return q.getResultList(); } @@ -151,7 +151,7 @@ public class JpaRbacManager extends AbstractRBACManager { if (myRole == null) { throw new RbacObjectNotFoundException("Role not found "+role.getName()); } - myRole.setPermissions(new ArrayList()); + myRole.setPermissions( new ArrayList<>( )); em.remove(myRole); fireRbacRoleRemoved(myRole); } @@ -210,10 +210,10 @@ public class JpaRbacManager extends AbstractRBACManager { } @Override - public List getAllPermissions() throws RbacManagerException { + public List getAllPermissions() throws RbacManagerException { final EntityManager em = getEm(); TypedQuery q = em.createQuery("SELECT p FROM JpaPermission p",JpaPermission.class); - return (List)(List)q.getResultList(); + return q.getResultList(); } @Transactional @@ -251,8 +251,7 @@ public class JpaRbacManager extends AbstractRBACManager { throw new RbacObjectInvalidException("Operation is not JpaOperation object"); } final EntityManager em = getEm(); - Operation savedOperation = em.merge(operation); - return savedOperation; + return em.merge(operation); } @Override @@ -266,9 +265,9 @@ public class JpaRbacManager extends AbstractRBACManager { } @Override - public List getAllOperations() throws RbacManagerException { + public List getAllOperations() throws RbacManagerException { final EntityManager em = getEm(); - Query q = em.createQuery("SELECT o FROM JpaOperation o"); + TypedQuery q = em.createQuery("SELECT o FROM JpaOperation o", JpaOperation.class); return q.getResultList(); } @@ -306,8 +305,7 @@ public class JpaRbacManager extends AbstractRBACManager { throw new RbacObjectInvalidException("Resource is not JpaResource"); } final EntityManager em = getEm(); - Resource savedResource = em.merge(resource); - return savedResource; + return em.merge(resource); } // Overriding to add the transactional attribute here @@ -330,10 +328,10 @@ public class JpaRbacManager extends AbstractRBACManager { } @Override - public List getAllResources() throws RbacManagerException { + public List getAllResources() throws RbacManagerException { final EntityManager em = getEm(); TypedQuery q = em.createQuery("SELECT r FROM JpaResource r",JpaResource.class); - return (List)(List)q.getResultList(); + return q.getResultList(); } @Transactional @@ -385,17 +383,17 @@ public class JpaRbacManager extends AbstractRBACManager { } @Override - public List getAllUserAssignments() throws RbacManagerException { + public List getAllUserAssignments() throws RbacManagerException { final EntityManager em = getEm(); - Query q = em.createQuery("SELECT ua FROM JpaUserAssignment ua"); + TypedQuery q = em.createQuery("SELECT ua FROM JpaUserAssignment ua", JpaUserAssignment.class); return q.getResultList(); } @Override - public List getUserAssignmentsForRoles(Collection roleNames) throws RbacManagerException { + public List getUserAssignmentsForRoles(Collection roleNames) throws RbacManagerException { try { final EntityManager em = getEm(); - Query q = em.createQuery("SELECT ua FROM JpaUserAssignment ua WHERE ua.roleNames IN :roles"); + TypedQuery q = em.createQuery("SELECT ua FROM JpaUserAssignment ua WHERE ua.roleNames IN :roles", JpaUserAssignment.class); q.setParameter("roles", roleNames); return q.getResultList(); } catch (Exception ex) { diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java index 565409b1..0d8966e4 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java @@ -99,9 +99,8 @@ public class JpaRole extends AbstractRole implements Serializable { } @Override - public List getPermissions() { - // Maybe better to create a new list? - return (List)(List)permissions; + public List getPermissions() { + return permissions; } @Override diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/LdapRbacManager.java b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/LdapRbacManager.java index 6ecfdf90..435b8274 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/LdapRbacManager.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/LdapRbacManager.java @@ -115,6 +115,7 @@ public class LdapRbacManager private boolean writableLdap = false; + @Override @PostConstruct public void initialize() { @@ -122,47 +123,55 @@ public class LdapRbacManager } + @Override public void addChildRole( Role role, Role childRole ) throws RbacObjectInvalidException, RbacManagerException { this.rbacImpl.addChildRole( role, childRole ); } + @Override public void addListener( RBACManagerListener listener ) { super.addListener( listener ); this.rbacImpl.addListener( listener ); } + @Override public Operation createOperation( String name ) throws RbacManagerException { return this.rbacImpl.createOperation( name ); } + @Override public Permission createPermission( String name ) throws RbacManagerException { return this.rbacImpl.createPermission( name ); } + @Override public Permission createPermission( String name, String operationName, String resourceIdentifier ) throws RbacManagerException { return this.rbacImpl.createPermission( name, operationName, resourceIdentifier ); } + @Override public Resource createResource( String identifier ) throws RbacManagerException { return this.rbacImpl.createResource( identifier ); } + @Override public Role createRole( String name ) { return this.rbacImpl.createRole( name ); } + @Override public UserAssignment createUserAssignment( String username ) throws RbacManagerException { @@ -170,6 +179,7 @@ public class LdapRbacManager return this.rbacImpl.createUserAssignment( username ); } + @Override public void eraseDatabase() { if ( writableLdap ) @@ -204,6 +214,7 @@ public class LdapRbacManager /** * @see org.apache.archiva.redback.rbac.RBACManager#getAllAssignableRoles() */ + @Override public List getAllAssignableRoles() throws RbacManagerException { @@ -229,24 +240,28 @@ public class LdapRbacManager } } - public List getAllOperations() + @Override + public List getAllOperations() throws RbacManagerException { return this.rbacImpl.getAllOperations(); } - public List getAllPermissions() + @Override + public List getAllPermissions() throws RbacManagerException { return this.rbacImpl.getAllPermissions(); } - public List getAllResources() + @Override + public List getAllResources() throws RbacManagerException { return this.rbacImpl.getAllResources(); } + @Override public List getAllRoles() throws RbacManagerException { @@ -277,6 +292,7 @@ public class LdapRbacManager } + @Override public List getAllUserAssignments() throws RbacManagerException { @@ -407,7 +423,7 @@ public class LdapRbacManager protected List getRealRoles() throws RbacManagerException { - List roles = this.rbacImpl.getAllRoles(); + List roles = this.rbacImpl.getAllRoles(); List roleNames = new ArrayList( roles.size() ); for ( Role role : roles ) { @@ -416,6 +432,7 @@ public class LdapRbacManager return roleNames; } + @Override public Collection getAssignedRoles( String username ) throws RbacManagerException { @@ -454,19 +471,22 @@ public class LdapRbacManager } } + @Override public Collection getAssignedRoles( UserAssignment userAssignment ) throws RbacManagerException { return getAssignedRoles( userAssignment.getPrincipal() ); } - public Map getChildRoles( Role role ) + @Override + public Map getChildRoles( Role role ) throws RbacManagerException { return this.rbacImpl.getChildRoles( role ); } - public Map getParentRoles( Role role ) + @Override + public Map getParentRoles( Role role ) throws RbacManagerException { return this.rbacImpl.getParentRoles( role ); @@ -488,36 +508,42 @@ public class LdapRbacManager // } - public Set getEffectiveRoles( Role role ) + @Override + public Set getEffectiveRoles( Role role ) throws RbacManagerException { return this.rbacImpl.getEffectiveRoles( role ); } + @Override public Resource getGlobalResource() throws RbacManagerException { return this.rbacImpl.getGlobalResource(); } + @Override public Operation getOperation( String operationName ) throws RbacManagerException { return this.rbacImpl.getOperation( operationName ); } + @Override public Permission getPermission( String permissionName ) throws RbacManagerException { return this.rbacImpl.getPermission( permissionName ); } + @Override public Resource getResource( String resourceIdentifier ) throws RbacManagerException { return this.rbacImpl.getResource( resourceIdentifier ); } + @Override public Role getRole( String roleName ) throws RbacManagerException { @@ -555,12 +581,14 @@ public class LdapRbacManager return role; } - public Map getRoles( Collection roleNames ) + @Override + public Map getRoles( Collection roleNames ) throws RbacManagerException { return this.rbacImpl.getRoles( roleNames ); } + @Override public Collection getUnassignedRoles( String username ) throws RbacManagerException { @@ -604,6 +632,7 @@ public class LdapRbacManager } } + @Override public UserAssignment getUserAssignment( String username ) throws RbacManagerException { @@ -643,33 +672,39 @@ public class LdapRbacManager //return this.rbacImpl.getUserAssignment( username ); } - public List getUserAssignmentsForRoles( Collection roleNames ) + @Override + public List getUserAssignmentsForRoles( Collection roleNames ) throws RbacManagerException { // TODO from ldap return this.rbacImpl.getUserAssignmentsForRoles( roleNames ); } + @Override public boolean operationExists( Operation operation ) { return this.rbacImpl.operationExists( operation ); } + @Override public boolean operationExists( String name ) { return this.rbacImpl.operationExists( name ); } + @Override public boolean permissionExists( Permission permission ) { return this.rbacImpl.permissionExists( permission ); } + @Override public boolean permissionExists( String name ) { return this.rbacImpl.permissionExists( name ); } + @Override public void rbacInit( boolean freshdb ) { if ( rbacImpl instanceof RBACManagerListener ) @@ -678,6 +713,7 @@ public class LdapRbacManager } } + @Override public void rbacPermissionRemoved( Permission permission ) { if ( rbacImpl instanceof RBACManagerListener ) @@ -687,6 +723,7 @@ public class LdapRbacManager } + @Override public void rbacPermissionSaved( Permission permission ) { if ( rbacImpl instanceof RBACManagerListener ) @@ -696,6 +733,7 @@ public class LdapRbacManager } + @Override public void rbacRoleRemoved( Role role ) { if ( rbacImpl instanceof RBACManagerListener ) @@ -705,6 +743,7 @@ public class LdapRbacManager } + @Override public void rbacRoleSaved( Role role ) { if ( rbacImpl instanceof RBACManagerListener ) @@ -714,6 +753,7 @@ public class LdapRbacManager } + @Override public void rbacUserAssignmentRemoved( UserAssignment userAssignment ) { if ( rbacImpl instanceof RBACManagerListener ) @@ -723,6 +763,7 @@ public class LdapRbacManager } + @Override public void rbacUserAssignmentSaved( UserAssignment userAssignment ) { if ( rbacImpl instanceof RBACManagerListener ) @@ -732,47 +773,55 @@ public class LdapRbacManager } + @Override public void removeListener( RBACManagerListener listener ) { this.rbacImpl.removeListener( listener ); } + @Override public void removeOperation( Operation operation ) throws RbacManagerException { this.rbacImpl.removeOperation( operation ); } + @Override public void removeOperation( String operationName ) throws RbacManagerException { this.rbacImpl.removeOperation( operationName ); } + @Override public void removePermission( Permission permission ) throws RbacManagerException { this.rbacImpl.removePermission( permission ); } + @Override public void removePermission( String permissionName ) throws RbacManagerException { this.rbacImpl.removePermission( permissionName ); } + @Override public void removeResource( Resource resource ) throws RbacManagerException { this.rbacImpl.removeResource( resource ); } + @Override public void removeResource( String resourceIdentifier ) throws RbacManagerException { this.rbacImpl.removeResource( resourceIdentifier ); } + @Override public void removeRole( Role role ) throws RbacManagerException { @@ -805,6 +854,7 @@ public class LdapRbacManager } } + @Override public void removeRole( String roleName ) throws RbacManagerException { @@ -815,6 +865,7 @@ public class LdapRbacManager removeRole( new RoleImpl( roleName ) ); } + @Override public void removeUserAssignment( String username ) throws RbacManagerException { @@ -823,6 +874,7 @@ public class LdapRbacManager this.rbacImpl.removeUserAssignment( username ); } + @Override public void removeUserAssignment( UserAssignment userAssignment ) throws RbacManagerException { @@ -834,11 +886,13 @@ public class LdapRbacManager this.rbacImpl.removeUserAssignment( userAssignment ); } + @Override public boolean resourceExists( Resource resource ) { return this.rbacImpl.resourceExists( resource ); } + @Override public boolean resourceExists( String identifier ) { return this.rbacImpl.resourceExists( identifier ); @@ -894,24 +948,28 @@ public class LdapRbacManager } } + @Override public Operation saveOperation( Operation operation ) throws RbacManagerException { return this.rbacImpl.saveOperation( operation ); } + @Override public Permission savePermission( Permission permission ) throws RbacManagerException { return this.rbacImpl.savePermission( permission ); } + @Override public Resource saveResource( Resource resource ) throws RbacManagerException { return this.rbacImpl.saveResource( resource ); } + @Override public synchronized Role saveRole( Role role ) throws RbacManagerException { @@ -950,6 +1008,7 @@ public class LdapRbacManager //return new RoleImpl( role.getName(), role.getPermissions() ); } + @Override public synchronized void saveRoles( Collection roles ) throws RbacManagerException { @@ -981,6 +1040,7 @@ public class LdapRbacManager } + @Override public UserAssignment saveUserAssignment( UserAssignment userAssignment ) throws RbacManagerException { @@ -1045,6 +1105,7 @@ public class LdapRbacManager } } + @Override public boolean userAssignmentExists( String principal ) { if ( userAssignmentsCache.hasKey( principal ) ) @@ -1084,6 +1145,7 @@ public class LdapRbacManager return false; } + @Override public boolean userAssignmentExists( UserAssignment assignment ) { if ( assignment == null ) @@ -1145,76 +1207,91 @@ public class LdapRbacManager this.permissions = permissions; } + @Override public void addPermission( Permission permission ) { this.permissions.add( permission ); } + @Override public void addChildRoleName( String name ) { this.childRoleNames.add( name ); } + @Override public List getChildRoleNames() { return this.childRoleNames; } + @Override public String getDescription() { return this.description; } + @Override public String getName() { return this.name; } + @Override public List getPermissions() { return this.permissions; } + @Override public boolean isAssignable() { return true; } + @Override public void removePermission( Permission permission ) { this.permissions.remove( permission ); } + @Override public void setAssignable( boolean assignable ) { // no op } + @Override public void setChildRoleNames( List names ) { this.childRoleNames = names; } + @Override public void setDescription( String description ) { this.description = description; } + @Override public void setName( String name ) { this.name = name; } + @Override public void setPermissions( List permissions ) { this.permissions = permissions; } + @Override public boolean isPermanent() { return true; } + @Override public void setPermanent( boolean permanent ) { // no op @@ -1282,16 +1359,19 @@ public class LdapRbacManager } } + @Override public String getPrincipal() { return this.username; } + @Override public List getRoleNames() { return this.roleNames; } + @Override public void addRoleName( Role role ) { if ( role == null ) @@ -1301,6 +1381,7 @@ public class LdapRbacManager this.roleNames.add( role.getName() ); } + @Override public void addRoleName( String roleName ) { if ( roleName == null ) @@ -1310,6 +1391,7 @@ public class LdapRbacManager this.roleNames.add( roleName ); } + @Override public void removeRoleName( Role role ) { if ( role == null ) @@ -1319,6 +1401,7 @@ public class LdapRbacManager this.roleNames.remove( role.getName() ); } + @Override public void removeRoleName( String roleName ) { if ( roleName == null ) @@ -1328,21 +1411,25 @@ public class LdapRbacManager this.roleNames.remove( roleName ); } + @Override public void setPrincipal( String principal ) { this.username = principal; } + @Override public void setRoleNames( List roles ) { this.roleNames = roles; } + @Override public boolean isPermanent() { return this.permanent; } + @Override public void setPermanent( boolean permanent ) { this.permanent = permanent; @@ -1368,11 +1455,13 @@ public class LdapRbacManager return true; } + @Override public String getDescriptionKey() { return "archiva.redback.rbacmanager.ldap"; } + @Override public boolean isReadOnly() { return !writableLdap; diff --git a/redback-rbac/redback-rbac-role-manager/src/main/java/org/apache/archiva/redback/role/processor/DefaultRoleModelProcessor.java b/redback-rbac/redback-rbac-role-manager/src/main/java/org/apache/archiva/redback/role/processor/DefaultRoleModelProcessor.java index 6a6a0a07..9275a9c0 100644 --- a/redback-rbac/redback-rbac-role-manager/src/main/java/org/apache/archiva/redback/role/processor/DefaultRoleModelProcessor.java +++ b/redback-rbac/redback-rbac-role-manager/src/main/java/org/apache/archiva/redback/role/processor/DefaultRoleModelProcessor.java @@ -167,7 +167,7 @@ public class DefaultRoleModelProcessor throw new RoleManagerException( "cycle detected: this should have been caught in validation", e ); } - List allRoles; + List allRoles; try { allRoles = rbacManager.getAllRoles(); @@ -187,7 +187,7 @@ public class DefaultRoleModelProcessor { ModelRole roleProfile = RoleModelUtils.getModelRole( model, roleId ); - List permissions = processPermissions( roleProfile.getPermissions() ); + List permissions = processPermissions( roleProfile.getPermissions() ); boolean roleExists = allRoleNames.contains( roleProfile.getName() );// false; @@ -292,7 +292,7 @@ public class DefaultRoleModelProcessor log.info( "time to process roles model: {} ms", stopWatch.getTime() ); } - private List processPermissions( List permissions ) + private List processPermissions( List permissions ) throws RoleManagerException { List rbacPermissions = new ArrayList( permissions.size() ); diff --git a/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/AbstractRoleManagerTest.java b/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/AbstractRoleManagerTest.java index eb3ce1e7..2b31d9fe 100644 --- a/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/AbstractRoleManagerTest.java +++ b/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/AbstractRoleManagerTest.java @@ -65,7 +65,7 @@ public abstract class AbstractRoleManagerTest throws Exception { - List all = rbacManager.getAllResources(); + List all = rbacManager.getAllResources(); assertTrue( rbacManager.resourceExists( "*" ) ); diff --git a/redback-rbac/redback-rbac-tests/src/main/java/org/apache/archiva/redback/tests/AbstractRbacManagerTestCase.java b/redback-rbac/redback-rbac-tests/src/main/java/org/apache/archiva/redback/tests/AbstractRbacManagerTestCase.java index 65af6947..5ec4cc5c 100644 --- a/redback-rbac/redback-rbac-tests/src/main/java/org/apache/archiva/redback/tests/AbstractRbacManagerTestCase.java +++ b/redback-rbac/redback-rbac-tests/src/main/java/org/apache/archiva/redback/tests/AbstractRbacManagerTestCase.java @@ -467,7 +467,7 @@ public abstract class AbstractRbacManagerTestCase assertEquals( 1, manager.getAllUserAssignments().size() ); - Set assignedPermissions = manager.getAssignedPermissions( adminPrincipal ); + Set assignedPermissions = manager.getAssignedPermissions( adminPrincipal ); assertThat( assignedPermissions ).isNotNull().isNotEmpty().hasSize( 1 ); @@ -689,7 +689,7 @@ public abstract class AbstractRbacManagerTestCase afterSetup(); // Get the List of Assigned Roles for user bob. - Collection assignedRoles = manager.getAssignedRoles( username ); + Collection assignedRoles = manager.getAssignedRoles( username ); assertThat( assignedRoles ).isNotNull().isNotEmpty().hasSize( 3 ); } @@ -733,7 +733,7 @@ public abstract class AbstractRbacManagerTestCase assertThat( manager.getAllPermissions() ).isNotNull().isNotEmpty().hasSize( 3 ); // Get the List of Assigned Roles for user bob. - Collection assignedPermissions = manager.getAssignedPermissions( username ); + Collection assignedPermissions = manager.getAssignedPermissions( username ); assertThat( assignedPermissions ).isNotNull().isNotEmpty().hasSize( 1 ); } @@ -852,16 +852,16 @@ public abstract class AbstractRbacManagerTestCase rbacManager.saveUserAssignment( assignment ); assertEquals( incAssignements( 1 ), rbacManager.getAllUserAssignments().size() ); - List permissions = rbacManager.getAllPermissions(); + List permissions = rbacManager.getAllPermissions(); Assertions.assertThat( permissions ).isNotNull().isNotEmpty().hasSize( 6 ); - List roles = rbacManager.getAllRoles(); + List roles = rbacManager.getAllRoles(); Assertions.assertThat( roles ).isNotNull().isNotEmpty().hasSize( 4 ); afterSetup(); // Get the List of Assigned Roles for user bob. - Collection assignedPermissions = rbacManager.getAssignedPermissions( username ); + Collection assignedPermissions = rbacManager.getAssignedPermissions( username ); assertNotNull( assignedPermissions ); assertEquals( 6, assignedPermissions.size() );