mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-07 19:51:49 +02:00
added public bzr url
This commit is contained in:
@@ -36,15 +36,15 @@ package sonia.scm.repository;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.Type;
|
||||
import sonia.scm.io.ExtendedCommand;
|
||||
import sonia.scm.plugin.ext.Extension;
|
||||
import sonia.scm.store.StoreFactory;
|
||||
import sonia.scm.util.SecurityUtil;
|
||||
import sonia.scm.web.security.WebSecurityContext;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -60,6 +60,9 @@ public class BzrRepositoryHandler
|
||||
extends AbstractSimpleRepositoryHandler<BzrConfig>
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String PUBLIC_RESOURCEPATH_BASE = "/public/bzr/";
|
||||
|
||||
/** Field description */
|
||||
public static final String TYPE_DISPLAYNAME = "Bazaar";
|
||||
|
||||
@@ -69,10 +72,6 @@ public class BzrRepositoryHandler
|
||||
/** Field description */
|
||||
public static final Type TYPE = new Type(TYPE_NAME, TYPE_DISPLAYNAME);
|
||||
|
||||
/** the logger for BzrRepositoryHandler */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(BzrRepositoryHandler.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -80,11 +79,42 @@ public class BzrRepositoryHandler
|
||||
*
|
||||
*
|
||||
* @param storeFactory
|
||||
* @param securityContextProvider
|
||||
*/
|
||||
@Inject
|
||||
public BzrRepositoryHandler(StoreFactory storeFactory)
|
||||
public BzrRepositoryHandler(
|
||||
StoreFactory storeFactory,
|
||||
Provider<WebSecurityContext> securityContextProvider)
|
||||
{
|
||||
super(storeFactory);
|
||||
this.securityContextProvider = securityContextProvider;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String createResourcePath(Repository repository)
|
||||
{
|
||||
String resourcePath = null;
|
||||
|
||||
if (SecurityUtil.isAnonymous(securityContextProvider))
|
||||
{
|
||||
resourcePath = PUBLIC_RESOURCEPATH_BASE.concat(repository.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
resourcePath = super.createResourcePath(repository);
|
||||
}
|
||||
|
||||
return resourcePath;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@@ -145,4 +175,9 @@ public class BzrRepositoryHandler
|
||||
{
|
||||
return BzrConfig.class;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Provider<WebSecurityContext> securityContextProvider;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.repository.BzrRepositoryHandler;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.web.filter.HttpFilter;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Singleton
|
||||
public class BzrPublicFilter extends HttpFilter
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static final Pattern REGEX_REPOSITORYNAME =
|
||||
Pattern.compile("/public/bzr/([^/]+)");
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param repositoryManager
|
||||
*/
|
||||
@Inject
|
||||
public BzrPublicFilter(RepositoryManager repositoryManager)
|
||||
{
|
||||
this.repositoryManager = repositoryManager;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param chain
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ServletException
|
||||
*/
|
||||
@Override
|
||||
protected void doFilter(HttpServletRequest request,
|
||||
HttpServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
String requestURI = HttpUtil.getStrippedURI(request);
|
||||
Matcher m = REGEX_REPOSITORYNAME.matcher(requestURI);
|
||||
|
||||
if (m.find())
|
||||
{
|
||||
String name = m.group(1);
|
||||
Repository repository =
|
||||
repositoryManager.get(BzrRepositoryHandler.TYPE_NAME, name);
|
||||
|
||||
if ((repository != null) && repository.isPublicReadable())
|
||||
{
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private RepositoryManager repositoryManager;
|
||||
}
|
||||
@@ -51,6 +51,9 @@ public class BzrServletModule extends ServletModule
|
||||
/** Field description */
|
||||
public static final String MAPPING_BZR = "/bzr/*";
|
||||
|
||||
/** Field description */
|
||||
public static final String MAPPING_PUBLICBZR = "/public/bzr/*";
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -60,8 +63,10 @@ public class BzrServletModule extends ServletModule
|
||||
@Override
|
||||
protected void configureServlets()
|
||||
{
|
||||
filter(MAPPING_BZR).through(BasicAuthenticationFilter.class);
|
||||
filter(MAPPING_BZR,
|
||||
MAPPING_PUBLICBZR).through(BasicAuthenticationFilter.class);
|
||||
filter(MAPPING_BZR).through(BzrPermissionFilter.class);
|
||||
serve(MAPPING_BZR).with(BzrCGIServlet.class);
|
||||
filter(MAPPING_PUBLICBZR).through(BzrPublicFilter.class);
|
||||
serve(MAPPING_BZR, MAPPING_PUBLICBZR).with(BzrCGIServlet.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ package sonia.scm.util;
|
||||
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.security.ScmSecurityException;
|
||||
import sonia.scm.security.SecurityContext;
|
||||
import sonia.scm.user.User;
|
||||
@@ -111,4 +112,31 @@ public class SecurityUtil
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param contextProvider
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isAnonymous(
|
||||
Provider<? extends SecurityContext> contextProvider)
|
||||
{
|
||||
return isAnonymous(contextProvider.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isAnonymous(SecurityContext context)
|
||||
{
|
||||
return SCMContext.USER_ANONYMOUS.equals(context.getUser().getName());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user