mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
move Authenticator and Filters from scm-webapp to scm-web-api
This commit is contained in:
@@ -17,8 +17,8 @@ import sonia.scm.filter.SecurityFilter;
|
||||
import sonia.scm.filter.StaticResourceFilter;
|
||||
import sonia.scm.plugin.ScriptResourceServlet;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.security.Authenticator;
|
||||
import sonia.scm.security.DemoAuthenticator;
|
||||
import sonia.scm.web.security.Authenticator;
|
||||
import sonia.scm.web.security.DemoAuthenticator;
|
||||
import sonia.scm.web.ScmWebPluginContext;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
@@ -90,16 +90,16 @@ public class ScmServletModule extends ServletModule
|
||||
{
|
||||
SCMContextProvider context = SCMContext.getContext();
|
||||
|
||||
bind(Authenticator.class).to(DemoAuthenticator.class);
|
||||
bind(SCMContextProvider.class).toInstance(context);
|
||||
bind(Authenticator.class).to(DemoAuthenticator.class);
|
||||
bind(RepositoryManager.class).toInstance(context.getRepositoryManager());
|
||||
bind(ScmWebPluginContext.class).toInstance(webPluginContext);
|
||||
|
||||
// filters
|
||||
filter(PATTERN_PAGE,
|
||||
/*filter(PATTERN_PAGE,
|
||||
PATTERN_STATIC_RESOURCES).through(StaticResourceFilter.class);
|
||||
filter(PATTERN_PAGE, PATTERN_COMPRESSABLE).through(GZipFilter.class);
|
||||
filter(PATTERN_RESTAPI).through(SecurityFilter.class);
|
||||
filter(PATTERN_RESTAPI).through(SecurityFilter.class);*/
|
||||
|
||||
// plugin resources
|
||||
serve(PATTERN_PLUGIN_SCRIPT).with(ScriptResourceServlet.class);
|
||||
|
||||
@@ -16,7 +16,7 @@ import sonia.scm.ScmState;
|
||||
import sonia.scm.User;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.repository.RepositoryType;
|
||||
import sonia.scm.security.Authenticator;
|
||||
import sonia.scm.web.security.Authenticator;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ package sonia.scm.filter;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.web.filter.HttpFilter;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.util.WebUtil;
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.filter;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class HttpFilter implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param chain
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ServletException
|
||||
*/
|
||||
protected abstract void doFilter(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
FilterChain chain)
|
||||
throws IOException, ServletException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param chain
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ServletException
|
||||
*/
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
if ((request instanceof HttpServletRequest)
|
||||
&& (response instanceof HttpServletResponse))
|
||||
{
|
||||
doFilter((HttpServletRequest) request, (HttpServletResponse) response,
|
||||
chain);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("request is not an http request");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param filterConfig
|
||||
*
|
||||
* @throws ServletException
|
||||
*/
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException
|
||||
{
|
||||
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ package sonia.scm.filter;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.web.filter.HttpFilter;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@@ -25,7 +26,7 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import sonia.scm.security.Authenticator;
|
||||
import sonia.scm.web.security.Authenticator;
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -9,6 +9,7 @@ package sonia.scm.filter;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.web.filter.HttpFilter;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.util.WebUtil;
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.security;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.User;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface Authenticator
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param username
|
||||
* @param password
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public User authenticate(HttpServletRequest request, String username,
|
||||
String password);
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public User getUser(HttpServletRequest request);
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
|
||||
package sonia.scm.security;
|
||||
package sonia.scm.web.security;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
@@ -75,7 +75,7 @@ public class DemoAuthenticator implements Authenticator
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Override
|
||||
public User getUser(HttpServletRequest request)
|
||||
{
|
||||
User user = null;
|
||||
Reference in New Issue
Block a user