ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1329199 [1/5] - in /ace/trunk: ./ ace-authenticationprocessor-basicauth/src/main/java/org/apache/ace/authenticationprocessor/basicauth/ ace-client-automation/src/main/java/org/apache/ace/client/automation/ ace-client-repository-api/src/mai...
Date Mon, 23 Apr 2012 12:15:06 GMT
Author: jawi
Date: Mon Apr 23 12:15:01 2012
New Revision: 1329199

URL: http://svn.apache.org/viewvc?rev=1329199&view=rev
Log:
ACE-255: implement an authentication mechanism to protected public interfaces.

Added:
    ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactResource.java   (with props)
    ace/trunk/ace-client-repository-impl/src/test/java/org/apache/ace/client/repository/impl/RepositoryAdminLoginContextImplTest.java   (with props)
    ace/trunk/ace-connectionfactory/   (with props)
    ace/trunk/ace-connectionfactory/pom.xml   (with props)
    ace/trunk/ace-connectionfactory/src/
    ace/trunk/ace-connectionfactory/src/main/
    ace/trunk/ace-connectionfactory/src/main/java/
    ace/trunk/ace-connectionfactory/src/main/java/org/
    ace/trunk/ace-connectionfactory/src/main/java/org/apache/
    ace/trunk/ace-connectionfactory/src/main/java/org/apache/ace/
    ace/trunk/ace-connectionfactory/src/main/java/org/apache/ace/connectionfactory/
    ace/trunk/ace-connectionfactory/src/main/java/org/apache/ace/connectionfactory/ConnectionFactory.java   (with props)
    ace/trunk/ace-connectionfactory/src/main/java/org/apache/ace/connectionfactory/impl/
    ace/trunk/ace-connectionfactory/src/main/java/org/apache/ace/connectionfactory/impl/Activator.java   (with props)
    ace/trunk/ace-connectionfactory/src/main/java/org/apache/ace/connectionfactory/impl/ConnectionFactoryImpl.java   (with props)
    ace/trunk/ace-connectionfactory/src/main/java/org/apache/ace/connectionfactory/impl/UrlCredentials.java   (with props)
    ace/trunk/ace-connectionfactory/src/main/java/org/apache/ace/connectionfactory/impl/UrlCredentialsFactory.java   (with props)
    ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/
    ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/authentication/ObrAuthenticationTest.java   (with props)
    ace/trunk/ace-target-devgateway/src/main/resources/conf/org.apache.ace.target.log.factory/
      - copied from r1327840, ace/trunk/ace-target-devgateway/src/main/resources/conf/org.apache.ace.gateway.log.factory/
    ace/trunk/ace-target-devgateway/src/main/resources/conf/org.apache.ace.target.log.store.factory/
      - copied from r1327840, ace/trunk/ace-target-devgateway/src/main/resources/conf/org.apache.ace.gateway.log.store.factory/
    ace/trunk/ace-target-devgateway/src/main/resources/conf/org.apache.ace.target.log.sync.factory/
      - copied from r1327840, ace/trunk/ace-target-devgateway/src/main/resources/conf/org.apache.ace.gateway.log.sync.factory/
Removed:
    ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/gateway/log/
    ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/target/log/task/Connection.java
    ace/trunk/ace-gateway-log/src/test/java/org/apache/ace/gateway/log/
    ace/trunk/ace-target-devgateway/src/main/resources/conf/org.apache.ace.gateway.log.factory/
    ace/trunk/ace-target-devgateway/src/main/resources/conf/org.apache.ace.gateway.log.store.factory/
    ace/trunk/ace-target-devgateway/src/main/resources/conf/org.apache.ace.gateway.log.sync.factory/
Modified:
    ace/trunk/ace-authenticationprocessor-basicauth/src/main/java/org/apache/ace/authenticationprocessor/basicauth/BasicHttpAuthenticationProcessor.java
    ace/trunk/ace-client-automation/src/main/java/org/apache/ace/client/automation/AutoTargetOperator.java
    ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/RepositoryAdminLoginContext.java
    ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactPreprocessor.java
    ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactRecognizer.java
    ace/trunk/ace-client-repository-helper-base/pom.xml
    ace/trunk/ace-client-repository-helper-base/src/main/java/org/apache/ace/client/repository/helper/base/ArtifactPreprocessorBase.java
    ace/trunk/ace-client-repository-helper-base/src/main/java/org/apache/ace/client/repository/helper/base/VelocityArtifactPreprocessor.java
    ace/trunk/ace-client-repository-helper-base/src/test/java/org/apache/ace/client/repository/helper/base/VelocityArtifactPreprocessorTest.java
    ace/trunk/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/BundleHelperImpl.java
    ace/trunk/ace-client-repository-helper-configuration/pom.xml
    ace/trunk/ace-client-repository-helper-configuration/src/main/java/org/apache/ace/client/repository/helper/configuration/impl/Activator.java
    ace/trunk/ace-client-repository-helper-configuration/src/main/java/org/apache/ace/client/repository/helper/configuration/impl/ConfigurationHelperImpl.java
    ace/trunk/ace-client-repository-helper-configuration/src/test/java/org/apache/ace/client/repository/helper/configuration/impl/ConfigurationHelperImplTest.java
    ace/trunk/ace-client-repository-helper-user/pom.xml
    ace/trunk/ace-client-repository-helper-user/src/main/java/org/apache/ace/client/repository/helper/user/impl/Activator.java
    ace/trunk/ace-client-repository-helper-user/src/main/java/org/apache/ace/client/repository/helper/user/impl/UserHelperImpl.java
    ace/trunk/ace-client-repository-impl/pom.xml
    ace/trunk/ace-client-repository-impl/src/main/java/org/apache/ace/client/repository/impl/Activator.java
    ace/trunk/ace-client-repository-impl/src/main/java/org/apache/ace/client/repository/impl/ArtifactRepositoryImpl.java
    ace/trunk/ace-client-repository-impl/src/main/java/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java
    ace/trunk/ace-client-repository-impl/src/main/java/org/apache/ace/client/repository/impl/RepositoryAdminLoginContextImpl.java
    ace/trunk/ace-client-repository-impl/src/main/java/org/apache/ace/client/repository/stateful/impl/StatefulTargetRepositoryImpl.java
    ace/trunk/ace-client-repository-impl/src/test/java/org/apache/ace/client/repository/impl/CachedRepositoryImplTest.java
    ace/trunk/ace-client-rest/pom.xml
    ace/trunk/ace-client-rest/src/main/java/org/apache/ace/client/rest/RESTClientServlet.java
    ace/trunk/ace-client-rest/src/main/java/org/apache/ace/client/rest/Workspace.java
    ace/trunk/ace-configurator-useradmin-task/src/main/java/org/apache/ace/configurator/useradmin/task/UpdateUserAdminTask.java
    ace/trunk/ace-deployment-provider-repositorybased/src/main/java/org/apache/ace/deployment/provider/repositorybased/RepositoryBasedProvider.java
    ace/trunk/ace-deployment-servlet/pom.xml
    ace/trunk/ace-deployment-servlet/src/main/java/org/apache/ace/deployment/servlet/DeploymentServlet.java
    ace/trunk/ace-deployment-streamgenerator/pom.xml
    ace/trunk/ace-deployment-streamgenerator/src/main/java/org/apache/ace/deployment/streamgenerator/impl/Activator.java
    ace/trunk/ace-deployment-streamgenerator/src/main/java/org/apache/ace/deployment/streamgenerator/impl/StreamGeneratorImpl.java
    ace/trunk/ace-deployment-streamgenerator/src/test/java/org/apache/ace/deployment/streamgenerator/impl/StreamTest.java
    ace/trunk/ace-deployment-task-base/pom.xml
    ace/trunk/ace-deployment-task-base/src/main/java/org/apache/ace/deployment/service/impl/Activator.java
    ace/trunk/ace-deployment-task-base/src/main/java/org/apache/ace/deployment/service/impl/DeploymentServiceImpl.java
    ace/trunk/ace-deployment-task-base/src/test/java/org/apache/ace/deployment/service/impl/DeploymentServiceImplTest.java
    ace/trunk/ace-deployment-verifier-ui/pom.xml
    ace/trunk/ace-deployment-verifier-ui/src/main/java/org/apache/ace/deployment/verifier/ui/ACEVerifierExtension.java
    ace/trunk/ace-deployment-verifier-ui/src/main/java/org/apache/ace/deployment/verifier/ui/Activator.java
    ace/trunk/ace-gateway-log/pom.xml
    ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/target/log/LogSyncConfigurator.java
    ace/trunk/ace-gateway-log/src/main/java/org/apache/ace/target/log/task/LogSyncTask.java
    ace/trunk/ace-gateway-log/src/test/java/org/apache/ace/target/log/task/LogSyncTaskTest.java
    ace/trunk/ace-http-redirector/src/main/java/org/apache/ace/http/redirector/Activator.java
    ace/trunk/ace-integrationtests/pom.xml
    ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/Options.java
    ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/deployment/DeploymentIntegrationTest.java
    ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/log/LogIntegrationTest.java
    ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/repository/RepositoryTest.java
    ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/repositoryadmin/RepositoryAdminTest.java
    ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java
    ace/trunk/ace-launcher/src/main/java/org/apache/ace/launcher/Main.java
    ace/trunk/ace-log-servlet/pom.xml
    ace/trunk/ace-log-servlet/src/main/java/org/apache/ace/server/log/servlet/Activator.java
    ace/trunk/ace-log-servlet/src/main/java/org/apache/ace/server/log/servlet/LogServlet.java
    ace/trunk/ace-log-servlet/src/test/java/org/apache/ace/server/log/servlet/LogServletTest.java
    ace/trunk/ace-log-task/pom.xml
    ace/trunk/ace-log-task/src/main/java/org/apache/ace/server/log/task/Activator.java
    ace/trunk/ace-log-task/src/main/java/org/apache/ace/server/log/task/LogSyncTask.java
    ace/trunk/ace-managementagent/pom.xml
    ace/trunk/ace-managementagent/src/main/java/org/apache/ace/managementagent/Activator.java
    ace/trunk/ace-obr-servlet/pom.xml
    ace/trunk/ace-obr-servlet/src/main/java/org/apache/ace/obr/servlet/BundleServlet.java
    ace/trunk/ace-repository-api/src/main/java/org/apache/ace/repository/Repository.java
    ace/trunk/ace-repository-api/src/main/java/org/apache/ace/repository/RepositoryReplication.java
    ace/trunk/ace-repository-ext/pom.xml
    ace/trunk/ace-repository-ext/src/main/java/org/apache/ace/repository/ext/impl/CachedRepositoryImpl.java
    ace/trunk/ace-repository-ext/src/main/java/org/apache/ace/repository/ext/impl/RemoteRepository.java
    ace/trunk/ace-repository-servlet/pom.xml
    ace/trunk/ace-repository-servlet/src/main/java/org/apache/ace/repository/servlet/RepositoryReplicationServlet.java
    ace/trunk/ace-repository-servlet/src/main/java/org/apache/ace/repository/servlet/RepositoryServlet.java
    ace/trunk/ace-repository-servlet/src/main/java/org/apache/ace/repository/servlet/RepositoryServletBase.java
    ace/trunk/ace-repository-task/pom.xml
    ace/trunk/ace-repository-task/src/main/java/org/apache/ace/repository/task/Activator.java
    ace/trunk/ace-repository-task/src/main/java/org/apache/ace/repository/task/RepositoryReplicationTask.java
    ace/trunk/ace-scheduler/src/test/java/org/apache/ace/scheduler/ExecuterTest.java
    ace/trunk/ace-scheduler/src/test/java/org/apache/ace/scheduler/SchedulerTest.java
    ace/trunk/ace-server-log-ui/pom.xml
    ace/trunk/ace-tageditor/pom.xml
    ace/trunk/ace-target-devgateway/pom.xml
    ace/trunk/ace-target-devserver/pom.xml
    ace/trunk/ace-target-devserver/src/main/resources/conf/org.apache.ace.client.rest.cfg
    ace/trunk/ace-target-devserver/src/main/resources/conf/org.apache.ace.deployment.provider.repositorybased.cfg
    ace/trunk/ace-target-devserver/src/main/resources/conf/org.apache.ace.deployment.servlet.cfg
    ace/trunk/ace-target-devserver/src/main/resources/conf/org.apache.ace.obr.servlet.cfg
    ace/trunk/ace-target-devserver/src/main/resources/conf/org.apache.ace.repository.servlet.RepositoryReplicationServlet.cfg
    ace/trunk/ace-target-devserver/src/main/resources/conf/org.apache.ace.repository.servlet.RepositoryServlet.cfg
    ace/trunk/ace-target-devserver/src/main/resources/conf/org.apache.ace.server.log.servlet.factory/auditlog.cfg
    ace/trunk/ace-target-devserver/src/main/resources/conf/org.apache.ace.webui.vaadin.cfg
    ace/trunk/ace-target-mgmt-ui/pom.xml
    ace/trunk/ace-webui-vaadin/pom.xml
    ace/trunk/ace-webui-vaadin/src/main/java/org/apache/ace/webui/vaadin/AddArtifactWindow.java
    ace/trunk/ace-webui-vaadin/src/main/java/org/apache/ace/webui/vaadin/VaadinClient.java
    ace/trunk/ace-webui-vaadin/src/main/java/org/apache/ace/webui/vaadin/VaadinServlet.java
    ace/trunk/ace-webui-vaadin/src/main/java/org/apache/ace/webui/vaadin/component/MainActionToolbar.java
    ace/trunk/pom.xml
    ace/trunk/pom/pom.xml

