List of usage examples for org.apache.http.auth AuthScope ANY_HOST
String ANY_HOST
To view the source code for org.apache.http.auth AuthScope ANY_HOST.
Click Source Link
From source file:org.apache.maven.wagon.providers.http.BasicAuthScopeTest.java
/** * Test AuthScope override for all values overridden with "ANY" *///from ww w . j av a2 s.c o m @Test public void testGetScopeAllAny() { BasicAuthScope scope = new BasicAuthScope(); scope.setHost("ANY"); scope.setPort("ANY"); scope.setRealm("ANY"); AuthScope authScope = scope.getScope("original.host.com", 3456); Assert.assertEquals(AuthScope.ANY_HOST, authScope.getHost()); Assert.assertEquals(AuthScope.ANY_PORT, authScope.getPort()); Assert.assertEquals(AuthScope.ANY_REALM, authScope.getRealm()); }
From source file:org.cerberus.util.HTTPSession.java
/** * Start a HTTP Session with authorisation * * @param username/*w ww .ja v a 2s .c o m*/ * @param password */ public void startSession(String username, String password) { // Create your httpclient client = new DefaultHttpClient(); client.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true); // Then provide the right credentials client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password)); // Generate BASIC scheme object and stick it to the execution context basicAuth = new BasicScheme(); context = new BasicHttpContext(); context.setAttribute("preemptive-auth", basicAuth); // Add as the first (because of the zero) request interceptor // It will first intercept the request and preemptively initialize the authentication scheme if there is not client.addRequestInterceptor(new PreemptiveAuth(), 0); }
From source file:org.jugvale.peoplemanagement.client.service.RESTPersonService.java
private void createClient() { Credentials credentials = new UsernamePasswordCredentials(username, password); DefaultHttpClient httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager()); httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), credentials);/*from w ww . j av a 2s . c om*/ client = new ResteasyClientBuilder().httpEngine(new ApacheHttpClient4Engine(httpClient)).build(); }
From source file:org.mule.jenkins.Helper.java
public void setClientInfo() { client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(user, password)); BasicScheme basicAuth = new BasicScheme(); context.setAttribute("preemptive-auth", basicAuth); client.addRequestInterceptor(new PreemptiveAuth(), 0); }
From source file:org.dmfs.android.authenticator.handlers.BasicHttpClientAuthenticationHandler.java
@Override public void authenticate(AbstractHttpClient client) { // just set the credentials assuming that proper authentication schemes are registered with the AbstractHttpClient. CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, mAuthToken.getRealm()), new UsernamePasswordCredentials(mAuthToken.getUsername(), mAuthToken.getPassword())); client.setCredentialsProvider(credsProvider); }
From source file:org.gradle.internal.resource.transport.http.HttpClientConfigurer.java
private void configureCredentials(DefaultHttpClient httpClient, PasswordCredentials credentials) { String username = credentials.getUsername(); if (username != null && username.length() > 0) { useCredentials(httpClient, credentials, AuthScope.ANY_HOST, AuthScope.ANY_PORT); // Use preemptive authorisation if no other authorisation has been established httpClient.addRequestInterceptor(new PreemptiveAuth(new BasicScheme()), 0); }/* ww w . ja v a 2 s .co m*/ }
From source file:org.apache.maven.wagon.providers.http.BasicAuthScope.java
/** * Create an authScope given the /repository/host and /repository/password * and the /server/basicAuth or /server/proxyBasicAuth host, port and realm * settings. The basicAuth setting should override the repository settings * host and/or port if host, port or realm is set to "ANY". * <p/>//from ww w . j a va 2s .c o m * Realm can also be set to a specific string and will be set if * /server/basicAuthentication/realm is non-null * * @param host The server setting's /server/host value * @param port The server setting's /server/port value * @return */ public AuthScope getScope(String host, int port) { if (getHost() != null // && "ANY".compareTo(getHost()) == 0 // && getPort() != null // && "ANY".compareTo(getPort()) == 0 // && getRealm() != null // && "ANY".compareTo(getRealm()) == 0) { return AuthScope.ANY; } String scopeHost = host; if (getHost() != null) { if ("ANY".compareTo(getHost()) == 0) { scopeHost = AuthScope.ANY_HOST; } else { scopeHost = getHost(); } } int scopePort = port > -1 ? port : AuthScope.ANY_PORT; // -1 for server/port settings does this, but providing an override here // in // the BasicAuthScope config if (getPort() != null) { if ("ANY".compareTo(getPort()) == 0) { scopePort = AuthScope.ANY_PORT; } else { scopePort = Integer.parseInt(getPort()); } } String scopeRealm = AuthScope.ANY_REALM; if (getRealm() != null) { if ("ANY".compareTo(getRealm()) != 0) { scopeRealm = getRealm(); } else { scopeRealm = getRealm(); } } return new AuthScope(scopeHost, scopePort, scopeRealm); }
From source file:pydio.sdk.java.http.AjxpHttpClient.java
public void refreshCredentials(UsernamePasswordCredentials credentials) { this.getCredentialsProvider().setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), credentials); }
From source file:com.cognifide.qa.bb.provider.http.HttpClientProvider.java
private AuthScope getAuthScope(String urlString) { String host = AuthScope.ANY_HOST; int port = AuthScope.ANY_PORT; try {/*from ww w .j ava2s.co m*/ URI uri = new URI(urlString); host = StringUtils.defaultString(uri.getHost(), AuthScope.ANY_HOST); port = uri.getPort(); } catch (URISyntaxException e) { LOG.error("Could not parse '{}' as a valid URI", urlString, e); } return new AuthScope(host, port); }
From source file:org.opennms.opennms.pris.plugins.defaults.source.HttpRequisitionSource.java
@Override public Object dump() throws Exception { Requisition requisition = null;//w w w . j a v a 2 s. c o m if (getUrl() != null) { HttpClientBuilder builder = HttpClientBuilder.create(); // If username and password was found, inject the credentials if (getUserName() != null && getPassword() != null) { CredentialsProvider provider = new BasicCredentialsProvider(); // Create the authentication scope AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM); // Create credential pair UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(getUserName(), getPassword()); // Inject the credentials provider.setCredentials(scope, credentials); // Set the default credentials provider builder.setDefaultCredentialsProvider(provider); } HttpClient client = builder.build(); HttpGet request = new HttpGet(getUrl()); HttpResponse response = client.execute(request); try { BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); JAXBContext jaxbContext = JAXBContext.newInstance(Requisition.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); requisition = (Requisition) jaxbUnmarshaller.unmarshal(bufferedReader); } catch (JAXBException e) { LOGGER.error("The response did not contain a valid requisition as xml.", e); } LOGGER.debug("Got Requisition {}", requisition); } else { LOGGER.error("Parameter requisition.url is missing in requisition.properties"); } if (requisition == null) { LOGGER.error("Requisition is null for unknown reasons"); return null; } LOGGER.info("HttpRequisitionSource delivered for requisition '{}'", requisition.getNodes().size()); return requisition; }