Skip to content
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

Unable to push local repo into http server #75

Open
raminpix opened this issue Apr 16, 2020 · 7 comments
Open

Unable to push local repo into http server #75

raminpix opened this issue Apr 16, 2020 · 7 comments

Comments

@raminpix
Copy link

raminpix commented Apr 16, 2020

Hi,
I ran the Example under httpserver and want to push my local repository to http://localhost:8080/TestRepo .But it fails in authentication:
Authentication failed for 'http://localhost:8080/TestRepo/'
So how could I provide authentication mechanism for GitServlet to accept credentials?
I also tried extending org.eclipse.jgit.http.server.GitServlet in a servlet project running on a standalone Jetty, but I faced the similar issue.

@centic9
Copy link
Owner

centic9 commented Apr 16, 2020

Added the necessary configuration-line which seems to allow pushing to the repository via HTTP.

But please note that this sample server does not do much useful stuff, it is mostly just a sample to show that the GitServlet does work basically.

@raminpix
Copy link
Author

Thanks, but how to add credentials to the GitServlet? Is there any sample code or documentation? I didn't find helpful stuff yet.

@centic9
Copy link
Owner

centic9 commented Apr 17, 2020

Unfortunately I don't have much knowledge about it and I also could not find much information when I worked on this sample.

I am not a JGit developer at all, so you might need to contact JGit developers to get more information.

@raminpix
Copy link
Author

Ok, Thanks. So if I find something useful, I will share it.

@raminpix
Copy link
Author

I asked JGit developers and here is the solution that I found (based on the answer):

In my java web application (a simple servlet application) I defined a security constraint and basic login config in web.xml:

<security-constraint>
	<display-name>SecurityConstraint</display-name>
	<web-resource-collection>
		<web-resource-name>MyWebResource</web-resource-name>
			<url-pattern>/*</url-pattern>
		</web-resource-collection>
		<auth-constraint>
			<role-name>admin</role-name>
		</auth-constraint>
		<user-data-constraint>
			<transport-guarantee>NONE</transport-guarantee>
		</user-data-constraint>	
</security-constraint>
<login-config>
	<auth-method>BASIC</auth-method>
	<realm-name>Test Realm</realm-name>
</login-config>

Also in jetty 9.4 standalone server (my servlet container) I defined a bean for handling security in jetty/etc/jetty.xml:

<Call name="addBean">
  <Arg>
        <New class="org.eclipse.jetty.security.HashLoginService">
             <Set name="name">My Realm</Set>
             <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
             <Set name="hotReload">true</Set>
       </New>
 </Arg>
</Call>

Also I created realm.properties under jetty/etc that contained users credentials and roles:
adminuser:secret123,admin

note that adminuser is a username and secret123 is password and admin is role that defined in web.xml in the first step.

So the user with adminuser username and the role of admin is able to clone, push and fetch repositories which is configured to be accessible under GitServlet.

Here is my extended class from org.eclipse.jgit.http.server.GitServlet in my web application:

import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import org.eclipse.jgit.http.server.GitServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@WebServlet(value = "/git/*",
		initParams = { @WebInitParam(name = "base-path", value = GitMainServlet.BASE_DIR),
				@WebInitParam(name = "export-all", value = "true") })
public class MyGitServlet extends GitServlet {
	private static final long serialVersionUID = 1L;

	Logger logger = LoggerFactory.getLogger(GitMainServlet.class);

	public static final String BASE_DIR = "/home/ramin/Development/Projects/SimpleServlet/repo/";

}

@centic9
Copy link
Owner

centic9 commented Apr 20, 2020

Thanks for the update, I will review if some of that should be incorporated into the sample in this project.

@centic9 centic9 reopened this Apr 20, 2020
@raminpix
Copy link
Author

Great. I'm available to help if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants