mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
merge with branch apache-shiro
This commit is contained in:
@@ -39,6 +39,9 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -51,9 +54,9 @@ import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.repository.RepositoryNotFoundException;
|
||||
import sonia.scm.repository.RepositoryUtil;
|
||||
import sonia.scm.security.CipherUtil;
|
||||
import sonia.scm.security.Tokens;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.Util;
|
||||
import sonia.scm.web.security.WebSecurityContext;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -120,16 +123,14 @@ public class HgHookCallbackServlet extends HttpServlet
|
||||
* @param securityContextProvider
|
||||
*/
|
||||
@Inject
|
||||
public HgHookCallbackServlet(
|
||||
RepositoryManager repositoryManager, HgRepositoryHandler handler,
|
||||
HgHookManager hookManager, Provider<HgContext> contextProvider,
|
||||
Provider<WebSecurityContext> securityContextProvider)
|
||||
public HgHookCallbackServlet(RepositoryManager repositoryManager,
|
||||
HgRepositoryHandler handler, HgHookManager hookManager,
|
||||
Provider<HgContext> contextProvider)
|
||||
{
|
||||
this.repositoryManager = repositoryManager;
|
||||
this.handler = handler;
|
||||
this.hookManager = hookManager;
|
||||
this.contextProvider = contextProvider;
|
||||
this.securityContextProvider = securityContextProvider;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -146,7 +147,7 @@ public class HgHookCallbackServlet extends HttpServlet
|
||||
*/
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException
|
||||
throws ServletException, IOException
|
||||
{
|
||||
String ping = request.getParameter(PARAM_PING);
|
||||
|
||||
@@ -172,8 +173,8 @@ public class HgHookCallbackServlet extends HttpServlet
|
||||
*/
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
String strippedURI = HttpUtil.getStrippedURI(request);
|
||||
Matcher m = REGEX_URL.matcher(strippedURI);
|
||||
@@ -194,7 +195,7 @@ public class HgHookCallbackServlet extends HttpServlet
|
||||
|
||||
if (Util.isNotEmpty(credentials))
|
||||
{
|
||||
authenticate(request, response, credentials);
|
||||
authenticate(request, credentials);
|
||||
}
|
||||
|
||||
hookCallback(response, repositoryId, type, challenge, node);
|
||||
@@ -228,8 +229,7 @@ public class HgHookCallbackServlet extends HttpServlet
|
||||
* @param response
|
||||
* @param credentials
|
||||
*/
|
||||
private void authenticate(HttpServletRequest request,
|
||||
HttpServletResponse response, String credentials)
|
||||
private void authenticate(HttpServletRequest request, String credentials)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -241,10 +241,10 @@ public class HgHookCallbackServlet extends HttpServlet
|
||||
|
||||
if (credentialsArray.length >= 2)
|
||||
{
|
||||
WebSecurityContext context = securityContextProvider.get();
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
|
||||
context.authenticate(request, response, credentialsArray[0],
|
||||
credentialsArray[1]);
|
||||
subject.login(Tokens.createAuthenticationToken(request,
|
||||
credentialsArray[0], credentialsArray[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -266,8 +266,8 @@ public class HgHookCallbackServlet extends HttpServlet
|
||||
* @throws IOException
|
||||
*/
|
||||
private void fireHook(HttpServletResponse response, String repositoryName,
|
||||
String node, RepositoryHookType type)
|
||||
throws IOException
|
||||
String node, RepositoryHookType type)
|
||||
throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -277,9 +277,8 @@ public class HgHookCallbackServlet extends HttpServlet
|
||||
}
|
||||
|
||||
repositoryManager.fireHookEvent(HgRepositoryHandler.TYPE_NAME,
|
||||
repositoryName,
|
||||
new HgRepositoryHookEvent(handler,
|
||||
repositoryName, node, type));
|
||||
repositoryName,
|
||||
new HgRepositoryHookEvent(handler, repositoryName, node, type));
|
||||
}
|
||||
catch (RepositoryNotFoundException ex)
|
||||
{
|
||||
@@ -310,9 +309,8 @@ public class HgHookCallbackServlet extends HttpServlet
|
||||
* @throws IOException
|
||||
*/
|
||||
private void hookCallback(HttpServletResponse response,
|
||||
String repositoryName, String typeName,
|
||||
String challenge, String node)
|
||||
throws IOException
|
||||
String repositoryName, String typeName, String challenge, String node)
|
||||
throws IOException
|
||||
{
|
||||
if (hookManager.isAcceptAble(challenge))
|
||||
{
|
||||
@@ -404,7 +402,4 @@ public class HgHookCallbackServlet extends HttpServlet
|
||||
|
||||
/** Field description */
|
||||
private RepositoryManager repositoryManager;
|
||||
|
||||
/** Field description */
|
||||
private Provider<WebSecurityContext> securityContextProvider;
|
||||
}
|
||||
|
||||
@@ -36,17 +36,15 @@ package sonia.scm.web;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.RepositoryProvider;
|
||||
import sonia.scm.web.filter.ProviderPermissionFilter;
|
||||
import sonia.scm.web.security.WebSecurityContext;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -61,15 +59,15 @@ public class HgPermissionFilter extends ProviderPermissionFilter
|
||||
*
|
||||
*
|
||||
* @param securityContextProvider
|
||||
*
|
||||
* @param configuration
|
||||
* @param repositoryProvider
|
||||
*/
|
||||
@Inject
|
||||
public HgPermissionFilter(
|
||||
ScmConfiguration configuration,
|
||||
Provider<WebSecurityContext> securityContextProvider,
|
||||
RepositoryProvider repositoryProvider)
|
||||
public HgPermissionFilter(ScmConfiguration configuration,
|
||||
RepositoryProvider repositoryProvider)
|
||||
{
|
||||
super(configuration, securityContextProvider, repositoryProvider);
|
||||
super(configuration, repositoryProvider);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user