1 package org.apache.maven.archiva.web.startup;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.archiva.common.ArchivaException;
23 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
24 import org.apache.maven.archiva.configuration.ConfigurationNames;
25 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
26 import org.apache.maven.archiva.security.ArchivaRoleConstants;
27 import org.codehaus.plexus.logging.AbstractLogEnabled;
28 import org.codehaus.plexus.redback.role.RoleManager;
29 import org.codehaus.plexus.redback.role.RoleManagerException;
30 import org.codehaus.plexus.registry.Registry;
31 import org.codehaus.plexus.registry.RegistryListener;
33 import java.util.List;
36 * ConfigurationSynchronization
38 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
41 * @plexus.component role="org.apache.maven.archiva.web.startup.SecuritySynchronization"
44 public class SecuritySynchronization
45 extends AbstractLogEnabled
46 implements RegistryListener
49 * @plexus.requirement role-hint="default"
51 private RoleManager roleManager;
56 private ArchivaConfiguration archivaConfiguration;
58 public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
60 if ( ConfigurationNames.isManagedRepositories( propertyName ) )
62 synchConfiguration( archivaConfiguration.getConfiguration().getManagedRepositories() );
66 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
71 private void synchConfiguration( List<ManagedRepositoryConfiguration> repos )
73 // NOTE: Remote Repositories do not have roles or security placed around them.
75 for ( ManagedRepositoryConfiguration repoConfig : repos )
77 // manage roles for repositories
80 if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
81 repoConfig.getId() ) )
83 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
87 if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER,
88 repoConfig.getId() ) )
90 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER,
94 catch ( RoleManagerException e )
97 getLogger().error( "Unable to create roles for configured repositories: " + e.getMessage(), e );
102 public void startup()
103 throws ArchivaException
105 synchConfiguration( archivaConfiguration.getConfiguration().getManagedRepositories() );
106 archivaConfiguration.addChangeListener( this );