remove deprecated stuff

This commit is contained in:
Sebastian Sdorra
2014-01-03 10:34:34 +01:00
parent 39ad99f5e9
commit aec7773239
82 changed files with 168 additions and 10455 deletions

View File

@@ -69,11 +69,9 @@ import sonia.scm.plugin.DefaultPluginManager;
import sonia.scm.plugin.Plugin;
import sonia.scm.plugin.PluginLoader;
import sonia.scm.plugin.PluginManager;
import sonia.scm.repository.ChangesetViewerUtil;
import sonia.scm.repository.DefaultRepositoryManager;
import sonia.scm.repository.DefaultRepositoryProvider;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryBrowserUtil;
import sonia.scm.repository.RepositoryDAO;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.repository.RepositoryManagerProvider;
@@ -96,7 +94,6 @@ import sonia.scm.security.KeyGenerator;
import sonia.scm.security.LoginAttemptHandler;
import sonia.scm.security.MessageDigestEncryptionHandler;
import sonia.scm.security.RepositoryPermissionResolver;
import sonia.scm.security.SecurityContext;
import sonia.scm.security.SecuritySystem;
import sonia.scm.store.BlobStoreFactory;
import sonia.scm.store.ConfigurationEntryStoreFactory;
@@ -109,11 +106,9 @@ import sonia.scm.store.ListenableStoreFactory;
import sonia.scm.store.StoreFactory;
import sonia.scm.template.DefaultEngine;
import sonia.scm.template.FreemarkerTemplateEngine;
import sonia.scm.template.FreemarkerTemplateHandler;
import sonia.scm.template.MustacheTemplateEngine;
import sonia.scm.template.TemplateEngine;
import sonia.scm.template.TemplateEngineFactory;
import sonia.scm.template.TemplateHandler;
import sonia.scm.template.TemplateServlet;
import sonia.scm.url.RestJsonUrlProvider;
import sonia.scm.url.RestXmlUrlProvider;
@@ -134,10 +129,8 @@ import sonia.scm.web.filter.LoggingFilter;
import sonia.scm.web.security.AdministrationContext;
import sonia.scm.web.security.ApiBasicAuthenticationFilter;
import sonia.scm.web.security.AuthenticationManager;
import sonia.scm.web.security.BasicSecurityContext;
import sonia.scm.web.security.ChainAuthenticatonManager;
import sonia.scm.web.security.DefaultAdministrationContext;
import sonia.scm.web.security.WebSecurityContext;
//~--- JDK imports ------------------------------------------------------------
@@ -282,8 +275,6 @@ public class ScmServletModule extends ServletModule
// bind security stuff
bind(PermissionResolver.class, RepositoryPermissionResolver.class);
bind(AuthenticationManager.class, ChainAuthenticatonManager.class);
bind(SecurityContext.class).to(BasicSecurityContext.class);
bind(WebSecurityContext.class).to(BasicSecurityContext.class);
bind(SecuritySystem.class).to(DefaultSecuritySystem.class);
bind(AdministrationContext.class, DefaultAdministrationContext.class);
bind(LoginAttemptHandler.class, ConfigurableLoginAttemptHandler.class);
@@ -303,8 +294,6 @@ public class ScmServletModule extends ServletModule
bindDecorated(GroupManager.class, DefaultGroupManager.class,
GroupManagerProvider.class);
bind(CGIExecutorFactory.class, DefaultCGIExecutorFactory.class);
bind(ChangesetViewerUtil.class);
bind(RepositoryBrowserUtil.class);
// bind httpclient
bind(HttpClient.class, URLHttpClient.class);
@@ -362,7 +351,6 @@ public class ScmServletModule extends ServletModule
serve(PATTERN_PLUGIN_SCRIPT).with(ScriptResourceServlet.class);
// template
bind(TemplateHandler.class).to(FreemarkerTemplateHandler.class);
serve(PATTERN_INDEX, "/").with(TemplateServlet.class);
Multibinder<TemplateEngine> engineBinder =
@@ -593,8 +581,8 @@ public class ScmServletModule extends ServletModule
//~--- fields ---------------------------------------------------------------
/** Field description */
private ClassOverrides overrides;
private final ClassOverrides overrides;
/** Field description */
private DefaultPluginLoader pluginLoader;
private final DefaultPluginLoader pluginLoader;
}

View File

