From: Joakim Erdfelt Date: Mon, 15 Oct 2007 20:39:26 +0000 (+0000) Subject: [MRM-398] configure guest access by default for pre-configured repositories X-Git-Tag: archiva-1.0-beta-3~84 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=912b15a3474696311b1e294dfc68b86a692e8bd7;p=archiva.git [MRM-398] configure guest access by default for pre-configured repositories Reverted partially r584279. (some good fixes for related bugs in place) Introduced ArchivaConfiguration.isDefaulted() to aide SecuritySynchronization (startup task in archiva-webapp) to add guest user read-only roles if the configuration was set to default for some reason. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@584902 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java index 9a52f7aa6..f15ca0542 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java @@ -23,9 +23,6 @@ import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.security.ArchivaRoleConstants; -import org.codehaus.plexus.redback.rbac.RBACManager; -import org.codehaus.plexus.redback.rbac.RbacManagerException; -import org.codehaus.plexus.redback.rbac.UserAssignment; import org.codehaus.plexus.redback.role.RoleManager; import org.codehaus.plexus.redback.role.RoleManagerException; @@ -48,11 +45,6 @@ public abstract class AbstractManagedRepositoriesAction */ protected RoleManager roleManager; - /** - * @plexus.requirement role-hint="cached" - */ - protected RBACManager rbacManager; - public RoleManager getRoleManager() { return roleManager; @@ -98,18 +90,6 @@ public abstract class AbstractManagedRepositoriesAction { roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ); } - - try - { - UserAssignment ua = rbacManager.getUserAssignment( ArchivaRoleConstants.GUEST_ROLE ); - ua.addRoleName( ArchivaRoleConstants.REPOSITORY_OBSERVER_ROLE_PREFIX + " - " + repoId ); - rbacManager.saveUserAssignment( ua ); - } - catch ( RbacManagerException e ) - { - getLogger().warn( "Unable to add role [" + ArchivaRoleConstants.REPOSITORY_OBSERVER_ROLE_PREFIX + " - " - + repoId + "] to Guest user.", e ); - } } protected void removeContents( ManagedRepositoryConfiguration existingRepository ) diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/SecuritySynchronization.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/SecuritySynchronization.java index b2e37ec0d..c63dbe060 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/SecuritySynchronization.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/SecuritySynchronization.java @@ -25,6 +25,9 @@ import org.apache.maven.archiva.configuration.ConfigurationNames; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.security.ArchivaRoleConstants; import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.redback.rbac.RBACManager; +import org.codehaus.plexus.redback.rbac.RbacManagerException; +import org.codehaus.plexus.redback.rbac.UserAssignment; import org.codehaus.plexus.redback.role.RoleManager; import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.registry.Registry; @@ -49,6 +52,11 @@ public class SecuritySynchronization * @plexus.requirement role-hint="default" */ private RoleManager roleManager; + + /** + * @plexus.requirement role-hint="cached" + */ + private RBACManager rbacManager; /** * @plexus.requirement @@ -104,5 +112,29 @@ public class SecuritySynchronization { synchConfiguration( archivaConfiguration.getConfiguration().getManagedRepositories() ); archivaConfiguration.addChangeListener( this ); + + if ( archivaConfiguration.isDefaulted() ) + { + assignRepositoryObserverToGuestUser( archivaConfiguration.getConfiguration().getManagedRepositories() ); + } + } + + private void assignRepositoryObserverToGuestUser( List repos ) + { + for ( ManagedRepositoryConfiguration repoConfig : repos ) + { + String repoId = repoConfig.getId(); + try + { + UserAssignment ua = rbacManager.getUserAssignment( ArchivaRoleConstants.GUEST_ROLE ); + ua.addRoleName( ArchivaRoleConstants.REPOSITORY_OBSERVER_ROLE_PREFIX + " - " + repoId ); + rbacManager.saveUserAssignment( ua ); + } + catch ( RbacManagerException e ) + { + getLogger().warn( "Unable to add role [" + ArchivaRoleConstants.REPOSITORY_OBSERVER_ROLE_PREFIX + " - " + + repoId + "] to Guest user.", e ); + } + } } }