List of usage examples for org.eclipse.jgit.transport URIish getUser
public String getUser()
From source file:com.genuitec.eclipse.gerrit.tools.internal.gps.model.GpsGitRepositoriesConfig.java
License:Open Source License
private String getRepoUrl(Repository repository) { try {/* w w w.j a va 2 s . c o m*/ RemoteConfig config = new RemoteConfig(repository.getConfig(), "origin"); //$NON-NLS-1$ for (URIish uri : config.getURIs()) { if (uri.getUser() != null) { return uri.setUser("user-name").toASCIIString(); //$NON-NLS-1$ } return uri.toASCIIString(); } } catch (Exception e) { GerritToolsPlugin.getDefault().log(e); } return null; }
From source file:com.google.gerrit.server.git.SecureCredentialsProvider.java
License:Apache License
@Override public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem { String username = uri.getUser(); if (username == null) { username = cfgUser;/*from w ww. jav a 2 s . com*/ } if (username == null) { return false; } String password = uri.getPass(); if (password == null) { password = cfgPass; } if (password == null) { return false; } for (CredentialItem i : items) { if (i instanceof CredentialItem.Username) { ((CredentialItem.Username) i).setValue(username); } else if (i instanceof CredentialItem.Password) { ((CredentialItem.Password) i).setValue(password.toCharArray()); } else { throw new UnsupportedCredentialItem(uri, i.getPromptText()); } } return true; }
From source file:com.googlesource.gerrit.plugins.github.git.GitHubRepository.java
License:Apache License
public CredentialsProvider getCredentialsProvider() { return new CredentialsProvider() { @Override//from ww w. j av a 2 s. c o m public boolean supports(CredentialItem... items) { for (CredentialItem i : items) { if (i instanceof CredentialItem.Username) { continue; } else if (i instanceof CredentialItem.Password) { continue; } else { return false; } } return true; } @Override public boolean isInteractive() { return false; } @Override public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem { String user = uri.getUser(); if (user == null) { user = GitHubRepository.this.username; } if (user == null) { return false; } String passwd = GitHubRepository.this.password; if (passwd == null) { return false; } for (CredentialItem i : items) { if (i instanceof CredentialItem.Username) { ((CredentialItem.Username) i).setValue(user); } else if (i instanceof CredentialItem.Password) { ((CredentialItem.Password) i).setValue(passwd.toCharArray()); } else { throw new UnsupportedCredentialItem(uri, i.getPromptText()); } } return true; } }; }
From source file:com.madgag.agit.GUICredentialsProvider.java
License:Open Source License
private void handle(URIish uri, CredentialItem.StringType ci) { if (ci instanceof CredentialItem.Username && uri.getUser() != null) { ci.setValue(uri.getUser());/*ww w .j a va2 s . co m*/ } else { ci.setValue(blockingPrompt.request(prompt(String.class, uiNotificationFor(ci)))); } }
From source file:it.com.atlassian.labs.speakeasy.util.jgit.HttpAuthMethod.java
License:Eclipse Distribution License
/** * Update this method with the credentials from the URIish. * * @param uri// w ww . j a v a 2s .co m * the URI used to create the connection. * @param credentialsProvider * the credentials provider, or null. If provided, * {@link URIish#getPass() credentials in the URI} are ignored. * * @return true if the authentication method is able to provide * authorization for the given URI */ boolean authorize(URIish uri, CredentialsProvider credentialsProvider) { String username; String password; if (credentialsProvider != null) { CredentialItem.Username u = new CredentialItem.Username(); CredentialItem.Password p = new CredentialItem.Password(); if (credentialsProvider.supports(u, p) && credentialsProvider.get(uri, u, p)) { username = u.getValue(); password = new String(p.getValue()); p.clear(); } else return false; } else { username = uri.getUser(); password = uri.getPass(); } if (username != null) { authorize(username, password); return true; } return false; }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.agent.UpdaterImpl.java
License:Apache License
private boolean isRequireAuth(@NotNull String url) { try {//from ww w. j a v a 2 s.c om URIish uri = new URIish(url); String scheme = uri.getScheme(); if (scheme == null || "git".equals(scheme)) //no auth for anonymous protocol and for local repositories return false; String user = uri.getUser(); if (user != null) //respect a user specified in config return false; return true; } catch (URISyntaxException e) { return false; } }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.AuthSettings.java
License:Apache License
private String readUsername(Map<String, String> properties) { if (myAuthMethod == AuthenticationMethod.ANONYMOUS) return null; String url = properties.get(Constants.FETCH_URL); String username = null;// w ww . ja v a 2 s .com try { URIish u = new URIish(url); username = u.getUser(); } catch (URISyntaxException e) { //ignore } String explicitUsername = properties.get(Constants.USERNAME); if (explicitUsername != null) username = explicitUsername; return username; }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.AuthSettings.java
License:Apache License
public CredentialsProvider toCredentialsProvider() { return new CredentialsProvider() { @Override/*from ww w. j av a2s . com*/ public boolean isInteractive() { return false; } @Override public boolean supports(CredentialItem... items) { for (CredentialItem i : items) { if (i instanceof CredentialItem.Username && myAuthMethod != AuthenticationMethod.ANONYMOUS) continue; if (i instanceof CredentialItem.Password && myAuthMethod == AuthenticationMethod.PASSWORD && myPassword != null) continue; return false; } return true; } @Override public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem { boolean allValuesSupplied = true; for (CredentialItem i : items) { if (i instanceof CredentialItem.Username) { allValuesSupplied &= supplyUsername(uri, (CredentialItem.Username) i); } else if (i instanceof CredentialItem.Password) { allValuesSupplied &= supplyPassword((CredentialItem.Password) i); } else if (i instanceof CredentialItem.StringType && "Passphrase for ".equals(i.getPromptText())) { //we provider a passphrase to the jsch, if we are asked about it //then the original passphrase was incorrect throw new WrongPassphraseException(uri); } else { throw new UnsupportedCredentialItem(uri, i.getPromptText()); } } return allValuesSupplied; } private boolean supplyUsername(URIish uri, CredentialItem.Username item) { if (myAuthMethod == AuthenticationMethod.ANONYMOUS) return false; String username = myUserName != null ? myUserName : uri.getUser(); if (username == null) return false; item.setValue(username); return true; } private boolean supplyPassword(CredentialItem.Password item) { if (myAuthMethod != AuthenticationMethod.PASSWORD) return false; if (myPassword == null) return false; item.setValue(myPassword.toCharArray()); return true; } }; }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitUrlSupport.java
License:Apache License
@NotNull private Map<String, String> getAuthSettings(@NotNull VcsUrl url, @NotNull URIish uri) { Map<String, String> authSettings = new HashMap<String, String>(); authSettings.put(Constants.AUTH_METHOD, getAuthMethod(url, uri).toString()); Credentials credentials = url.getCredentials(); if (credentials != null) { authSettings.put(Constants.USERNAME, credentials.getUsername()); authSettings.put(Constants.PASSWORD, credentials.getPassword()); } else {/* w ww . jav a 2s . c o m*/ authSettings.put(Constants.USERNAME, uri.getUser()); } return authSettings; }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitUtils.java
License:Apache License
public static boolean isAnonymousGitWithUsername(@NotNull URIish uri) { return "git".equals(uri.getScheme()) && uri.getUser() != null; }