mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 14:35:45 +01:00
fix UserManager
This commit is contained in:
@@ -81,23 +81,4 @@ public interface Manager<T extends TypedObject, E extends Exception>
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Collection<T> getAll();
|
public Collection<T> getAll();
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
* @param <H>
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public <H extends Handler<T, E>> H getHandler(String type);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Collection<Type> getTypes();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,28 +31,39 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.user;
|
package sonia.scm;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
|
*
|
||||||
|
* @param <T>
|
||||||
|
* @param <E>
|
||||||
*/
|
*/
|
||||||
public class UserHandlerNotFoundException extends UserException
|
public interface TypeManager<T extends TypedObject, E extends Exception>
|
||||||
|
extends Manager<T, E>
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private static final long serialVersionUID = -4704703054646330523L;
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs ...
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param message
|
* @param type
|
||||||
|
* @param <H>
|
||||||
|
*
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public UserHandlerNotFoundException(String message)
|
public <H extends Handler<T, E>> H getHandler(String type);
|
||||||
{
|
|
||||||
super(message);
|
/**
|
||||||
}
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Collection<Type> getTypes();
|
||||||
}
|
}
|
||||||
@@ -36,14 +36,14 @@ package sonia.scm.repository;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import sonia.scm.ListenerSupport;
|
import sonia.scm.ListenerSupport;
|
||||||
import sonia.scm.Manager;
|
import sonia.scm.TypeManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public interface RepositoryManager
|
public interface RepositoryManager
|
||||||
extends Manager<Repository, RepositoryException>,
|
extends TypeManager<Repository, RepositoryException>,
|
||||||
ListenerSupport<RepositoryListener>
|
ListenerSupport<RepositoryListener>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -29,17 +29,67 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.user;
|
package sonia.scm.user;
|
||||||
|
|
||||||
import sonia.scm.Handler;
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import sonia.scm.HandlerEvent;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public interface UserHandler extends Handler<User, UserException>
|
public abstract class AbstractUserManager implements UserManager
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param listener
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addListener(UserListener listener)
|
||||||
|
{
|
||||||
|
listenerSet.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param listener
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void removeListener(UserListener listener)
|
||||||
|
{
|
||||||
|
listenerSet.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
protected void fireEvent(User user, HandlerEvent event)
|
||||||
|
{
|
||||||
|
for (UserListener listener : listenerSet)
|
||||||
|
{
|
||||||
|
listener.onEvent(user, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private Set<UserListener> listenerSet = new HashSet<UserListener>();
|
||||||
}
|
}
|
||||||
@@ -1,422 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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.user;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.google.inject.Singleton;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import sonia.scm.ConfigurationException;
|
|
||||||
import sonia.scm.HandlerEvent;
|
|
||||||
import sonia.scm.SCMContextProvider;
|
|
||||||
import sonia.scm.Type;
|
|
||||||
import sonia.scm.util.AssertUtil;
|
|
||||||
import sonia.scm.util.IOUtil;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class BasicUserManager implements UserManager
|
|
||||||
{
|
|
||||||
|
|
||||||
/** the logger for BasicUserManager */
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(BasicUserManager.class);
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param handlerSet
|
|
||||||
*/
|
|
||||||
@Inject
|
|
||||||
public BasicUserManager(Set<UserHandler> handlerSet)
|
|
||||||
{
|
|
||||||
AssertUtil.assertIsNotEmpty(handlerSet);
|
|
||||||
|
|
||||||
for (UserHandler handler : handlerSet)
|
|
||||||
{
|
|
||||||
addHandler(handler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param listener
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void addListener(UserListener listener)
|
|
||||||
{
|
|
||||||
listenerSet.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException
|
|
||||||
{
|
|
||||||
for (UserHandler handler : handlerMap.values())
|
|
||||||
{
|
|
||||||
IOUtil.close(handler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param user
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void create(User user) throws Exception, IOException
|
|
||||||
{
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("create user {} of type {}", user.getName(), user.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
AssertUtil.assertIsValid(user);
|
|
||||||
getHandler(user).create(user);
|
|
||||||
fireEvent(user, HandlerEvent.CREATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param user
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void delete(User user) throws Exception, IOException
|
|
||||||
{
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("delete user {} of type {}", user.getName(), user.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
getHandler(user).delete(user);
|
|
||||||
fireEvent(user, HandlerEvent.DELETE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void init(SCMContextProvider context)
|
|
||||||
{
|
|
||||||
for (UserHandler handler : handlerMap.values())
|
|
||||||
{
|
|
||||||
handler.init(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param user
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void modify(User user) throws Exception, IOException
|
|
||||||
{
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("modify user {} of type {}", user.getName(), user.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
AssertUtil.assertIsValid(user);
|
|
||||||
getHandler(user).modify(user);
|
|
||||||
fireEvent(user, HandlerEvent.MODIFY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param user
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void refresh(User user) throws Exception, IOException
|
|
||||||
{
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("refresh user {} of type {}", user.getName(), user.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
// getHandler(user).refresh(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param listener
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void removeListener(UserListener listener)
|
|
||||||
{
|
|
||||||
listenerSet.remove(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public User get(String id)
|
|
||||||
{
|
|
||||||
User user = null;
|
|
||||||
|
|
||||||
for (UserHandler handler : handlerMap.values())
|
|
||||||
{
|
|
||||||
if (handler.isConfigured())
|
|
||||||
{
|
|
||||||
|
|
||||||
// user = handler.get(id);
|
|
||||||
if (user != null)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Collection<User> getAll()
|
|
||||||
{
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("fetch all users");
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<User> repositories = new HashSet<User>();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* for (UserHandler handler : handlerMap.values())
|
|
||||||
* {
|
|
||||||
* if (handler.isConfigured())
|
|
||||||
* {
|
|
||||||
* Collection<User> handlerRepositories = handler.getAll();
|
|
||||||
*
|
|
||||||
* if (handlerRepositories != null)
|
|
||||||
* {
|
|
||||||
* repositories.addAll(handlerRepositories);
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("fetched {} users", repositories.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
return repositories;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public UserHandler getHandler(String type)
|
|
||||||
{
|
|
||||||
return handlerMap.get(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Collection<Type> getTypes()
|
|
||||||
{
|
|
||||||
return typeSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param handler
|
|
||||||
*/
|
|
||||||
private void addHandler(UserHandler handler)
|
|
||||||
{
|
|
||||||
AssertUtil.assertIsNotNull(handler);
|
|
||||||
|
|
||||||
Type type = handler.getType();
|
|
||||||
|
|
||||||
AssertUtil.assertIsNotNull(type);
|
|
||||||
|
|
||||||
if (handlerMap.containsKey(type.getName()))
|
|
||||||
{
|
|
||||||
throw new ConfigurationException(
|
|
||||||
type.getName().concat("allready registered"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logger.isInfoEnabled())
|
|
||||||
{
|
|
||||||
logger.info("added UserHandler {} for type {}", handler.getClass(), type);
|
|
||||||
}
|
|
||||||
|
|
||||||
handlerMap.put(type.getName(), handler);
|
|
||||||
typeSet.add(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param user
|
|
||||||
* @param event
|
|
||||||
*/
|
|
||||||
private void fireEvent(User user, HandlerEvent event)
|
|
||||||
{
|
|
||||||
for (UserListener listener : listenerSet)
|
|
||||||
{
|
|
||||||
listener.onEvent(user, event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param user
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @throws UserException
|
|
||||||
*/
|
|
||||||
private UserHandler getHandler(User user) throws UserException
|
|
||||||
{
|
|
||||||
AssertUtil.assertIsNotNull(user);
|
|
||||||
|
|
||||||
String type = user.getType();
|
|
||||||
|
|
||||||
AssertUtil.assertIsNotEmpty(type);
|
|
||||||
|
|
||||||
UserHandler handler = handlerMap.get(type);
|
|
||||||
|
|
||||||
if (handler == null)
|
|
||||||
{
|
|
||||||
throw new UserHandlerNotFoundException(
|
|
||||||
"could not find UserHandler for ".concat(type));
|
|
||||||
}
|
|
||||||
else if (!handler.isConfigured())
|
|
||||||
{
|
|
||||||
throw new UserException(
|
|
||||||
"UserHandler for type ".concat(type).concat(" is not configured"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private Set<UserListener> listenerSet = new HashSet<UserListener>();
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private Map<String, UserHandler> handlerMap = new HashMap<String,
|
|
||||||
UserHandler>();
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private Set<Type> typeSet = new LinkedHashSet<Type>();
|
|
||||||
}
|
|
||||||
@@ -43,17 +43,4 @@ import sonia.scm.Manager;
|
|||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public interface UserManager
|
public interface UserManager
|
||||||
extends Manager<User, Exception>, ListenerSupport<UserListener>
|
extends Manager<User, Exception>, ListenerSupport<UserListener> {}
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public UserHandler getHandler(String type);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -41,12 +41,12 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.SCMContextProvider;
|
import sonia.scm.SCMContextProvider;
|
||||||
import sonia.scm.Type;
|
import sonia.scm.user.AbstractUserManager;
|
||||||
import sonia.scm.user.User;
|
import sonia.scm.user.User;
|
||||||
import sonia.scm.user.UserAllreadyExistException;
|
import sonia.scm.user.UserAllreadyExistException;
|
||||||
import sonia.scm.user.UserException;
|
import sonia.scm.user.UserException;
|
||||||
import sonia.scm.user.UserHandler;
|
|
||||||
import sonia.scm.util.IOUtil;
|
import sonia.scm.util.IOUtil;
|
||||||
|
import sonia.scm.util.Util;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -64,31 +64,22 @@ import javax.xml.bind.JAXB;
|
|||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class XmlUserHandler implements UserHandler
|
public class XmlUserManager extends AbstractUserManager
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String ADMIN_PATH = "/sonia/scm/config/admin-account.xml";
|
public static final String ADMIN_PATH = "/sonia/scm/config/admin-account.xml";
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String FILE_EXTENSION = ".xml";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String TYPE_DISPLAYNAME = "XML";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String TYPE_NAME = "xml";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final Type type = new Type(TYPE_NAME, TYPE_DISPLAYNAME);
|
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String DATABASEFILE =
|
public static final String DATABASEFILE =
|
||||||
"config".concat(File.separator).concat("users.xml");
|
"config".concat(File.separator).concat("users.xml");
|
||||||
|
|
||||||
/** the logger for XmlUserHandler */
|
/** Field description */
|
||||||
|
public static final String TYPE = "xml";
|
||||||
|
|
||||||
|
/** the logger for XmlUserManager */
|
||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
LoggerFactory.getLogger(XmlUserHandler.class);
|
LoggerFactory.getLogger(XmlUserManager.class);
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
@@ -122,9 +113,14 @@ public class XmlUserHandler implements UserHandler
|
|||||||
throw new UserAllreadyExistException();
|
throw new UserAllreadyExistException();
|
||||||
}
|
}
|
||||||
|
|
||||||
user.setType(TYPE_NAME);
|
String type = user.getType();
|
||||||
|
|
||||||
synchronized (XmlUserHandler.class)
|
if (Util.isEmpty(type))
|
||||||
|
{
|
||||||
|
user.setType(TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (XmlUserManager.class)
|
||||||
{
|
{
|
||||||
userDB.add(user.clone());
|
userDB.add(user.clone());
|
||||||
storeDB();
|
storeDB();
|
||||||
@@ -147,7 +143,7 @@ public class XmlUserHandler implements UserHandler
|
|||||||
|
|
||||||
if (userDB.contains(name))
|
if (userDB.contains(name))
|
||||||
{
|
{
|
||||||
synchronized (XmlUserHandler.class)
|
synchronized (XmlUserManager.class)
|
||||||
{
|
{
|
||||||
userDB.remove(name);
|
userDB.remove(name);
|
||||||
storeDB();
|
storeDB();
|
||||||
@@ -201,9 +197,7 @@ public class XmlUserHandler implements UserHandler
|
|||||||
|
|
||||||
if (userDB.contains(name))
|
if (userDB.contains(name))
|
||||||
{
|
{
|
||||||
user.setType(TYPE_NAME);
|
synchronized (XmlUserManager.class)
|
||||||
|
|
||||||
synchronized (XmlUserHandler.class)
|
|
||||||
{
|
{
|
||||||
userDB.remove(name);
|
userDB.remove(name);
|
||||||
userDB.add(user.clone());
|
userDB.add(user.clone());
|
||||||
@@ -225,6 +219,7 @@ public class XmlUserHandler implements UserHandler
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws UserException
|
* @throws UserException
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void refresh(User user) throws UserException, IOException
|
public void refresh(User user) throws UserException, IOException
|
||||||
{
|
{
|
||||||
User fresh = userDB.get(user.getName());
|
User fresh = userDB.get(user.getName());
|
||||||
@@ -247,6 +242,7 @@ public class XmlUserHandler implements UserHandler
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public User get(String id)
|
public User get(String id)
|
||||||
{
|
{
|
||||||
User user = userDB.get(id);
|
User user = userDB.get(id);
|
||||||
@@ -265,6 +261,7 @@ public class XmlUserHandler implements UserHandler
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public Collection<User> getAll()
|
public Collection<User> getAll()
|
||||||
{
|
{
|
||||||
LinkedList<User> users = new LinkedList<User>();
|
LinkedList<User> users = new LinkedList<User>();
|
||||||
@@ -277,30 +274,6 @@ public class XmlUserHandler implements UserHandler
|
|||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Type getType()
|
|
||||||
{
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isConfigured()
|
|
||||||
{
|
|
||||||
return (userDBFile != null) && userDBFile.exists();
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -309,7 +282,7 @@ public class XmlUserHandler implements UserHandler
|
|||||||
*/
|
*/
|
||||||
private void createAdminAccount()
|
private void createAdminAccount()
|
||||||
{
|
{
|
||||||
InputStream input = XmlUserHandler.class.getResourceAsStream(ADMIN_PATH);
|
InputStream input = XmlUserManager.class.getResourceAsStream(ADMIN_PATH);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -36,7 +36,6 @@ 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 ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -65,7 +64,6 @@ public class SCMPlugin
|
|||||||
public SCMPlugin()
|
public SCMPlugin()
|
||||||
{
|
{
|
||||||
repositoryHandlers = new HashSet<Class<? extends RepositoryHandler>>();
|
repositoryHandlers = new HashSet<Class<? extends RepositoryHandler>>();
|
||||||
userHandlers = new HashSet<Class<? extends UserHandler>>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -92,17 +90,6 @@ public class SCMPlugin
|
|||||||
return securityConfig;
|
return securityConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Set<Class<? extends UserHandler>> getUserHandlers()
|
|
||||||
{
|
|
||||||
return userHandlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -139,17 +126,6 @@ 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
|
||||||
*
|
*
|
||||||
@@ -172,11 +148,6 @@ public class SCMPlugin
|
|||||||
@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;
|
||||||
|
|||||||
@@ -51,10 +51,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.UserHandler;
|
||||||
import sonia.scm.user.UserManager;
|
import sonia.scm.user.UserManager;
|
||||||
import sonia.scm.user.xml.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;
|
||||||
@@ -83,6 +83,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import javax.xml.bind.JAXB;
|
import javax.xml.bind.JAXB;
|
||||||
import sonia.scm.repository.xml.XmlRepositoryManager;
|
import sonia.scm.repository.xml.XmlRepositoryManager;
|
||||||
|
import sonia.scm.user.xml.XmlUserManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -168,7 +169,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(XmlRepositoryManager.class);
|
bind(RepositoryManager.class).to(XmlRepositoryManager.class);
|
||||||
bind(UserManager.class).to(BasicUserManager.class);
|
bind(UserManager.class).to(XmlUserManager.class);
|
||||||
bind(ScmWebPluginContext.class).toInstance(webPluginContext);
|
bind(ScmWebPluginContext.class).toInstance(webPluginContext);
|
||||||
|
|
||||||
// filter(PATTERN_RESTAPI).through(LoggingFilter.class);
|
// filter(PATTERN_RESTAPI).through(LoggingFilter.class);
|
||||||
@@ -269,13 +270,6 @@ public class ScmServletModule extends ServletModule
|
|||||||
Set<Class<? extends RepositoryHandler>> repositoryHandlerSet =
|
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
|
// security stuff
|
||||||
Class<? extends EncryptionHandler> encryptionHandler =
|
Class<? extends EncryptionHandler> encryptionHandler =
|
||||||
@@ -292,13 +286,6 @@ public class ScmServletModule extends ServletModule
|
|||||||
repositoryHandlerSet.addAll(pluginRepositoryHandlers);
|
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();
|
||||||
|
|
||||||
@@ -325,7 +312,6 @@ 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, repositoryHandlerSet);
|
bindRepositoryHandlers(repositoryHandlerBinder, repositoryHandlerSet);
|
||||||
bindUserHandlers(userHandlerBinder, userHandlerSet);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class JsonJaxbContextResolver implements ContextResolver<JAXBContext>
|
|||||||
this.context = new JSONJAXBContext(
|
this.context = new JSONJAXBContext(
|
||||||
JSONConfiguration.mapped().rootUnwrapping(true).arrays(
|
JSONConfiguration.mapped().rootUnwrapping(true).arrays(
|
||||||
"member", "groups", "permissions", "repositories",
|
"member", "groups", "permissions", "repositories",
|
||||||
"repositoryTypes").nonStrings(
|
"repositoryTypes", "users").nonStrings(
|
||||||
"readable", "writeable", "groupPermission",
|
"readable", "writeable", "groupPermission",
|
||||||
"admin").build(), types.toArray(new Class[0]));
|
"admin").build(), types.toArray(new Class[0]));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import sonia.scm.SCMContextProvider;
|
import sonia.scm.SCMContextProvider;
|
||||||
import sonia.scm.security.EncryptionHandler;
|
import sonia.scm.security.EncryptionHandler;
|
||||||
import sonia.scm.user.User;
|
import sonia.scm.user.User;
|
||||||
import sonia.scm.user.xml.XmlUserHandler;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -52,6 +51,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import sonia.scm.user.UserManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -86,7 +86,7 @@ public class XmlAuthenticator implements Authenticator
|
|||||||
HttpServletResponse response, String username,
|
HttpServletResponse response, String username,
|
||||||
String password)
|
String password)
|
||||||
{
|
{
|
||||||
User user = userHandler.get(username);
|
User user = userManager.get(username);
|
||||||
|
|
||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
@@ -153,5 +153,5 @@ public class XmlAuthenticator implements Authenticator
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
@Inject
|
@Inject
|
||||||
private XmlUserHandler userHandler;
|
private UserManager userManager;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user