List of usage examples for org.apache.http.auth AuthScope getScheme
public String getScheme()
From source file:com.openshift.internal.restclient.authorization.OpenShiftCredentialsProvider.java
@Override public Credentials getCredentials(AuthScope authscope) { final String scheme = authscope.getScheme().toLowerCase(); if (creds.containsKey(scheme)) { return creds.get(scheme); }/*from w w w . j a va2 s . c o m*/ return provider.getCredentials(authscope); }
From source file:com.asakusafw.shafu.internal.core.net.ShafuCredentialsProvider.java
@Override public Credentials getCredentials(AuthScope authscope) { String host = authscope.getHost(); if (host != AuthScope.ANY_HOST) { Scope scope = new Scope(authscope.getScheme(), host, authscope.getPort(), authscope.getRealm()); for (IHttpCredentialsProvider provider : Activator.getExtensions().createHttpCredentialsProvider()) { try { IHttpCredentials creds = provider.find(scope); if (creds != null) { return new UsernamePasswordCredentials(creds.getUserName(), creds.getPassword()); }/*from w w w . j a va2 s . c o m*/ } catch (CoreException e) { LogUtil.log(e.getStatus()); } } } return super.getCredentials(authscope); }
From source file:org.opentravel.schemacompiler.repository.impl.NTLMSystemCredentialsProvider.java
public Credentials getCredentials(final AuthScope authscope) { Credentials credentials = super.getCredentials(authscope); if (AuthSchemes.NTLM.toUpperCase(Locale.ENGLISH).equals(authscope.getScheme())) { credentials = super.getCredentials(authscope); return traslateToNTLMCredentials(credentials); }/*from w w w.ja v a2s .co m*/ return credentials; }
From source file:com.nesscomputing.httpclient.factory.httpclient4.InternalCredentialsProvider.java
@Override public Credentials getCredentials(final AuthScope authScope) { for (final HttpClientAuthProvider authProvider : authProviders) { if (authProvider.acceptRequest(authScope.getScheme(), authScope.getHost(), authScope.getPort(), authScope.getRealm())) { return new Credentials() { @Override//ww w . jav a 2 s . c o m public Principal getUserPrincipal() { return new BasicUserPrincipal(authProvider.getUser()); } @Override public String getPassword() { return authProvider.getPassword(); } }; } } return null; }
From source file:com.mooregreatsoftware.gitprocess.lib.CredentialHelperCredentialsProvider.java
@Nullable @Override// ww w . j a v a 2 s . c o m @SuppressWarnings("override.return.invalid") public Credentials getCredentials(AuthScope authscope) { if (authscope == null) return null; @SuppressWarnings("argument.type.incompatible") URI uri = e(() -> new URI(authscope.getScheme(), null, authscope.getHost(), authscope.getPort(), null, null, null)); final String credentialHelper = remoteConfig.credentialHelper(uri); if (credentialHelper == null) return null; final String progName; if (credentialHelper.startsWith("/")) { progName = credentialHelper; } else { progName = "git-credential-" + credentialHelper; } return null; }
From source file:org.apache.taverna.activities.rest.RESTActivityCredentialsProvider.java
@Override public Credentials getCredentials(AuthScope authscope) { logger.info("Looking for credentials for: Host - " + authscope.getHost() + ";" + "Port - " + authscope.getPort() + ";" + "Realm - " + authscope.getRealm() + ";" + "Authentication scheme - " + authscope.getScheme()); // Ask the superclass first Credentials creds = super.getCredentials(authscope); if (creds != null) { /*// ww w. j a va 2 s. c o m * We have used setCredentials() on this class (for proxy host, * port, username,password) just before we invoked the http request, * which will then pick the proxy credentials up from here. */ return creds; } // Otherwise, ask Credential Manager if is can provide the credential String AUTHENTICATION_REQUEST_MSG = "This REST service requires authentication in " + authscope.getRealm(); try { UsernamePassword credentials = null; /* * if port is 80 - use HTTP, don't append port if port is 443 - use * HTTPS, don't append port any other port - append port + do 2 * tests: * * --- test HTTPS first has...() * --- if not there, do get...() for HTTP (which will save the thing) * * (save both these entries for HTTP + HTTPS if not there) */ // build the service URI back to front StringBuilder serviceURI = new StringBuilder(); serviceURI.insert(0, "/#" + URLEncoder.encode(authscope.getRealm(), "UTF-16")); if (authscope.getPort() != DEFAULT_HTTP_PORT && authscope.getPort() != DEFAULT_HTTPS_PORT) { // non-default port - add port name to the URI serviceURI.insert(0, ":" + authscope.getPort()); } serviceURI.insert(0, authscope.getHost()); serviceURI.insert(0, "://"); // now the URI is complete, apart from the protocol name if (authscope.getPort() == DEFAULT_HTTP_PORT || authscope.getPort() == DEFAULT_HTTPS_PORT) { // definitely HTTP or HTTPS serviceURI.insert(0, (authscope.getPort() == DEFAULT_HTTP_PORT ? HTTP_PROTOCOL : HTTPS_PROTOCOL)); // request credentials from CrendentialManager credentials = credentialManager.getUsernameAndPasswordForService(URI.create(serviceURI.toString()), true, AUTHENTICATION_REQUEST_MSG); } else { /* * non-default port - will need to try both HTTP and HTTPS; just * check (no pop-up will be shown) if credentials are there - * one protocol that matched will be used; if */ if (credentialManager .hasUsernamePasswordForService(URI.create(HTTPS_PROTOCOL + serviceURI.toString()))) { credentials = credentialManager.getUsernameAndPasswordForService( URI.create(HTTPS_PROTOCOL + serviceURI.toString()), true, AUTHENTICATION_REQUEST_MSG); } else if (credentialManager .hasUsernamePasswordForService(URI.create(HTTP_PROTOCOL + serviceURI.toString()))) { credentials = credentialManager.getUsernameAndPasswordForService( URI.create(HTTP_PROTOCOL + serviceURI.toString()), true, AUTHENTICATION_REQUEST_MSG); } else { /* * Neither of the two options succeeded, request details with a * popup for HTTP... */ credentials = credentialManager.getUsernameAndPasswordForService( URI.create(HTTP_PROTOCOL + serviceURI.toString()), true, AUTHENTICATION_REQUEST_MSG); /* * ...then save a second entry with HTTPS protocol (if the * user has chosen to save the credentials) */ if (credentials != null && credentials.isShouldSave()) { credentialManager.addUsernameAndPasswordForService(credentials, URI.create(HTTPS_PROTOCOL + serviceURI.toString())); } } } if (credentials != null) { logger.info("Credentials obtained successfully"); return new RESTActivityCredentials(credentials.getUsername(), credentials.getPasswordAsString()); } } catch (Exception e) { logger.error("Unexpected error while trying to obtain user's credential from CredentialManager", e); } // error or nothing was found logger.info("Credentials not found - the user must have refused to enter them."); return null; }
From source file:org.eclipse.ecf.internal.provider.filetransfer.httpclient4.HttpClientProxyCredentialProvider.java
public Credentials getCredentials(AuthScope authscope) { Trace.entering(Activator.PLUGIN_ID, DebugOptions.METHODS_ENTERING, HttpClientProxyCredentialProvider.class, "getCredentials " + authscope); //$NON-NLS-1$ // First check to see whether given authscope matches any authscope // already cached. Credentials result = matchCredentials(this.cachedCredentials, authscope); // If we have a match, return credentials if (result != null) return result; // If we don't have a match, first get ECF proxy, if any Proxy proxy = getECFProxy();/*from w w w. j a v a 2s. co m*/ if (proxy == null) return null; // Make sure that authscope and proxy host and port match if (!matchAuthScopeAndProxy(authscope, proxy)) return null; // Then match scheme, and get credentials from proxy (if it's scheme we know about) Credentials credentials = null; if ("ntlm".equalsIgnoreCase(authscope.getScheme())) { //$NON-NLS-1$ credentials = getNTLMCredentials(proxy); } else if ("basic".equalsIgnoreCase(authscope.getScheme()) || //$NON-NLS-1$ "digest".equalsIgnoreCase(authscope.getScheme())) { //$NON-NLS-1$ final String proxyUsername = proxy.getUsername(); final String proxyPassword = proxy.getPassword(); // If credentials present for proxy then we're done if (proxyUsername != null) { credentials = new UsernamePasswordCredentials(proxyUsername, proxyPassword); } } else if ("negotiate".equalsIgnoreCase(authscope.getScheme())) { //$NON-NLS-1$ Trace.trace(Activator.PLUGIN_ID, "SPNEGO is not supported, if you can contribute support, please do so."); //$NON-NLS-1$ } else { Trace.trace(Activator.PLUGIN_ID, "Unrecognized authentication scheme."); //$NON-NLS-1$ } // Put found credentials in cache for next time if (credentials != null) cachedCredentials.put(authscope, credentials); return credentials; }