From a2442befca1e7b9c9f81cc434d86cf7b7ed8cd41 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Mon, 16 Nov 2020 17:26:53 +0100 Subject: [PATCH] Update after redback API changes --- .../lucene/test/TestRBACManager.java | 24 +++++++++ .../lucene/test/TestRoleManager.java | 2 +- .../web/security/ArchivaRbacManager.java | 50 ++++++++++++++++++- .../archiva/web/rss/RoleManagerStub.java | 2 +- 4 files changed, 75 insertions(+), 3 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-indexer-consumers/src/test/java/org/apache/archiva/consumers/lucene/test/TestRBACManager.java b/archiva-modules/archiva-base/archiva-consumers/archiva-indexer-consumers/src/test/java/org/apache/archiva/consumers/lucene/test/TestRBACManager.java index adcc42550..26e891dcb 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-indexer-consumers/src/test/java/org/apache/archiva/consumers/lucene/test/TestRBACManager.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-indexer-consumers/src/test/java/org/apache/archiva/consumers/lucene/test/TestRBACManager.java @@ -78,12 +78,24 @@ public class TestRBACManager implements RBACManager return null; } + @Override + public Role createRole( String id, String name ) + { + return null; + } + @Override public boolean roleExists( String name ) { return false; } + @Override + public boolean roleExistsById( String id ) throws RbacManagerException + { + return false; + } + @Override public boolean roleExists( Role role ) { @@ -111,6 +123,12 @@ public class TestRBACManager implements RBACManager return null; } + @Override + public Role getRoleById( String id ) throws RbacObjectNotFoundException, RbacManagerException + { + return null; + } + @Override public Map getRoles( Collection roleNames ) throws RbacObjectNotFoundException, RbacManagerException @@ -167,6 +185,12 @@ public class TestRBACManager implements RBACManager //To change body of implemented methods use File | Settings | File Templates. } + @Override + public void removeRoleById( String id ) throws RbacObjectNotFoundException, RbacManagerException + { + + } + @Override public Permission createPermission( String name ) throws RbacManagerException diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-indexer-consumers/src/test/java/org/apache/archiva/consumers/lucene/test/TestRoleManager.java b/archiva-modules/archiva-base/archiva-consumers/archiva-indexer-consumers/src/test/java/org/apache/archiva/consumers/lucene/test/TestRoleManager.java index 8f3bb644f..dd87dfc04 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-indexer-consumers/src/test/java/org/apache/archiva/consumers/lucene/test/TestRoleManager.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-indexer-consumers/src/test/java/org/apache/archiva/consumers/lucene/test/TestRoleManager.java @@ -61,7 +61,7 @@ public class TestRoleManager } @Override - public void updateRole( String templateId, String oldResource, String newResource ) + public void moveTemplatedRole( String templateId, String oldResource, String newResource ) throws RoleManagerException { //To change body of implemented methods use File | Settings | File Templates. diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaRbacManager.java b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaRbacManager.java index 67dc4b7a4..d0995b735 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaRbacManager.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaRbacManager.java @@ -79,6 +79,10 @@ public class ArchivaRbacManager @Named( value = "cache#roles" ) private Cache rolesCache; + @Inject + @Named( value = "cache#rolesById" ) + private Cache rolesByIdCache; + @Inject @Named( value = "cache#userAssignments" ) private Cache userAssignmentsCache; @@ -134,6 +138,7 @@ public class ArchivaRbacManager operationsCache.clear(); permissionsCache.clear(); rolesCache.clear(); + rolesByIdCache.clear(); userAssignmentsCache.clear(); userPermissionsCache.clear(); effectiveRoleSetCache.clear(); @@ -160,6 +165,12 @@ public class ArchivaRbacManager return getRbacManagerForWrite().createRole( name ); } + @Override + public Role createRole( String id, String name ) + { + return getRbacManagerForWrite( ).createRole( id, name ); + } + @Override public Role saveRole( Role role ) throws RbacObjectInvalidException, RbacManagerException @@ -235,6 +246,7 @@ public class ArchivaRbacManager if ( role != null ) { rolesCache.put( role.getName(), role ); + rolesByIdCache.put( role.getId( ), role ); return role; } } @@ -248,7 +260,42 @@ public class ArchivaRbacManager { throw new RbacManagerException( lastException.getMessage(), lastException ); } - return null; + throw new RbacObjectNotFoundException( "Role not found " + roleName ); + } + + @Override + public Role getRoleById( String id ) throws RbacObjectNotFoundException, RbacManagerException + { + Role el = rolesByIdCache.get( id ); + if ( el != null ) + { + return el; + } + + Exception lastException = null; + for ( RBACManager rbacManager : rbacManagersPerId.values() ) + { + try + { + Role role = rbacManager.getRoleById( id ); + if ( role != null ) + { + rolesCache.put( role.getName(), role ); + rolesByIdCache.put( role.getId( ), role ); + return role; + } + } + catch ( Exception e ) + { + lastException = e; + } + } + log.debug( "cannot find role for id: ‘{}", id ); + if ( lastException != null ) + { + throw new RbacManagerException( lastException.getMessage(), lastException ); + } + throw new RbacObjectNotFoundException( "Role not found " + id ); } @Override @@ -295,6 +342,7 @@ public class ArchivaRbacManager { rbacManager.removeRole( role ); rolesCache.remove( role.getName() ); + rolesByIdCache.remove( role.getId( ) ); allFailed = false; } catch ( Exception e ) diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/web/rss/RoleManagerStub.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/web/rss/RoleManagerStub.java index 7b3e31200..442f21d37 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/web/rss/RoleManagerStub.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/web/rss/RoleManagerStub.java @@ -61,7 +61,7 @@ public class RoleManagerStub } @Override - public void updateRole( String templateId, String oldResource, String newResource ) + public void moveTemplatedRole( String templateId, String oldResource, String newResource ) throws RoleManagerException { //To change body of implemented methods use File | Settings | File Templates. -- 2.39.5