Modified: ace/trunk/ace-authenticationprocessor-basicauth/src/main/java/org/apache/ace/authenticationprocessor/basicauth/BasicHttpAuthenticationProcessor.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-authenticationprocessor-basicauth/src/main/java/org/apache/ace/authenticationprocessor/basicauth/BasicHttpAuthenticationProcessor.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-authenticationprocessor-basicauth/src/main/java/org/apache/ace/authenticationprocessor/basicauth/BasicHttpAuthenticationProcessor.java (original)
+++ ace/trunk/ace-authenticationprocessor-basicauth/src/main/java/org/apache/ace/authenticationprocessor/basicauth/BasicHttpAuthenticationProcessor.java Mon Apr 23 12:15:01 2012
@@ -27,6 +27,7 @@ import org.apache.ace.authentication.api
 import org.apache.commons.codec.binary.Base64;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedService;
+import org.osgi.service.useradmin.Role;
 import org.osgi.service.useradmin.User;
 import org.osgi.service.useradmin.UserAdmin;
 
@@ -88,7 +89,7 @@ public class BasicHttpAuthenticationProc
             return null;
         }
 
-        User user = userAdmin.getUser(m_keyUsername, credentials[0]);
+        User user = getUser(userAdmin, credentials[0]);
         if (user == null || !user.hasCredential(m_keyPassword, credentials[1])) {
             // Invalid/unknown user!
             return null;
@@ -141,4 +142,27 @@ public class BasicHttpAuthenticationProc
             throw new RuntimeException(e);
         }
     }
+
+    /**
+     * Searches for a user with a given name.
+     * <p>
+     * This method first looks whether there's a user with the property 
+     * "m_keyUsername" that matches the given username, if not found, it will 
+     * try to retrieve a role with the given name.
+     * </p>
+     * 
+     * @param userAdmin the {@link UserAdmin} service to get users from;
+     * @param name the name of the user to retrieve.
+     * @return a {@link User}, can be <code>null</code> if no such user is found.
+     */
+    private User getUser(UserAdmin userAdmin, String name) {
+        Role user = null;
+        if (m_keyUsername != null) {
+            user = userAdmin.getUser(m_keyUsername, name);
+        }
+        if (user == null) {
+            user = userAdmin.getRole(name);
+        }
+        return (user instanceof User) ? (User) user : null;
+    }
 }

Modified: ace/trunk/ace-client-automation/src/main/java/org/apache/ace/client/automation/AutoTargetOperator.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-automation/src/main/java/org/apache/ace/client/automation/AutoTargetOperator.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-automation/src/main/java/org/apache/ace/client/automation/AutoTargetOperator.java (original)
+++ ace/trunk/ace-client-automation/src/main/java/org/apache/ace/client/automation/AutoTargetOperator.java Mon Apr 23 12:15:01 2012
@@ -71,9 +71,14 @@ public class AutoTargetOperator implemen
             String customerName = getConfigValue( ConfigItem.CUSTOMER_NAME);
 
             RepositoryAdminLoginContext loginContext = m_reposAdmin.createLoginContext(user);
-            loginContext.addShopRepository(url, customerName, getConfigValue( ConfigItem.STORE_REPOSITORY), false)
-            .addTargetRepository(url, customerName, getConfigValue( ConfigItem.TARGET_REPOSITORY), true)
-            .addDeploymentRepository(url, customerName, getConfigValue( ConfigItem.DEPLOYMENT_REPOSITORY), true);
+            loginContext
+                .add(loginContext.createShopRepositoryContext()
+                    .setLocation(url).setCustomer(customerName).setName(getConfigValue(ConfigItem.STORE_REPOSITORY)))
+                .add(loginContext.createTargetRepositoryContext()
+                    .setLocation(url).setCustomer(customerName).setName(getConfigValue(ConfigItem.TARGET_REPOSITORY)).setWriteable())
+                .add(loginContext.createDeploymentRepositoryContext()
+                    .setLocation(url).setCustomer(customerName).setName(getConfigValue(ConfigItem.DEPLOYMENT_REPOSITORY)).setWriteable());
+
             m_reposAdmin.login(loginContext);
 
             // start refresh task

