mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
added injection support for authentication, group, repository and user listeners
This commit is contained in:
@@ -109,6 +109,16 @@ public class BindingExtensionProcessor implements ExtensionProcessor
|
||||
Multibinder<ChangesetPreProcessorFactory> changesetPreProcessorFactoryBinder =
|
||||
Multibinder.newSetBinder(binder, ChangesetPreProcessorFactory.class);
|
||||
|
||||
// listeners
|
||||
Multibinder<RepositoryListener> repositoryListenerBinder =
|
||||
Multibinder.newSetBinder(binder, RepositoryListener.class);
|
||||
Multibinder<UserListener> userListenerBinder =
|
||||
Multibinder.newSetBinder(binder, UserListener.class);
|
||||
Multibinder<GroupListener> groupListenerBinder =
|
||||
Multibinder.newSetBinder(binder, GroupListener.class);
|
||||
Multibinder<AuthenticationListener> authenticationListenerBinder =
|
||||
Multibinder.newSetBinder(binder, AuthenticationListener.class);
|
||||
|
||||
authenticators.addBinding().to(XmlAuthenticationHandler.class);
|
||||
|
||||
for (Class extensionClass : extensions)
|
||||
@@ -147,9 +157,8 @@ public class BindingExtensionProcessor implements ExtensionProcessor
|
||||
logger.info("bind GroupListener {}", extensionClass.getName());
|
||||
}
|
||||
|
||||
GroupListener listener = (GroupListener) extensionClass.newInstance();
|
||||
|
||||
groupListeners.add(listener);
|
||||
binder.bind(extensionClass);
|
||||
groupListenerBinder.addBinding().to(extensionClass);
|
||||
}
|
||||
else if (UserListener.class.isAssignableFrom(extensionClass))
|
||||
{
|
||||
@@ -158,9 +167,8 @@ public class BindingExtensionProcessor implements ExtensionProcessor
|
||||
logger.info("bind UserListener {}", extensionClass.getName());
|
||||
}
|
||||
|
||||
UserListener listener = (UserListener) extensionClass.newInstance();
|
||||
|
||||
userListeners.add(listener);
|
||||
binder.bind(extensionClass);
|
||||
userListenerBinder.addBinding().to(extensionClass);
|
||||
}
|
||||
else if (RepositoryListener.class.isAssignableFrom(extensionClass))
|
||||
{
|
||||
@@ -169,10 +177,8 @@ public class BindingExtensionProcessor implements ExtensionProcessor
|
||||
logger.info("bind RepositoryListener {}", extensionClass.getName());
|
||||
}
|
||||
|
||||
RepositoryListener listener =
|
||||
(RepositoryListener) extensionClass.newInstance();
|
||||
|
||||
repositoryListeners.add(listener);
|
||||
binder.bind(extensionClass);
|
||||
repositoryListenerBinder.addBinding().to(extensionClass);
|
||||
}
|
||||
else if (AuthenticationListener.class.isAssignableFrom(extensionClass))
|
||||
{
|
||||
@@ -182,10 +188,8 @@ public class BindingExtensionProcessor implements ExtensionProcessor
|
||||
extensionClass.getName());
|
||||
}
|
||||
|
||||
AuthenticationListener listener =
|
||||
(AuthenticationListener) extensionClass.newInstance();
|
||||
|
||||
authenticationListeners.add(listener);
|
||||
binder.bind(extensionClass);
|
||||
authenticationListenerBinder.addBinding().to(extensionClass);
|
||||
}
|
||||
else if (ResourceHandler.class.isAssignableFrom(extensionClass))
|
||||
{
|
||||
@@ -285,17 +289,6 @@ public class BindingExtensionProcessor implements ExtensionProcessor
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<AuthenticationListener> getAuthenticationListeners()
|
||||
{
|
||||
return authenticationListeners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -307,17 +300,6 @@ public class BindingExtensionProcessor implements ExtensionProcessor
|
||||
return fileSystemClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<GroupListener> getGroupListeners()
|
||||
{
|
||||
return groupListeners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -340,28 +322,6 @@ public class BindingExtensionProcessor implements ExtensionProcessor
|
||||
return moduleSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<RepositoryListener> getRepositoryListeners()
|
||||
{
|
||||
return repositoryListeners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<UserListener> getUserListeners()
|
||||
{
|
||||
return userListeners;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -420,18 +380,4 @@ public class BindingExtensionProcessor implements ExtensionProcessor
|
||||
|
||||
/** Field description */
|
||||
private Set<Module> moduleSet;
|
||||
|
||||
/** Field description */
|
||||
private Set<RepositoryListener> repositoryListeners =
|
||||
new HashSet<RepositoryListener>();
|
||||
|
||||
/** Field description */
|
||||
private Set<AuthenticationListener> authenticationListeners =
|
||||
new HashSet<AuthenticationListener>();
|
||||
|
||||
/** Field description */
|
||||
private Set<UserListener> userListeners = new HashSet<UserListener>();
|
||||
|
||||
/** Field description */
|
||||
private Set<GroupListener> groupListeners = new HashSet<GroupListener>();
|
||||
}
|
||||
|
||||
@@ -151,20 +151,17 @@ public class ScmContextListener extends GuiceServletContextListener
|
||||
RepositoryManager repositoryManager =
|
||||
injector.getInstance(RepositoryManager.class);
|
||||
|
||||
repositoryManager.addListeners(bindExtProcessor.getRepositoryListeners());
|
||||
repositoryManager.addHooks(bindExtProcessor.getHooks());
|
||||
repositoryManager.init(context);
|
||||
|
||||
// init UserManager
|
||||
UserManager userManager = injector.getInstance(UserManager.class);
|
||||
|
||||
userManager.addListeners(bindExtProcessor.getUserListeners());
|
||||
userManager.init(context);
|
||||
|
||||
// init GroupManager
|
||||
GroupManager groupManager = injector.getInstance(GroupManager.class);
|
||||
|
||||
groupManager.addListeners(bindExtProcessor.getGroupListeners());
|
||||
groupManager.init(context);
|
||||
|
||||
// init Authenticator
|
||||
@@ -172,8 +169,6 @@ public class ScmContextListener extends GuiceServletContextListener
|
||||
injector.getInstance(AuthenticationManager.class);
|
||||
|
||||
authenticationManager.init(context);
|
||||
authenticationManager.addListeners(
|
||||
bindExtProcessor.getAuthenticationListeners());
|
||||
|
||||
return injector;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ import sonia.scm.group.AbstractGroupManager;
|
||||
import sonia.scm.group.Group;
|
||||
import sonia.scm.group.GroupAllreadyExistExeption;
|
||||
import sonia.scm.group.GroupException;
|
||||
import sonia.scm.group.GroupListener;
|
||||
import sonia.scm.search.SearchRequest;
|
||||
import sonia.scm.search.SearchUtil;
|
||||
import sonia.scm.security.SecurityContext;
|
||||
@@ -68,6 +69,7 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -95,13 +97,16 @@ public class XmlGroupManager extends AbstractGroupManager
|
||||
*
|
||||
* @param securityContextProvider
|
||||
* @param storeFactory
|
||||
* @param groupListenerProvider
|
||||
*/
|
||||
@Inject
|
||||
public XmlGroupManager(Provider<SecurityContext> securityContextProvider,
|
||||
StoreFactory storeFactory)
|
||||
StoreFactory storeFactory,
|
||||
Provider<Set<GroupListener>> groupListenerProvider)
|
||||
{
|
||||
this.securityContextProvider = securityContextProvider;
|
||||
this.store = storeFactory.getStore(XmlGroupDatabase.class, STORE_NAME);
|
||||
this.groupListenerProvider = groupListenerProvider;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -215,6 +220,13 @@ public class XmlGroupManager extends AbstractGroupManager
|
||||
{
|
||||
groupDB = new XmlGroupDatabase();
|
||||
}
|
||||
|
||||
Set<GroupListener> listeners = groupListenerProvider.get();
|
||||
|
||||
if (Util.isNotEmpty(listeners))
|
||||
{
|
||||
addListeners(listeners);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -482,6 +494,9 @@ public class XmlGroupManager extends AbstractGroupManager
|
||||
/** Field description */
|
||||
private XmlGroupDatabase groupDB;
|
||||
|
||||
/** Field description */
|
||||
private Provider<Set<GroupListener>> groupListenerProvider;
|
||||
|
||||
/** Field description */
|
||||
private Provider<SecurityContext> securityContextProvider;
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ import sonia.scm.repository.RepositoryHandler;
|
||||
import sonia.scm.repository.RepositoryHandlerNotFoundException;
|
||||
import sonia.scm.repository.RepositoryHook;
|
||||
import sonia.scm.repository.RepositoryHookEvent;
|
||||
import sonia.scm.repository.RepositoryListener;
|
||||
import sonia.scm.repository.RepositoryNotFoundException;
|
||||
import sonia.scm.security.ScmSecurityException;
|
||||
import sonia.scm.store.Store;
|
||||
@@ -111,15 +112,18 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
|
||||
* @param securityContextProvider
|
||||
* @param storeFactory
|
||||
* @param handlerSet
|
||||
* @param repositoryListenersProvider
|
||||
*/
|
||||
@Inject
|
||||
public XmlRepositoryManager(
|
||||
SCMContextProvider contextProvider,
|
||||
Provider<WebSecurityContext> securityContextProvider,
|
||||
StoreFactory storeFactory, Set<RepositoryHandler> handlerSet)
|
||||
StoreFactory storeFactory, Set<RepositoryHandler> handlerSet,
|
||||
Provider<Set<RepositoryListener>> repositoryListenersProvider)
|
||||
{
|
||||
this.securityContextProvider = securityContextProvider;
|
||||
this.store = storeFactory.getStore(XmlRepositoryDatabase.class, STORE_NAME);
|
||||
this.repositoryListenersProvider = repositoryListenersProvider;
|
||||
handlerMap = new HashMap<String, RepositoryHandler>();
|
||||
types = new HashSet<Type>();
|
||||
|
||||
@@ -288,6 +292,13 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
|
||||
{
|
||||
repositoryDB = new XmlRepositoryDatabase();
|
||||
}
|
||||
|
||||
Set<RepositoryListener> listeners = repositoryListenersProvider.get();
|
||||
|
||||
if (Util.isNotEmpty(listeners))
|
||||
{
|
||||
addListeners(listeners);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -764,6 +775,9 @@ public class XmlRepositoryManager extends AbstractRepositoryManager
|
||||
/** Field description */
|
||||
private XmlRepositoryDatabase repositoryDB;
|
||||
|
||||
/** Field description */
|
||||
private Provider<Set<RepositoryListener>> repositoryListenersProvider;
|
||||
|
||||
/** Field description */
|
||||
private Provider<WebSecurityContext> securityContextProvider;
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ import sonia.scm.user.AbstractUserManager;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserAllreadyExistException;
|
||||
import sonia.scm.user.UserException;
|
||||
import sonia.scm.user.UserListener;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.CollectionAppender;
|
||||
import sonia.scm.util.IOUtil;
|
||||
@@ -71,6 +72,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
@@ -109,13 +111,16 @@ public class XmlUserManager extends AbstractUserManager
|
||||
*
|
||||
* @param scurityContextProvider
|
||||
* @param storeFactory
|
||||
* @param userListenerProvider
|
||||
*/
|
||||
@Inject
|
||||
public XmlUserManager(Provider<WebSecurityContext> scurityContextProvider,
|
||||
StoreFactory storeFactory)
|
||||
StoreFactory storeFactory,
|
||||
Provider<Set<UserListener>> userListenerProvider)
|
||||
{
|
||||
this.scurityContextProvider = scurityContextProvider;
|
||||
this.store = storeFactory.getStore(XmlUserDatabase.class, STORE_NAME);
|
||||
this.userListenerProvider = userListenerProvider;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -248,6 +253,13 @@ public class XmlUserManager extends AbstractUserManager
|
||||
userDB = new XmlUserDatabase();
|
||||
createDefaultAccounts();
|
||||
}
|
||||
|
||||
Set<UserListener> listeners = userListenerProvider.get();
|
||||
|
||||
if (Util.isNotEmpty(listeners))
|
||||
{
|
||||
addListeners(listeners);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -551,4 +563,7 @@ public class XmlUserManager extends AbstractUserManager
|
||||
|
||||
/** Field description */
|
||||
private XmlUserDatabase userDB;
|
||||
|
||||
/** Field description */
|
||||
private Provider<Set<UserListener>> userListenerProvider;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ package sonia.scm.web.security;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -48,6 +49,7 @@ import sonia.scm.security.EncryptionHandler;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -82,19 +84,24 @@ public class ChainAuthenticatonManager extends AbstractAuthenticationManager
|
||||
* @param authenticationHandlerSet
|
||||
* @param encryptionHandler
|
||||
* @param cacheManager
|
||||
* @param authenticationListenerProvider
|
||||
*/
|
||||
@Inject
|
||||
public ChainAuthenticatonManager(
|
||||
Set<AuthenticationHandler> authenticationHandlerSet,
|
||||
EncryptionHandler encryptionHandler, CacheManager cacheManager)
|
||||
EncryptionHandler encryptionHandler, CacheManager cacheManager,
|
||||
Provider<Set<AuthenticationListener>> authenticationListenerProvider)
|
||||
{
|
||||
AssertUtil.assertIsNotEmpty(authenticationHandlerSet);
|
||||
AssertUtil.assertIsNotNull(cacheManager);
|
||||
this.authenticationHandlerSet = authenticationHandlerSet;
|
||||
this.encryptionHandler = encryptionHandler;
|
||||
this.authenticationListenerProvider = authenticationListenerProvider;
|
||||
this.cache = cacheManager.getCache(String.class,
|
||||
AuthenticationCacheValue.class,
|
||||
CACHE_NAME);
|
||||
|
||||
// addListeners(authenticationListeners);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -166,6 +173,14 @@ public class ChainAuthenticatonManager extends AbstractAuthenticationManager
|
||||
{
|
||||
authenticator.init(context);
|
||||
}
|
||||
|
||||
Set<AuthenticationListener> listeners =
|
||||
authenticationListenerProvider.get();
|
||||
|
||||
if (Util.isNotEmpty(listeners))
|
||||
{
|
||||
addListeners(listeners);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -297,6 +312,9 @@ public class ChainAuthenticatonManager extends AbstractAuthenticationManager
|
||||
/** Field description */
|
||||
private Set<AuthenticationHandler> authenticationHandlerSet;
|
||||
|
||||
/** Field description */
|
||||
private Provider<Set<AuthenticationListener>> authenticationListenerProvider;
|
||||
|
||||
/** Field description */
|
||||
private Cache<String, AuthenticationCacheValue> cache;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user