USERAUTH falla al usar JGit para acceder a git repo de forma segura para PullCommand ()

Estoy tratando de hacer un git pull usando la API de JGit con el siguiente código

public class gitHubTest {
    JSch jsch = new JSch();

    // Defining the private key file location explicitly
    String userHome = System.getProperty("user.home");
    String privateKey = userHome + "/.ssh/id_rsa";
    String knownHostsFile = userHome + "/.ssh/known_hosts";
    Repository localRepo = new FileRepository("/LocalPath/.git");

    public gitHubTest() throws Exception {
        jsch.setConfig("StrictHostKeyChecking", "no");
        jsch.setKnownHosts(knownHostsFile);
        jsch.addIdentity(privateKey);
        System.out.println("privateKey :" + privateKey);
        Git git = new Git(localRepo);
        PullCommand pullcmd = git.pull();
        pullcmd.call();
    }
}

Seguimiento de pila de error:

org.eclipse.jgit.api.errors.TransportException: [email protected]:remote.git: USERAUTH fail
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:245)
at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:288)
at gitHubTest.<init>(gitHubTest.java:47)
at WebhooksServer.main(WebhooksServer.java:13)
Caused by: org.eclipse.jgit.errors.TransportException: [email protected]:remote.git: USERAUTH fail
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:160)
at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:137)
at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:274)
at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:169)
at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:136)
at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:122)
at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1236)
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:234)
... 3 more

Caused by: com.jcraft.jsch.JSchException: USERAUTH fail
at com.jcraft.jsch.UserAuthPublicKey.start(UserAuthPublicKey.java:119)
at com.jcraft.jsch.Session.connect(Session.java:470)
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:117)
... 10 more

Algunas sugerencias que verifiqué muestran, necesitamos crear una instancia de JschConfigSessionFactory y luego anular el método configure () para pasar la frase de contraseña. He intentado hacerlo ya. Entonces muestra un error. Me he referidohttp://www.codeaffine.com/2014/12/09/jgit-authentication/ que se lee bien pero no para mi PullCommand.

Alguien puede ayudarme porfavor? Ya he leído y probado muchas publicaciones aquí, pero nada resuelve mi problema con precisión.

Implementación de código con el método configure ():

public class gitHubTest {
JSch jsch = new JSch();
String userHome = System.getProperty("user.home");
String privateKey = userHome + "/.ssh/id_rsa";
String knownHostsFile = userHome + "/.ssh/known_hosts";

public gitHubTest() throws IOException, JSchException, GitAPIException {
    Repository localRepo = new FileRepository("/LocalPath/branch.git");
    final String remoteURL = "[email protected]:remote.git";
    JSch.setConfig("StrictHostKeyChecking", "no");
    jsch.setKnownHosts(knownHostsFile);
    jsch.addIdentity(privateKey);
    JschConfigSessionFactory sessionFactory = new JschConfigSessionFactory() {
    @Override
    protected void configure(OpenSshConfig.Host host, Session session) {
        CredentialsProvider cp = new CredentialsProvider() {
            @Override
            public boolean isInteractive() {
                return false;
            }
            @Override
            public boolean supports(CredentialItem... credentialItems) {
                return false;
            }
            @Override
            public boolean get(URIish urIish, CredentialItem... credentialItems) throws UnsupportedCredentialItem {
                return false;
            }
        };
        UserInfo userInfo = new CredentialsProviderUserInfo(session,cp);
        session.setUserInfo(userInfo);
    }
    };
SshSessionFactory.setInstance(sessionFactory);
Git git = new Git(localRepo);
PullCommand pullcmd = git.pull();
pullcmd.call();
}}

Esto da el mismo error.

Respuestas a la pregunta(1)

Su respuesta a la pregunta