Modified: ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/RepositoryAdminLoginContext.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/RepositoryAdminLoginContext.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/RepositoryAdminLoginContext.java (original)
+++ ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/RepositoryAdminLoginContext.java Mon Apr 23 12:15:01 2012
@@ -26,57 +26,83 @@ import java.net.URL;
  */
 public interface RepositoryAdminLoginContext
 {
+    /**
+     * Provides a common interface for all repository contexts.
+     * 
+     * @param <T> the actual context type to return in this builder.
+     */
+    public interface BaseRepositoryContext<T extends BaseRepositoryContext<?>> {
+    
+        /**
+         * @param location the location of the repository where this set's data resides.
+         * @return this context.
+         */
+        T setLocation(URL location);
+    
+        /**
+         * @param customer the customer name for the location of the repository where this set's data resides.
+         * @return this context.
+         */
+        T setCustomer(String customer);
+    
+        /**
+         * @param name the repository name for the location of the repository where this set's data resides.
+         * @return this context.
+         */
+        T setName(String name);
+    
+        /**
+         * Marks this repository as writable (default is read-only).
+         * 
+         * @return this context.
+         */
+        T setWriteable();
+    }
 
     /**
-     * Adds a set of repositories and their location to this login context.
-     * @param repositoryLocation The location of the repository where this set's data resides.
-     * @param repositoryCustomer The customer name for the location of the repository where this set's data resides.
-     * @param repositoryName The repository name for the location of the repository where this set's data resides.
-     * @param writeAccess Whether or not we need write access to this location. If <code>false</code>, readonly access
-     * will be used.
-     * @param objectRepositories The interfaces classes of the repositories to be used for this set.
-     * @return this object, to allow chaining.
+     * Denotes a context for creating shop repositories.
      */
-    @SuppressWarnings("unchecked")
-    public RepositoryAdminLoginContext addRepositories(URL repositoryLocation, String repositoryCustomer, String repositoryName, boolean writeAccess, Class<? extends ObjectRepository>... objectRepositories);
+    public static interface ShopRepositoryContext extends BaseRepositoryContext<ShopRepositoryContext> {
+    }
 
     /**
-     * Adds a shop repository to this login context.
-     * @param repositoryLocation The location of the repository where this set's data resides.
-     * @param repositoryCustomer The customer name for the location of the repository where this set's data resides.
-     * @param repositoryName The repository name for the location of the repository where this set's data resides.
-     * @param writeAccess Whether or not we need write access to this location. If <code>false</code>, readonly access
-     * will be used.
-     * @return this object, to allow chaining.
+     * Denotes a context for creating target repositories.
      */
-    public RepositoryAdminLoginContext addShopRepository(URL repositoryLocation, String repositoryCustomer, String repositoryName, boolean writeAccess);
+    public static interface TargetRepositoryContext extends BaseRepositoryContext<TargetRepositoryContext> {
+    }
 
     /**
-     * When uploads are needed, this is the base OBR that will be used.
-     * @param base The URL of the OBR to be used.
-     * @return this object, to allow chaining.
+     * Denotes a context for creating deployment repositories.
      */
-    public RepositoryAdminLoginContext setObrBase(URL base);
+    public static interface DeploymentRepositoryContext extends BaseRepositoryContext<DeploymentRepositoryContext> {
+    }
 
     /**
-     * Adds a target repository to this login context.
-     * @param repositoryLocation The location of the repository where this set's data resides.
-     * @param repositoryCustomer The customer name for the location of the repository where this set's data resides.
-     * @param repositoryName The repository name for the location of the repository where this set's data resides.
-     * @param writeAccess Whether or not we need write access to this location. If <code>false</code>, readonly access
-     * will be used.
-     * @return this object, to allow chaining.
+     * @return a new shop repository context, never <code>null</code>.
      */
-    public RepositoryAdminLoginContext addTargetRepository(URL repositoryLocation, String repositoryCustomer, String repositoryName, boolean writeAccess);
+    public ShopRepositoryContext createShopRepositoryContext();
 
     /**
-     * Adds a deployment repository to this login context.
-     * @param repositoryLocation The location of the repository where this set's data resides.
-     * @param repositoryCustomer The customer name for the location of the repository where this set's data resides.
-     * @param repositoryName The repository name for the location of the repository where this set's data resides.
-     * @param writeAccess Whether or not we need write access to this location. If <code>false</code>, readonly access
-     * will be used.
+     * @return a new target repository context, never <code>null</code>.
+     */
+    public TargetRepositoryContext createTargetRepositoryContext();
+
+    /**
+     * @return a new deployment repository context, never <code>null</code>.
+     */
+    public DeploymentRepositoryContext createDeploymentRepositoryContext();
+
+    /**
+     * @param repositoryContext the context to add, cannot be <code>null</code>.
+     * @return this context, never <code>null</code>.
+     */
+    public RepositoryAdminLoginContext add(BaseRepositoryContext<?> repositoryContext);
+
+    /**
+     * When uploads are needed, this is the base OBR that will be used.
+     * 
+     * @param base The URL of the OBR to be used.
      * @return this object, to allow chaining.
      */
-    public RepositoryAdminLoginContext addDeploymentRepository(URL repositoryLocation, String repositoryCustomer, String repositoryName, boolean writeAccess);
-}
\ No newline at end of file
+    public RepositoryAdminLoginContext setObrBase(URL base);
+}

Modified: ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactPreprocessor.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactPreprocessor.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactPreprocessor.java (original)
+++ ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactPreprocessor.java Mon Apr 23 12:15:01 2012
@@ -22,11 +22,12 @@ import java.io.IOException;
 import java.net.URL;
 
 /**
- *  An ArtifactPreprocessor processes an artifact before it is deployed.
+ * An ArtifactPreprocessor processes an artifact before it is deployed.
  */
 public interface ArtifactPreprocessor {
     /**
      * Preprocesses a single artifact, uploads it to the obr, and returns the new URL as a string.
+     *
      * @param url A string representing a URL to the original artifact.
      * @param props A PropertyResolver which can be used to fill in 'holes' in the template.
      * @param targetID The targetID of the target for which this artifact is being processed.
@@ -40,13 +41,14 @@ public interface ArtifactPreprocessor {
     /**
      * Indicates whether the template should be processed again, given the properties, and the version to which it
      * should be compared.
+     * 
      * @param url A string representing a URL to the original artifact.
      * @param props A PropertyResolver which can be used to fill in 'holes' in the template.
      * @param targetID The targetID of the target for which this artifact is being processed.
      * @param version The deployment version for which this artifact is being processed.
      * @param fromVersion The deployment version to which the current one should be compared.
      * @return <code>false</code> if the version of the processed artifact identified by <code>fromVersion</code>
-     * is identical to what would be created using the new <code>props</code>; <code>true</code> otherwise.
+     *         is identical to what would be created using the new <code>props</code>; <code>true</code> otherwise.
      * @throws java.io.IOException
      */
     public boolean needsNewVersion(String url, PropertyResolver props, String targetID, String fromVersion);

Modified: ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactRecognizer.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactRecognizer.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactRecognizer.java (original)
+++ ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactRecognizer.java Mon Apr 23 12:15:01 2012
@@ -18,7 +18,6 @@
  */
 package org.apache.ace.client.repository.helper;
 
-import java.net.URL;
 import java.util.Map;
 
 /**
@@ -30,38 +29,41 @@ public interface ArtifactRecognizer
     /**
      * Tries to determine the type of the artifact. If this recognizer cannot determine the type, it
      * should return <code>null</code>.
-     * @param artifact A URL to a 'physical' artifact.
+     * 
+     * @param artifact the artifact to recognize, cannot be <code>null</code>.
      * @return The mimetype of the artifact, or <code>null</code> if the artifact is not recognized.
      */
-    public String recognize(URL artifact);
+    public String recognize(ArtifactResource artifact);
 
     /**
      * Gets the relevant metadata for this artifact.
-     * @param artifact A URL to a 'physical' artifact.
+     * 
+     * @param artifact the artifact to extract the metadata for, cannot be <code>null</code>.
      * @return A map of strings, representing the relevant metadata specific for this artifact. The
-     * keys are best defined in the corresponding <code>ArtifactHelper</code> interface for this type of artifact.
-     * This function should also set the <code>ArtifactObject.KEY_PROCESSOR_PID</code> attribute.<br>
-     * Optionally, <code>ArtifactObject.KEY_ARTIFACT_NAME</code> and <code>ArtifactObject.KEY_ARTIFACT_DESCRIPTION</code>
-     * can be set.
+     *         keys are best defined in the corresponding <code>ArtifactHelper</code> interface for this type of artifact.
+     *         This function should also set the <code>ArtifactObject.KEY_PROCESSOR_PID</code> attribute.<br>
+     *         Optionally, <code>ArtifactObject.KEY_ARTIFACT_NAME</code> and <code>ArtifactObject.KEY_ARTIFACT_DESCRIPTION</code>
+     *         can be set.
      * @throws IllegalArgumentException when the metadata cannot be retrieved from the <code>artifact</code>.
      */
-    public Map<String, String> extractMetaData(URL artifact) throws IllegalArgumentException;
+    public Map<String, String> extractMetaData(ArtifactResource artifact) throws IllegalArgumentException;
 
     /**
      * Indicates whether this recognizer can handle (i.e., extract metadata) from an artifact of
      * a given mime type.
+     * 
      * @param mimetype The mimetype of an artifact.
      * @return <code>true</code> when this type should be able to be handled by this recognizer;
-     * <code>false</code> otherwise.
+     *         <code>false</code> otherwise.
      */
     public boolean canHandle(String mimetype);
-    
+
     /**
      * Returns a preferred extension for the file name if a new one is created.
      * 
-     * @param artifact The url to the artifact.
+     * @param artifact the artifact to get the extension for, cannot be <code>null</code>.
      * 
      * @return The extension that is preferred or an empty string if there is none.
      */
-    public String getExtension(URL artifact);
+    public String getExtension(ArtifactResource artifact);
 }
\ No newline at end of file

Added: ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactResource.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactResource.java?rev=1329199&view=auto
==============================================================================
--- ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactResource.java (added)
+++ ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactResource.java Mon Apr 23 12:15:01 2012
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+package org.apache.ace.client.repository.helper;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * Denotes a 'physical' artifact that is located by an URL, and provide means to access the contents of this artifact.
+ * <p>
+ * Note that an artifact can be located on a remote machine, which might need credentials to access its contents. 
+ * This interface allows one to access the resource without having to worry about supplying those credentials, as the
+ * implementor of this class has to worry about this instead.
+ * </p>
+ */
+public interface ArtifactResource {
+
+    /**
+     * Returns the location of this artifact.
+     * <p>
+     * Note that although {@link URL#openConnection()} allows you to directly open a connection to the resource,
+     * in fact this may fail due to, for example, missing authentication credentials. Use {@link #openStream()}
+     * instead to access the contents of the resource.
+     * </p>
+     * 
+     * @return the URL to the 'physical' location of the artifact, never <code>null</code>.
+     */
+    URL getURL();
+
+    /**
+     * Provides access to the contents of the artifact.
+     * 
+     * @return an input stream, never <code>null</code>. 
+     * @throws IOException in case of I/O errors opening the artifact.
+     * @see #getURL()
+     */
+    InputStream openStream() throws IOException;
+}