@@ -1016,8 +1016,24 @@ public class RepositoryResource
@Override
protected Repository prepareForReturn(Repository repository)
{
RepositoryUtil.appendUrl(configuration, repositoryManager, repository);
prepareRepository(repository);
if (isOwner(repository))
{
if (repository.getPermissions() == null)
{
repository.setPermissions(new ArrayList<Permission>());
}
}
else
{
if (logger.isTraceEnabled())
{
logger.trace("remove properties and permissions from repository, "
+ "because the user is not privileged");
}
repository.setProperties(null);
repository.setPermissions(null);
}
return repository;
}
@@ -1050,38 +1066,6 @@ public class RepositoryResource
return PATH_PART;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param repository
*/
private void prepareRepository(Repository repository)
{
if (isOwner(repository))
{
if (repository.getPermissions() == null)
{
repository.setPermissions(new ArrayList<Permission>());
}
}
else
{
if (logger.isTraceEnabled())
{
logger.trace("remove properties and permissions from repository, "
+ "because the user is not privileged");
}
repository.setProperties(null);
repository.setPermissions(null);
}
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*

View File

@@ -559,52 +559,6 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
return getAll(null, start, limit);
}
/**
* Method description
*
*
* @param repository
*
* @return
*
* @throws RepositoryException
*/
@Override
public BlameViewer getBlameViewer(Repository repository)
throws RepositoryException
{
AssertUtil.assertIsNotNull(repository);
BlameViewer viewer = null;
if (isReader(repository))
{
viewer = getHandler(repository).getBlameViewer(repository);
}
return viewer;
}
/**
* Method description
*
*
* @param repository
*
* @return
*
* @throws RepositoryException
*/
@Override
public ChangesetViewer getChangesetViewer(Repository repository)
throws RepositoryException
{
AssertUtil.assertIsNotNull(repository);
isReader(repository);
return getHandler(repository).getChangesetViewer(repository);
}
/**
* Method description
*
@@ -626,33 +580,7 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
return validTypes;
}
/**
* Method description
*
*
* @param repository
*
* @return
*
* @throws RepositoryException
*/
@Override
public DiffViewer getDiffViewer(Repository repository)
throws RepositoryException
{
AssertUtil.assertIsNotNull(repository);
DiffViewer viewer = null;
if (isReader(repository))
{
viewer = getHandler(repository).getDiffViewer(repository);
}
return viewer;
}
/**
* Method description
*
@@ -779,26 +707,6 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
return repositoryDAO.getLastModified();
}
/**
* Method description
*
*
* @param repository
*
* @return
*
* @throws RepositoryException
*/
@Override
public RepositoryBrowser getRepositoryBrowser(Repository repository)
throws RepositoryException
{
AssertUtil.assertIsNotNull(repository);
isReader(repository);
return getHandler(repository).getRepositoryBrowser(repository);
}
/**
* Method description
*

View File

@@ -98,7 +98,7 @@ public class FreemarkerTemplateEngine implements TemplateEngine
new MultiTemplateLoader(
new TemplateLoader[] {
new WebappTemplateLoader(servletContext, DIRECTORY_ROOT),
new ClassTemplateLoader(FreemarkerTemplateHandler.class,
new ClassTemplateLoader(FreemarkerTemplateEngine.class,
DIRECTORY_ROOT)
}
)

View File

@@ -1,162 +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.template;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import com.google.inject.Singleton;
import freemarker.cache.ClassTemplateLoader;
import freemarker.cache.MultiTemplateLoader;
import freemarker.cache.TemplateLoader;
import freemarker.cache.WebappTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//~--- JDK imports ------------------------------------------------------------
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Writer;
import java.util.Locale;
import java.util.Map;
import javax.servlet.ServletContext;
/**
*
* @author Sebastian Sdorra
*/
@Singleton
public class FreemarkerTemplateHandler implements TemplateHandler
{
/** Field description */
public static final String DIRECTORY_CLASS_TEMPLATES = "/templates";
/** Field description */
public static final String DIRECTORY_TEMPLATES = "/";
/** Field description */
public static final String ENCODING = "UTF-8";
/** Field description */
public static final String EXTENSION = ".html";
/** the logger for FreemarkerTemplateHandler */
private static final Logger logger =
LoggerFactory.getLogger(FreemarkerTemplateHandler.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param servletContext
*/
@Inject
public FreemarkerTemplateHandler(ServletContext servletContext)
{
configuration = new Configuration();
configuration.setEncoding(Locale.ENGLISH, ENCODING);
//J-
configuration.setTemplateLoader(
new MultiTemplateLoader(
new TemplateLoader[] {
new WebappTemplateLoader(servletContext, DIRECTORY_TEMPLATES),
new ClassTemplateLoader(FreemarkerTemplateHandler.class,
DIRECTORY_CLASS_TEMPLATES)
}
)
);
//J+
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param templateName
* @param writer
* @param params
*
* @throws IOException
*/
@Override
public void render(String templateName, Writer writer,
Map<String, ? extends Object> params)
throws IOException
{
if (!templateName.endsWith(EXTENSION))
{
templateName = templateName.concat(EXTENSION);
}
Template template = configuration.getTemplate(templateName, ENCODING);
if (template == null)
{
throw new FileNotFoundException(
"file ".concat(templateName).concat(" not found"));
}
else
{
try
{
template.process(params, writer);
}
catch (TemplateException ex)
{
logger.error("could not render template ".concat(templateName), ex);
throw new IOException(ex);
}
}
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private Configuration configuration;
}

View File

@@ -1,250 +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.web.security;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.group.GroupNames;
import sonia.scm.security.Tokens;
import sonia.scm.user.User;
import sonia.scm.user.UserManager;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
import java.util.Collections;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
*
* @author Sebastian Sdorra
*/
public class BasicSecurityContext implements WebSecurityContext
{
/** Field description */
public static final String SCM_CREDENTIALS = "SCM_CREDENTIALS";
/** Field description */
public static final String USER_ANONYMOUS = "anonymous";
/** the logger for BasicSecurityContext */
private static final Logger logger =
LoggerFactory.getLogger(BasicSecurityContext.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param configuration
* @param userManager
*/
@Inject
public BasicSecurityContext(ScmConfiguration configuration,
UserManager userManager)
{
this.configuration = configuration;
this.userManager = userManager;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param request
* @param response
* @param username
* @param password
*
* @return
*/
@Override
public User authenticate(HttpServletRequest request,
HttpServletResponse response, String username, String password)
{
User user = null;
try
{
Subject subject = SecurityUtils.getSubject();
subject.login(Tokens.createAuthenticationToken(request, username,
password));
user = subject.getPrincipals().oneByType(User.class);
}
catch (AuthenticationException ex)
{
if (logger.isWarnEnabled())
{
logger.warn("authentication failed", ex);
}
}
return user;
}
/**
* Method description
*
*
* @param request
* @param response
*/
@Override
public void logout(HttpServletRequest request, HttpServletResponse response)
{
SecurityUtils.getSubject().logout();
HttpSession session = request.getSession(false);
if (session != null)
{
session.invalidate();
}
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public Collection<String> getGroups()
{
GroupNames groups = getPrincipal(GroupNames.class);
Collection<String> groupCollection = null;
if (groups != null)
{
groupCollection = groups.getCollection();
}
else
{
groupCollection = Collections.EMPTY_LIST;
}
return groupCollection;
}
/**
* Method description
*
*
* @return
*/
@Override
public User getUser()
{
User user = getPrincipal(User.class);
if ((user == null) && configuration.isAnonymousAccessEnabled())
{
user = userManager.get(USER_ANONYMOUS);
}
return user;
}
/**
* Method description
*
*
* @return
*/
@Override
public boolean isAuthenticated()
{
return getUser() != null;
}
/**
* Method description
*
*
* @param clazz
* @param <T>
*
* @return
*/
private <T> T getPrincipal(Class<T> clazz)
{
T result = null;
Subject subject = SecurityUtils.getSubject();
if (subject.isAuthenticated() || subject.isRemembered())
{
PrincipalCollection pc = subject.getPrincipals();
if (pc != null)
{
result = pc.oneByType(clazz);
}
}
return result;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private ScmConfiguration configuration;
/** Field description */
private UserManager userManager;
}

View File

@@ -1,92 +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.web.security;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Provider;
import sonia.scm.SCMContext;
/**
*
* @author Sebastian Sdorra
* @deprecated
*/
@Deprecated
public final class SecurityUtil
{
/**
* Constructs ...
*
*/
private SecurityUtil() {}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param securityContextProvider
*
* @return
*/
public static String getUsername(
Provider<WebSecurityContext> securityContextProvider)
{
return getUsername(securityContextProvider.get());
}
/**
* Method description
*
*
* @param securityContext
*
* @return
*/
public static String getUsername(WebSecurityContext securityContext)
{
String user = SCMContext.USER_ANONYMOUS;
if ((securityContext != null) && (securityContext.getUser() != null))
{
user = securityContext.getUser().getName();
}
return user;
}
}