2010-11-05 19:47:52 +01:00
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-16 18:50:32 +01:00
|
|
|
package sonia.scm.user;
|
2010-11-05 19:47:52 +01:00
|
|
|
|
|
|
|
|
//~--- non-JDK imports --------------------------------------------------------
|
|
|
|
|
|
2016-12-06 22:04:13 +01:00
|
|
|
import com.github.sdorra.ssp.PermissionActionCheck;
|
2010-11-28 11:32:41 +01:00
|
|
|
import com.google.inject.Inject;
|
2010-11-05 19:47:52 +01:00
|
|
|
import com.google.inject.Singleton;
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
2014-01-11 13:45:23 +01:00
|
|
|
import sonia.scm.HandlerEventType;
|
2010-11-05 19:47:52 +01:00
|
|
|
import sonia.scm.SCMContextProvider;
|
2011-02-12 15:43:27 +01:00
|
|
|
import sonia.scm.TransformFilter;
|
2011-02-11 19:44:10 +01:00
|
|
|
import sonia.scm.search.SearchRequest;
|
|
|
|
|
import sonia.scm.search.SearchUtil;
|
2011-01-04 17:17:48 +01:00
|
|
|
import sonia.scm.util.AssertUtil;
|
2011-06-09 21:32:30 +02:00
|
|
|
import sonia.scm.util.CollectionAppender;
|
2010-11-05 19:47:52 +01:00
|
|
|
import sonia.scm.util.IOUtil;
|
2010-11-26 15:37:35 +01:00
|
|
|
import sonia.scm.util.Util;
|
2010-11-05 19:47:52 +01:00
|
|
|
|
|
|
|
|
//~--- JDK imports ------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
2011-06-09 21:32:30 +02:00
|
|
|
import java.util.ArrayList;
|
2010-11-05 19:47:52 +01:00
|
|
|
import java.util.Collection;
|
2011-06-09 22:10:30 +02:00
|
|
|
import java.util.Collections;
|
2011-06-09 21:46:22 +02:00
|
|
|
import java.util.Comparator;
|
2011-06-09 21:32:30 +02:00
|
|
|
import java.util.List;
|
2010-11-05 19:47:52 +01:00
|
|
|
|
2010-12-30 13:03:01 +01:00
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
|
import javax.xml.bind.JAXBException;
|
|
|
|
|
import javax.xml.bind.Unmarshaller;
|
2010-11-05 19:47:52 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @author Sebastian Sdorra
|
|
|
|
|
*/
|
|
|
|
|
@Singleton
|
2012-03-16 18:50:32 +01:00
|
|
|
public class DefaultUserManager extends AbstractUserManager
|
2010-11-05 19:47:52 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** Field description */
|
2010-11-06 15:56:44 +01:00
|
|
|
public static final String ADMIN_PATH = "/sonia/scm/config/admin-account.xml";
|
2010-11-05 19:47:52 +01:00
|
|
|
|
2010-12-30 13:03:01 +01:00
|
|
|
/** Field description */
|
|
|
|
|
public static final String ANONYMOUS_PATH =
|
|
|
|
|
"/sonia/scm/config/anonymous-account.xml";
|
|
|
|
|
|
2010-11-05 19:47:52 +01:00
|
|
|
/** Field description */
|
2010-12-05 19:26:38 +01:00
|
|
|
public static final String STORE_NAME = "users";
|
2010-11-05 19:47:52 +01:00
|
|
|
|
2010-11-26 15:37:35 +01:00
|
|
|
/** the logger for XmlUserManager */
|
2010-11-05 19:47:52 +01:00
|
|
|
private static final Logger logger =
|
2012-03-16 18:50:32 +01:00
|
|
|
LoggerFactory.getLogger(DefaultUserManager.class);
|
2010-11-05 19:47:52 +01:00
|
|
|
|
2010-11-28 11:32:41 +01:00
|
|
|
//~--- constructors ---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructs ...
|
|
|
|
|
*
|
2012-03-15 21:38:47 +01:00
|
|
|
* @param userDAO
|
2010-11-28 11:32:41 +01:00
|
|
|
*/
|
|
|
|
|
@Inject
|
2014-01-03 11:32:40 +01:00
|
|
|
public DefaultUserManager(UserDAO userDAO)
|
2010-11-28 11:32:41 +01:00
|
|
|
{
|
2012-03-15 21:38:47 +01:00
|
|
|
this.userDAO = userDAO;
|
2010-11-28 11:32:41 +01:00
|
|
|
}
|
|
|
|
|
|
2010-11-05 19:47:52 +01:00
|
|
|
//~--- methods --------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void close() throws IOException
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-04 15:58:13 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param username
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean contains(String username)
|
|
|
|
|
{
|
2012-03-15 21:38:47 +01:00
|
|
|
return userDAO.contains(username);
|
2010-12-04 15:58:13 +01:00
|
|
|
}
|
|
|
|
|
|
2010-11-05 19:47:52 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param user
|
|
|
|
|
*
|
|
|
|
|
* @throws IOException
|
|
|
|
|
* @throws UserException
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void create(User user) throws UserException, IOException
|
|
|
|
|
{
|
2012-03-16 09:44:32 +01:00
|
|
|
String type = user.getType();
|
|
|
|
|
|
|
|
|
|
if (Util.isEmpty(type))
|
|
|
|
|
{
|
|
|
|
|
user.setType(userDAO.getType());
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-05 17:33:29 +01:00
|
|
|
if (logger.isInfoEnabled())
|
|
|
|
|
{
|
|
|
|
|
logger.info("create user {} of type {}", user.getName(), user.getType());
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-06 22:04:13 +01:00
|
|
|
UserPermissions.create().check();
|
2010-11-28 11:32:41 +01:00
|
|
|
|
2012-03-15 21:38:47 +01:00
|
|
|
if (userDAO.contains(user.getName()))
|
2010-11-05 19:47:52 +01:00
|
|
|
{
|
2016-12-07 22:28:06 +01:00
|
|
|
throw new UserAlreadyExistsException(user.getName());
|
2010-11-05 19:47:52 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-04 17:28:09 +01:00
|
|
|
AssertUtil.assertIsValid(user);
|
2010-12-05 17:46:26 +01:00
|
|
|
user.setCreationDate(System.currentTimeMillis());
|
2014-01-11 13:45:23 +01:00
|
|
|
fireEvent(HandlerEventType.BEFORE_CREATE, user);
|
2012-03-15 21:38:47 +01:00
|
|
|
userDAO.add(user);
|
2014-01-11 13:45:23 +01:00
|
|
|
fireEvent(HandlerEventType.CREATE, user);
|
2010-11-05 19:47:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param user
|
|
|
|
|
*
|
|
|
|
|
* @throws IOException
|
|
|
|
|
* @throws UserException
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void delete(User user) throws UserException, IOException
|
|
|
|
|
{
|
2010-12-05 17:33:29 +01:00
|
|
|
if (logger.isInfoEnabled())
|
|
|
|
|
{
|
|
|
|
|
logger.info("delete user {} of type {}", user.getName(), user.getType());
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-07 15:19:00 +01:00
|
|
|
String name = user.getName();
|
2016-12-06 22:04:13 +01:00
|
|
|
UserPermissions.delete(name).check();
|
2010-11-05 19:47:52 +01:00
|
|
|
|
2012-03-15 21:38:47 +01:00
|
|
|
if (userDAO.contains(name))
|
2010-11-05 19:47:52 +01:00
|
|
|
{
|
2014-01-11 13:45:23 +01:00
|
|
|
fireEvent(HandlerEventType.BEFORE_DELETE, user);
|
2012-03-15 21:38:47 +01:00
|
|
|
userDAO.delete(user);
|
2014-01-11 13:45:23 +01:00
|
|
|
fireEvent(HandlerEventType.DELETE, user);
|
2010-11-05 19:47:52 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-01-29 20:39:08 +01:00
|
|
|
throw new UserNotFoundException("user does not exists");
|
2010-11-05 19:47:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param context
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void init(SCMContextProvider context)
|
|
|
|
|
{
|
|
|
|
|
|
2014-11-25 08:13:48 +01:00
|
|
|
// create default account only, if no other account is available
|
|
|
|
|
if (userDAO.getAll().isEmpty())
|
2010-11-05 19:47:52 +01:00
|
|
|
{
|
2010-12-30 13:03:01 +01:00
|
|
|
createDefaultAccounts();
|
2010-11-05 19:47:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param user
|
|
|
|
|
*
|
|
|
|
|
* @throws IOException
|
|
|
|
|
* @throws UserException
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void modify(User user) throws UserException, IOException
|
|
|
|
|
{
|
2016-12-06 22:04:13 +01:00
|
|
|
String name = user.getName();
|
2010-12-05 17:33:29 +01:00
|
|
|
if (logger.isInfoEnabled())
|
|
|
|
|
{
|
|
|
|
|
logger.info("modify user {} of type {}", user.getName(), user.getType());
|
|
|
|
|
}
|
2014-01-11 13:45:23 +01:00
|
|
|
|
2016-12-06 22:04:13 +01:00
|
|
|
UserPermissions.modify(user).check();
|
2014-01-11 13:45:23 +01:00
|
|
|
User oldUser = userDAO.get(name);
|
2010-11-05 19:47:52 +01:00
|
|
|
|
2014-01-11 13:45:23 +01:00
|
|
|
if (oldUser != null)
|
2010-11-05 19:47:52 +01:00
|
|
|
{
|
2011-01-04 17:28:09 +01:00
|
|
|
AssertUtil.assertIsValid(user);
|
2011-01-13 20:19:06 +01:00
|
|
|
user.setLastModified(System.currentTimeMillis());
|
2014-01-11 13:45:23 +01:00
|
|
|
fireEvent(HandlerEventType.BEFORE_MODIFY, user, oldUser);
|
2012-03-15 21:38:47 +01:00
|
|
|
userDAO.modify(user);
|
2014-01-11 13:45:23 +01:00
|
|
|
fireEvent(HandlerEventType.MODIFY, user, oldUser);
|
2010-11-05 19:47:52 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-01-29 20:39:08 +01:00
|
|
|
throw new UserNotFoundException("user does not exists");
|
2010-11-05 19:47:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param user
|
|
|
|
|
*
|
|
|
|
|
* @throws IOException
|
|
|
|
|
* @throws UserException
|
|
|
|
|
*/
|
2010-11-26 15:37:35 +01:00
|
|
|
@Override
|
2010-11-05 19:47:52 +01:00
|
|
|
public void refresh(User user) throws UserException, IOException
|
|
|
|
|
{
|
2010-12-05 17:33:29 +01:00
|
|
|
if (logger.isInfoEnabled())
|
|
|
|
|
{
|
|
|
|
|
logger.info("refresh user {} of type {}", user.getName(), user.getType());
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-06 22:04:13 +01:00
|
|
|
UserPermissions.read(user).check();
|
2012-03-15 21:38:47 +01:00
|
|
|
User fresh = userDAO.get(user.getName());
|
2010-11-05 19:47:52 +01:00
|
|
|
|
|
|
|
|
if (fresh == null)
|
|
|
|
|
{
|
2013-01-29 20:39:08 +01:00
|
|
|
throw new UserNotFoundException("user does not exists");
|
2010-11-05 19:47:52 +01:00
|
|
|
}
|
|
|
|
|
|
2010-11-25 21:56:06 +01:00
|
|
|
fresh.copyProperties(user);
|
2010-11-05 19:47:52 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-11 19:44:10 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param searchRequest
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Collection<User> search(final SearchRequest searchRequest)
|
|
|
|
|
{
|
2011-02-12 11:24:08 +01:00
|
|
|
if (logger.isDebugEnabled())
|
|
|
|
|
{
|
|
|
|
|
logger.debug("search user with query {}", searchRequest.getQuery());
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-06 22:04:13 +01:00
|
|
|
final PermissionActionCheck<User> check = UserPermissions.read();
|
|
|
|
|
return SearchUtil.search(searchRequest, userDAO.getAll(), new TransformFilter<User>() {
|
2011-02-12 15:43:27 +01:00
|
|
|
@Override
|
|
|
|
|
public User accept(User user)
|
2011-02-11 19:44:10 +01:00
|
|
|
{
|
2011-02-12 15:43:27 +01:00
|
|
|
User result = null;
|
2016-12-06 22:04:13 +01:00
|
|
|
if (check.isPermitted(user) && matches(searchRequest, user)) {
|
2011-02-12 15:43:27 +01:00
|
|
|
result = user.clone();
|
2011-02-11 19:44:10 +01:00
|
|
|
}
|
2011-02-12 15:43:27 +01:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
});
|
2011-02-11 19:44:10 +01:00
|
|
|
}
|
2016-12-06 22:04:13 +01:00
|
|
|
|
|
|
|
|
private boolean matches(SearchRequest searchRequest, User user) {
|
|
|
|
|
return SearchUtil.matchesOne(searchRequest, user.getName(), user.getDisplayName(), user.getMail());
|
|
|
|
|
}
|
2011-02-11 19:44:10 +01:00
|
|
|
|
2010-11-05 19:47:52 +01:00
|
|
|
//~--- get methods ----------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2010-11-26 15:37:35 +01:00
|
|
|
@Override
|
2010-11-05 19:47:52 +01:00
|
|
|
public User get(String id)
|
|
|
|
|
{
|
2016-12-06 22:04:13 +01:00
|
|
|
UserPermissions.read().check(id);
|
|
|
|
|
|
2012-03-15 21:38:47 +01:00
|
|
|
User user = userDAO.get(id);
|
2010-11-05 19:47:52 +01:00
|
|
|
|
2010-11-07 15:19:00 +01:00
|
|
|
if (user != null)
|
2010-11-05 19:47:52 +01:00
|
|
|
{
|
2010-11-07 15:19:00 +01:00
|
|
|
user = user.clone();
|
2010-11-05 19:47:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2010-11-26 15:37:35 +01:00
|
|
|
@Override
|
2010-11-05 19:47:52 +01:00
|
|
|
public Collection<User> getAll()
|
2011-06-09 22:10:30 +02:00
|
|
|
{
|
|
|
|
|
return getAll(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param comparator
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Collection<User> getAll(Comparator<User> comparator)
|
2010-11-05 19:47:52 +01:00
|
|
|
{
|
2016-12-06 22:04:13 +01:00
|
|
|
List<User> users = new ArrayList<>();
|
2010-11-05 19:47:52 +01:00
|
|
|
|
2016-12-06 22:04:13 +01:00
|
|
|
PermissionActionCheck<User> check = UserPermissions.read();
|
|
|
|
|
for (User user : userDAO.getAll()) {
|
|
|
|
|
if (check.isPermitted(user)) {
|
|
|
|
|
users.add(user.clone());
|
|
|
|
|
}
|
2010-11-05 19:47:52 +01:00
|
|
|
}
|
|
|
|
|
|
2016-12-06 22:04:13 +01:00
|
|
|
if (comparator != null) {
|
2011-06-09 22:10:30 +02:00
|
|
|
Collections.sort(users, comparator);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-05 19:47:52 +01:00
|
|
|
return users;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-09 21:32:30 +02:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
2011-06-09 21:46:22 +02:00
|
|
|
*
|
|
|
|
|
* @param comaparator
|
2011-06-09 21:32:30 +02:00
|
|
|
* @param start
|
|
|
|
|
* @param limit
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
2016-12-06 22:04:13 +01:00
|
|
|
public Collection<User> getAll(Comparator<User> comaparator, int start, int limit) {
|
|
|
|
|
final PermissionActionCheck<User> check = UserPermissions.read();
|
2012-03-15 21:38:47 +01:00
|
|
|
return Util.createSubCollection(userDAO.getAll(), comaparator,
|
2012-08-30 13:20:26 +02:00
|
|
|
new CollectionAppender<User>()
|
2011-06-09 21:32:30 +02:00
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void append(Collection<User> collection, User item)
|
|
|
|
|
{
|
2016-12-06 22:04:13 +01:00
|
|
|
if (check.isPermitted(item)) {
|
|
|
|
|
collection.add(item.clone());
|
|
|
|
|
}
|
2011-06-09 21:32:30 +02:00
|
|
|
}
|
|
|
|
|
}, start, limit);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-09 21:46:22 +02:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param start
|
|
|
|
|
* @param limit
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Collection<User> getAll(int start, int limit)
|
|
|
|
|
{
|
|
|
|
|
return getAll(null, start, limit);
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-16 09:44:32 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public String getDefaultType()
|
|
|
|
|
{
|
|
|
|
|
return userDAO.getType();
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-12 19:55:18 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Long getLastModified()
|
|
|
|
|
{
|
2012-03-15 21:38:47 +01:00
|
|
|
return userDAO.getLastModified();
|
2011-02-12 19:55:18 +01:00
|
|
|
}
|
|
|
|
|
|
2010-11-05 19:47:52 +01:00
|
|
|
//~--- methods --------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
2010-12-30 13:03:01 +01:00
|
|
|
*
|
|
|
|
|
* @param unmarshaller
|
|
|
|
|
* @param path
|
2010-11-05 19:47:52 +01:00
|
|
|
*/
|
2010-12-30 13:03:01 +01:00
|
|
|
private void createDefaultAccount(Unmarshaller unmarshaller, String path)
|
2010-11-05 19:47:52 +01:00
|
|
|
{
|
2012-03-16 18:50:32 +01:00
|
|
|
InputStream input = DefaultUserManager.class.getResourceAsStream(path);
|
2010-11-05 19:47:52 +01:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2010-12-30 13:03:01 +01:00
|
|
|
User user = (User) unmarshaller.unmarshal(input);
|
2010-11-07 15:19:00 +01:00
|
|
|
|
2012-03-18 17:21:33 +01:00
|
|
|
user.setType(userDAO.getType());
|
2010-12-31 14:58:11 +01:00
|
|
|
user.setCreationDate(System.currentTimeMillis());
|
2012-03-15 21:38:47 +01:00
|
|
|
userDAO.add(user);
|
2010-11-05 19:47:52 +01:00
|
|
|
}
|
2010-11-07 15:19:00 +01:00
|
|
|
catch (Exception ex)
|
2010-11-05 19:47:52 +01:00
|
|
|
{
|
2010-12-30 13:03:01 +01:00
|
|
|
logger.error("could not create account", ex);
|
2010-11-05 19:47:52 +01:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
IOUtil.close(input);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-30 13:03:01 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
private void createDefaultAccounts()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-11-25 08:13:48 +01:00
|
|
|
logger.info("create default accounts");
|
|
|
|
|
|
2010-12-30 13:03:01 +01:00
|
|
|
JAXBContext context = JAXBContext.newInstance(User.class);
|
|
|
|
|
Unmarshaller unmarshaller = context.createUnmarshaller();
|
|
|
|
|
|
|
|
|
|
createDefaultAccount(unmarshaller, ADMIN_PATH);
|
|
|
|
|
createDefaultAccount(unmarshaller, ANONYMOUS_PATH);
|
|
|
|
|
}
|
|
|
|
|
catch (JAXBException ex)
|
|
|
|
|
{
|
2012-10-04 10:50:19 +02:00
|
|
|
logger.error("could not create default accounts", ex);
|
2010-12-30 13:03:01 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-05 19:47:52 +01:00
|
|
|
//~--- fields ---------------------------------------------------------------
|
|
|
|
|
|
2010-12-05 18:02:35 +01:00
|
|
|
/** Field description */
|
2014-01-03 11:32:40 +01:00
|
|
|
private final UserDAO userDAO;
|
2010-11-05 19:47:52 +01:00
|
|
|
}
|