List of usage examples for org.eclipse.jgit.transport CredentialsProvider getDefault
public static CredentialsProvider getDefault()
From source file:org.apache.gobblin.service.modules.core.GitMonitoringService.java
License:Apache License
GitMonitoringService(Config config) {
Preconditions.checkArgument(config.hasPath(ConfigurationKeys.GIT_MONITOR_REPO_URI),
ConfigurationKeys.GIT_MONITOR_REPO_URI + " needs to be specified.");
String repositoryUri = config.getString(ConfigurationKeys.GIT_MONITOR_REPO_URI);
this.repositoryDir = config.getString(ConfigurationKeys.GIT_MONITOR_REPO_DIR);
String branchName = config.getString(ConfigurationKeys.GIT_MONITOR_BRANCH_NAME);
this.pollingInterval = config.getInt(ConfigurationKeys.GIT_MONITOR_POLLING_INTERVAL);
this.folderName = config.getString(ConfigurationKeys.GIT_MONITOR_CONFIG_BASE_DIR);
boolean shouldCheckpointHashes = ConfigUtils.getBoolean(config, SHOULD_CHECKPOINT_HASHES, true);
PasswordManager passwordManager = PasswordManager.getInstance(ConfigUtils.configToState(config));
Either<CredentialsProvider, SshSessionFactory> providerSessionFactoryEither;
boolean isSshWithPublicKeyEnabled = ConfigUtils.getBoolean(config,
ConfigurationKeys.GIT_MONITOR_SSH_WITH_PUBLIC_KEY_ENABLED, false);
if (isSshWithPublicKeyEnabled) {
this.privateKeyPath = ConfigUtils.getString(config, ConfigurationKeys.GIT_MONITOR_SSH_PRIVATE_KEY_PATH,
null);//from w ww . jav a2 s . c o m
String privateKeyBase64Encoded = ConfigUtils.getString(config,
ConfigurationKeys.GIT_MONITOR_SSH_PRIVATE_KEY_BASE64_ENCODED, null);
if ((Strings.isNullOrEmpty(this.privateKeyPath))
&& ((Strings.isNullOrEmpty(privateKeyBase64Encoded)))) {
throw new RuntimeException("Path to private key or private key string must be provided");
}
if (!Strings.isNullOrEmpty(privateKeyBase64Encoded)) {
this.privateKey = Base64.decodeBase64(privateKeyBase64Encoded);
}
String passPhraseEnc = ConfigUtils.getString(config, ConfigurationKeys.GIT_MONITOR_SSH_PASSPHRASE,
null);
if (!Strings.isNullOrEmpty(passPhraseEnc)) {
this.passphrase = passwordManager.readPassword(passPhraseEnc);
}
providerSessionFactoryEither = Either.right(getSshSessionFactory());
this.isJschLoggerEnabled = ConfigUtils.getBoolean(config,
ConfigurationKeys.GIT_MONITOR_JSCH_LOGGER_ENABLED, false);
this.strictHostKeyCheckingEnabled = ConfigUtils.getBoolean(config,
ConfigurationKeys.GIT_MONITOR_SSH_STRICT_HOST_KEY_CHECKING_ENABLED, true);
this.knownHosts = ConfigUtils.getString(config, ConfigurationKeys.GIT_MONITOR_SSH_KNOWN_HOSTS, null);
this.knownHostsFile = ConfigUtils.getString(config, ConfigurationKeys.GIT_MONITOR_SSH_KNOWN_HOSTS_FILE,
null);
if (strictHostKeyCheckingEnabled && Strings.isNullOrEmpty(knownHostsFile)
&& Strings.isNullOrEmpty(knownHosts)) {
throw new RuntimeException(
"Either StrictHostKeyChecking should be disabled or a knownHostFile or knownHosts string must be provided");
}
} else { //Use CredentialsProvider
String username = ConfigUtils.getString(config, ConfigurationKeys.GIT_MONITOR_USERNAME, null);
String passwordEnc = ConfigUtils.getString(config, ConfigurationKeys.GIT_MONITOR_PASSWORD, null);
String password = null;
if (passwordEnc != null) {
password = passwordManager.readPassword(passwordEnc);
}
CredentialsProvider credentialsProvider;
//Instantiate CredentialsProvider if username/password is provided.
if (!Strings.isNullOrEmpty(username) && !Strings.isNullOrEmpty(password)) {
credentialsProvider = new UsernamePasswordCredentialsProvider(username, password);
} else {
credentialsProvider = CredentialsProvider.getDefault();
}
providerSessionFactoryEither = Either.left(credentialsProvider);
}
try {
this.gitRepo = new GitMonitoringService.GitRepository(repositoryUri, repositoryDir, branchName,
providerSessionFactoryEither, shouldCheckpointHashes);
} catch (GitAPIException | IOException e) {
throw new RuntimeException("Could not open git repository", e);
}
Path folderPath = new Path(this.repositoryDir, this.folderName);
this.javaPropsExtensions = Sets.newHashSet(config.getString(JAVA_PROPS_EXTENSIONS).split(","));
Set<String> hoconFileExtensions = Sets.newHashSet(config.getString(HOCON_FILE_EXTENSIONS).split(","));
try {
this.pullFileLoader = new PullFileLoader(folderPath,
FileSystem.get(URI.create(ConfigurationKeys.LOCAL_FS_URI), new Configuration()),
this.javaPropsExtensions, hoconFileExtensions);
} catch (IOException e) {
throw new RuntimeException("Could not create pull file loader", e);
}
this.scheduledExecutor = Executors.newSingleThreadScheduledExecutor(
ExecutorsUtils.newThreadFactory(Optional.of(log), Optional.of("FetchGitConfExecutor")));
}
From source file:org.eclipse.egit.core.EclipseSshSessionFactory.java
License:Open Source License
@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)); }//from w w w . ja va 2 s. com }
From source file:org.jboss.arquillian.ios.impl.WaxSim.java
License:Apache License
private File prepareBinary(String gitRemote, boolean verbose) throws IOException { File repository = null;// w w w. jav a2 s. co m try { repository = File.createTempFile("arq-ios", "waxsim"); repository.delete(); repository.mkdirs(); repository.deleteOnExit(); LOG.log(Level.INFO, "git clone <{0}>.", gitRemote); Git.cloneRepository().setDirectory(repository).setURI(gitRemote) .setCredentialsProvider(CredentialsProvider.getDefault()).call(); } catch (Exception e) { throw new IOException("Can't clone <" + gitRemote + ">", e); } LOG.info("building waxsim"); List<String> output = ProcessExecutor.execute(repository, "xcodebuild", "-project", "WaxSim.xcodeproj"); if (verbose) { for (String line : output) { System.out.println(line); } } return new File(repository, "build" + File.separator + "Release" + File.separator + "waxsim"); }
From source file:org.jboss.tools.openshift.express.internal.ui.command.TailFilesHandler.java
License:Open Source License
/** * Starting the tail process on the remote OpenShift Platform. This method * relies on the JGit SSH support (including JSch) to open a connection AND * execute a command in a single invocation. The connection establishement * requires an SSH key, and the passphrase is prompted to the user if * necessary.//from w ww . j av a 2 s . co m * @param sshUrl * @param filePattern * @param optionsAndFile * @param console * @return * @throws URISyntaxException * @throws IOException */ private TailServerLogWorker startTailProcess(final String sshUrl, final String optionsAndFile, final MessageConsole console) throws URISyntaxException, IOException { JSch.setLogger(new JschToEclipseLogger()); final SshSessionFactory sshSessionFactory = SshSessionFactory.getInstance(); URI uri = new URI(sshUrl); uri.getHost(); final URIish urish = new URIish().setHost(uri.getHost()).setUser(uri.getUserInfo()); RemoteSession remoteSession = sshSessionFactory.getSession(urish, CredentialsProvider.getDefault(), FS.DETECTED, 0); final String command = new TailCommandBuilder(optionsAndFile).build(); Logger.debug("ssh command to execute: " + command); Process process = remoteSession.exec(command, 0); return new TailServerLogWorker(console, process, remoteSession); }
From source file:org.kie.commons.java.nio.fs.jgit.JGitFileSystemProvider.java
License:Apache License
private CredentialsProvider buildCredential(final Map<String, ?> env) { if (env != null) { if (env.containsKey(USER_NAME)) { if (env.containsKey(PASSWORD)) { return new UsernamePasswordCredentialsProvider(env.get(USER_NAME).toString(), env.get(PASSWORD).toString()); }/*from w ww . j a v a2 s . c om*/ return new UsernamePasswordCredentialsProvider(env.get(USER_NAME).toString(), ""); } } return CredentialsProvider.getDefault(); }
From source file:org.kie.commons.java.nio.fs.jgit.JGitFileSystemTest.java
License:Apache License
@Test public void testOnlyLocalRoot() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystem fileSystem = new JGitFileSystem(fsProvider, null, git, "my-repo", CredentialsProvider.getDefault()); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.getRootDirectories()).hasSize(1); final Path root = fileSystem.getRootDirectories().iterator().next(); assertThat(root.toString()).isEqualTo("/"); assertThat(root.getRoot().toString()).isEqualTo("/"); }
From source file:org.kie.commons.java.nio.fs.jgit.JGitFileSystemTest.java
License:Apache License
@Test public void testRemoteRoot() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final File tempDir = createTempDirectory(); final Git git = Git.cloneRepository().setNoCheckout(false).setBare(true).setCloneAllBranches(true) .setURI(setupGit().getRepository().getDirectory().toString()).setDirectory(tempDir).call(); final JGitFileSystem fileSystem = new JGitFileSystem(fsProvider, null, git, "my-repo", CredentialsProvider.getDefault()); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.getRootDirectories()).hasSize(1); final Path root = fileSystem.getRootDirectories().iterator().next(); assertThat(root.toString()).isEqualTo("/"); assertThat(root.getRoot().toString()).isEqualTo("/"); }
From source file:org.kie.commons.java.nio.fs.jgit.JGitFileSystemTest.java
License:Apache License
@Test public void testProvider() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystem fileSystem = new JGitFileSystem(fsProvider, null, git, "my-repo", CredentialsProvider.getDefault()); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.provider()).isEqualTo(fsProvider); }
From source file:org.kie.commons.java.nio.fs.jgit.JGitFileSystemTest.java
License:Apache License
@Test(expected = IllegalStateException.class) public void testClose() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystem fileSystem = new JGitFileSystem(fsProvider, null, git, "my-repo", CredentialsProvider.getDefault()); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.isOpen()).isTrue(); assertThat(fileSystem.getFileStores()).isNotNull(); fileSystem.close();/*from ww w . ja va2 s . co m*/ assertThat(fileSystem.isOpen()).isFalse(); assertThat(fileSystem.getFileStores()).isNotNull(); }
From source file:org.kie.commons.java.nio.fs.jgit.JGitFileSystemTest.java
License:Apache License
@Test public void testSupportedFileAttributeViews() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystem fileSystem = new JGitFileSystem(fsProvider, null, git, "my-repo", CredentialsProvider.getDefault()); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.supportedFileAttributeViews()).isNotEmpty().hasSize(2).contains("basic", "version"); }