USERAUTH fail using JGit to access git repo securely for PullCommand()

孤街浪徒 提交于 2019-11-29 12:54:26
mohanjot

I could figure out some of the issues I was facing. Here's solution to it:

  1. if auth has to be done without the passphrase, generate the id_rsa without passphrase

  2. We needed to override getJSch(final OpenSshConfig.Host hc, FS fs) making use of addIdentity in the configure of SshSessionfactory:

    SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
        @Override
        protected void configure(OpenSshConfig.Host host, Session sess ion) {
            session.setConfig("StrictHostKeyChecking", "no");
        }
    
        @Override
        protected JSch getJSch(final OpenSshConfig.Host hc, FS fs) throws JSchException {
            JSch jsch = super.getJSch(hc, fs);
            jsch.removeAllIdentity();
            jsch.addIdentity("/path/to/private/key");
            return jsch;
        }
    };
    
  3. We need to call needs to be instantiated differently:

    PullCommand pull = git.pull().setTransportConfigCallback(new TransportConfigCallback() {
    
        @Override
        public void configure(Transport transport) {
            SshTransport sshTransport = (SshTransport) transport;
            sshTransport.setSshSessionFactory(sshSessionFactory);
        }
    });
    

And then call pull instance:

PullResult pullResult = pull.call();

I hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!