Jgit two authentication methods used with remote warehouse links (SSH and HTTPS)

Source: Internet
Author: User

Jgitjava apigit Storehouse of warehouse, by eclipse company maintenance. he provided apiapi is a direct role in the low-level warehouse objects, high-level api

jgit mainly through ssh and http (S)

(1)HTTPS- https://example.com/repo.git

Clonecommand Clonecommand = git.clonereposity ();

Clonecommand through the Setcredentialsprovider () method, by assigning a Usernamepasswordcredentialsprovider object, To provide user name and password login.

(It is not recommended to use HTTP, but it is also possible)

(2) SSH with public Key-

Links that are actually accessed through the public key:

[Email Protected]***.***.***/user/***.git

SSH uses the public key to access the authentication information through the Jsch library. In Jgit, the abstract class of jschconfigsessionfactory is provided, and the code is as follows:

New jschconfigsessionfactory () {@Override    protectedvoid/*  release hos  TKey check, also means that can accept unknown remote host files, this is not safe, this mode is only used for testing purposes.      use SSH-KEYSCAN-T RSA hostname to collect host data.  */session.setconfig ("stricthostkeychecking", "no");}  ;

The following is the registration of the authentication information in the command:

New Transportconfigcall Back () {publicvoid  Configure (Transporttransport) { Sshtransport Sshtransport=(sshtransport) transport;sshtransport.setsshsessionfactory (sshSessionFactory) ;}}

3) SSH with Password-ssh://[email Protected]/repo.git

Using the Jschconfigsessionfactory overridden in the Configure method above, set password, specifically not detailed.

Jgit two authentication methods used with remote warehouse links (SSH and HTTPS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.