List of usage examples for org.eclipse.jgit.transport JschConfigSessionFactory JschConfigSessionFactory
JschConfigSessionFactory
From source file:org.opentravel.otm.forum2016.GitRepositorySynchronizer.java
License:Apache License
/** * Returns a <code>TransportConfigCallback</code> for SSL communications when * accessing the remote Git repository./* w w w . j av a2s . co m*/ * * @return TransportConfigCallback */ private TransportConfigCallback getTransportConfigCallback() { final SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() { protected void configure(OpenSshConfig.Host host, Session session) { } }; return new TransportConfigCallback() { public void configure(Transport transport) { if (transport instanceof SshTransport) { ((SshTransport) transport).setSshSessionFactory(sshSessionFactory); } } }; }
From source file:org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.java
License:Apache License
private void initialize() { if (!this.initialized) { SshSessionFactory.setInstance(new JschConfigSessionFactory() { @Override/*from www . j a va2 s. c om*/ protected void configure(Host hc, Session session) { session.setConfig("StrictHostKeyChecking", isStrictHostKeyChecking() ? "yes" : "no"); } }); this.initialized = true; } }
From source file:org.springframework.cloud.config.server.JGitEnvironmentRepository.java
License:Apache License
private void initialize() { if (getUri().startsWith("file:") && !this.initialized) { SshSessionFactory.setInstance(new JschConfigSessionFactory() { @Override/*from w w w. j a v a 2 s . c om*/ protected void configure(Host hc, Session session) { session.setConfig("StrictHostKeyChecking", "no"); } }); this.initialized = true; } }
From source file:org.springframework.cloud.config.server.ssh.FileBasedSshTransportConfigCallback.java
License:Apache License
@Override public void configure(Transport transport) { SshSessionFactory.setInstance(new JschConfigSessionFactory() { @Override//from ww w . j a v a2 s. c om protected void configure(OpenSshConfig.Host hc, Session session) { session.setConfig("StrictHostKeyChecking", sshUriProperties.isStrictHostKeyChecking() ? "yes" : "no"); } }); }
From source file:serendipitytranslator.mainWindow.MainFrame.java
License:Open Source License
private void initApplication() { try {//from w w w . jav a 2 s . c o m l.addHandler(new FileHandler("error.log")); } catch (IOException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } executorService = Executors.newSingleThreadExecutor(); PluginList.setSettings(settingsDialog); language = settingsDialog.getLanguage(); settingsDialog.setMainWindowSizeAndPosition(this); translateFrame.setLocation(this.getX() + this.getWidth(), 0); progressBar.setVisible(false); cancelButton.setVisible(false); settingsDialog.addPropertyChangeListener(this); pluginTable.setModel(new PluginTableModel(plugins)); pluginTable.setColumnModel(new PluginColumnModel()); pluginTable.setDefaultRenderer(PluginStatus.class, new PluginTableRenderer()); pluginTable.setDefaultRenderer(DocumentationStatus.class, new PluginTableRenderer()); TableRowSorter sorter = new TableRowSorter<PluginTableModel>((PluginTableModel) pluginTable.getModel()); sorter.setRowFilter(new RowFilter<PluginTableModel, Integer>() { @Override public boolean include(Entry<? extends PluginTableModel, ? extends Integer> entry) { PluginTableModel tableModel = entry.getModel(); PluginStatus status = (PluginStatus) tableModel.getValueAt(entry.getIdentifier(), 5); DocumentationStatus docStatus = (DocumentationStatus) tableModel.getValueAt(entry.getIdentifier(), 7); return !(settingsDialog.isShowEmptyPlugins() && status.equals(PluginStatus.problem) && docStatus.equals(DocumentationStatus.problem)); } }); pluginTable.setRowSorter(sorter); translateFrame.addPropertyChangeListener(this); try { updateApplication(); } catch (MalformedURLException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.INFO, ex.getMessage()); } catch (IOException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.INFO, ex.getMessage()); } JschConfigSessionFactory sessionFactory = new JschConfigSessionFactory() { @Override protected void configure(OpenSshConfig.Host hc, Session session) { CredentialsProvider provider = new CredentialsProvider() { @Override public boolean isInteractive() { System.out.println("CredentialProvider: check if interactive"); return false; } @Override public boolean supports(CredentialItem... items) { System.out.println("CredentialProvider: request if next items are supported"); for (CredentialItem ci : items) { System.out.println("\t\t" + ci.getClass().getName() + "; " + ci.getPromptText() + "; secured = " + ci.isValueSecure()); } return true; } @Override public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem { System.out.println("CredentialProvider: item request for URI: " + uri); for (CredentialItem item : items) { System.out.println("\t\t setting item: class = " + item.getClass().getName() + "; prompt = " + item.getPromptText() + "; string = " + item.toString() + "; secure = " + item.isValueSecure()); JPanel userPanel = new JPanel(); JLabel passwordLbl = new JLabel(item.getPromptText()); JPasswordField pf = new JPasswordField(); userPanel.setLayout(new GridLayout(2, 1)); userPanel.add(passwordLbl); userPanel.add(pf); int okCxl = JOptionPane.showConfirmDialog(null, userPanel, "Set password", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (okCxl == JOptionPane.OK_OPTION) { String password = new String(pf.getPassword()); //System.err.println("You entered: " + password); ((CredentialItem.StringType) item).setValue(password); } } return true; } }; UserInfo userInfo = new CredentialsProviderUserInfo(session, provider); session.setUserInfo(userInfo); } }; SshSessionFactory.setInstance(sessionFactory); updateLanguage(); }
From source file:sh.isaac.provider.sync.git.SyncServiceGIT.java
License:Apache License
/** * If you are in an HK2 environment, you would be better served getting this from HK2 (by asking for it by interface and name) * but in other enviornments, when HK2 may not be up, you may construct it directly. */// w ww .j a v a 2 s . com public SyncServiceGIT() { synchronized (jschConfigured) { if (jschConfigured.getCount() > 0) { LOG.debug("Disabling strict host key checking"); final SshSessionFactory factory = new JschConfigSessionFactory() { @Override protected void configure(Host hc, Session session) { session.setConfig("StrictHostKeyChecking", "no"); } }; SshSessionFactory.setInstance(factory); JSch.setLogger(new com.jcraft.jsch.Logger() { private final HashMap<Integer, Consumer<String>> logMap = new HashMap<>(); private final HashMap<Integer, BooleanSupplier> enabledMap = new HashMap<>(); { // Note- JSCH is _really_ verbose at the INFO level, so I'm mapping info to DEBUG. this.logMap.put(com.jcraft.jsch.Logger.DEBUG, LOG::debug); this.logMap.put(com.jcraft.jsch.Logger.ERROR, LOG::debug); // error this.logMap.put(com.jcraft.jsch.Logger.FATAL, LOG::debug); // error this.logMap.put(com.jcraft.jsch.Logger.INFO, LOG::debug); this.logMap.put(com.jcraft.jsch.Logger.WARN, LOG::debug); // warn this.enabledMap.put(com.jcraft.jsch.Logger.DEBUG, LOG::isDebugEnabled); this.enabledMap.put(com.jcraft.jsch.Logger.ERROR, LOG::isErrorEnabled); this.enabledMap.put(com.jcraft.jsch.Logger.FATAL, LOG::isErrorEnabled); this.enabledMap.put(com.jcraft.jsch.Logger.INFO, LOG::isDebugEnabled); this.enabledMap.put(com.jcraft.jsch.Logger.WARN, LOG::isWarnEnabled); } @Override public void log(int level, String message) { this.logMap.get(level).accept(message); } @Override public boolean isEnabled(int level) { return this.enabledMap.get(level).getAsBoolean(); } }); jschConfigured.countDown(); } } }
From source file:uk.ac.cam.cl.dtg.segue.database.GitDb.java
License:Apache License
/** * This method will execute a fetch on the configured remote git repository and will return the latest sha. * /*from w w w.j a va 2 s. co m*/ * @return The version id of the latest version after the fetch. */ public synchronized String fetchLatestFromRemote() { try { SshSessionFactory factory = new JschConfigSessionFactory() { @Override public void configure(final Host hc, final com.jcraft.jsch.Session session) { session.setConfig("StrictHostKeyChecking", "no"); } @Override protected JSch getJSch(final OpenSshConfig.Host hc, final org.eclipse.jgit.util.FS fs) throws JSchException { JSch jsch = super.getJSch(hc, fs); jsch.removeAllIdentity(); if (null != privateKey) { jsch.addIdentity(privateKey); } return jsch; } }; if (this.sshFetchUrl != null) { SshSessionFactory.setInstance(factory); } RefSpec refSpec = new RefSpec("+refs/heads/*:refs/remotes/origin/*"); FetchResult result = gitHandle.fetch().setRefSpecs(refSpec).setRemote(sshFetchUrl).call(); TrackingRefUpdate refUpdate = result.getTrackingRefUpdate("refs/remotes/origin/master"); if (refUpdate != null) { if (refUpdate.getResult() == RefUpdate.Result.LOCK_FAILURE) { log.error("Failed to fetch. The git repository may be corrupted. " + "Hopefully, this will not be a problem."); } else { log.info("Fetched latest from git. Latest version is: " + this.getHeadSha()); } } } catch (GitAPIException e) { log.error("Error while trying to pull the latest from the remote repository.", e); } return this.getHeadSha(); }
From source file:uk.ac.cam.UROP.twentyfourteen.database.GitDb.java
/** * Clone a repository and return a GitDb object. * <p>//from www .ja va 2 s. c o m * Note, you may wish to delete the directory after you have finished with it. * This is entirely your responsibility! * * @param src Source repository path * @param dest Destination directory * @param bare Clone bare? * @param branch Branch to clone */ public GitDb(String src, File dest, boolean bare, String branch, String remote, final String privateKey) throws IOException { this.privateKey = privateKey; this.sshFetchUrl = src; try { SshSessionFactory factory = new JschConfigSessionFactory() { @Override public void configure(Host hc, com.jcraft.jsch.Session session) { // // TODO: Bad! // session.setConfig("StrictHostKeyChecking", "no"); } @Override protected JSch getJSch(final OpenSshConfig.Host hc, org.eclipse.jgit.util.FS fs) throws JSchException { JSch jsch = super.getJSch(hc, fs); jsch.removeAllIdentity(); if (null != privateKey) { jsch.addIdentity(privateKey); } return jsch; } }; if (src != null) SshSessionFactory.setInstance(factory); this.gitHandle = Git.cloneRepository().setURI(src).setDirectory(dest).setBare(bare).setBranch(branch) .setRemote(remote).call(); this.gitHandle = Git.open(dest); } catch (GitAPIException e) { log.error("Error while trying to clone the repository.", e); throw new RuntimeException("Error while trying to clone the repository." + e); } }
From source file:uk.ac.cam.UROP.twentyfourteen.database.GitDb.java
/** * This method will execute a fetch on the configured remote git repository * and will return the latest sha./*from www .j a v a2 s .c o m*/ * * @return The version id of the latest version after the fetch. */ public synchronized String pullLatestFromRemote() { try { SshSessionFactory factory = new JschConfigSessionFactory() { @Override public void configure(Host hc, com.jcraft.jsch.Session session) { // TODO: Bad! session.setConfig("StrictHostKeyChecking", "no"); } @Override protected JSch getJSch(final OpenSshConfig.Host hc, org.eclipse.jgit.util.FS fs) throws JSchException { JSch jsch = super.getJSch(hc, fs); jsch.removeAllIdentity(); if (null != privateKey) { jsch.addIdentity(privateKey); } return jsch; } }; if (this.sshFetchUrl != null) SshSessionFactory.setInstance(factory); RefSpec refSpec = new RefSpec("+refs/heads/*:refs/remotes/origin/*"); FetchResult r = gitHandle.fetch().setRefSpecs(refSpec).setRemote(sshFetchUrl).call(); log.debug("Fetched the following advertised Refs." + r.getAdvertisedRefs().toString()); log.debug("Fetched latest from git result: " + this.getHeadSha()); } catch (GitAPIException e) { log.error("Error while trying to pull the latest from the remote repository.", e); } return this.getHeadSha(); }