use of org.apache.http.auth.AuthScope in project wildfly by wildfly.
the class SAML2GlobalSSOandLogoutTestCase method testSSOandGLO.
/**
* Tests PicketLink IdP to handle Single Sing On and Global Logout
*
* @throws Exception
*/
@Test
public void testSSOandGLO() throws Exception {
final DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.setRedirectStrategy(Utils.REDIRECT_STRATEGY);
try {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(PicketLinkTestBase.ANIL, PicketLinkTestBase.ANIL);
httpClient.getCredentialsProvider().setCredentials(new AuthScope(null, idpUrl.getPort()), credentials);
String response = PicketLinkTestBase.makeCall(sp1Url, httpClient, 200);
assertTrue("SP1 index page was not reached", response.contains("Welcome to SP1"));
//now we change credentials so when they are requested again we get 403 - Forbidden
credentials = new UsernamePasswordCredentials(PicketLinkTestBase.MARCUS, PicketLinkTestBase.MARCUS);
httpClient.getCredentialsProvider().setCredentials(new AuthScope(null, idpUrl.getPort()), credentials);
response = PicketLinkTestBase.makeCall(sp2Url, httpClient, 200);
assertTrue("SP2 index page was not reached", response.contains("Welcome to SP2"));
URL logoutUrl = new URL(sp1Url.toExternalForm() + LOGOUT_PARAMETER);
response = PicketLinkTestBase.makeCall(logoutUrl, httpClient, 200);
assertTrue("Logout page was not reached", response.contains("Logout"));
PicketLinkTestBase.makeCall(sp1Url, httpClient, 403);
PicketLinkTestBase.makeCall(sp2Url, httpClient, 403);
} finally {
httpClient.getConnectionManager().shutdown();
}
}
use of org.apache.http.auth.AuthScope in project cloudstack by apache.
the class NexentaNmsClient method getClient.
protected DefaultHttpClient getClient() {
if (httpClient == null) {
if (nmsUrl.getSchema().equalsIgnoreCase("http")) {
httpClient = getHttpClient();
} else {
httpClient = getHttpsClient();
}
AuthScope authScope = new AuthScope(nmsUrl.getHost(), nmsUrl.getPort(), AuthScope.ANY_SCHEME, "basic");
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(nmsUrl.getUsername(), nmsUrl.getPassword());
httpClient.getCredentialsProvider().setCredentials(authScope, credentials);
}
return httpClient;
}
use of org.apache.http.auth.AuthScope in project apex-core by apache.
the class WebServicesClient method setupUserPassAuthScheme.
private static void setupUserPassAuthScheme(AuthScheme scheme, String httpScheme, AuthSchemeProvider provider, ConfigProvider configuration) {
String username = configuration.getProperty(scheme, "username");
String password = configuration.getProperty(scheme, "password");
if ((username != null) && (password != null)) {
LOG.info("Setting up scheme {}", scheme);
AuthScope authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, httpScheme);
Credentials credentials = new UsernamePasswordCredentials(username, password);
setupHttpAuthScheme(httpScheme, provider, authScope, credentials);
} else if ((username != null) || (password != null)) {
LOG.warn("Not setting up scheme {}, missing credentials {}", scheme, (username == null) ? "username" : "password");
}
}
use of org.apache.http.auth.AuthScope in project indy by Commonjava.
the class AbstractHttproxFunctionalTest method proxyContext.
protected HttpClientContext proxyContext(final String user, final String pass) {
final CredentialsProvider creds = new BasicCredentialsProvider();
creds.setCredentials(new AuthScope(HOST, proxyPort), new UsernamePasswordCredentials(user, pass));
final HttpClientContext ctx = HttpClientContext.create();
ctx.setCredentialsProvider(creds);
return ctx;
}
use of org.apache.http.auth.AuthScope in project stanbol by apache.
the class StanbolTestBase method waitForServerReady.
@Before
public void waitForServerReady() throws Exception {
log.debug("> before {}#waitForServerReady()", getClass().getSimpleName());
// initialize instance request builder and HTTP client
builder = new RequestBuilder(serverBaseUrl);
//TODO:user name and pwd
String credentials = getCredentials();
if (credentials != null && !credentials.isEmpty()) {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(HttpHost.create(serverBaseUrl)), new UsernamePasswordCredentials(credentials));
httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
} else {
httpClient = HttpClients.createDefault();
}
executor = new RequestExecutor(httpClient);
if (serverReady) {
log.debug(" ... server already marked as ready!");
return;
}
// Timeout for readiness test
final String sec = System.getProperty(SERVER_READY_TIMEOUT_PROP);
final int timeoutSec = sec == null ? 60 : Integer.valueOf(sec);
log.info("Will wait up to " + timeoutSec + " seconds for server to become ready");
final long endTime = System.currentTimeMillis() + timeoutSec * 1000L;
// Get the list of paths to test and expected content regexps
final List<String> testPaths = new ArrayList<String>();
final TreeSet<Object> propertyNames = new TreeSet<Object>();
propertyNames.addAll(System.getProperties().keySet());
for (Object o : propertyNames) {
final String key = (String) o;
if (key.startsWith(SERVER_READY_PROP_PREFIX)) {
testPaths.add(System.getProperty(key));
}
}
// Consider the server ready if it responds to a GET on each of
// our configured request paths with a 200 result and content
// that matches the regexp supplied with the path
long sleepTime = 100;
readyLoop: while (!serverReady && System.currentTimeMillis() < endTime) {
// Wait a bit between checks, to let the server come up
Thread.sleep(sleepTime);
sleepTime = Math.min(5000L, sleepTime * 2);
// A test path is in the form path:substring or just path, in which case
// we don't check that the content contains the substring
log.debug(" - check serverReady Paths");
for (String p : testPaths) {
final String[] s = p.split(":");
final String path = s[0];
final String substring = (s.length > 0 ? s[1] : null);
final String url = serverBaseUrl + path;
log.debug(" > url: {}", url);
log.debug(" > content: {}", substring);
final HttpGet get = new HttpGet(url);
//authenticate as admin with password admin
get.setHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
for (int i = 2; i + 1 < s.length; i = i + 2) {
log.debug(" > header: {}:{}", s[i], s[i + 1]);
if (s[i] != null && !s[i].isEmpty() && s[i + 1] != null && !s[i + 1].isEmpty()) {
get.setHeader(s[i], s[i + 1]);
}
}
CloseableHttpResponse response = null;
HttpEntity entity = null;
try {
log.debug(" > execute: {}", get);
response = httpClient.execute(get);
log.debug(" > response: {}", response);
entity = response.getEntity();
final int status = response.getStatusLine().getStatusCode();
if (status != 200) {
log.info("Got {} at {} - will retry", status, url);
continue readyLoop;
} else {
log.debug("Got {} at {} - will retry", status, url);
}
if (substring != null) {
if (entity == null) {
log.info("No entity returned for {} - will retry", url);
continue readyLoop;
}
final String content = EntityUtils.toString(entity);
if (!content.contains(substring)) {
log.info("Returned content for {} does not contain " + "{} - will retry", url, substring);
continue readyLoop;
}
}
} catch (HttpHostConnectException e) {
log.info("Got HttpHostConnectException at " + url + " - will retry");
continue readyLoop;
} finally {
EntityUtils.consumeQuietly(entity);
if (response != null) {
response.close();
}
}
}
serverReady = true;
log.info("Got expected content for all configured requests, server is ready");
}
if (!serverReady) {
throw new Exception("Server not ready after " + timeoutSec + " seconds");
}
}
Aggregations