mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 14:05:44 +01:00
added UserHandler to plugin framework
This commit is contained in:
@@ -29,15 +29,17 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.web.plugin;
|
package sonia.scm.web.plugin;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import sonia.scm.repository.RepositoryHandler;
|
import sonia.scm.repository.RepositoryHandler;
|
||||||
|
import sonia.scm.user.UserHandler;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -62,35 +64,8 @@ public class SCMPlugin
|
|||||||
*/
|
*/
|
||||||
public SCMPlugin()
|
public SCMPlugin()
|
||||||
{
|
{
|
||||||
handlers = new HashSet<Class<? extends RepositoryHandler>>();
|
repositoryHandlers = new HashSet<Class<? extends RepositoryHandler>>();
|
||||||
}
|
userHandlers = new HashSet<Class<? extends UserHandler>>();
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param handlerClass
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean addHandler(Class<? extends RepositoryHandler> handlerClass)
|
|
||||||
{
|
|
||||||
return handlers.add(handlerClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param handlerClass
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean removeHandler(Class<? extends RepositoryHandler> handlerClass)
|
|
||||||
{
|
|
||||||
return handlers.remove(handlerClass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -101,9 +76,9 @@ public class SCMPlugin
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Collection<Class<? extends RepositoryHandler>> getHandlers()
|
public Set<Class<? extends RepositoryHandler>> getRepositoryHandlers()
|
||||||
{
|
{
|
||||||
return handlers;
|
return repositoryHandlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,6 +92,17 @@ public class SCMPlugin
|
|||||||
return securityConfig;
|
return securityConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Set<Class<? extends UserHandler>> getUserHandlers()
|
||||||
|
{
|
||||||
|
return userHandlers;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -130,6 +116,18 @@ public class SCMPlugin
|
|||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
//~--- set methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param repositoryHandlers
|
||||||
|
*/
|
||||||
|
public void setRepositoryHandlers(
|
||||||
|
Set<Class<? extends RepositoryHandler>> repositoryHandlers)
|
||||||
|
{
|
||||||
|
this.repositoryHandlers = repositoryHandlers;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -141,6 +139,17 @@ public class SCMPlugin
|
|||||||
this.securityConfig = securityConfig;
|
this.securityConfig = securityConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param userHandlers
|
||||||
|
*/
|
||||||
|
public void setUserHandlers(Set<Class<? extends UserHandler>> userHandlers)
|
||||||
|
{
|
||||||
|
this.userHandlers = userHandlers;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -157,12 +166,17 @@ public class SCMPlugin
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
@XmlElementWrapper(name = "repository-handlers")
|
@XmlElementWrapper(name = "repository-handlers")
|
||||||
@XmlElement(name = "repository-handler")
|
@XmlElement(name = "repository-handler")
|
||||||
private Set<Class<? extends RepositoryHandler>> handlers;
|
private Set<Class<? extends RepositoryHandler>> repositoryHandlers;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@XmlElement(name = "security")
|
@XmlElement(name = "security")
|
||||||
private SecurityConfig securityConfig;
|
private SecurityConfig securityConfig;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
@XmlElementWrapper(name = "user-handlers")
|
||||||
|
@XmlElement(name = "user-handler")
|
||||||
|
private Set<Class<? extends UserHandler>> userHandlers;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@XmlElement(name = "web-plugin")
|
@XmlElement(name = "web-plugin")
|
||||||
private Class<? extends ScmWebPlugin> webPlugin;
|
private Class<? extends ScmWebPlugin> webPlugin;
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm;
|
package sonia.scm;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
@@ -42,6 +44,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.repository.RepositoryManager;
|
import sonia.scm.repository.RepositoryManager;
|
||||||
|
import sonia.scm.user.UserManager;
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
import sonia.scm.web.plugin.SCMPlugin;
|
import sonia.scm.web.plugin.SCMPlugin;
|
||||||
import sonia.scm.web.plugin.SCMPluginManager;
|
import sonia.scm.web.plugin.SCMPluginManager;
|
||||||
@@ -164,6 +167,9 @@ public class ContextListener extends GuiceServletContextListener
|
|||||||
// init RepositoryManager
|
// init RepositoryManager
|
||||||
injector.getInstance(RepositoryManager.class).init(SCMContext.getContext());
|
injector.getInstance(RepositoryManager.class).init(SCMContext.getContext());
|
||||||
|
|
||||||
|
// init UserManager
|
||||||
|
injector.getInstance(UserManager.class).init(SCMContext.getContext());
|
||||||
|
|
||||||
// init Authenticator
|
// init Authenticator
|
||||||
injector.getInstance(Authenticator.class).init(SCMContext.getContext());
|
injector.getInstance(Authenticator.class).init(SCMContext.getContext());
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm;
|
package sonia.scm;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
@@ -50,6 +52,10 @@ import sonia.scm.repository.RepositoryHandler;
|
|||||||
import sonia.scm.repository.RepositoryManager;
|
import sonia.scm.repository.RepositoryManager;
|
||||||
import sonia.scm.security.EncryptionHandler;
|
import sonia.scm.security.EncryptionHandler;
|
||||||
import sonia.scm.security.MessageDigestEncryptionHandler;
|
import sonia.scm.security.MessageDigestEncryptionHandler;
|
||||||
|
import sonia.scm.user.BasicUserManager;
|
||||||
|
import sonia.scm.user.UserHandler;
|
||||||
|
import sonia.scm.user.UserManager;
|
||||||
|
import sonia.scm.user.XmlUserHandler;
|
||||||
import sonia.scm.util.DebugServlet;
|
import sonia.scm.util.DebugServlet;
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
import sonia.scm.web.plugin.SCMPlugin;
|
import sonia.scm.web.plugin.SCMPlugin;
|
||||||
@@ -154,6 +160,7 @@ public class ScmServletModule extends ServletModule
|
|||||||
bind(RepositoryManager.class).annotatedWith(Undecorated.class).to(
|
bind(RepositoryManager.class).annotatedWith(Undecorated.class).to(
|
||||||
BasicRepositoryManager.class);
|
BasicRepositoryManager.class);
|
||||||
bind(RepositoryManager.class).to(CacheRepositoryManagerDecorator.class);
|
bind(RepositoryManager.class).to(CacheRepositoryManagerDecorator.class);
|
||||||
|
bind(UserManager.class).to(BasicUserManager.class);
|
||||||
bind(ScmWebPluginContext.class).toInstance(webPluginContext);
|
bind(ScmWebPluginContext.class).toInstance(webPluginContext);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -211,6 +218,28 @@ public class ScmServletModule extends ServletModule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param userHandlerBinder
|
||||||
|
* @param handlerSet
|
||||||
|
*/
|
||||||
|
private void bindUserHandlers(Multibinder<UserHandler> userHandlerBinder,
|
||||||
|
Set<Class<? extends UserHandler>> handlerSet)
|
||||||
|
{
|
||||||
|
for (Class<? extends UserHandler> handlerClass : handlerSet)
|
||||||
|
{
|
||||||
|
if (logger.isInfoEnabled())
|
||||||
|
{
|
||||||
|
logger.info("load UserHandler {}", handlerClass.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
bind(handlerClass);
|
||||||
|
userHandlerBinder.addBinding().to(handlerClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -223,22 +252,42 @@ public class ScmServletModule extends ServletModule
|
|||||||
|
|
||||||
if (Util.isNotEmpty(pluginSet))
|
if (Util.isNotEmpty(pluginSet))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// repository handlers
|
||||||
Multibinder<RepositoryHandler> repositoryHandlerBinder =
|
Multibinder<RepositoryHandler> repositoryHandlerBinder =
|
||||||
Multibinder.newSetBinder(binder(), RepositoryHandler.class);
|
Multibinder.newSetBinder(binder(), RepositoryHandler.class);
|
||||||
Set<Class<? extends RepositoryHandler>> handlerSet =
|
Set<Class<? extends RepositoryHandler>> repositoryHandlerSet =
|
||||||
new LinkedHashSet<Class<? extends RepositoryHandler>>();
|
new LinkedHashSet<Class<? extends RepositoryHandler>>();
|
||||||
|
|
||||||
|
// user handlers
|
||||||
|
Multibinder<UserHandler> userHandlerBinder =
|
||||||
|
Multibinder.newSetBinder(binder(), UserHandler.class);
|
||||||
|
Set<Class<? extends UserHandler>> userHandlerSet =
|
||||||
|
new LinkedHashSet<Class<? extends UserHandler>>();
|
||||||
|
|
||||||
|
userHandlerSet.add(XmlUserHandler.class);
|
||||||
|
|
||||||
|
// security stuff
|
||||||
Class<? extends EncryptionHandler> encryptionHandler =
|
Class<? extends EncryptionHandler> encryptionHandler =
|
||||||
MessageDigestEncryptionHandler.class;
|
MessageDigestEncryptionHandler.class;
|
||||||
Class<? extends Authenticator> authenticator = XmlAuthenticator.class;
|
Class<? extends Authenticator> authenticator = XmlAuthenticator.class;
|
||||||
|
|
||||||
for (SCMPlugin plugin : pluginSet)
|
for (SCMPlugin plugin : pluginSet)
|
||||||
{
|
{
|
||||||
Collection<Class<? extends RepositoryHandler>> handlers =
|
Collection<Class<? extends RepositoryHandler>> pluginRepositoryHandlers =
|
||||||
plugin.getHandlers();
|
plugin.getRepositoryHandlers();
|
||||||
|
|
||||||
if (Util.isNotEmpty(handlers))
|
if (Util.isNotEmpty(pluginRepositoryHandlers))
|
||||||
{
|
{
|
||||||
handlerSet.addAll(handlers);
|
repositoryHandlerSet.addAll(pluginRepositoryHandlers);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collection<Class<? extends UserHandler>> pluginUserHandlers =
|
||||||
|
plugin.getUserHandlers();
|
||||||
|
|
||||||
|
if (Util.isNotEmpty(pluginUserHandlers))
|
||||||
|
{
|
||||||
|
userHandlerSet.addAll(pluginUserHandlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
SecurityConfig securityConfig = plugin.getSecurityConfig();
|
SecurityConfig securityConfig = plugin.getSecurityConfig();
|
||||||
@@ -265,7 +314,8 @@ public class ScmServletModule extends ServletModule
|
|||||||
|
|
||||||
bind(EncryptionHandler.class).to(encryptionHandler);
|
bind(EncryptionHandler.class).to(encryptionHandler);
|
||||||
bind(Authenticator.class).to(authenticator);
|
bind(Authenticator.class).to(authenticator);
|
||||||
bindRepositoryHandlers(repositoryHandlerBinder, handlerSet);
|
bindRepositoryHandlers(repositoryHandlerBinder, repositoryHandlerSet);
|
||||||
|
bindUserHandlers(userHandlerBinder, userHandlerSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user