]> source.dussan.org Git - archiva.git/commitdiff
fix package: my bad I missed to do a clean before my tests
authorOlivier Lamy <olamy@apache.org>
Fri, 9 Dec 2011 08:32:41 +0000 (08:32 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 9 Dec 2011 08:32:41 +0000 (08:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1212277 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/web/spring/RepositoryListenerFactoryBean.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/web/startup/ArchivaStartup.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/web/startup/Banner.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/web/startup/SecuritySynchronization.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/webapp/spring/RepositoryListenerFactoryBean.java [deleted file]
archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/webapp/startup/ArchivaStartup.java [deleted file]
archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/webapp/startup/Banner.java [deleted file]
archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/webapp/startup/SecuritySynchronization.java [deleted file]

diff --git a/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/web/spring/RepositoryListenerFactoryBean.java b/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/web/spring/RepositoryListenerFactoryBean.java
new file mode 100644 (file)
index 0000000..5822902
--- /dev/null
@@ -0,0 +1,64 @@
+package org.apache.archiva.web.spring;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.repository.events.RepositoryListener;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+import java.util.List;
+
+/**
+ * @todo though we will eventually remove this altogether, an interim cleanup would be to genericise this
+ * and replace the calls in RepositoryContentConsumers with calls to the same thing
+ */
+public class RepositoryListenerFactoryBean
+    implements FactoryBean, ApplicationContextAware
+{
+
+    private ApplicationContext applicationContext;
+
+    public void setApplicationContext( ApplicationContext applicationContext )
+        throws BeansException
+    {
+        this.applicationContext = applicationContext;
+    }
+
+    public Object getObject()
+        throws Exception
+    {
+        return applicationContext.getBeansOfType( RepositoryListener.class ).values();
+    }
+
+    @SuppressWarnings("unchecked")
+    public Class<List> getObjectType()
+    {
+        return List.class;
+    }
+
+    public boolean isSingleton()
+    {
+        return true;
+    }
+
+    
+}
diff --git a/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/web/startup/ArchivaStartup.java b/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/web/startup/ArchivaStartup.java
new file mode 100644 (file)
index 0000000..46aca0b
--- /dev/null
@@ -0,0 +1,208 @@
+package org.apache.archiva.web.startup;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.common.ArchivaException;
+import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
+import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
+import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
+import org.apache.maven.index.NexusIndexer;
+import org.apache.maven.index.context.IndexingContext;
+import org.codehaus.plexus.taskqueue.Task;
+import org.codehaus.plexus.taskqueue.execution.ThreadedTaskQueueExecutor;
+import org.codehaus.redback.components.scheduler.DefaultScheduler;
+import org.quartz.SchedulerException;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import java.lang.reflect.Field;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+
+/**
+ * ArchivaStartup - the startup of all archiva features in a deterministic order.
+ *
+ * @version $Id$
+ */
+public class ArchivaStartup
+    implements ServletContextListener
+{
+    private ThreadedTaskQueueExecutor tqeDbScanning;
+
+    private ThreadedTaskQueueExecutor tqeRepoScanning;
+
+    private ThreadedTaskQueueExecutor tqeIndexing;
+
+    private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
+
+    private PlexusSisuBridge plexusSisuBridge;
+
+    private NexusIndexer nexusIndexer;
+
+    public void contextInitialized( ServletContextEvent contextEvent )
+    {
+        WebApplicationContext wac =
+            WebApplicationContextUtils.getRequiredWebApplicationContext( contextEvent.getServletContext() );
+
+        SecuritySynchronization securitySync = wac.getBean( SecuritySynchronization.class );
+
+        repositoryTaskScheduler =
+            wac.getBean( "archivaTaskScheduler#repository", RepositoryArchivaTaskScheduler.class );
+
+        Properties archivaRuntimeProperties = wac.getBean( "archivaRuntimeProperties", Properties.class );
+
+        tqeRepoScanning = wac.getBean( "taskQueueExecutor#repository-scanning", ThreadedTaskQueueExecutor.class );
+
+        tqeIndexing = wac.getBean( "taskQueueExecutor#indexing", ThreadedTaskQueueExecutor.class );
+
+        plexusSisuBridge = wac.getBean( PlexusSisuBridge.class );
+
+        try
+        {
+            nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
+        }
+        catch ( PlexusSisuBridgeException e )
+        {
+            throw new RuntimeException( "Unable to get NexusIndexer: " + e.getMessage(), e );
+        }
+        try
+        {
+            securitySync.startup();
+            repositoryTaskScheduler.startup();
+            Banner.display( (String) archivaRuntimeProperties.get( "archiva.version" ) );
+        }
+        catch ( ArchivaException e )
+        {
+            throw new RuntimeException( "Unable to properly startup archiva: " + e.getMessage(), e );
+        }
+    }
+
+    public void contextDestroyed( ServletContextEvent contextEvent )
+    {
+        WebApplicationContext applicationContext =
+            WebApplicationContextUtils.getRequiredWebApplicationContext( contextEvent.getServletContext() );
+
+        // TODO check this stop
+
+        /*
+        if ( applicationContext != null && applicationContext instanceof ClassPathXmlApplicationContext )
+        {
+            ( (ClassPathXmlApplicationContext) applicationContext ).close();
+        } */
+
+        if ( applicationContext != null ) //&& applicationContext instanceof PlexusWebApplicationContext )
+        {
+            // stop task queue executors
+            stopTaskQueueExecutor( tqeDbScanning );
+            stopTaskQueueExecutor( tqeRepoScanning );
+            stopTaskQueueExecutor( tqeIndexing );
+
+            // stop the DefaultArchivaTaskScheduler and its scheduler
+            if ( repositoryTaskScheduler != null )
+            {
+                try
+                {
+                    repositoryTaskScheduler.stop();
+                }
+                catch ( SchedulerException e )
+                {
+                    e.printStackTrace();
+                }
+
+                try
+                {
+                    // shutdown the scheduler, otherwise Quartz scheduler and Threads still exists
+                    Field schedulerField = repositoryTaskScheduler.getClass().getDeclaredField( "scheduler" );
+                    schedulerField.setAccessible( true );
+
+                    DefaultScheduler scheduler = (DefaultScheduler) schedulerField.get( repositoryTaskScheduler );
+                    scheduler.stop();
+                }
+                catch ( Exception e )
+                {
+                    e.printStackTrace();
+                }
+            }
+
+            // close the application context
+            //applicationContext.close();
+            // TODO fix close call
+            //applicationContext.
+        }
+
+        // closing correctly indexer to close correctly lock and file
+        for ( IndexingContext indexingContext : nexusIndexer.getIndexingContexts().values() )
+        {
+            try
+            {
+                indexingContext.close( false );
+            }
+            catch ( Exception e )
+            {
+                contextEvent.getServletContext().log( "skip error closing indexingContext " + e.getMessage() );
+            }
+        }
+
+    }
+
+    private void stopTaskQueueExecutor( ThreadedTaskQueueExecutor taskQueueExecutor )
+    {
+        if ( taskQueueExecutor != null )
+        {
+            Task currentTask = taskQueueExecutor.getCurrentTask();
+            if ( currentTask != null )
+            {
+                taskQueueExecutor.cancelTask( currentTask );
+            }
+
+            try
+            {
+                taskQueueExecutor.stop();
+                ExecutorService service = getExecutorServiceForTTQE( taskQueueExecutor );
+                if ( service != null )
+                {
+                    service.shutdown();
+                }
+            }
+            catch ( Exception e )
+            {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    private ExecutorService getExecutorServiceForTTQE( ThreadedTaskQueueExecutor ttqe )
+    {
+        ExecutorService service = null;
+        try
+        {
+            Field executorServiceField = ttqe.getClass().getDeclaredField( "executorService" );
+            executorServiceField.setAccessible( true );
+            service = (ExecutorService) executorServiceField.get( ttqe );
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+        return service;
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/web/startup/Banner.java b/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/web/startup/Banner.java
new file mode 100644 (file)
index 0000000..344cbe6
--- /dev/null
@@ -0,0 +1,229 @@
+package org.apache.archiva.web.startup;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.LoggerFactory;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Banner 
+ *
+ * @version $Id$
+ */
+public class Banner
+{
+    private static final String eol = System.getProperty("line.separator");
+
+    public static String encode( String raw )
+    {
+        // Canonicalize line ends to make them easier to process
+        raw = raw.replace("\r\n", "\n").replace("\r", "\n");
+
+        StringBuilder encoded = new StringBuilder();
+        int rawlen = raw.length();
+
+        for ( int i = 0; i < rawlen; i++ )
+        {
+            char c = raw.charAt( i );
+            if ( c == '\\' )
+            {
+                encoded.append( "$." );
+            }
+            else if ( c == '$' )
+            {
+                encoded.append( "$$" );
+            }
+            else if ( c == '\n' )
+            {
+                encoded.append( "$n" );
+            }
+            else if ( Character.isDigit( c ) )
+            {
+                encoded.append( c );
+            }
+            else if ( Character.isLetter( c ) )
+            {
+                encoded.append( rot13( c ) );
+            }
+            else if ( i < raw.length() - 1 )
+            {
+                char nc;
+                boolean done = false;
+                int count = 0;
+                for ( int n = i; !done; n++ )
+                {
+                    if ( n >= rawlen )
+                    {
+                        break;
+                    }
+
+                    nc = raw.charAt( n );
+
+                    if ( nc != c )
+                    {
+                        done = true;
+                    }
+                    else
+                    {
+                        count++;
+                    }
+                }
+                if ( count < 3 )
+                {
+                    encoded.append( c );
+                }
+                else
+                {
+                    encoded.append( "$" ).append( String.valueOf( count ) ).append( c );
+                    i += count - 1;
+                }
+            }
+            else
+            {
+                encoded.append( c );
+            }
+        }
+
+        return encoded.toString();
+    }
+
+    public static String decode( String encoded )
+    {
+        StringBuilder decoded = new StringBuilder();
+        int enlen = encoded.length();
+        for ( int i = 0; i < enlen; i++ )
+        {
+            char c = encoded.charAt( i );
+            if ( c == '$' )
+            {
+                char nc = encoded.charAt( i + 1 );
+                if ( nc == '$' )
+                {
+                    decoded.append( '$' );
+                    i++;
+                }
+                else if ( nc == '.' )
+                {
+                    decoded.append( '\\' );
+                    i++;
+                }
+                else if ( nc == 'n' )
+                {
+                    decoded.append( eol );
+                    i++;
+                }
+                else if ( Character.isDigit( nc ) )
+                {
+                    int count = 0;
+                    int nn = i + 1;
+                    while ( Character.isDigit( nc ) )
+                    {
+                        count = ( count * 10 );
+                        count += ( nc - '0' );
+                        nc = encoded.charAt( ++nn );
+                    }
+                    for ( int d = 0; d < count; d++ )
+                    {
+                        decoded.append( nc );
+                    }
+                    i = nn;
+                }
+            }
+            else if ( Character.isLetter( c ) )
+            {
+                decoded.append( rot13( c ) );
+            }
+            else
+            {
+                decoded.append( c );
+            }
+        }
+
+        return decoded.toString();
+    }
+
+    private static char rot13( char c )
+    {
+        if ( ( c >= 'a' ) && ( c <= 'z' ) )
+        {
+            char dc = c += 13;
+            if ( dc > 'z' )
+            {
+                dc -= 26;
+            }
+            return dc;
+        }
+        else if ( ( c >= 'A' ) && ( c <= 'Z' ) )
+        {
+            char dc = c += 13;
+            if ( dc > 'Z' )
+            {
+                dc -= 26;
+            }
+            return dc;
+        }
+        else
+        {
+            return c;
+        }
+    }
+
+    public static String injectVersion( String text, String version )
+    {
+        Pattern pat = Pattern.compile( "#{2,}" );
+        Matcher mat = pat.matcher( text );
+        StringBuilder ret = new StringBuilder();
+        int off = 0;
+
+        while ( mat.find( off ) )
+        {
+            ret.append( text.substring( off, mat.start() ) );
+            String repl = mat.group();
+            ret.append( StringUtils.center( version, repl.length() ) );
+            off = mat.end();
+        }
+
+        ret.append( text.substring( off ) );
+
+        return ret.toString();
+    }
+
+    public static String getBanner( String version )
+    {
+        String encodedBanner = "$26 $34_$n$15 /$._$7 /$34 $.$n$14 /`/@),$4 |  Ba" +
+                " orunys bs nyy bs gur nycnpnf   |$n$14 |  (~'  __| gbvyvat njnl ba " +
+                "gur Ncnpur Nepuvin |$n$6 _,--.$3_/  |$4 $.$5  cebwrpg grnz, V jbhyq y" +
+                "vxr gb$3 |$n$4 ,' ,$5 ($3 |$5 $.$5     jrypbzr lbh gb Nepuvin$6 |$" +
+                "n$4 |  ($6 $.  /$6 |  $32#  |$n$5 $.  )$._/  ,_/$7 |$36 |$n$5 / /$3 " +
+                "( |/$9 |     uggc://nepuvin.ncnpur.bet/     |$n$4 ( |$4 ( |$10 |     hf" +
+                "ref@nepuvin.ncnpur.bet$7 |$n$5 $.|$5 $.|$11 $.$34_/$n$n";
+
+        return injectVersion( decode( encodedBanner ), version );
+    }
+
+    public static void display( String version )
+    {
+        String banner = getBanner( version );
+       LoggerFactory.getLogger( Banner.class ).info( StringUtils.repeat( "_", 25 ) + eol + banner );
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/web/startup/SecuritySynchronization.java b/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/web/startup/SecuritySynchronization.java
new file mode 100644 (file)
index 0000000..76d81fe
--- /dev/null
@@ -0,0 +1,245 @@
+package org.apache.archiva.web.startup;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.common.ArchivaException;
+import org.apache.archiva.configuration.ArchivaConfiguration;
+import org.apache.archiva.configuration.ConfigurationNames;
+import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.archiva.security.common.ArchivaRoleConstants;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+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.redback.system.check.EnvironmentCheck;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.codehaus.plexus.registry.Registry;
+import org.codehaus.plexus.registry.RegistryListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * ConfigurationSynchronization
+ *
+ * @version $Id$
+ */
+@Service
+public class SecuritySynchronization
+    implements RegistryListener
+{
+    private Logger log = LoggerFactory.getLogger( SecuritySynchronization.class );
+
+    @Inject
+    private RoleManager roleManager;
+
+    @Inject
+    @Named( value = "rBACManager#cached" )
+    private RBACManager rbacManager;
+
+    private Map<String, EnvironmentCheck> checkers;
+
+    @Inject
+    private ArchivaConfiguration archivaConfiguration;
+
+    @Inject
+    private ApplicationContext applicationContext;
+
+    @PostConstruct
+    public void initialize()
+    {
+        checkers = getBeansOfType( EnvironmentCheck.class );
+    }
+
+    protected <T> Map<String, T> getBeansOfType( Class<T> clazz )
+    {
+        //TODO do some caching here !!!
+        // olamy : with plexus we get only roleHint
+        // as per convention we named spring bean role#hint remove role# if exists
+        Map<String, T> springBeans = applicationContext.getBeansOfType( clazz );
+
+        Map<String, T> beans = new HashMap<String, T>( springBeans.size() );
+
+        for ( Entry<String, T> entry : springBeans.entrySet() )
+        {
+            String key = StringUtils.substringAfterLast( entry.getKey(), "#" );
+            beans.put( key, entry.getValue() );
+        }
+        return beans;
+    }
+
+    public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
+    {
+        if ( ConfigurationNames.isManagedRepositories( propertyName ) )
+        {
+            synchConfiguration( archivaConfiguration.getConfiguration().getManagedRepositories() );
+        }
+    }
+
+    public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
+    {
+        /* do nothing */
+    }
+
+    private void synchConfiguration( List<ManagedRepositoryConfiguration> repos )
+    {
+        // NOTE: Remote Repositories do not have roles or security placed around them.
+
+        for ( ManagedRepositoryConfiguration repoConfig : repos )
+        {
+            // manage roles for repositories
+            try
+            {
+                if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
+                                                       repoConfig.getId() ) )
+                {
+                    roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
+                                                     repoConfig.getId() );
+                }
+                else
+                {
+                    roleManager.verifyTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
+                                                     repoConfig.getId() );
+                }
+
+                if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER,
+                                                       repoConfig.getId() ) )
+                {
+                    roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER,
+                                                     repoConfig.getId() );
+                }
+                else
+                {
+                    roleManager.verifyTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER,
+                                                     repoConfig.getId() );
+                }
+            }
+            catch ( RoleManagerException e )
+            {
+                // Log error.
+                log.error( "Unable to create roles for configured repositories: " + e.getMessage(), e );
+            }
+        }
+    }
+
+    public void startup()
+        throws ArchivaException
+    {
+        executeEnvironmentChecks();
+
+        synchConfiguration( archivaConfiguration.getConfiguration().getManagedRepositories() );
+        archivaConfiguration.addChangeListener( this );
+
+        if ( archivaConfiguration.isDefaulted() )
+        {
+            assignRepositoryObserverToGuestUser( archivaConfiguration.getConfiguration().getManagedRepositories() );
+        }
+    }
+
+    private void executeEnvironmentChecks()
+        throws ArchivaException
+    {
+        if ( ( checkers == null ) || CollectionUtils.isEmpty( checkers.values() ) )
+        {
+            throw new ArchivaException(
+                "Unable to initialize the Redback Security Environment, " + "no Environment Check components found." );
+        }
+
+        List<String> violations = new ArrayList<String>();
+
+        for ( Entry<String, EnvironmentCheck> entry : checkers.entrySet() )
+        {
+            EnvironmentCheck check = entry.getValue();
+            List<String> v = new ArrayList<String>();
+            check.validateEnvironment( v );
+            log.info( "Environment Check: " + entry.getKey() + " -> " + v.size() + " violation(s)" );
+            for ( String s : v )
+            {
+                violations.add( "[" + entry.getKey() + "] " + s );
+            }
+        }
+
+        if ( CollectionUtils.isNotEmpty( violations ) )
+        {
+            StringBuilder msg = new StringBuilder();
+            msg.append( "EnvironmentCheck Failure.\n" );
+            msg.append( "======================================================================\n" );
+            msg.append( " ENVIRONMENT FAILURE !! \n" );
+            msg.append( "\n" );
+
+            for ( String violation : violations )
+            {
+                msg.append( violation ).append( "\n" );
+            }
+
+            msg.append( "\n" );
+            msg.append( "======================================================================" );
+            log.error( msg.toString() );
+
+            throw new ArchivaException( "Unable to initialize Redback Security Environment, [" + violations.size()
+                                            + "] violation(s) encountered, See log for details." );
+        }
+    }
+
+    private void assignRepositoryObserverToGuestUser( List<ManagedRepositoryConfiguration> repos )
+    {
+        for ( ManagedRepositoryConfiguration repoConfig : repos )
+        {
+            String repoId = repoConfig.getId();
+
+            String principal = UserManager.GUEST_USERNAME;
+
+            try
+            {
+                UserAssignment ua;
+
+                if ( rbacManager.userAssignmentExists( principal ) )
+                {
+                    ua = rbacManager.getUserAssignment( principal );
+                }
+                else
+                {
+                    ua = rbacManager.createUserAssignment( principal );
+                }
+
+                ua.addRoleName( ArchivaRoleConstants.toRepositoryObserverRoleName( repoId ) );
+                rbacManager.saveUserAssignment( ua );
+            }
+            catch ( RbacManagerException e )
+            {
+                log.warn( "Unable to add role [" + ArchivaRoleConstants.toRepositoryObserverRoleName( repoId ) + "] to "
+                              + principal + " user.", e );
+            }
+        }
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/webapp/spring/RepositoryListenerFactoryBean.java b/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/webapp/spring/RepositoryListenerFactoryBean.java
deleted file mode 100644 (file)
index 14e1672..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-package org.apache.archiva.webapp.spring;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.archiva.repository.events.RepositoryListener;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-
-import java.util.List;
-
-/**
- * @todo though we will eventually remove this altogether, an interim cleanup would be to genericise this
- * and replace the calls in RepositoryContentConsumers with calls to the same thing
- */
-public class RepositoryListenerFactoryBean
-    implements FactoryBean, ApplicationContextAware
-{
-
-    private ApplicationContext applicationContext;
-
-    public void setApplicationContext( ApplicationContext applicationContext )
-        throws BeansException
-    {
-        this.applicationContext = applicationContext;
-    }
-
-    public Object getObject()
-        throws Exception
-    {
-        return applicationContext.getBeansOfType( RepositoryListener.class ).values();
-    }
-
-    @SuppressWarnings("unchecked")
-    public Class<List> getObjectType()
-    {
-        return List.class;
-    }
-
-    public boolean isSingleton()
-    {
-        return true;
-    }
-
-    
-}
diff --git a/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/webapp/startup/ArchivaStartup.java b/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/webapp/startup/ArchivaStartup.java
deleted file mode 100644 (file)
index 3ad800e..0000000
+++ /dev/null
@@ -1,208 +0,0 @@
-package org.apache.archiva.webapp.startup;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.archiva.common.ArchivaException;
-import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
-import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
-import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
-import org.apache.maven.index.NexusIndexer;
-import org.apache.maven.index.context.IndexingContext;
-import org.codehaus.plexus.taskqueue.Task;
-import org.codehaus.plexus.taskqueue.execution.ThreadedTaskQueueExecutor;
-import org.codehaus.redback.components.scheduler.DefaultScheduler;
-import org.quartz.SchedulerException;
-import org.springframework.web.context.WebApplicationContext;
-import org.springframework.web.context.support.WebApplicationContextUtils;
-
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import java.lang.reflect.Field;
-import java.util.Properties;
-import java.util.concurrent.ExecutorService;
-
-/**
- * ArchivaStartup - the startup of all archiva features in a deterministic order.
- *
- * @version $Id$
- */
-public class ArchivaStartup
-    implements ServletContextListener
-{
-    private ThreadedTaskQueueExecutor tqeDbScanning;
-
-    private ThreadedTaskQueueExecutor tqeRepoScanning;
-
-    private ThreadedTaskQueueExecutor tqeIndexing;
-
-    private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
-
-    private PlexusSisuBridge plexusSisuBridge;
-
-    private NexusIndexer nexusIndexer;
-
-    public void contextInitialized( ServletContextEvent contextEvent )
-    {
-        WebApplicationContext wac =
-            WebApplicationContextUtils.getRequiredWebApplicationContext( contextEvent.getServletContext() );
-
-        SecuritySynchronization securitySync = wac.getBean( SecuritySynchronization.class );
-
-        repositoryTaskScheduler =
-            wac.getBean( "archivaTaskScheduler#repository", RepositoryArchivaTaskScheduler.class );
-
-        Properties archivaRuntimeProperties = wac.getBean( "archivaRuntimeProperties", Properties.class );
-
-        tqeRepoScanning = wac.getBean( "taskQueueExecutor#repository-scanning", ThreadedTaskQueueExecutor.class );
-
-        tqeIndexing = wac.getBean( "taskQueueExecutor#indexing", ThreadedTaskQueueExecutor.class );
-
-        plexusSisuBridge = wac.getBean( PlexusSisuBridge.class );
-
-        try
-        {
-            nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
-        }
-        catch ( PlexusSisuBridgeException e )
-        {
-            throw new RuntimeException( "Unable to get NexusIndexer: " + e.getMessage(), e );
-        }
-        try
-        {
-            securitySync.startup();
-            repositoryTaskScheduler.startup();
-            Banner.display( (String) archivaRuntimeProperties.get( "archiva.version" ) );
-        }
-        catch ( ArchivaException e )
-        {
-            throw new RuntimeException( "Unable to properly startup archiva: " + e.getMessage(), e );
-        }
-    }
-
-    public void contextDestroyed( ServletContextEvent contextEvent )
-    {
-        WebApplicationContext applicationContext =
-            WebApplicationContextUtils.getRequiredWebApplicationContext( contextEvent.getServletContext() );
-
-        // TODO check this stop
-
-        /*
-        if ( applicationContext != null && applicationContext instanceof ClassPathXmlApplicationContext )
-        {
-            ( (ClassPathXmlApplicationContext) applicationContext ).close();
-        } */
-
-        if ( applicationContext != null ) //&& applicationContext instanceof PlexusWebApplicationContext )
-        {
-            // stop task queue executors
-            stopTaskQueueExecutor( tqeDbScanning );
-            stopTaskQueueExecutor( tqeRepoScanning );
-            stopTaskQueueExecutor( tqeIndexing );
-
-            // stop the DefaultArchivaTaskScheduler and its scheduler
-            if ( repositoryTaskScheduler != null )
-            {
-                try
-                {
-                    repositoryTaskScheduler.stop();
-                }
-                catch ( SchedulerException e )
-                {
-                    e.printStackTrace();
-                }
-
-                try
-                {
-                    // shutdown the scheduler, otherwise Quartz scheduler and Threads still exists
-                    Field schedulerField = repositoryTaskScheduler.getClass().getDeclaredField( "scheduler" );
-                    schedulerField.setAccessible( true );
-
-                    DefaultScheduler scheduler = (DefaultScheduler) schedulerField.get( repositoryTaskScheduler );
-                    scheduler.stop();
-                }
-                catch ( Exception e )
-                {
-                    e.printStackTrace();
-                }
-            }
-
-            // close the application context
-            //applicationContext.close();
-            // TODO fix close call
-            //applicationContext.
-        }
-
-        // closing correctly indexer to close correctly lock and file
-        for ( IndexingContext indexingContext : nexusIndexer.getIndexingContexts().values() )
-        {
-            try
-            {
-                indexingContext.close( false );
-            }
-            catch ( Exception e )
-            {
-                contextEvent.getServletContext().log( "skip error closing indexingContext " + e.getMessage() );
-            }
-        }
-
-    }
-
-    private void stopTaskQueueExecutor( ThreadedTaskQueueExecutor taskQueueExecutor )
-    {
-        if ( taskQueueExecutor != null )
-        {
-            Task currentTask = taskQueueExecutor.getCurrentTask();
-            if ( currentTask != null )
-            {
-                taskQueueExecutor.cancelTask( currentTask );
-            }
-
-            try
-            {
-                taskQueueExecutor.stop();
-                ExecutorService service = getExecutorServiceForTTQE( taskQueueExecutor );
-                if ( service != null )
-                {
-                    service.shutdown();
-                }
-            }
-            catch ( Exception e )
-            {
-                e.printStackTrace();
-            }
-        }
-    }
-
-    private ExecutorService getExecutorServiceForTTQE( ThreadedTaskQueueExecutor ttqe )
-    {
-        ExecutorService service = null;
-        try
-        {
-            Field executorServiceField = ttqe.getClass().getDeclaredField( "executorService" );
-            executorServiceField.setAccessible( true );
-            service = (ExecutorService) executorServiceField.get( ttqe );
-        }
-        catch ( Exception e )
-        {
-            e.printStackTrace();
-        }
-        return service;
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/webapp/startup/Banner.java b/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/webapp/startup/Banner.java
deleted file mode 100644 (file)
index 27cf88d..0000000
+++ /dev/null
@@ -1,229 +0,0 @@
-package org.apache.archiva.webapp.startup;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.LoggerFactory;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Banner 
- *
- * @version $Id$
- */
-public class Banner
-{
-    private static final String eol = System.getProperty("line.separator");
-
-    public static String encode( String raw )
-    {
-        // Canonicalize line ends to make them easier to process
-        raw = raw.replace("\r\n", "\n").replace("\r", "\n");
-
-        StringBuilder encoded = new StringBuilder();
-        int rawlen = raw.length();
-
-        for ( int i = 0; i < rawlen; i++ )
-        {
-            char c = raw.charAt( i );
-            if ( c == '\\' )
-            {
-                encoded.append( "$." );
-            }
-            else if ( c == '$' )
-            {
-                encoded.append( "$$" );
-            }
-            else if ( c == '\n' )
-            {
-                encoded.append( "$n" );
-            }
-            else if ( Character.isDigit( c ) )
-            {
-                encoded.append( c );
-            }
-            else if ( Character.isLetter( c ) )
-            {
-                encoded.append( rot13( c ) );
-            }
-            else if ( i < raw.length() - 1 )
-            {
-                char nc;
-                boolean done = false;
-                int count = 0;
-                for ( int n = i; !done; n++ )
-                {
-                    if ( n >= rawlen )
-                    {
-                        break;
-                    }
-
-                    nc = raw.charAt( n );
-
-                    if ( nc != c )
-                    {
-                        done = true;
-                    }
-                    else
-                    {
-                        count++;
-                    }
-                }
-                if ( count < 3 )
-                {
-                    encoded.append( c );
-                }
-                else
-                {
-                    encoded.append( "$" ).append( String.valueOf( count ) ).append( c );
-                    i += count - 1;
-                }
-            }
-            else
-            {
-                encoded.append( c );
-            }
-        }
-
-        return encoded.toString();
-    }
-
-    public static String decode( String encoded )
-    {
-        StringBuilder decoded = new StringBuilder();
-        int enlen = encoded.length();
-        for ( int i = 0; i < enlen; i++ )
-        {
-            char c = encoded.charAt( i );
-            if ( c == '$' )
-            {
-                char nc = encoded.charAt( i + 1 );
-                if ( nc == '$' )
-                {
-                    decoded.append( '$' );
-                    i++;
-                }
-                else if ( nc == '.' )
-                {
-                    decoded.append( '\\' );
-                    i++;
-                }
-                else if ( nc == 'n' )
-                {
-                    decoded.append( eol );
-                    i++;
-                }
-                else if ( Character.isDigit( nc ) )
-                {
-                    int count = 0;
-                    int nn = i + 1;
-                    while ( Character.isDigit( nc ) )
-                    {
-                        count = ( count * 10 );
-                        count += ( nc - '0' );
-                        nc = encoded.charAt( ++nn );
-                    }
-                    for ( int d = 0; d < count; d++ )
-                    {
-                        decoded.append( nc );
-                    }
-                    i = nn;
-                }
-            }
-            else if ( Character.isLetter( c ) )
-            {
-                decoded.append( rot13( c ) );
-            }
-            else
-            {
-                decoded.append( c );
-            }
-        }
-
-        return decoded.toString();
-    }
-
-    private static char rot13( char c )
-    {
-        if ( ( c >= 'a' ) && ( c <= 'z' ) )
-        {
-            char dc = c += 13;
-            if ( dc > 'z' )
-            {
-                dc -= 26;
-            }
-            return dc;
-        }
-        else if ( ( c >= 'A' ) && ( c <= 'Z' ) )
-        {
-            char dc = c += 13;
-            if ( dc > 'Z' )
-            {
-                dc -= 26;
-            }
-            return dc;
-        }
-        else
-        {
-            return c;
-        }
-    }
-
-    public static String injectVersion( String text, String version )
-    {
-        Pattern pat = Pattern.compile( "#{2,}" );
-        Matcher mat = pat.matcher( text );
-        StringBuilder ret = new StringBuilder();
-        int off = 0;
-
-        while ( mat.find( off ) )
-        {
-            ret.append( text.substring( off, mat.start() ) );
-            String repl = mat.group();
-            ret.append( StringUtils.center( version, repl.length() ) );
-            off = mat.end();
-        }
-
-        ret.append( text.substring( off ) );
-
-        return ret.toString();
-    }
-
-    public static String getBanner( String version )
-    {
-        String encodedBanner = "$26 $34_$n$15 /$._$7 /$34 $.$n$14 /`/@),$4 |  Ba" +
-                " orunys bs nyy bs gur nycnpnf   |$n$14 |  (~'  __| gbvyvat njnl ba " +
-                "gur Ncnpur Nepuvin |$n$6 _,--.$3_/  |$4 $.$5  cebwrpg grnz, V jbhyq y" +
-                "vxr gb$3 |$n$4 ,' ,$5 ($3 |$5 $.$5     jrypbzr lbh gb Nepuvin$6 |$" +
-                "n$4 |  ($6 $.  /$6 |  $32#  |$n$5 $.  )$._/  ,_/$7 |$36 |$n$5 / /$3 " +
-                "( |/$9 |     uggc://nepuvin.ncnpur.bet/     |$n$4 ( |$4 ( |$10 |     hf" +
-                "ref@nepuvin.ncnpur.bet$7 |$n$5 $.|$5 $.|$11 $.$34_/$n$n";
-
-        return injectVersion( decode( encodedBanner ), version );
-    }
-
-    public static void display( String version )
-    {
-        String banner = getBanner( version );
-       LoggerFactory.getLogger( Banner.class ).info( StringUtils.repeat( "_", 25 ) + eol + banner );
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/webapp/startup/SecuritySynchronization.java b/archiva-modules/archiva-web/archiva-webapp-common/src/main/java/org/apache/archiva/webapp/startup/SecuritySynchronization.java
deleted file mode 100644 (file)
index 1a8a797..0000000
+++ /dev/null
@@ -1,245 +0,0 @@
-package org.apache.archiva.webapp.startup;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.archiva.common.ArchivaException;
-import org.apache.archiva.configuration.ArchivaConfiguration;
-import org.apache.archiva.configuration.ConfigurationNames;
-import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.archiva.security.common.ArchivaRoleConstants;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang.StringUtils;
-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.redback.system.check.EnvironmentCheck;
-import org.codehaus.plexus.redback.users.UserManager;
-import org.codehaus.plexus.registry.Registry;
-import org.codehaus.plexus.registry.RegistryListener;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.ApplicationContext;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-import javax.inject.Named;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * ConfigurationSynchronization
- *
- * @version $Id$
- */
-@Service
-public class SecuritySynchronization
-    implements RegistryListener
-{
-    private Logger log = LoggerFactory.getLogger( SecuritySynchronization.class );
-
-    @Inject
-    private RoleManager roleManager;
-
-    @Inject
-    @Named( value = "rBACManager#cached" )
-    private RBACManager rbacManager;
-
-    private Map<String, EnvironmentCheck> checkers;
-
-    @Inject
-    private ArchivaConfiguration archivaConfiguration;
-
-    @Inject
-    private ApplicationContext applicationContext;
-
-    @PostConstruct
-    public void initialize()
-    {
-        checkers = getBeansOfType( EnvironmentCheck.class );
-    }
-
-    protected <T> Map<String, T> getBeansOfType( Class<T> clazz )
-    {
-        //TODO do some caching here !!!
-        // olamy : with plexus we get only roleHint
-        // as per convention we named spring bean role#hint remove role# if exists
-        Map<String, T> springBeans = applicationContext.getBeansOfType( clazz );
-
-        Map<String, T> beans = new HashMap<String, T>( springBeans.size() );
-
-        for ( Entry<String, T> entry : springBeans.entrySet() )
-        {
-            String key = StringUtils.substringAfterLast( entry.getKey(), "#" );
-            beans.put( key, entry.getValue() );
-        }
-        return beans;
-    }
-
-    public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
-    {
-        if ( ConfigurationNames.isManagedRepositories( propertyName ) )
-        {
-            synchConfiguration( archivaConfiguration.getConfiguration().getManagedRepositories() );
-        }
-    }
-
-    public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
-    {
-        /* do nothing */
-    }
-
-    private void synchConfiguration( List<ManagedRepositoryConfiguration> repos )
-    {
-        // NOTE: Remote Repositories do not have roles or security placed around them.
-
-        for ( ManagedRepositoryConfiguration repoConfig : repos )
-        {
-            // manage roles for repositories
-            try
-            {
-                if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
-                                                       repoConfig.getId() ) )
-                {
-                    roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
-                                                     repoConfig.getId() );
-                }
-                else
-                {
-                    roleManager.verifyTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
-                                                     repoConfig.getId() );
-                }
-
-                if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER,
-                                                       repoConfig.getId() ) )
-                {
-                    roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER,
-                                                     repoConfig.getId() );
-                }
-                else
-                {
-                    roleManager.verifyTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER,
-                                                     repoConfig.getId() );
-                }
-            }
-            catch ( RoleManagerException e )
-            {
-                // Log error.
-                log.error( "Unable to create roles for configured repositories: " + e.getMessage(), e );
-            }
-        }
-    }
-
-    public void startup()
-        throws ArchivaException
-    {
-        executeEnvironmentChecks();
-
-        synchConfiguration( archivaConfiguration.getConfiguration().getManagedRepositories() );
-        archivaConfiguration.addChangeListener( this );
-
-        if ( archivaConfiguration.isDefaulted() )
-        {
-            assignRepositoryObserverToGuestUser( archivaConfiguration.getConfiguration().getManagedRepositories() );
-        }
-    }
-
-    private void executeEnvironmentChecks()
-        throws ArchivaException
-    {
-        if ( ( checkers == null ) || CollectionUtils.isEmpty( checkers.values() ) )
-        {
-            throw new ArchivaException(
-                "Unable to initialize the Redback Security Environment, " + "no Environment Check components found." );
-        }
-
-        List<String> violations = new ArrayList<String>();
-
-        for ( Entry<String, EnvironmentCheck> entry : checkers.entrySet() )
-        {
-            EnvironmentCheck check = entry.getValue();
-            List<String> v = new ArrayList<String>();
-            check.validateEnvironment( v );
-            log.info( "Environment Check: " + entry.getKey() + " -> " + v.size() + " violation(s)" );
-            for ( String s : v )
-            {
-                violations.add( "[" + entry.getKey() + "] " + s );
-            }
-        }
-
-        if ( CollectionUtils.isNotEmpty( violations ) )
-        {
-            StringBuilder msg = new StringBuilder();
-            msg.append( "EnvironmentCheck Failure.\n" );
-            msg.append( "======================================================================\n" );
-            msg.append( " ENVIRONMENT FAILURE !! \n" );
-            msg.append( "\n" );
-
-            for ( String violation : violations )
-            {
-                msg.append( violation ).append( "\n" );
-            }
-
-            msg.append( "\n" );
-            msg.append( "======================================================================" );
-            log.error( msg.toString() );
-
-            throw new ArchivaException( "Unable to initialize Redback Security Environment, [" + violations.size()
-                                            + "] violation(s) encountered, See log for details." );
-        }
-    }
-
-    private void assignRepositoryObserverToGuestUser( List<ManagedRepositoryConfiguration> repos )
-    {
-        for ( ManagedRepositoryConfiguration repoConfig : repos )
-        {
-            String repoId = repoConfig.getId();
-
-            String principal = UserManager.GUEST_USERNAME;
-
-            try
-            {
-                UserAssignment ua;
-
-                if ( rbacManager.userAssignmentExists( principal ) )
-                {
-                    ua = rbacManager.getUserAssignment( principal );
-                }
-                else
-                {
-                    ua = rbacManager.createUserAssignment( principal );
-                }
-
-                ua.addRoleName( ArchivaRoleConstants.toRepositoryObserverRoleName( repoId ) );
-                rbacManager.saveUserAssignment( ua );
-            }
-            catch ( RbacManagerException e )
-            {
-                log.warn( "Unable to add role [" + ArchivaRoleConstants.toRepositoryObserverRoleName( repoId ) + "] to "
-                              + principal + " user.", e );
-            }
-        }
-    }
-}