| | |
| | | import java.io.IOException;
|
| | | import java.text.MessageFormat;
|
| | |
|
| | | import javax.inject.Inject;
|
| | | import javax.inject.Singleton;
|
| | | import javax.servlet.FilterChain;
|
| | | import javax.servlet.ServletException;
|
| | | import javax.servlet.ServletRequest;
|
| | |
| | | import javax.servlet.http.HttpServletResponse;
|
| | |
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.manager.IProjectManager;
|
| | | import com.gitblit.manager.IRepositoryManager;
|
| | | import com.gitblit.manager.IRuntimeManager;
|
| | | import com.gitblit.manager.ISessionManager;
|
| | | import com.gitblit.models.ProjectModel;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.UserModel;
|
| | |
| | | * @author James Moger
|
| | | *
|
| | | */
|
| | | @Singleton
|
| | | public class SyndicationFilter extends AuthenticationFilter {
|
| | |
|
| | | private final IRuntimeManager runtimeManager;
|
| | | private final IRepositoryManager repositoryManager;
|
| | | private final IProjectManager projectManager;
|
| | |
|
| | | @Inject
|
| | | public SyndicationFilter(
|
| | | IRuntimeManager runtimeManager,
|
| | | ISessionManager sessionManager,
|
| | | IRepositoryManager repositoryManager,
|
| | | IProjectManager projectManager) {
|
| | |
|
| | | super(sessionManager);
|
| | | this.runtimeManager = runtimeManager;
|
| | | this.repositoryManager = repositoryManager;
|
| | | this.projectManager = projectManager;
|
| | | }
|
| | |
|
| | | /**
|
| | | * Extract the repository name from the url.
|
| | |
| | | String fullUrl = getFullUrl(httpRequest);
|
| | | String name = extractRequestedName(fullUrl);
|
| | |
|
| | | ProjectModel project = GitBlit.self().getProjectModel(name);
|
| | | ProjectModel project = projectManager.getProjectModel(name);
|
| | | RepositoryModel model = null;
|
| | |
|
| | | if (project == null) {
|
| | | // try loading a repository model
|
| | | model = GitBlit.self().getRepositoryModel(name);
|
| | | model = repositoryManager.getRepositoryModel(name);
|
| | | if (model == null) {
|
| | | // repository not found. send 404.
|
| | | logger.info(MessageFormat.format("ARF: {0} ({1})", fullUrl,
|
| | |
| | | if (model.accessRestriction.atLeast(AccessRestrictionType.VIEW)) {
|
| | | if (user == null) {
|
| | | // challenge client to provide credentials. send 401.
|
| | | if (GitBlit.isDebugMode()) {
|
| | | if (runtimeManager.isDebugMode()) {
|
| | | logger.info(MessageFormat.format("ARF: CHALLENGE {0}", fullUrl));
|
| | | }
|
| | | httpResponse.setHeader("WWW-Authenticate", CHALLENGE);
|
| | |
| | | return;
|
| | | }
|
| | | // valid user, but not for requested access. send 403.
|
| | | if (GitBlit.isDebugMode()) {
|
| | | if (runtimeManager.isDebugMode()) {
|
| | | logger.info(MessageFormat.format("ARF: {0} forbidden to access {1}",
|
| | | user.username, fullUrl));
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | if (GitBlit.isDebugMode()) {
|
| | | if (runtimeManager.isDebugMode()) {
|
| | | logger.info(MessageFormat.format("ARF: {0} ({1}) unauthenticated", fullUrl,
|
| | | HttpServletResponse.SC_CONTINUE));
|
| | | }
|