Skip to content

Modernize, implement HTTP auth #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
<version>1.4</version>
</extension>
</extensions>
2 changes: 2 additions & 0 deletions .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-Pmight-produce-incrementals
-Pconsume-incrementals
24 changes: 16 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.532</version>
<version>4.76</version>
</parent>

<artifactId>git-userContent</artifactId>
Expand All @@ -15,7 +15,11 @@
<description>
This plugin manages JENKINS_HOME/userContent under Git
</description>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Git+userContent+Plugin</url>
<url>https://github.com/jenkinsci/git-userContent-plugin</url>

<properties>
<jenkins.version>2.361.4</jenkins.version>
</properties>

<scm>
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
Expand All @@ -25,30 +29,34 @@
<licenses>
<license>
<name>The MIT license</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
<url>https://www.opensource.org/licenses/mit</url>
</license>
</licenses>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.modules</groupId>
<artifactId>sshd</artifactId>
<version>1.1</version>
<scope>provided</scope><!-- this is in the core -->
<version>3.322.v159e91f6a_550</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git-server</artifactId>
<version>1.6</version>
<version>115.v132fd6e5777a_</version>
</dependency>
</dependencies>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package org.jenkinsci.plugins.gitUserContent;

import hudson.Extension;
import hudson.model.RootAction;
import hudson.model.UnprotectedRootAction;
import hudson.security.ACL;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import jenkins.model.Jenkins;
import org.jenkinsci.main.modules.sshd.SSHD;
import org.jenkinsci.plugins.gitserver.FileBackedHttpGitRepository;

import javax.inject.Inject;
import java.io.File;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

/**
* Exposes Git repository at http://server/jenkins/userContent.git
*
* @author Kohsuke Kawaguchi
*/
@Extension
public class GitUserContentRepository extends FileBackedHttpGitRepository implements RootAction {
public class GitUserContentRepository extends FileBackedHttpGitRepository implements UnprotectedRootAction {
@Inject
public SSHD sshd;

Expand All @@ -39,4 +45,15 @@ public String getDisplayName() {
public String getUrlName() {
return "userContent.git";
}

@Override
public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
if (!Jenkins.get().hasPermission(Jenkins.READ) && ACL.isAnonymous2(Jenkins.getAuthentication2())) {
rsp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
rsp.setHeader("WWW-Authenticate", "Basic realm=\"Jenkins user\"");
return;
}
Jenkins.get().checkPermission(Jenkins.READ);
super.doDynamic(req, rsp);
}
}
4 changes: 4 additions & 0 deletions src/main/resources/index.jelly
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?jelly escape-by-default='true'?>
<div>
This plugin manages JENKINS_HOME/userContent under Git.
</div>