mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-01 21:29:47 +01:00
improve git client detection at GitPermissionFilter to include jgit
This commit is contained in:
@@ -70,6 +70,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import sonia.scm.web.GitUserAgentProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -77,6 +78,8 @@ import javax.servlet.http.HttpServletRequest;
|
||||
*/
|
||||
public final class GitUtil
|
||||
{
|
||||
|
||||
private static final GitUserAgentProvider GIT_USER_AGENT_PROVIDER = new GitUserAgentProvider();
|
||||
|
||||
/** Field description */
|
||||
public static final String REF_HEAD = "HEAD";
|
||||
@@ -698,7 +701,7 @@ public final class GitUtil
|
||||
*/
|
||||
public static boolean isGitClient(HttpServletRequest request)
|
||||
{
|
||||
return HttpUtil.userAgentStartsWith(request, USERAGENT_GIT);
|
||||
return GIT_USER_AGENT_PROVIDER.parseUserAgent(request.getHeader(HttpUtil.HEADER_USERAGENT)) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,80 +55,49 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
*
|
||||
* GitPermissionFilter decides if a git request requires write or read privileges.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Singleton
|
||||
public class GitPermissionFilter extends ProviderPermissionFilter
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String PARAMETER_SERVICE = "service";
|
||||
private static final String PARAMETER_SERVICE = "service";
|
||||
|
||||
/** Field description */
|
||||
public static final String PARAMETER_VALUE_RECEIVE = "git-receive-pack";
|
||||
private static final String PARAMETER_VALUE_RECEIVE = "git-receive-pack";
|
||||
|
||||
/** Field description */
|
||||
public static final String URI_RECEIVE_PACK = "git-receive-pack";
|
||||
private static final String URI_RECEIVE_PACK = "git-receive-pack";
|
||||
|
||||
/** Field description */
|
||||
public static final String URI_REF_INFO = "/info/refs";
|
||||
private static final String URI_REF_INFO = "/info/refs";
|
||||
|
||||
public static final String METHOD_LFS_UPLOAD = "PUT";
|
||||
private static final String METHOD_LFS_UPLOAD = "PUT";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
* Constructs a new instance of the GitPermissionFilter.
|
||||
*
|
||||
* @param configuration
|
||||
* @param repositoryProvider
|
||||
* @param configuration scm main configuration
|
||||
* @param repositoryProvider repository provider
|
||||
*/
|
||||
@Inject
|
||||
public GitPermissionFilter(ScmConfiguration configuration,
|
||||
RepositoryProvider repositoryProvider)
|
||||
{
|
||||
public GitPermissionFilter(ScmConfiguration configuration, RepositoryProvider repositoryProvider) {
|
||||
super(configuration, repositoryProvider);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
protected void sendNotEnoughPrivilegesError(HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
throws IOException
|
||||
{
|
||||
if (GitUtil.isGitClient(request))
|
||||
{
|
||||
protected void sendNotEnoughPrivilegesError(HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException {
|
||||
if (GitUtil.isGitClient(request)) {
|
||||
GitSmartHttpTools.sendError(request, response,
|
||||
HttpServletResponse.SC_FORBIDDEN,
|
||||
ClientMessages.get(request).notEnoughPrivileges());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
super.sendNotEnoughPrivilegesError(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected boolean isWriteRequest(HttpServletRequest request) {
|
||||
return isReceivePackRequest(request) ||
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.util.Locale;
|
||||
import sonia.scm.plugin.ext.Extension;
|
||||
|
||||
/**
|
||||
* UserAgent provider for git related clients.
|
||||
* UserAgent provider for git related clients.
|
||||
* @author Sebastian Sdorra <sebastian.sdorra@gmail.com>
|
||||
* @since 1.45
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user