Propchange: ace/trunk/ace-client-repository-api/src/main/java/org/apache/ace/client/repository/helper/ArtifactResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ace/trunk/ace-client-repository-helper-base/pom.xml
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-helper-base/pom.xml?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-helper-base/pom.xml (original)
+++ ace/trunk/ace-client-repository-helper-base/pom.xml Mon Apr 23 12:15:01 2012
@@ -86,7 +86,8 @@
 	        !org.apache.tools.ant,
 	        !org.apache.tools.ant.taskdefs,
 	        !org.jdom.output,
-	        org.apache.ace.client.repository.helper;version=${project.version}
+	        org.apache.ace.client.repository.helper;version=${project.version},
+	        org.apache.ace.connectionfactory;version=${project.version}
         </import.package>
         <embed.dependency>
             velocity, xpp3, commons-collections, commons-lang
@@ -107,6 +108,10 @@
             <artifactId>org.apache.ace.client.repository.api</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.connectionfactory</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
         </dependency>

Modified: ace/trunk/ace-client-repository-helper-base/src/main/java/org/apache/ace/client/repository/helper/base/ArtifactPreprocessorBase.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-helper-base/src/main/java/org/apache/ace/client/repository/helper/base/ArtifactPreprocessorBase.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-helper-base/src/main/java/org/apache/ace/client/repository/helper/base/ArtifactPreprocessorBase.java (original)
+++ ace/trunk/ace-client-repository-helper-base/src/main/java/org/apache/ace/client/repository/helper/base/ArtifactPreprocessorBase.java Mon Apr 23 12:15:01 2012
@@ -34,6 +34,7 @@ import java.net.URLConnection;
 
 import org.apache.ace.client.repository.helper.ArtifactPreprocessor;
 import org.apache.ace.client.repository.helper.PropertyResolver;
+import org.apache.ace.connectionfactory.ConnectionFactory;
 
 /**
  * This class can be used as a base class for artifact preprocessors. It comes with its
@@ -42,6 +43,15 @@ import org.apache.ace.client.repository.
 public abstract class ArtifactPreprocessorBase implements ArtifactPreprocessor {
 
     protected static final int BUFFER_SIZE = 4 * 1024;
+    
+    protected final ConnectionFactory m_connectionFactory;
+
+    /**
+     * @param connectionFactory
+     */
+    protected ArtifactPreprocessorBase(ConnectionFactory connectionFactory) {
+        m_connectionFactory = connectionFactory;
+    }
 
     /**
      * Uploads an artifact to an OBR.
@@ -145,8 +155,7 @@ public abstract class ArtifactPreprocess
         return new URL(obrBase, name);
     }
 
-    public abstract String preprocess(String url, PropertyResolver props, String targetID, String version, URL obrBase)
-        throws IOException;
+    public abstract String preprocess(String url, PropertyResolver props, String targetID, String version, URL obrBase) throws IOException;
 
     public abstract boolean needsNewVersion(String url, PropertyResolver props, String targetID, String fromVersion);
 
@@ -207,7 +216,8 @@ public abstract class ArtifactPreprocess
         OutputStream output = null;
 
         try {
-            URLConnection connection = url.openConnection();
+            URLConnection connection = m_connectionFactory.createConnection(url);
+
             connection.setDoOutput(true);
             connection.setDoInput(true);
             output = connection.getOutputStream();

Modified: ace/trunk/ace-client-repository-helper-base/src/main/java/org/apache/ace/client/repository/helper/base/VelocityArtifactPreprocessor.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-helper-base/src/main/java/org/apache/ace/client/repository/helper/base/VelocityArtifactPreprocessor.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-helper-base/src/main/java/org/apache/ace/client/repository/helper/base/VelocityArtifactPreprocessor.java (original)
+++ ace/trunk/ace-client-repository-helper-base/src/main/java/org/apache/ace/client/repository/helper/base/VelocityArtifactPreprocessor.java Mon Apr 23 12:15:01 2012
@@ -38,6 +38,7 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.ace.client.repository.helper.PropertyResolver;
+import org.apache.ace.connectionfactory.ConnectionFactory;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.Velocity;
 
@@ -56,8 +57,11 @@ public class VelocityArtifactPreprocesso
 
     /**
      * Creates a new {@link VelocityArtifactPreprocessor} instance.
+     * @param connectionFactory 
      */
