From 2f4b1d241950261ce635d84f04ed45132e88e2ba Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Thu, 26 Nov 2020 22:21:03 +0100 Subject: [PATCH] Adding id methods for roles --- .../consumers/lucene/test/TestRBACManager.java | 18 +++++++++++++++--- .../consumers/lucene/test/TestRoleManager.java | 6 ++++-- .../security/common/ArchivaRoleConstants.java | 6 ++++++ .../archiva/security/AbstractSecurityTest.java | 2 +- .../ArchivaLockedAdminEnvironmentCheck.java | 2 +- .../web/security/ArchivaRbacManager.java | 12 ++++++------ .../web/startup/SecuritySynchronization.java | 4 ++-- .../archiva/web/rss/RoleManagerStub.java | 6 ++++-- 8 files changed, 39 insertions(+), 17 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 26e891dcb..a74d5bc8c 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 @@ -144,19 +144,31 @@ public class TestRBACManager implements RBACManager } @Override - public Map getChildRoles( Role role ) + public Map getChildRoleNames( Role role ) throws RbacManagerException { return null; //To change body of implemented methods use File | Settings | File Templates. } @Override - public Map getParentRoles( Role role ) + public Map getChildRoleIds( Role role ) throws RbacManagerException + { + return null; + } + + @Override + public Map getParentRoleNames( Role role ) throws RbacManagerException { return null; //To change body of implemented methods use File | Settings | File Templates. } + @Override + public Map getParentRoleIds( Role role ) throws RbacManagerException + { + return null; + } + @Override public List getAllRoles() throws RbacManagerException @@ -399,7 +411,7 @@ public class TestRBACManager implements RBACManager } @Override - public List getUserAssignmentsForRoles( Collection roleNames ) + public List getUserAssignmentsForRoles( Collection roleIds ) throws RbacManagerException { return null; //To change body of implemented methods use File | Settings | File Templates. 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 dd87dfc04..c0a04da74 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 @@ -47,10 +47,11 @@ public class TestRoleManager } @Override - public void createTemplatedRole( String templateId, String resource ) + public String createTemplatedRole( String templateId, String resource ) throws RoleManagerException { //To change body of implemented methods use File | Settings | File Templates. + return null; } @Override @@ -61,10 +62,11 @@ public class TestRoleManager } @Override - public void moveTemplatedRole( String templateId, String oldResource, String newResource ) + public String moveTemplatedRole( String templateId, String oldResource, String newResource ) throws RoleManagerException { //To change body of implemented methods use File | Settings | File Templates. + return null; } @Override diff --git a/archiva-modules/archiva-base/archiva-security-common/src/main/java/org/apache/archiva/security/common/ArchivaRoleConstants.java b/archiva-modules/archiva-base/archiva-security-common/src/main/java/org/apache/archiva/security/common/ArchivaRoleConstants.java index 36ab17c6a..4700d9646 100644 --- a/archiva-modules/archiva-base/archiva-security-common/src/main/java/org/apache/archiva/security/common/ArchivaRoleConstants.java +++ b/archiva-modules/archiva-base/archiva-security-common/src/main/java/org/apache/archiva/security/common/ArchivaRoleConstants.java @@ -40,6 +40,7 @@ public class ArchivaRoleConstants public static final String REPOSITORY_MANAGER_ROLE_PREFIX = "Repository Manager"; public static final String REPOSITORY_OBSERVER_ROLE_PREFIX = "Repository Observer"; + public static final String REPOSITORY_OBSERVER_ROLE_ID_PREFIX = "archiva-repository-observer"; // operations public static final String OPERATION_MANAGE_USERS = "archiva-manage-users"; @@ -87,4 +88,9 @@ public class ArchivaRoleConstants { return REPOSITORY_OBSERVER_ROLE_PREFIX + " - " + repoId; } + + public static String toRepositoryObserverRoleId( String repoId ) + { + return REPOSITORY_OBSERVER_ROLE_ID_PREFIX + "." + repoId; + } } diff --git a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/AbstractSecurityTest.java b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/AbstractSecurityTest.java index 6487e9d23..d877c69f1 100644 --- a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/AbstractSecurityTest.java +++ b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/AbstractSecurityTest.java @@ -170,7 +170,7 @@ public abstract class AbstractSecurityTest log.info( "ignore RbacObjectNotFoundException for id {} during restoreGuestInitialValues", userId ); return; } - userAssignment.setRoleNames( new ArrayList( Arrays.asList( "Guest" ) ) ); + userAssignment.setRoleIds( new ArrayList( Arrays.asList( "guest" ) ) ); rbacManager.saveUserAssignment( userAssignment ); CacheManager.getInstance().clearAll(); } diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaLockedAdminEnvironmentCheck.java b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaLockedAdminEnvironmentCheck.java index 86f27fcf1..b30e28ed1 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaLockedAdminEnvironmentCheck.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaLockedAdminEnvironmentCheck.java @@ -112,7 +112,7 @@ public class ArchivaLockedAdminEnvironmentCheck continue; } List roles = new ArrayList<>(); - roles.add( RedbackRoleConstants.SYSTEM_ADMINISTRATOR_ROLE ); + roles.add( RedbackRoleConstants.SYSTEM_ADMINISTRATOR_ROLE_ID ); List systemAdminstrators; try 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 d0995b735..4884882eb 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 @@ -812,9 +812,9 @@ public class ArchivaRbacManager UserAssignment userAssignment = rbacManager.getUserAssignment( principal ); if ( userAssignment != null ) { - for ( String roleName : userAssignment.getRoleNames() ) + for ( String roleId : userAssignment.getRoleIds() ) { - ua.addRoleName( roleName ); + ua.addRoleId( roleId ); } } } @@ -900,9 +900,9 @@ public class ArchivaRbacManager UserAssignment userAssignment = allUserAssignments.get( ua.getPrincipal() ); if ( userAssignment != null ) { - for ( String roleName : ua.getRoleNames() ) + for ( String roleId : ua.getRoleIds() ) { - userAssignment.addRoleName( roleName ); + userAssignment.addRoleId( roleId ); } } allUserAssignments.put( ua.getPrincipal(), ua ); @@ -923,7 +923,7 @@ public class ArchivaRbacManager } @Override - public List getUserAssignmentsForRoles( Collection roleNames ) + public List getUserAssignmentsForRoles( Collection roleIds ) throws RbacManagerException { List allUserAssignments = new ArrayList<>(); @@ -933,7 +933,7 @@ public class ArchivaRbacManager { try { - List userAssignments = rbacManager.getUserAssignmentsForRoles( roleNames ); + List userAssignments = rbacManager.getUserAssignmentsForRoles( roleIds ); allUserAssignments.addAll( userAssignments ); diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/startup/SecuritySynchronization.java b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/startup/SecuritySynchronization.java index 7b487803b..dc0d2e882 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/startup/SecuritySynchronization.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/startup/SecuritySynchronization.java @@ -244,12 +244,12 @@ public class SecuritySynchronization ua = rbacManager.createUserAssignment( principal ); } - ua.addRoleName( ArchivaRoleConstants.toRepositoryObserverRoleName( repoId ) ); + ua.addRoleId( ArchivaRoleConstants.toRepositoryObserverRoleId( repoId ) ); rbacManager.saveUserAssignment( ua ); } catch ( RbacManagerException e ) { - log.warn( "Unable to add role [{}] to {} user.", ArchivaRoleConstants.toRepositoryObserverRoleName( repoId ), principal, e ); + log.warn( "Unable to add role [{}] to {} user.", ArchivaRoleConstants.toRepositoryObserverRoleId( repoId ), principal, 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 442f21d37..b1a32a24a 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 @@ -47,10 +47,11 @@ public class RoleManagerStub } @Override - public void createTemplatedRole( String templateId, String resource ) + public String createTemplatedRole( String templateId, String resource ) throws RoleManagerException { //To change body of implemented methods use File | Settings | File Templates. + return null; } @Override @@ -61,10 +62,11 @@ public class RoleManagerStub } @Override - public void moveTemplatedRole( String templateId, String oldResource, String newResource ) + public String moveTemplatedRole( String templateId, String oldResource, String newResource ) throws RoleManagerException { //To change body of implemented methods use File | Settings | File Templates. + return null; } @Override -- 2.39.5