use of org.apache.http.auth.AuthScope in project platform_external_apache-http by android.
the class BasicCredentialsProvider method matchCredentials.
/**
* Find matching {@link Credentials credentials} for the given authentication scope.
*
* @param map the credentials hash map
* @param authscope the {@link AuthScope authentication scope}
* @return the credentials
*
*/
private static Credentials matchCredentials(final HashMap<AuthScope, Credentials> map, final AuthScope authscope) {
// see if we get a direct hit
Credentials creds = map.get(authscope);
if (creds == null) {
// Nope.
// Do a full scan
int bestMatchFactor = -1;
AuthScope bestMatch = null;
for (AuthScope current : map.keySet()) {
int factor = authscope.match(current);
if (factor > bestMatchFactor) {
bestMatchFactor = factor;
bestMatch = current;
}
}
if (bestMatch != null) {
creds = map.get(bestMatch);
}
}
return creds;
}
use of org.apache.http.auth.AuthScope in project jmeter by apache.
the class AuthManager method setupCredentials.
/**
* Configure credentials and auth scheme on client if an authorization is
* available for url
* @param client {@link HttpClient}
* @param url URL to test
* @param credentialsProvider {@link CredentialsProvider}
* @param localHost host running JMeter
*/
public void setupCredentials(HttpClient client, URL url, CredentialsProvider credentialsProvider, String localHost) {
Authorization auth = getAuthForURL(url);
if (auth != null) {
String username = auth.getUser();
String realm = auth.getRealm();
String domain = auth.getDomain();
if (log.isDebugEnabled()) {
log.debug(username + " > D=" + domain + " R=" + realm + " M=" + auth.getMechanism());
}
if (Mechanism.KERBEROS.equals(auth.getMechanism())) {
((AbstractHttpClient) client).getAuthSchemes().register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(isStripPort(url)));
credentialsProvider.setCredentials(new AuthScope(null, -1, null), USE_JAAS_CREDENTIALS);
} else {
credentialsProvider.setCredentials(new AuthScope(url.getHost(), url.getPort(), realm.length() == 0 ? null : realm), new NTCredentials(username, auth.getPass(), localHost, domain));
}
}
}
use of org.apache.http.auth.AuthScope in project jena by apache.
the class TestAuth method withCreds.
private static HttpClient withCreds(URI scope, String uname, String password) {
BasicCredentialsProvider credsProv = new BasicCredentialsProvider();
credsProv.setCredentials(new AuthScope(scope.getHost(), scope.getPort()), new UsernamePasswordCredentials(uname, password));
return HttpClients.custom().setDefaultCredentialsProvider(credsProv).build();
}
use of org.apache.http.auth.AuthScope in project jena by apache.
the class TestAuth method query_with_auth_07.
@Test(expected = QueryExceptionHTTP.class)
public void query_with_auth_07() throws URISyntaxException {
QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
// Auth credentials for valid user with correct password but scoped to
// wrong URI
qe.setClient(withBasicAuth(new AuthScope("example", authPort), "allowed", "password"));
qe.execAsk();
}
use of org.apache.http.auth.AuthScope in project jena by apache.
the class TestAuth method query_with_auth_08.
@Test
public void query_with_auth_08() throws URISyntaxException {
QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
// Auth credentials for valid user with correct password and scoped to
// correct URI
qe.setClient(withBasicAuth(new AuthScope("localhost", authPort), "allowed", "password"));
Assert.assertTrue(qe.execAsk());
}
Aggregations