--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
+ <modelVersion>4.0.0</modelVersion>\r
+ <parent>\r
+ <groupId>org.apache.archiva</groupId>\r
+ <artifactId>archiva-web</artifactId>\r
+ <version>1.4-M2-SNAPSHOT</version>\r
+ </parent>\r
+\r
+ <artifactId>archiva-webapp-common</artifactId>\r
+\r
+ <name>archiva-webapp-common</name>\r
+\r
+ <dependencies>\r
+ <dependency>\r
+ <groupId>org.apache.archiva</groupId>\r
+ <artifactId>metadata-repository-api</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.apache.archiva</groupId>\r
+ <artifactId>archiva-configuration</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.apache.archiva</groupId>\r
+ <artifactId>archiva-security-common</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.apache.archiva</groupId>\r
+ <artifactId>archiva-plexus-bridge</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.apache.archiva</groupId>\r
+ <artifactId>archiva-scheduler-repository</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.codehaus.redback</groupId>\r
+ <artifactId>redback-rbac-model</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.codehaus.redback</groupId>\r
+ <artifactId>redback-rbac-role-manager</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.codehaus.redback</groupId>\r
+ <artifactId>redback-system</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>javax.servlet</groupId>\r
+ <artifactId>servlet-api</artifactId>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.codehaus.redback.components</groupId>\r
+ <artifactId>spring-taskqueue</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.codehaus.redback.components</groupId>\r
+ <artifactId>spring-quartz</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.quartz-scheduler</groupId>\r
+ <artifactId>quartz</artifactId>\r
+ <exclusions>\r
+ <exclusion>\r
+ <groupId>c3p0</groupId>\r
+ <artifactId>c3p0</artifactId>\r
+ </exclusion>\r
+ <exclusion>\r
+ <groupId>javax.transaction</groupId>\r
+ <artifactId>jta</artifactId>\r
+ </exclusion>\r
+ </exclusions>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.springframework</groupId>\r
+ <artifactId>spring-core</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.springframework</groupId>\r
+ <artifactId>spring-beans</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.springframework</groupId>\r
+ <artifactId>spring-context-support</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.springframework</groupId>\r
+ <artifactId>spring-web</artifactId>\r
+ </dependency>\r
+ </dependencies>\r
+\r
+</project>\r
--- /dev/null
+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;
+ }
+
+
+}
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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 );
+ }
+}
--- /dev/null
+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 );
+ }
+ }
+ }
+}
--- /dev/null
+<?xml version="1.0"?>
+
+<!--
+ ~ 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util-3.0.xsd"
+ default-lazy-init="true">
+
+ <context:annotation-config/>
+ <context:component-scan base-package="org.apache.archiva.web.spring, org.apache.archiva.web.startup"/>
+
+</beans>
\ No newline at end of file
<version>1.4-M2-SNAPSHOT</version>\r
</parent>\r
<artifactId>archiva-webapp-js</artifactId>\r
- <version>1.4-M2-SNAPSHOT</version>\r
<packaging>war</packaging>\r
\r
<name>Archiva Web :: Javascript Application</name>\r
<scope>provided</scope>\r
</dependency>\r
\r
+ <dependency>\r
+ <groupId>org.apache.archiva</groupId>\r
+ <artifactId>archiva-webapp-common</artifactId>\r
+ </dependency>\r
+\r
<dependency>\r
<groupId>org.apache.archiva</groupId>\r
<artifactId>archiva-webdav</artifactId>\r
+++ /dev/null
-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;
- }
-
-
-}
+++ /dev/null
-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;
- }
-}
+++ /dev/null
-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 java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.LoggerFactory;
-
-/**
- * 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 );
- }
-}
+++ /dev/null
-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.security.common.ArchivaRoleConstants;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang.StringUtils;
-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.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 );
- }
- }
- }
-}
default-lazy-init="true">
<context:annotation-config/>
- <context:component-scan base-package="org.apache.archiva.web"/>
+
<util:properties id="archivaRuntimeProperties" location="classpath:application.properties" />
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-webdav</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-webapp-common</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<modules>
<module>archiva-applet</module>
<module>archiva-security</module>
- <module>archiva-webapp</module>
<module>archiva-webdav</module>
<module>archiva-rss</module>
<module>archiva-xmlrpc</module>
<module>archiva-rest</module>
+ <module>archiva-webapp-common</module>
+ <module>archiva-webapp</module>
</modules>
<build>
<artifactId>archiva-webdav</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-webapp-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-rss</artifactId>