List of usage examples for org.eclipse.jgit.transport CredentialItem.Password clear
public abstract void clear();
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 w w. ja v a 2s . c o 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:org.jenkinsci.plugins.gitclient.jgit.PreemptiveAuthHttpClientConnection.java
License:Eclipse Distribution License
private HttpClient getClient() { if (client == null) { final HttpClientBuilder builder = HttpClientBuilder.create(); CredentialItem.Username u = new CredentialItem.Username(); CredentialItem.Password p = new CredentialItem.Password(); final URIish serviceUri; try {//from w w w . jav a2s . co m serviceUri = new URIish(urlStr); } catch (final URISyntaxException e) { throw new Error(e); } final HttpHost targetHost = new HttpHost(serviceUri.getHost(), serviceUri.getPort(), serviceUri.getScheme()); CredentialsProvider clientCredentialsProvider = new SystemDefaultCredentialsProvider(); if (credentialsProvider.supports(u, p)) { URIish uri = serviceUri; while (uri != null) { if (credentialsProvider.get(uri, u, p)) { final String userName = u.getValue(); final String password = new String(p.getValue()); p.clear(); final Credentials credentials = createNTCredentials(userName, password); final AuthScope authScope = new AuthScope(targetHost); clientCredentialsProvider = new BasicCredentialsProvider(); clientCredentialsProvider.setCredentials(authScope, credentials); break; } uri = goUp(uri); } } builder.setDefaultCredentialsProvider(clientCredentialsProvider); if (proxy != null && !Proxy.NO_PROXY.equals(proxy)) { isUsingProxy = true; configureProxy(builder, proxy); } final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom(); if (readTimeout != null) requestConfigBuilder.setSocketTimeout(readTimeout); if (timeout != null) requestConfigBuilder.setConnectTimeout(timeout); if (followRedirects != null) requestConfigBuilder.setRedirectsEnabled(followRedirects); requestConfigBuilder.setAuthenticationEnabled(true); final RequestConfig requestConfig = requestConfigBuilder.build(); builder.setDefaultRequestConfig(requestConfig); if (hostnameverifier != null) { builder.setSSLHostnameVerifier(hostnameverifier); } client = builder.build(); } return client; }