Example usage for org.eclipse.jgit.transport JschSession JschSession

List of usage examples for org.eclipse.jgit.transport JschSession JschSession

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport JschSession JschSession.

Prototype

public JschSession(Session session, URIish uri) 

Source Link

Document

Create a new session object by passing the real Jsch session and the URI information.

Usage

From source file:org.eclipse.orion.server.git.GitSshSessionFactory.java

License:Open Source License

@Override
public RemoteSession getSession(URIish uri, CredentialsProvider credentialsProvider, FS fs, int tms)
        throws TransportException {
    int port = uri.getPort();
    String user = uri.getUser();//from w  w w. j a  v a 2s  .c  o m
    String pass = uri.getPass();
    if (credentialsProvider instanceof GitCredentialsProvider) {
        if (port <= 0)
            port = SSH_PORT;

        GitCredentialsProvider cp = (GitCredentialsProvider) credentialsProvider;
        if (user == null) {
            CredentialItem.Username u = new CredentialItem.Username();
            if (cp.supports(u) && cp.get(cp.getUri(), u)) {
                user = u.getValue();
            }
        }
        if (pass == null) {
            CredentialItem.Password p = new CredentialItem.Password();
            if (cp.supports(p) && cp.get(cp.getUri(), p)) {
                pass = new String(p.getValue());
            }
        }

        try {
            final SessionHandler session = new SessionHandler(user, uri.getHost(), port, cp.getKnownHosts(),
                    cp.getPrivateKey(), cp.getPublicKey(), cp.getPassphrase());
            if (pass != null)
                session.setPassword(pass);
            if (credentialsProvider != null && !credentialsProvider.isInteractive()) {
                session.setUserInfo(new CredentialsProviderUserInfo(session.getSession(), credentialsProvider));
            }

            session.connect(tms);

            return new JschSession(session.getSession(), uri);
        } catch (JSchException e) {
            throw new TransportException(uri, e.getMessage(), e);
        }
    }
    return null;
}