mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 22:15:45 +01:00
improve plugin management
This commit is contained in:
@@ -14,20 +14,29 @@ import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.util.ServiceUtil;
|
||||
import sonia.scm.util.Util;
|
||||
import sonia.scm.web.ScmWebPlugin;
|
||||
import sonia.scm.web.ScmWebPluginContext;
|
||||
import sonia.scm.web.plugin.SCMPlugin;
|
||||
import sonia.scm.web.plugin.SCMPluginManager;
|
||||
import sonia.scm.web.plugin.ScmWebPlugin;
|
||||
import sonia.scm.web.plugin.ScmWebPluginContext;
|
||||
import sonia.scm.web.security.Authenticator;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import sonia.scm.web.security.Authenticator;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -36,6 +45,12 @@ import sonia.scm.web.security.Authenticator;
|
||||
public class ContextListener extends GuiceServletContextListener
|
||||
{
|
||||
|
||||
/** the logger for ContextListener */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(ContextListener.class);
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -45,9 +60,7 @@ public class ContextListener extends GuiceServletContextListener
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent servletContextEvent)
|
||||
{
|
||||
List<ScmWebPlugin> plugins = ServiceUtil.getServices(ScmWebPlugin.class);
|
||||
|
||||
for (ScmWebPlugin plugin : plugins)
|
||||
for (ScmWebPlugin plugin : webPluginSet)
|
||||
{
|
||||
plugin.contextDestroyed(webPluginContext);
|
||||
}
|
||||
@@ -64,14 +77,38 @@ public class ContextListener extends GuiceServletContextListener
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent servletContextEvent)
|
||||
{
|
||||
webPluginContext =
|
||||
new ScmWebPluginContext(servletContextEvent.getServletContext());
|
||||
pluginManager = new SCMPluginManager();
|
||||
|
||||
List<ScmWebPlugin> plugins = ServiceUtil.getServices(ScmWebPlugin.class);
|
||||
|
||||
for (ScmWebPlugin plugin : plugins)
|
||||
try
|
||||
{
|
||||
plugin.contextInitialized(webPluginContext);
|
||||
pluginManager.load();
|
||||
webPluginContext =
|
||||
new ScmWebPluginContext(servletContextEvent.getServletContext());
|
||||
|
||||
for (SCMPlugin plugin : pluginManager.getPlugins())
|
||||
{
|
||||
try
|
||||
{
|
||||
webPluginSet.add(plugin.getWebPlugin().newInstance());
|
||||
}
|
||||
catch (InstantiationException ex)
|
||||
{
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
catch (IllegalAccessException ex)
|
||||
{
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
for (ScmWebPlugin plugin : webPluginSet)
|
||||
{
|
||||
plugin.contextInitialized(webPluginContext);
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
super.contextInitialized(servletContextEvent);
|
||||
@@ -112,6 +149,12 @@ public class ContextListener extends GuiceServletContextListener
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private SCMPluginManager pluginManager;
|
||||
|
||||
/** Field description */
|
||||
private ScmWebPluginContext webPluginContext;
|
||||
|
||||
/** Field description */
|
||||
private Set<ScmWebPlugin> webPluginSet = new LinkedHashSet<ScmWebPlugin>();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import sonia.scm.cache.CacheManager;
|
||||
import sonia.scm.cache.CacheRepositoryManagerDecorator;
|
||||
import sonia.scm.cache.EhCacheManager;
|
||||
import sonia.scm.filter.SecurityFilter;
|
||||
import sonia.scm.plugin.SCMPluginManager;
|
||||
import sonia.scm.plugin.ScriptResourceServlet;
|
||||
import sonia.scm.repository.BasicRepositoryManager;
|
||||
import sonia.scm.repository.RepositoryHandler;
|
||||
@@ -28,7 +27,10 @@ import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.security.EncryptionHandler;
|
||||
import sonia.scm.security.MessageDigestEncryptionHandler;
|
||||
import sonia.scm.util.DebugServlet;
|
||||
import sonia.scm.web.ScmWebPluginContext;
|
||||
import sonia.scm.util.Util;
|
||||
import sonia.scm.web.plugin.SCMPlugin;
|
||||
import sonia.scm.web.plugin.SCMPluginManager;
|
||||
import sonia.scm.web.plugin.ScmWebPluginContext;
|
||||
import sonia.scm.web.security.Authenticator;
|
||||
import sonia.scm.web.security.BasicSecurityContext;
|
||||
import sonia.scm.web.security.SecurityContext;
|
||||
@@ -43,8 +45,11 @@ import com.sun.jersey.spi.container.servlet.ServletContainer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -117,8 +122,6 @@ public class ScmServletModule extends ServletModule
|
||||
bind(Authenticator.class).to(XmlAuthenticator.class);
|
||||
bind(SecurityContext.class).to(BasicSecurityContext.class);
|
||||
|
||||
Multibinder<RepositoryHandler> repositoryHandlerBinder =
|
||||
Multibinder.newSetBinder(binder(), RepositoryHandler.class);
|
||||
SCMPluginManager pluginManager = new SCMPluginManager();
|
||||
|
||||
try
|
||||
@@ -130,13 +133,7 @@ public class ScmServletModule extends ServletModule
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
for (Class<? extends RepositoryHandler> handler :
|
||||
pluginManager.getRepositoryHandlers())
|
||||
{
|
||||
bind(handler);
|
||||
repositoryHandlerBinder.addBinding().to(handler);
|
||||
}
|
||||
|
||||
loadPlugins(pluginManager);
|
||||
bind(CacheManager.class).to(EhCacheManager.class);
|
||||
bind(RepositoryManager.class).annotatedWith(Undecorated.class).to(
|
||||
BasicRepositoryManager.class);
|
||||
@@ -175,6 +172,61 @@ public class ScmServletModule extends ServletModule
|
||||
serve(PATTERN_RESTAPI).with(GuiceContainer.class, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryHandlerBinder
|
||||
* @param handlerSet
|
||||
*/
|
||||
private void bindRepositoryHandlers(
|
||||
Multibinder<RepositoryHandler> repositoryHandlerBinder,
|
||||
Set<Class<? extends RepositoryHandler>> handlerSet)
|
||||
{
|
||||
for (Class<? extends RepositoryHandler> handlerClass : handlerSet)
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("load RepositoryHandler {}", handlerClass.getName());
|
||||
}
|
||||
|
||||
bind(handlerClass);
|
||||
repositoryHandlerBinder.addBinding().to(handlerClass);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param pluginManager
|
||||
*/
|
||||
private void loadPlugins(SCMPluginManager pluginManager)
|
||||
{
|
||||
Set<SCMPlugin> pluginSet = pluginManager.getPlugins();
|
||||
|
||||
if (Util.isNotEmpty(pluginSet))
|
||||
{
|
||||
Multibinder<RepositoryHandler> repositoryHandlerBinder =
|
||||
Multibinder.newSetBinder(binder(), RepositoryHandler.class);
|
||||
Set<Class<? extends RepositoryHandler>> handlerSet =
|
||||
new LinkedHashSet<Class<? extends RepositoryHandler>>();
|
||||
|
||||
for (SCMPlugin plugin : pluginSet)
|
||||
{
|
||||
Collection<Class<? extends RepositoryHandler>> handlers =
|
||||
plugin.getHandlers();
|
||||
|
||||
if (Util.isNotEmpty(handlers))
|
||||
{
|
||||
handlerSet.addAll(handlers);
|
||||
}
|
||||
}
|
||||
|
||||
bindRepositoryHandlers(repositoryHandlerBinder, handlerSet);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -14,8 +14,8 @@ import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
import sonia.scm.web.ScmWebPluginContext;
|
||||
import sonia.scm.web.WebResource;
|
||||
import sonia.scm.web.plugin.ScmWebPluginContext;
|
||||
import sonia.scm.web.plugin.WebResource;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -71,9 +71,6 @@ public class XmlAuthenticator implements Authenticator
|
||||
|
||||
String encryptedPassword = encryptionHandler.encrypt(password);
|
||||
|
||||
System.out.println(encryptedPassword);
|
||||
System.out.println(user.getPassword());
|
||||
|
||||
if (!encryptedPassword.equalsIgnoreCase(user.getPassword()))
|
||||
{
|
||||
user = null;
|
||||
|
||||
Reference in New Issue
Block a user