Search in sources :

Example 1 with CredentialsProviderUserInfo

use of org.eclipse.jgit.transport.CredentialsProviderUserInfo in project Android-Password-Store by zeapo.

the class SshConfigSessionFactory method configure.

@Override
protected void configure(OpenSshConfig.Host hc, Session session) {
    session.setConfig("StrictHostKeyChecking", "no");
    session.setConfig("PreferredAuthentications", "publickey,password");
    CredentialsProvider provider = new CredentialsProvider() {

        @Override
        public boolean isInteractive() {
            return false;
        }

        @Override
        public boolean supports(CredentialItem... items) {
            return true;
        }

        @Override
        public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem {
            for (CredentialItem item : items) {
                if (item instanceof CredentialItem.Username) {
                    ((CredentialItem.Username) item).setValue(username);
                    continue;
                }
                if (item instanceof CredentialItem.StringType) {
                    ((CredentialItem.StringType) item).setValue(passphrase);
                }
            }
            return true;
        }
    };
    UserInfo userInfo = new CredentialsProviderUserInfo(session, provider);
    session.setUserInfo(userInfo);
}
Also used : URIish(org.eclipse.jgit.transport.URIish) CredentialItem(org.eclipse.jgit.transport.CredentialItem) UnsupportedCredentialItem(org.eclipse.jgit.errors.UnsupportedCredentialItem) UserInfo(com.jcraft.jsch.UserInfo) CredentialsProviderUserInfo(org.eclipse.jgit.transport.CredentialsProviderUserInfo) CredentialsProviderUserInfo(org.eclipse.jgit.transport.CredentialsProviderUserInfo) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider)

Example 2 with CredentialsProviderUserInfo

use of org.eclipse.jgit.transport.CredentialsProviderUserInfo in project MGit by maks.

the class SGitSessionFactory method configure.

@Override
protected void configure(Host host, Session session) {
    session.setConfig("StrictHostKeyChecking", "no");
    session.setConfig("PreferredAuthentications", "publickey,password");
    // Awful use of App singleton but not really any other way to get hold of a provider that needs
    // to have been initialised with an Android context
    UserInfo userInfo = new CredentialsProviderUserInfo(session, SGitApplication.getJschCredentialsProvider());
    session.setUserInfo(userInfo);
}
Also used : UserInfo(com.jcraft.jsch.UserInfo) CredentialsProviderUserInfo(org.eclipse.jgit.transport.CredentialsProviderUserInfo) CredentialsProviderUserInfo(org.eclipse.jgit.transport.CredentialsProviderUserInfo)

Example 3 with CredentialsProviderUserInfo

use of org.eclipse.jgit.transport.CredentialsProviderUserInfo in project egit by eclipse.

the class EclipseSshSessionFactory method configure.

@Override
protected void configure(final OpenSshConfig.Host hc, final Session session) {
    UserInfo userInfo = session.getUserInfo();
    if (!hc.isBatchMode() && userInfo == null) {
        final CredentialsProvider cp = CredentialsProvider.getDefault();
        session.setUserInfo(new CredentialsProviderUserInfo(session, cp));
    }
}
Also used : UserInfo(com.jcraft.jsch.UserInfo) CredentialsProviderUserInfo(org.eclipse.jgit.transport.CredentialsProviderUserInfo) CredentialsProviderUserInfo(org.eclipse.jgit.transport.CredentialsProviderUserInfo) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider)

Example 4 with CredentialsProviderUserInfo

use of org.eclipse.jgit.transport.CredentialsProviderUserInfo in project fabric8 by fabric8io.

the class GitUtils method configureCommand.

/**
 * Configures the transport of the command to deal with things like SSH
 */
public static <C extends GitCommand> void configureCommand(TransportCommand<C, ?> command, CredentialsProvider credentialsProvider, final File sshPrivateKey, final File sshPublicKey) {
    LOG.info("Using " + credentialsProvider);
    if (sshPrivateKey != null) {
        final CredentialsProvider provider = credentialsProvider;
        command.setTransportConfigCallback(new TransportConfigCallback() {

            @Override
            public void configure(Transport transport) {
                if (transport instanceof SshTransport) {
                    SshTransport sshTransport = (SshTransport) transport;
                    SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {

                        @Override
                        protected void configure(OpenSshConfig.Host host, Session session) {
                            session.setConfig("StrictHostKeyChecking", "no");
                            UserInfo userInfo = new CredentialsProviderUserInfo(session, provider);
                            session.setUserInfo(userInfo);
                        }

                        @Override
                        protected JSch createDefaultJSch(FS fs) throws JSchException {
                            JSch jsch = super.createDefaultJSch(fs);
                            jsch.removeAllIdentity();
                            String absolutePath = sshPrivateKey.getAbsolutePath();
                            if (LOG.isDebugEnabled()) {
                                LOG.debug("Adding identity privateKey: " + sshPrivateKey + " publicKey: " + sshPublicKey);
                            }
                            if (sshPublicKey != null) {
                                jsch.addIdentity(absolutePath, sshPublicKey.getAbsolutePath(), null);
                            } else {
                                jsch.addIdentity(absolutePath);
                            }
                            return jsch;
                        }
                    };
                    sshTransport.setSshSessionFactory(sshSessionFactory);
                }
            }
        });
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) UserInfo(com.jcraft.jsch.UserInfo) CredentialsProviderUserInfo(org.eclipse.jgit.transport.CredentialsProviderUserInfo) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) SshSessionFactory(org.eclipse.jgit.transport.SshSessionFactory) JSch(com.jcraft.jsch.JSch) FS(org.eclipse.jgit.util.FS) OpenSshConfig(org.eclipse.jgit.transport.OpenSshConfig) TransportConfigCallback(org.eclipse.jgit.api.TransportConfigCallback) CredentialsProviderUserInfo(org.eclipse.jgit.transport.CredentialsProviderUserInfo) JschConfigSessionFactory(org.eclipse.jgit.transport.JschConfigSessionFactory) SshTransport(org.eclipse.jgit.transport.SshTransport) Transport(org.eclipse.jgit.transport.Transport) SshTransport(org.eclipse.jgit.transport.SshTransport) Session(com.jcraft.jsch.Session) SSLSession(javax.net.ssl.SSLSession)

Aggregations

UserInfo (com.jcraft.jsch.UserInfo)4 CredentialsProviderUserInfo (org.eclipse.jgit.transport.CredentialsProviderUserInfo)4 CredentialsProvider (org.eclipse.jgit.transport.CredentialsProvider)3 JSch (com.jcraft.jsch.JSch)1 JSchException (com.jcraft.jsch.JSchException)1 Session (com.jcraft.jsch.Session)1 SSLSession (javax.net.ssl.SSLSession)1 TransportConfigCallback (org.eclipse.jgit.api.TransportConfigCallback)1 UnsupportedCredentialItem (org.eclipse.jgit.errors.UnsupportedCredentialItem)1 CredentialItem (org.eclipse.jgit.transport.CredentialItem)1 JschConfigSessionFactory (org.eclipse.jgit.transport.JschConfigSessionFactory)1 OpenSshConfig (org.eclipse.jgit.transport.OpenSshConfig)1 SshSessionFactory (org.eclipse.jgit.transport.SshSessionFactory)1 SshTransport (org.eclipse.jgit.transport.SshTransport)1 Transport (org.eclipse.jgit.transport.Transport)1 URIish (org.eclipse.jgit.transport.URIish)1 FS (org.eclipse.jgit.util.FS)1