diff --git a/scm-webapp/src/main/java/sonia/scm/plugin/AdvancedPluginConfiguration.java b/scm-webapp/src/main/java/sonia/scm/plugin/AdvancedPluginConfiguration.java new file mode 100644 index 0000000000..2421432655 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/plugin/AdvancedPluginConfiguration.java @@ -0,0 +1,164 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.plugin; + +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.common.collect.ImmutableSet; +import com.sun.xml.txw2.annotation.XmlCDATA; + +//~--- JDK imports ------------------------------------------------------------ + +import java.util.Set; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import sonia.scm.xml.XmlCipherStringAdapter; + +/** + * + * @author Sebastian Sdorra + * @since 1.41 + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "advanced-configuration") +public class AdvancedPluginConfiguration +{ + + /** + * Method description + * + * + * @return + */ + public Set getRepositories() + { + if (repositories == null) + { + repositories = ImmutableSet.of(); + } + + return repositories; + } + + /** + * Method description + * + * + * @return + */ + public Set getServers() + { + if (servers == null) + { + servers = ImmutableSet.of(); + } + + return servers; + } + + //~--- inner classes -------------------------------------------------------- + + /** + * Class description + * + * + * @version Enter version here..., 14/07/20 + * @author Enter your name here... + */ + @XmlAccessorType(XmlAccessType.FIELD) + public static class Server + { + + /** + * Method description + * + * + * @return + */ + public String getId() + { + return id; + } + + /** + * Method description + * + * + * @return + */ + public String getPassword() + { + return password; + } + + /** + * Method description + * + * + * @return + */ + public String getUsername() + { + return username; + } + + //~--- fields ------------------------------------------------------------- + + /** Field description */ + private String id; + + /** Field description */ + @XmlJavaTypeAdapter(XmlCipherStringAdapter.class) + private String password; + + /** Field description */ + private String username; + } + + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + @XmlElement(name = "repository") + @XmlElementWrapper(name = "repositories") + private Set repositories; + + /** Field description */ + @XmlElement(name = "server") + @XmlElementWrapper(name = "servers") + private Set servers; +} diff --git a/scm-webapp/src/main/java/sonia/scm/plugin/Aether.java b/scm-webapp/src/main/java/sonia/scm/plugin/Aether.java index 6a27d5758f..4cbd33185f 100644 --- a/scm-webapp/src/main/java/sonia/scm/plugin/Aether.java +++ b/scm-webapp/src/main/java/sonia/scm/plugin/Aether.java @@ -48,6 +48,8 @@ import org.sonatype.aether.collection.DependencyGraphTransformer; import org.sonatype.aether.graph.Dependency; import org.sonatype.aether.graph.DependencyFilter; import org.sonatype.aether.graph.DependencyNode; +import org.sonatype.aether.repository.Authentication; +import org.sonatype.aether.repository.AuthenticationSelector; import org.sonatype.aether.repository.LocalRepository; import org.sonatype.aether.repository.LocalRepositoryManager; import org.sonatype.aether.repository.Proxy; diff --git a/scm-webapp/src/main/java/sonia/scm/plugin/AetherAuthenticationSelector.java b/scm-webapp/src/main/java/sonia/scm/plugin/AetherAuthenticationSelector.java new file mode 100644 index 0000000000..9bc1bdb892 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/plugin/AetherAuthenticationSelector.java @@ -0,0 +1,116 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.plugin; + +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; + +import org.sonatype.aether.repository.Authentication; +import org.sonatype.aether.repository.AuthenticationSelector; +import org.sonatype.aether.repository.RemoteRepository; + +import sonia.scm.plugin.AdvancedPluginConfiguration.Server; + +//~--- JDK imports ------------------------------------------------------------ + +import java.util.Map; + +/** + * + * @author Sebastian Sdorra + * @since 1.41 + */ +public class AetherAuthenticationSelector implements AuthenticationSelector +{ + + /** + * Constructs ... + * + * + * @param configuration + */ + public AetherAuthenticationSelector(AdvancedPluginConfiguration configuration) + { + Builder builder = ImmutableMap.builder(); + + for (Server server : configuration.getServers()) + { + builder.put(server.getId(), server); + } + + servers = builder.build(); + } + + /** + * Constructs ... + * + * + * @param servers + */ + public AetherAuthenticationSelector(Map servers) + { + this.servers = servers; + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param repository + * + * @return + */ + @Override + public Authentication getAuthentication(RemoteRepository repository) + { + Authentication authentication = null; + Server server = servers.get(Strings.nullToEmpty(repository.getId())); + + if (server != null) + { + authentication = new Authentication(server.getUsername(), + server.getPassword()); + } + + return authentication; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private final Map servers; +} diff --git a/scm-webapp/src/main/java/sonia/scm/plugin/AetherPluginHandler.java b/scm-webapp/src/main/java/sonia/scm/plugin/AetherPluginHandler.java index 7de5397a23..37c4c6235e 100644 --- a/scm-webapp/src/main/java/sonia/scm/plugin/AetherPluginHandler.java +++ b/scm-webapp/src/main/java/sonia/scm/plugin/AetherPluginHandler.java @@ -82,6 +82,8 @@ public class AetherPluginHandler //~--- constructors --------------------------------------------------------- + private final AdvancedPluginConfiguration advancedPluginConfiguration; + /** * Constructs ... * @@ -92,10 +94,11 @@ public class AetherPluginHandler * @param configuration */ public AetherPluginHandler(PluginManager pluginManager, - SCMContextProvider context, ScmConfiguration configuration) + SCMContextProvider context, ScmConfiguration configuration, AdvancedPluginConfiguration advancedPluginConfiguration) { this.pluginManager = pluginManager; this.configuration = configuration; + this.advancedPluginConfiguration = advancedPluginConfiguration; localRepositoryDirectory = new File(context.getBaseDirectory(), BootstrapListener.PLUGIN_DIRECTORY); @@ -124,7 +127,7 @@ public class AetherPluginHandler logger.error("could not read classpath file", ex); } } - + IOUtil.mkdirs(localRepositoryDirectory); repositorySystem = Aether.createRepositorySystem(); localRepository = new LocalRepository(localRepositoryDirectory); diff --git a/scm-webapp/src/main/java/sonia/scm/plugin/DefaultPluginManager.java b/scm-webapp/src/main/java/sonia/scm/plugin/DefaultPluginManager.java index 4e75d5b84d..85c7eeef4e 100644 --- a/scm-webapp/src/main/java/sonia/scm/plugin/DefaultPluginManager.java +++ b/scm-webapp/src/main/java/sonia/scm/plugin/DefaultPluginManager.java @@ -35,6 +35,8 @@ package sonia.scm.plugin; //~--- non-JDK imports -------------------------------------------------------- +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.Sets; import com.google.common.io.Files; import com.google.inject.Inject; @@ -104,17 +106,15 @@ public class DefaultPluginManager public static final PluginFilter FILTER_UPDATES = new StatePluginFilter(PluginState.UPDATE_AVAILABLE); + + private static final String ADVANCED_CONFIGURATION = "advanced-configuration.xml"; + //~--- constructors --------------------------------------------------------- /** * Constructs ... * - * - * - * - * * @param context - * @param securityContextProvicer * @param configuration * @param pluginLoader * @param cacheManager @@ -151,9 +151,21 @@ public class DefaultPluginManager { throw new ConfigurationException(ex); } + + File file = new File(context.getBaseDirectory(), ADVANCED_CONFIGURATION); + if (file.exists()) + { + advancedPluginConfiguration = JAXB.unmarshal(file, AdvancedPluginConfiguration.class); + } else { + advancedPluginConfiguration = new AdvancedPluginConfiguration(); + } this.configuration.addListener(this); } + + + private final AdvancedPluginConfiguration advancedPluginConfiguration; + //~--- methods -------------------------------------------------------------- @@ -246,7 +258,7 @@ public class DefaultPluginManager } AetherPluginHandler aph = new AetherPluginHandler(this, context, - configuration); + configuration, advancedPluginConfiguration); Collection repositories = Sets.newHashSet(new PluginRepository("package-repository", "file://".concat(tempDirectory.getAbsolutePath()))); @@ -638,10 +650,14 @@ public class DefaultPluginManager if (pluginHandler == null) { pluginHandler = new AetherPluginHandler(this, - SCMContext.getContext(), configuration); + SCMContext.getContext(), configuration, advancedPluginConfiguration); } + + Builder builder = ImmutableSet.builder(); + builder.addAll(advancedPluginConfiguration.getRepositories()); + builder.addAll(center.getRepositories()); - pluginHandler.setPluginRepositories(center.getRepositories()); + pluginHandler.setPluginRepositories(builder.build()); } catch (Exception ex) {