-    public VelocityArtifactPreprocessor() {
+    public VelocityArtifactPreprocessor(ConnectionFactory connectionFactory) {
+        super(connectionFactory);
+
         try {
             m_md5 = MessageDigest.getInstance("MD5");
         }

Modified: ace/trunk/ace-client-repository-helper-base/src/test/java/org/apache/ace/client/repository/helper/base/VelocityArtifactPreprocessorTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-helper-base/src/test/java/org/apache/ace/client/repository/helper/base/VelocityArtifactPreprocessorTest.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-helper-base/src/test/java/org/apache/ace/client/repository/helper/base/VelocityArtifactPreprocessorTest.java (original)
+++ ace/trunk/ace-client-repository-helper-base/src/test/java/org/apache/ace/client/repository/helper/base/VelocityArtifactPreprocessorTest.java Mon Apr 23 12:15:01 2012
@@ -27,10 +27,13 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.net.URL;
+import java.net.URLConnection;
 
 import org.apache.ace.client.repository.helper.PropertyResolver;
+import org.apache.ace.connectionfactory.ConnectionFactory;
 import org.junit.Before;
 import org.junit.Test;
+import org.osgi.service.useradmin.User;
 
 /**
  * Test cases for {@link VelocityArtifactPreprocessor}.
@@ -59,7 +62,7 @@ public class VelocityArtifactPreprocesso
      */
     @Test
     public void testNeedsNewVersionChangedTemplateOk() throws Exception {
-        final VelocityArtifactPreprocessor vap = new VelocityArtifactPreprocessor();
+        final VelocityArtifactPreprocessor vap = createProcessor();
         
         String url = createArtifact("Message: [$context.msg]");
 
@@ -80,7 +83,7 @@ public class VelocityArtifactPreprocesso
      */
     @Test
     public void testNeedsNewVersionEmptyTemplateOk() throws Exception {
-        final VelocityArtifactPreprocessor vap = new VelocityArtifactPreprocessor();
+        final VelocityArtifactPreprocessor vap = createProcessor();
         
         String url = createArtifact("");
 
@@ -96,7 +99,7 @@ public class VelocityArtifactPreprocesso
      */
     @Test
     public void testNeedsNewVersionNonExistingTemplateOk() throws Exception {
-        final VelocityArtifactPreprocessor vap = new VelocityArtifactPreprocessor();
+        final VelocityArtifactPreprocessor vap = createProcessor();
         
         // Should be something that really doesn't exist somehow...
         String url = "file:///path/to/nowhere-" + System.currentTimeMillis();
@@ -110,7 +113,7 @@ public class VelocityArtifactPreprocesso
      */
     @Test
     public void testNeedsNewVersionUnchangedTemplateOk() throws Exception {
-        final VelocityArtifactPreprocessor vap = new VelocityArtifactPreprocessor();
+        final VelocityArtifactPreprocessor vap = createProcessor();
         
         String url = createArtifact("Message: [$context.msg]");
         
@@ -131,7 +134,7 @@ public class VelocityArtifactPreprocesso
     public void testPreprocessExistingNoTemplateOk() throws Exception {
         String url = createArtifact("Message: [context.msg]");
         
-        String newUrl = new VelocityArtifactPreprocessor().preprocess(url, m_resolver, TARGET, VERSION1, m_obrUrl);
+        String newUrl = createProcessor().preprocess(url, m_resolver, TARGET, VERSION1, m_obrUrl);
         assertNotNull(newUrl);
         // Verify that it is *not* uploaded...
         assertEquals(url, newUrl);
@@ -144,7 +147,7 @@ public class VelocityArtifactPreprocesso
     public void testPreprocessExistingRealTemplateOk() throws Exception {
         String url = createArtifact("Message: [$context.msg]");
         
-        String newUrl = new VelocityArtifactPreprocessor().preprocess(url, m_resolver, TARGET, VERSION1, m_obrUrl);
+        String newUrl = createProcessor().preprocess(url, m_resolver, TARGET, VERSION1, m_obrUrl);
         assertNotNull(newUrl);
         // Verify that it is actually uploaded...
         assertFalse(newUrl.equals(url));
@@ -160,7 +163,7 @@ public class VelocityArtifactPreprocesso
         // Should be something that really doesn't exist somehow...
         String url = "file:///path/to/nowhere-" + System.currentTimeMillis();
         
-        new VelocityArtifactPreprocessor().preprocess(url, m_resolver, TARGET, VERSION1, m_obrUrl);
+        createProcessor().preprocess(url, m_resolver, TARGET, VERSION1, m_obrUrl);
     }
 
     private String createArtifact(String string) throws IOException {
@@ -176,6 +179,18 @@ public class VelocityArtifactPreprocesso
         return tmpFile.toURI().toURL().toExternalForm();
     }
 
+    private VelocityArtifactPreprocessor createProcessor() {
+        return new VelocityArtifactPreprocessor(new ConnectionFactory() {
+            public URLConnection createConnection(URL url, User user) throws IOException {
+                return createConnection(url);
+            }
+
+            public URLConnection createConnection(URL url) throws IOException {
+                return url.openConnection();
+            }
+        });
+    }
+
     private String updateArtifact(String url, String string) throws IOException {
         URL uri = new URL(url);
         

Modified: ace/trunk/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/BundleHelperImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/BundleHelperImpl.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/BundleHelperImpl.java (original)
+++ ace/trunk/ace-client-repository-helper-bundle/src/main/java/org/apache/ace/client/repository/helper/bundle/impl/BundleHelperImpl.java Mon Apr 23 12:15:01 2012
@@ -19,7 +19,6 @@
 package org.apache.ace.client.repository.helper.bundle.impl;
 
 import java.io.IOException;
-import java.net.URL;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Map;
@@ -31,6 +30,7 @@ import org.apache.ace.client.repository.
 import org.apache.ace.client.repository.helper.ArtifactHelper;
 import org.apache.ace.client.repository.helper.ArtifactPreprocessor;
 import org.apache.ace.client.repository.helper.ArtifactRecognizer;
+import org.apache.ace.client.repository.helper.ArtifactResource;
 import org.apache.ace.client.repository.helper.bundle.BundleHelper;
 import org.apache.ace.client.repository.object.ArtifactObject;
 import org.apache.ace.util.VersionRange;
@@ -195,7 +195,7 @@ public class BundleHelperImpl implements
         return MIMETYPE.equals(mimetype);
     }
 
-    public Map<String, String> extractMetaData(URL artifact) throws IllegalArgumentException {
+    public Map<String, String> extractMetaData(ArtifactResource artifact) throws IllegalArgumentException {
         /*
          * Opens the URL as a Jar input stream, gets the manifest, and extracts headers from there.
          */
@@ -241,7 +241,7 @@ public class BundleHelperImpl implements
         }
     }
 
-    public String recognize(URL artifact) {
+    public String recognize(ArtifactResource artifact) {
         /*
          * Tries to find out whether this artifact is a bundle by (a) trying to open it as a
          * jar, (b) trying to extract the manifest, and (c) checking whether that manifest
@@ -276,7 +276,7 @@ public class BundleHelperImpl implements
         return null;
     }
     
-    public String getExtension(URL artifact) {
+    public String getExtension(ArtifactResource artifact) {
         return ".jar";
     }
 }
\ No newline at end of file

Modified: ace/trunk/ace-client-repository-helper-configuration/pom.xml
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-helper-configuration/pom.xml?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-helper-configuration/pom.xml (original)
+++ ace/trunk/ace-client-repository-helper-configuration/pom.xml Mon Apr 23 12:15:01 2012
@@ -71,6 +71,10 @@
             <artifactId>org.apache.ace.client.repository.helper.base</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.connectionfactory</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
         </dependency>

Modified: ace/trunk/ace-client-repository-helper-configuration/src/main/java/org/apache/ace/client/repository/helper/configuration/impl/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-helper-configuration/src/main/java/org/apache/ace/client/repository/helper/configuration/impl/Activator.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-helper-configuration/src/main/java/org/apache/ace/client/repository/helper/configuration/impl/Activator.java (original)
+++ ace/trunk/ace-client-repository-helper-configuration/src/main/java/org/apache/ace/client/repository/helper/configuration/impl/Activator.java Mon Apr 23 12:15:01 2012
@@ -25,6 +25,7 @@ import org.apache.ace.client.repository.
 import org.apache.ace.client.repository.helper.ArtifactRecognizer;
 import org.apache.ace.client.repository.helper.configuration.ConfigurationHelper;
 import org.apache.ace.client.repository.object.ArtifactObject;
+import org.apache.ace.connectionfactory.ConnectionFactory;
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
@@ -38,13 +39,15 @@ public class Activator extends Dependenc
     public synchronized void init(BundleContext context, DependencyManager manager) throws Exception {
         Dictionary<String, String> props = new Hashtable<String, String>();
         props.put(ArtifactObject.KEY_MIMETYPE, ConfigurationHelper.MIMETYPE);
+
         ConfigurationHelperImpl helperImpl = new ConfigurationHelperImpl();
         manager.add(createComponent()
-            .setInterface(ArtifactHelper.class.getName(), props)
-            .setImplementation(helperImpl));
-        manager.add(createComponent()
-            .setInterface(ArtifactRecognizer.class.getName(), null)
-            .setImplementation(helperImpl));
+            .setInterface(new String[] { ArtifactHelper.class.getName(), ArtifactRecognizer.class.getName() }, props)
+            .setImplementation(helperImpl)
+            .add(createServiceDependency()
+                .setService(ConnectionFactory.class)
+                .setRequired(true))
+            );
     }
 
     @Override

Modified: ace/trunk/ace-client-repository-helper-configuration/src/main/java/org/apache/ace/client/repository/helper/configuration/impl/ConfigurationHelperImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-helper-configuration/src/main/java/org/apache/ace/client/repository/helper/configuration/impl/ConfigurationHelperImpl.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-helper-configuration/src/main/java/org/apache/ace/client/repository/helper/configuration/impl/ConfigurationHelperImpl.java (original)
+++ ace/trunk/ace-client-repository-helper-configuration/src/main/java/org/apache/ace/client/repository/helper/configuration/impl/ConfigurationHelperImpl.java Mon Apr 23 12:15:01 2012
@@ -21,7 +21,6 @@ package org.apache.ace.client.repository
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URL;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Map;
@@ -31,9 +30,11 @@ import javax.xml.parsers.SAXParserFactor
 
 import org.apache.ace.client.repository.helper.ArtifactPreprocessor;
 import org.apache.ace.client.repository.helper.ArtifactRecognizer;
+import org.apache.ace.client.repository.helper.ArtifactResource;
 import org.apache.ace.client.repository.helper.base.VelocityArtifactPreprocessor;
 import org.apache.ace.client.repository.helper.configuration.ConfigurationHelper;
 import org.apache.ace.client.repository.object.ArtifactObject;
+import org.apache.ace.connectionfactory.ConnectionFactory;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
@@ -47,6 +48,11 @@ public class ConfigurationHelperImpl imp
 
     private final SAXParserFactory m_saxParserFactory;
 
+    // Injected by Dependency Manager
+    private volatile ConnectionFactory m_connectionFactory;
+    // Created in #start()
+    private volatile VelocityArtifactPreprocessor m_artifactPreprocessor;
+
     public ConfigurationHelperImpl() {
         m_saxParserFactory = SAXParserFactory.newInstance();
         m_saxParserFactory.setNamespaceAware(false);
@@ -57,11 +63,11 @@ public class ConfigurationHelperImpl imp
         return MIMETYPE.equals(mimetype);
     }
 
-    public Map<String, String> extractMetaData(URL artifact) throws IllegalArgumentException {
+    public Map<String, String> extractMetaData(ArtifactResource artifact) throws IllegalArgumentException {
         Map<String, String> result = new HashMap<String, String>();
         result.put(ArtifactObject.KEY_PROCESSOR_PID, PROCESSOR);
         result.put(ArtifactObject.KEY_MIMETYPE, MIMETYPE);
-        String name = new File(artifact.getFile()).getName();
+        String name = new File(artifact.getURL().getFile()).getName();
         String key = KEY_FILENAME + "-";
         int idx = name.indexOf(key);
         if (idx > -1) {
@@ -73,7 +79,7 @@ public class ConfigurationHelperImpl imp
         return result;
     }
 
-    public String recognize(URL artifact) {
+    public String recognize(ArtifactResource artifact) {
         MetaDataNamespaceCollector handler = new MetaDataNamespaceCollector();
         InputStream input = null;
         try {
@@ -130,15 +136,29 @@ public class ConfigurationHelperImpl imp
         return new String[] {KEY_FILENAME};
     }
 
-    private final static VelocityArtifactPreprocessor VELOCITY_ARTIFACT_PREPROCESSOR = new VelocityArtifactPreprocessor();
     public ArtifactPreprocessor getPreprocessor() {
-        return VELOCITY_ARTIFACT_PREPROCESSOR;
+        return m_artifactPreprocessor;
     }
     
-    public String getExtension(URL artifact) {
+    public String getExtension(ArtifactResource artifact) {
         return ".xml";
     }
 
+    /**
+     * Called by dependency manager upon start of this component.
+     */
+    protected void start() {
+        m_artifactPreprocessor = new VelocityArtifactPreprocessor(m_connectionFactory);
+    }
+
+    /**
+     * Called by dependency manager upon stopping of this component.
+     */
+    protected void stop() {
+        m_artifactPreprocessor = null;
+        
+    }
+
     static class MetaDataNamespaceCollector extends DefaultHandler {
 
         private String m_metaDataNameSpace = "";

Modified: ace/trunk/ace-client-repository-helper-configuration/src/test/java/org/apache/ace/client/repository/helper/configuration/impl/ConfigurationHelperImplTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-helper-configuration/src/test/java/org/apache/ace/client/repository/helper/configuration/impl/ConfigurationHelperImplTest.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-helper-configuration/src/test/java/org/apache/ace/client/repository/helper/configuration/impl/ConfigurationHelperImplTest.java (original)
+++ ace/trunk/ace-client-repository-helper-configuration/src/test/java/org/apache/ace/client/repository/helper/configuration/impl/ConfigurationHelperImplTest.java Mon Apr 23 12:15:01 2012
@@ -18,6 +18,11 @@
  */
 package org.apache.ace.client.repository.helper.configuration.impl;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.ace.client.repository.helper.ArtifactResource;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -28,35 +33,57 @@ public class ConfigurationHelperImplTest
     @Test
     public void testNamespace10Recognized() throws Exception {
         ConfigurationHelperImpl c = new ConfigurationHelperImpl();
-        String mime = c.recognize(this.getClass().getClassLoader().getResource("valid10.xml"));
+        String mime = c.recognize(convertToArtifactResource("valid10.xml"));
         Assert.assertNotNull(mime);
     }
 
     @Test
     public void testNamespace11Recognized() throws Exception {
         ConfigurationHelperImpl c = new ConfigurationHelperImpl();
-        String mime = c.recognize(this.getClass().getClassLoader().getResource("valid11.xml"));
+        String mime = c.recognize(convertToArtifactResource("valid11.xml"));
         Assert.assertNotNull(mime);
     }
 
     @Test
     public void testNamespace12Recognized() throws Exception {
         ConfigurationHelperImpl c = new ConfigurationHelperImpl();
-        String mime = c.recognize(this.getClass().getClassLoader().getResource("valid12.xml"));
+        String mime = c.recognize(convertToArtifactResource("valid12.xml"));
         Assert.assertNotNull(mime);
     }
 
     @Test
     public void testNamespace13NotRecognized() throws Exception {
         ConfigurationHelperImpl c = new ConfigurationHelperImpl();
-        String mime = c.recognize(this.getClass().getClassLoader().getResource("invalid13.xml"));
+        String mime = c.recognize(convertToArtifactResource("invalid13.xml"));
         Assert.assertNull(mime);
     }
 
     @Test
     public void testCanHandleCommentBeforeRoot() throws Exception {
         ConfigurationHelperImpl c = new ConfigurationHelperImpl();
-        String mime = c.recognize(this.getClass().getClassLoader().getResource("validWithComment.xml"));
+        String mime = c.recognize(convertToArtifactResource("validWithComment.xml"));
         Assert.assertNotNull(mime);
     }
+
+    /**
+     * @param url
+     * @return
+     */
+    private ArtifactResource convertToArtifactResource(final String res) {
+        if (res == null) {
+            return null;
+        }
+        
+        final URL url = getClass().getClassLoader().getResource(res);
+        
+        return new ArtifactResource() {
+            public URL getURL() {
+                return url;
+            }
+            
+            public InputStream openStream() throws IOException {
+                return getURL().openStream();
+            }
+        };
+    }
 }
\ No newline at end of file

Modified: ace/trunk/ace-client-repository-helper-user/pom.xml
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-helper-user/pom.xml?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-helper-user/pom.xml (original)
+++ ace/trunk/ace-client-repository-helper-user/pom.xml Mon Apr 23 12:15:01 2012
@@ -70,6 +70,10 @@
             <artifactId>org.apache.ace.client.repository.helper.base</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.connectionfactory</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
         </dependency>

Modified: ace/trunk/ace-client-repository-helper-user/src/main/java/org/apache/ace/client/repository/helper/user/impl/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-helper-user/src/main/java/org/apache/ace/client/repository/helper/user/impl/Activator.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-helper-user/src/main/java/org/apache/ace/client/repository/helper/user/impl/Activator.java (original)
+++ ace/trunk/ace-client-repository-helper-user/src/main/java/org/apache/ace/client/repository/helper/user/impl/Activator.java Mon Apr 23 12:15:01 2012
@@ -24,6 +24,7 @@ import org.apache.ace.client.repository.
 import org.apache.ace.client.repository.helper.ArtifactRecognizer;
 import org.apache.ace.client.repository.helper.user.UserAdminHelper;
 import org.apache.ace.client.repository.object.ArtifactObject;
+import org.apache.ace.connectionfactory.ConnectionFactory;
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
@@ -37,16 +38,17 @@ public class Activator extends Dependenc
     @Override
     public synchronized void init(BundleContext context, DependencyManager manager) throws Exception {
         Properties props = new Properties();
+        props.put(Constants.SERVICE_RANKING, 10);
         props.put(ArtifactObject.KEY_MIMETYPE, UserAdminHelper.MIMETYPE);
+
         UserHelperImpl helperImpl = new UserHelperImpl();
         manager.add(createComponent()
-            .setInterface(ArtifactHelper.class.getName(), props)
-            .setImplementation(helperImpl));
-        props = new Properties();
-        props.put(Constants.SERVICE_RANKING, 10);
-        manager.add(createComponent()
-            .setInterface(ArtifactRecognizer.class.getName(), props)
-            .setImplementation(helperImpl));
+            .setInterface(new String[]{ ArtifactHelper.class.getName(), ArtifactRecognizer.class.getName() }, props)
+            .setImplementation(helperImpl)
+            .add(createServiceDependency()
+                .setService(ConnectionFactory.class)
+                .setRequired(true))
+            );
     }
 
     @Override

Modified: ace/trunk/ace-client-repository-helper-user/src/main/java/org/apache/ace/client/repository/helper/user/impl/UserHelperImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-helper-user/src/main/java/org/apache/ace/client/repository/helper/user/impl/UserHelperImpl.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-helper-user/src/main/java/org/apache/ace/client/repository/helper/user/impl/UserHelperImpl.java (original)
+++ ace/trunk/ace-client-repository-helper-user/src/main/java/org/apache/ace/client/repository/helper/user/impl/UserHelperImpl.java Mon Apr 23 12:15:01 2012
@@ -20,7 +20,6 @@ package org.apache.ace.client.repository
 
 import java.io.File;
 import java.io.InputStream;
-import java.net.URL;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Map;
@@ -29,23 +28,30 @@ import javax.xml.parsers.DocumentBuilder
 
 import org.apache.ace.client.repository.helper.ArtifactPreprocessor;
 import org.apache.ace.client.repository.helper.ArtifactRecognizer;
+import org.apache.ace.client.repository.helper.ArtifactResource;
 import org.apache.ace.client.repository.helper.base.VelocityArtifactPreprocessor;
 import org.apache.ace.client.repository.helper.user.UserAdminHelper;
 import org.apache.ace.client.repository.object.ArtifactObject;
+import org.apache.ace.connectionfactory.ConnectionFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
 public class UserHelperImpl implements ArtifactRecognizer, UserAdminHelper {
 
+    // Injected by Dependency Manager
+    private volatile ConnectionFactory m_connectionFactory;
+    // Created in #start()
+    private volatile VelocityArtifactPreprocessor m_artifactPreprocessor;
+
     public boolean canHandle(String mimetype) {
         return MIMETYPE.equals(mimetype);
     }
 
-    public Map<String, String> extractMetaData(URL artifact) throws IllegalArgumentException {
+    public Map<String, String> extractMetaData(ArtifactResource artifact) throws IllegalArgumentException {
         Map<String, String> result = new HashMap<String, String>();
         result.put(ArtifactObject.KEY_PROCESSOR_PID, PROCESSOR);
         result.put(ArtifactObject.KEY_MIMETYPE, MIMETYPE);
-        String name = new File(artifact.getFile()).getName();
+        String name = new File(artifact.getURL().getFile()).getName();
         String key = ArtifactObject.KEY_ARTIFACT_NAME + "-";
         int idx = name.indexOf(key);
         if (idx > -1) {
@@ -56,9 +62,10 @@ public class UserHelperImpl implements A
         return result;
     }
 
-    public String recognize(URL artifact) {
+    public String recognize(ArtifactResource artifact) {
         try {
             InputStream in = artifact.openStream();
+            
             Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
             Node root = doc.getFirstChild();
             if (!root.getNodeName().equals("roles")) {
@@ -107,12 +114,26 @@ public class UserHelperImpl implements A
         return new String[] {ArtifactObject.KEY_ARTIFACT_NAME};
     }
 
-    private final static VelocityArtifactPreprocessor VELOCITY_ARTIFACT_PREPROCESSOR = new VelocityArtifactPreprocessor();
     public ArtifactPreprocessor getPreprocessor() {
-        return VELOCITY_ARTIFACT_PREPROCESSOR;
+        return m_artifactPreprocessor;
     }
     
-    public String getExtension(URL artifact) {
+    public String getExtension(ArtifactResource artifact) {
         return ".xml";
     }
+
+    /**
+     * Called by dependency manager upon start of this component.
+     */
+    protected void start() {
+        m_artifactPreprocessor = new VelocityArtifactPreprocessor(m_connectionFactory);
+    }
+
+    /**
+     * Called by dependency manager upon stopping of this component.
+     */
+    protected void stop() {
+        m_artifactPreprocessor = null;
+        
+    }
 }
\ No newline at end of file

Modified: ace/trunk/ace-client-repository-impl/pom.xml
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-impl/pom.xml?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-impl/pom.xml (original)
+++ ace/trunk/ace-client-repository-impl/pom.xml Mon Apr 23 12:15:01 2012
@@ -81,6 +81,10 @@
             <groupId>org.apache.ace</groupId>
             <artifactId>org.apache.ace.client.repository.api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.connectionfactory</artifactId>
+        </dependency>
          <dependency>
             <groupId>org.apache.ace</groupId>
             <artifactId>org.apache.ace.repository.api</artifactId>

Modified: ace/trunk/ace-client-repository-impl/src/main/java/org/apache/ace/client/repository/impl/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-impl/src/main/java/org/apache/ace/client/repository/impl/Activator.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-impl/src/main/java/org/apache/ace/client/repository/impl/Activator.java (original)
+++ ace/trunk/ace-client-repository-impl/src/main/java/org/apache/ace/client/repository/impl/Activator.java Mon Apr 23 12:15:01 2012
@@ -18,9 +18,11 @@
  */
 package org.apache.ace.client.repository.impl;
 
+import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.ace.client.repository.RepositoryAdmin;
@@ -29,11 +31,11 @@ import org.apache.ace.client.repository.
 import org.apache.ace.client.repository.object.Artifact2FeatureAssociation;
 import org.apache.ace.client.repository.object.ArtifactObject;
 import org.apache.ace.client.repository.object.DeploymentVersionObject;
-import org.apache.ace.client.repository.object.TargetObject;
-import org.apache.ace.client.repository.object.Feature2DistributionAssociation;
-import org.apache.ace.client.repository.object.FeatureObject;
 import org.apache.ace.client.repository.object.Distribution2TargetAssociation;
 import org.apache.ace.client.repository.object.DistributionObject;
+import org.apache.ace.client.repository.object.Feature2DistributionAssociation;
+import org.apache.ace.client.repository.object.FeatureObject;
+import org.apache.ace.client.repository.object.TargetObject;
 import org.apache.ace.client.repository.repository.ArtifactRepository;
 import org.apache.ace.client.repository.repository.DeploymentVersionRepository;
 import org.apache.ace.client.repository.repository.TargetRepository;
@@ -56,8 +58,14 @@ import org.osgi.service.prefs.Preference
  * creates all required repositories.
  */
 public class Activator extends DependencyActivatorBase implements SessionFactory {
-    private DependencyManager m_dependencyManager;
+    
+    private final Map<String, SessionData> m_sessions = new HashMap<String, SessionData>();
+
+    private volatile DependencyManager m_dependencyManager;
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public synchronized void init(BundleContext context, DependencyManager manager) throws Exception {
         m_dependencyManager = manager;
@@ -67,58 +75,70 @@ public class Activator extends Dependenc
         );
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public synchronized void destroy(BundleContext context, DependencyManager manager) throws Exception {
+        // Nop
     }
 
-    private Map<String, SessionData> m_sessions = new HashMap<String, SessionData>();
-    private static class SessionData {
-        public static SessionData EMPTY_SESSION = new SessionData();
-
-        private Component m_service;
-        private Component m_service2;
-    }
-
+    /**
+     * {@inheritDoc}
+     */
     public void createSession(String sessionID) {
-        boolean create = false;
+        SessionData sessionData = null;
         synchronized (m_sessions) {
             if (!m_sessions.containsKey(sessionID)) {
-                m_sessions.put(sessionID, SessionData.EMPTY_SESSION);
-                create = true;
+                sessionData = new SessionData();
+                m_sessions.put(sessionID, sessionData);
             }
         }
-        if (create) {
-            SessionData sd = createSessionServices(sessionID);
-            m_sessions.put(sessionID, sd);
+
+        // Allow session to be created outside the lock; to avoid potential deadlocks...
+        if (sessionData != null) {
+            createSessionServices(sessionData, sessionID);
         }
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public void destroySession(String sessionID) {
-        boolean destroy = false;
-        SessionData sd = SessionData.EMPTY_SESSION;
+        SessionData sessionData = null;
         synchronized (m_sessions) {
-            destroy = m_sessions.containsKey(sessionID);
-            sd = m_sessions.remove(sessionID);
+            sessionData = m_sessions.remove(sessionID);
         }
-        if (destroy && !sd.equals(SessionData.EMPTY_SESSION)) {
-            destroySessionServices(sessionID, sd);
+
+        // Allow session to be destroyed outside the lock; to avoid potential deadlocks...
+        if ((sessionData != null) && !sessionData.isEmpty()) {
+            destroySessionServices(sessionData, sessionID);
         }
     }
 
+    /**
+     * Creates all necessary session-related service for the given session.
+     * 
+     * @param sd the session data to keep the session-related services;
+     * @param sessionID the session ID to use.
+     */
     @SuppressWarnings("unchecked")
-    private SessionData createSessionServices(String sessionID) {
-        SessionData sd = new SessionData();
+    private void createSessionServices(SessionData sd, String sessionID) {
         RepositoryAdminImpl rai = new RepositoryAdminImpl(sessionID);
-        sd.m_service = createComponent()
+        Component comp1 = createComponent()
             .setInterface(RepositoryAdmin.class.getName(), rai.getSessionProps())
             .setImplementation(rai)
             .setComposition("getInstances")
             .add(createServiceDependency().setService(PreferencesService.class).setRequired(true))
             .add(createServiceDependency().setService(EventAdmin.class).setRequired(true))
             .add(createServiceDependency().setService(LogService.class).setRequired(false));
-        m_dependencyManager.add(sd.m_service);
+
+        String sessionFilter = "(" + SessionFactory.SERVICE_SID + "=" + sessionID + ")";
+        String auditLogFilter = "(&(" + Constants.OBJECTCLASS + "=" + LogStore.class.getName() + ")(name=auditlog))";
 
         Dictionary topic = new Hashtable();
+        topic.put(SessionFactory.SERVICE_SID, sessionID);
+        topic.put(EventConstants.EVENT_FILTER, sessionFilter);
         topic.put(EventConstants.EVENT_TOPIC, new String[] {
             ArtifactObject.TOPIC_ALL,
             Artifact2FeatureAssociation.TOPIC_ALL,
@@ -128,27 +148,70 @@ public class Activator extends Dependenc
             Distribution2TargetAssociation.TOPIC_ALL,
             TargetObject.TOPIC_ALL,
             DeploymentVersionObject.TOPIC_ALL,
-            RepositoryAdmin.TOPIC_REFRESH, RepositoryAdmin.TOPIC_LOGIN});
-        String filter = "(" + SessionFactory.SERVICE_SID + "=" + sessionID + ")";
-        topic.put(EventConstants.EVENT_FILTER, filter);
-        topic.put(SessionFactory.SERVICE_SID, sessionID);
+            RepositoryAdmin.TOPIC_REFRESH, 
+            RepositoryAdmin.TOPIC_LOGIN 
+        });
+        
         StatefulTargetRepositoryImpl statefulTargetRepositoryImpl = new StatefulTargetRepositoryImpl(sessionID);
-        sd.m_service2 = createComponent()
+        Component comp2 = createComponent()
             .setInterface(new String[] { StatefulTargetRepository.class.getName(), EventHandler.class.getName() }, topic)
             .setImplementation(statefulTargetRepositoryImpl)
-            .add(createServiceDependency().setService(ArtifactRepository.class, filter).setRequired(true))
-            .add(createServiceDependency().setService(TargetRepository.class, filter).setRequired(true))
-            .add(createServiceDependency().setService(DeploymentVersionRepository.class, filter).setRequired(true))
-            .add(createServiceDependency().setService(LogStore.class, "(&("+Constants.OBJECTCLASS+"="+LogStore.class.getName()+")(name=auditlog))").setRequired(false))
+            .add(createServiceDependency().setService(ArtifactRepository.class, sessionFilter).setRequired(true))
+            .add(createServiceDependency().setService(TargetRepository.class, sessionFilter).setRequired(true))
+            .add(createServiceDependency().setService(DeploymentVersionRepository.class, sessionFilter).setRequired(true))
+            .add(createServiceDependency().setService(LogStore.class, auditLogFilter).setRequired(false))
             .add(createServiceDependency().setService(BundleHelper.class).setRequired(true))
             .add(createServiceDependency().setService(EventAdmin.class).setRequired(true))
             .add(createServiceDependency().setService(LogService.class).setRequired(false));
-        m_dependencyManager.add(sd.m_service2);
-        return sd;
+
+        // Publish our components to our session data for later use...
+        sd.addComponents(m_dependencyManager, comp1, comp2);
     }
 
-    private void destroySessionServices(String sessionID, SessionData sd) {
-        m_dependencyManager.remove(sd.m_service2);
-        m_dependencyManager.remove(sd.m_service);
+    /**
+     * Removes the session-related services from the session.
+     * 
+     * @param sd the session data that keeps the session-related services;
+     * @param sessionID the session ID to use.
+     */
+    private void destroySessionServices(SessionData sd, String sessionID) {
+        sd.removeAllComponents(m_dependencyManager);
+    }
+
+    /**
+     * Small container that keeps the session-related services for us.
+     */
+    private static final class SessionData {
+        private final List<Component> m_services = new ArrayList<Component>();
+
+        final void addComponents(DependencyManager manager, Component... comps) {
+            synchronized (m_services) {
+                for (Component c : comps) {
+                    m_services.add(c);
+                }
+            }
+
+            for (Component c : comps) {
+                manager.add(c);
+            }
+        }
+
+        final void removeAllComponents(DependencyManager manager) {
+            Component[] comps;
+            synchronized (m_services) {
+                comps = m_services.toArray(new Component[m_services.size()]);
+                m_services.clear();
+            }
+            
+            for (Component c : comps) {
+                manager.remove(c);
+            }
+        }
+        
+        final boolean isEmpty() {
+            synchronized (m_services) {
+                return m_services.isEmpty();
+            }
+        }
     }
 }

Modified: ace/trunk/ace-client-repository-impl/src/main/java/org/apache/ace/client/repository/impl/ArtifactRepositoryImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-repository-impl/src/main/java/org/apache/ace/client/repository/impl/ArtifactRepositoryImpl.java?rev=1329199&r1=1329198&r2=1329199&view=diff
==============================================================================
--- ace/trunk/ace-client-repository-impl/src/main/java/org/apache/ace/client/repository/impl/ArtifactRepositoryImpl.java (original)
+++ ace/trunk/ace-client-repository-impl/src/main/java/org/apache/ace/client/repository/impl/ArtifactRepositoryImpl.java Mon Apr 23 12:15:01 2012
@@ -36,10 +36,12 @@ import org.apache.ace.client.repository.
 import org.apache.ace.client.repository.helper.ArtifactHelper;
 import org.apache.ace.client.repository.helper.ArtifactPreprocessor;
 import org.apache.ace.client.repository.helper.ArtifactRecognizer;
+import org.apache.ace.client.repository.helper.ArtifactResource;
 import org.apache.ace.client.repository.helper.bundle.BundleHelper;
 import org.apache.ace.client.repository.object.ArtifactObject;
 import org.apache.ace.client.repository.object.TargetObject;
 import org.apache.ace.client.repository.repository.ArtifactRepository;
+import org.apache.ace.connectionfactory.ConnectionFactory;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Filter;
@@ -61,38 +63,15 @@ import com.thoughtworks.xstream.io.Hiera
  */
 public class ArtifactRepositoryImpl extends ObjectRepositoryImpl<ArtifactObjectImpl, ArtifactObject> implements ArtifactRepository {
     private final static String XML_NODE = "artifacts";
-    private volatile BundleContext m_context; /*Injected by dependency manager*/
-    private volatile LogService m_log; /*Injected by dependency manager*/
-    private Map<String, ArtifactHelper> m_helpers = new HashMap<String, ArtifactHelper>();
+    
+    // Injected by Dependency Manager
+    private volatile BundleContext m_context;
+    private volatile LogService m_log;
+    private volatile ConnectionFactory m_connectionFactory;
+    
+    private final Map<String, ArtifactHelper> m_helpers = new HashMap<String, ArtifactHelper>();
     private URL m_obrBase;
 
-    /**
-     * Custom comparator which sorts service references by service rank, highest rank first.
-     */
-    private static Comparator<ServiceReference> SERVICE_RANK_COMPARATOR = new Comparator<ServiceReference>() { // TODO ServiceReferences are comparable by default now
-        public int compare(ServiceReference o1, ServiceReference o2) {
-            int rank1 = 0;
-            int rank2 = 0;
-            try {
-                Object rankObject1 = o1.getProperty(Constants.SERVICE_RANKING);
-                rank1 = (rankObject1 == null) ? 0 : ((Integer) rankObject1).intValue();
-            }
-            catch (ClassCastException cce) {
-                // No problem.
-            }
-            try {
-                Object rankObject2 = o2.getProperty(Constants.SERVICE_RANKING);
-                rank1 = (rankObject2 == null) ? 0 : ((Integer) rankObject2).intValue();
-            }
-            catch (ClassCastException cce) {
-                // No problem.
-            }
-
-            return rank1 - rank2;
-        }
-    };
-
-
     public ArtifactRepositoryImpl(ChangeNotifier notifier) {
         super(notifier, XML_NODE);
     }
@@ -247,24 +226,30 @@ public class ArtifactRepositoryImpl exte
         // If available, sort the references by service ranking.
         Arrays.sort(refs, SERVICE_RANK_COMPARATOR);
 
+        ArtifactResource resource = convertToArtifactResource(url);
+
         // Check all referenced services to find one that matches our input.
         ArtifactRecognizer recognizer = null;
         String foundMimetype = null;
         for (ServiceReference ref : refs) {
             ArtifactRecognizer candidate = (ArtifactRecognizer) m_context.getService(ref);
-            if (mimetype != null) {
-                if (candidate.canHandle(mimetype)) {
-                    recognizer = candidate;
-                    break;
+            try {
+                if (mimetype != null) {
+                    if (candidate.canHandle(mimetype)) {
+                        recognizer = candidate;
+                        break;
+                    }
                 }
-            }
-            else {
-                String candidateMime = candidate.recognize(url);
-                if (candidateMime != null) {
-                    foundMimetype = candidateMime;
-                    recognizer = candidate;
-                    break;
+                else {
+                    String candidateMime = candidate.recognize(resource);
+                    if (candidateMime != null) {
+                        foundMimetype = candidateMime;
+                        recognizer = candidate;
+                        break;
+                    }
                 }
+            } finally {
+                m_context.ungetService(ref);
             }
         }
 
@@ -350,7 +335,9 @@ public class ArtifactRepositoryImpl exte
     }
 
     private ArtifactObject importArtifact(URL artifact, ArtifactRecognizer recognizer, ArtifactHelper helper, String mimetype, boolean overwrite, boolean upload) throws IOException {
-        Map<String, String> attributes = recognizer.extractMetaData(artifact);
+        ArtifactResource resource = convertToArtifactResource(artifact);
+        
+        Map<String, String> attributes = recognizer.extractMetaData(resource);
         Map<String, String> tags = new HashMap<String, String>();
 
         helper.checkAttributes(attributes);
@@ -364,7 +351,7 @@ public class ArtifactRepositoryImpl exte
         attributes.put(ArtifactObject.KEY_URL, artifactURL);
         
         if (upload) {
-            attributes.put("upload", recognizer.getExtension(artifact));
+            attributes.put("upload", recognizer.getExtension(resource));
         }
 
         ArtifactObject result = create(attributes, tags);
@@ -399,10 +386,10 @@ public class ArtifactRepositoryImpl exte
         // First, check whether we can actually reach something from this URL.
         InputStream is = null;
         try {
-            is = artifact.openStream();
+            is = openInputStream(artifact);
         }
         catch (IOException ioe) {
-            throw new IllegalArgumentException("Artifact " + artifact.toString() + "does not point to a valid file.");
+            throw new IllegalArgumentException("Artifact " + artifact.toString() + " does not point to a valid file.");
         }
         finally {
             if (is != null) {
@@ -421,7 +408,6 @@ public class ArtifactRepositoryImpl exte
                 throw new IllegalArgumentException("Artifact " + artifact.toString() + "'s name contains an illegal character '" + new String(new byte[] {b}) + "'");
             }
         }
-
     }
 
     /**
@@ -440,19 +426,26 @@ public class ArtifactRepositoryImpl exte
         OutputStream output = null;
         URL url = null;
         try {
-            input = artifact.openStream();
+            input = openInputStream(artifact);
+
             url = new URL(m_obrBase, definition);
-            URLConnection connection = url.openConnection();
+
+            URLConnection connection = m_connectionFactory.createConnection(url);
+            
             connection.setDoOutput(true);
             connection.setDoInput(true);
             connection.setUseCaches(false);
             connection.setRequestProperty("Content-Type", mimetype);
+
             output = connection.getOutputStream();
+
             byte[] buffer = new byte[4 * 1024];
             for (int count = input.read(buffer); count != -1; count = input.read(buffer)) {
                 output.write(buffer, 0, count);
             }
+
             output.close();
+            
             if (connection instanceof HttpURLConnection) {
                 int responseCode = ((HttpURLConnection) connection).getResponseCode();
                 switch (responseCode) {
@@ -515,9 +508,66 @@ public class ArtifactRepositoryImpl exte
             return preprocessor.needsNewVersion(artifact.getURL(), new TargetPropertyResolver(target), targetID, fromVersion);
         }
     }
-    
 
     public URL getObrBase() {
         return m_obrBase;
     }
+
+    /**
+     * Custom comparator which sorts service references by service rank, highest rank first.
+     */
+    private static Comparator<ServiceReference> SERVICE_RANK_COMPARATOR = new Comparator<ServiceReference>() { // TODO ServiceReferences are comparable by default now
+        public int compare(ServiceReference o1, ServiceReference o2) {
+            int rank1 = 0;
+            int rank2 = 0;
+            try {
+                Object rankObject1 = o1.getProperty(Constants.SERVICE_RANKING);
+                rank1 = (rankObject1 == null) ? 0 : ((Integer) rankObject1).intValue();
+            }
+            catch (ClassCastException cce) {
+                // No problem.
+            }
+            try {
+                Object rankObject2 = o2.getProperty(Constants.SERVICE_RANKING);
+                rank1 = (rankObject2 == null) ? 0 : ((Integer) rankObject2).intValue();
+            }
+            catch (ClassCastException cce) {
+                // No problem.
+            }
+
+            return rank1 - rank2;
+        }
+    };
+    
+    private InputStream openInputStream(URL artifactURL) throws IOException {
+        URLConnection connection = m_connectionFactory.createConnection(artifactURL);
+        return connection.getInputStream();
+    }
+
+    /**
+     * Converts a given URL to a {@link ArtifactResource} that abstracts the way we access the contents of 
+     * the URL away from the URL itself. This way, we can avoid having to pass authentication credentials,
+     * or a {@link ConnectionFactory} to the artifact recognizers. 
+     *  
+     * @param url the URL to convert, can be <code>null</code> in which case <code>null</code> is returned.
+     * @return an {@link ArtifactResource}, or <code>null</code> if the given URL was <code>null</code>.
+     */
+    private ArtifactResource convertToArtifactResource(final URL url) {
+        if (url == null) {
+            return null;
+        }
+
+        return new ArtifactResource() {
+            public URL getURL() {
+                return url;
+            }
+            
+            public InputStream openStream() throws IOException {
+                // Take care of the fact that an URL could need credentials to be accessible!!!
+                URLConnection conn = m_connectionFactory.createConnection(getURL());
+                conn.setUseCaches(true);
+                return conn.getInputStream();
+            }
+        };
+    }
 }



Mime
View raw message