use of org.apache.commons.httpclient.auth.AuthScope in project lobcder by skoulouzis.
the class WebDAVSecurityTest method setUpClass.
@BeforeClass
public static void setUpClass() throws Exception {
String propBasePath = "etc" + File.separator + "test.properties";
Properties prop = TestSettings.getTestProperties(propBasePath);
String testURL = prop.getProperty("webdav.test.url");
// Some problem with the pom.xml. The properties are set but System.getProperty gets null
if (testURL == null) {
testURL = "http://localhost:8080/lobcder-1.0-SNAPSHOT/";
}
assertTrue(testURL != null);
if (!testURL.endsWith("/")) {
testURL = testURL + "/";
}
uri = URI.create(testURL);
root = uri.toASCIIString();
if (!root.endsWith("/")) {
root += "/";
}
username1 = prop.getProperty(("webdav.test.username1"), "");
if (username1 == null) {
username1 = "user1";
}
assertTrue(username1 != null);
password1 = prop.getProperty(("webdav.test.password1"), "");
if (password1 == null) {
password1 = "passwd1";
}
assertTrue(password1 != null);
username2 = prop.getProperty(("webdav.test.username2"), "");
if (username2 == null) {
username2 = "user2";
}
assertTrue(username2 != null);
password2 = prop.getProperty(("webdav.test.password2"), "");
if (password2 == null) {
password2 = "passwd2";
}
assertTrue(password2 != null);
client1 = new HttpClient();
assertNotNull(uri.getHost());
assertNotNull(uri.getPort());
assertNotNull(client1);
int port = uri.getPort();
if (port == -1) {
port = 443;
}
ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
Protocol https = new Protocol("https", socketFactory, port);
Protocol.registerProtocol("https", https);
client1.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username1, password1));
client2 = new HttpClient();
assertNotNull(uri.getHost());
assertNotNull(uri.getPort());
assertNotNull(client2);
client2.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username2, password2));
// acMgr = getAccessControlManager(superuser);
}
use of org.apache.commons.httpclient.auth.AuthScope in project maven-plugins by apache.
the class ClassicJiraDownloader method prepareBasicAuthentication.
/**
* Check and prepare for basic authentication.
*
* @param client The client to prepare
*/
private void prepareBasicAuthentication(HttpClient client) {
if ((webUser != null) && (webUser.length() > 0)) {
client.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials(webUser, webPassword);
getLog().debug("Using username: " + webUser + " for Basic Authentication.");
client.getState().setCredentials(new AuthScope(null, AuthScope.ANY_PORT, null, AuthScope.ANY_SCHEME), defaultcreds);
}
}
use of org.apache.commons.httpclient.auth.AuthScope in project maven-plugins by apache.
the class ClassicJiraDownloader method determineProxy.
/**
* Setup proxy access if we have to.
*
* @param client the HttpClient
*/
private void determineProxy(String jiraUrl, HttpClient client) {
// see whether there is any proxy defined in maven
getProxyInfo(jiraUrl);
if (proxyHost != null) {
client.getHostConfiguration().setProxy(proxyHost, proxyPort);
getLog().debug("Using proxy: " + proxyHost + " at port " + proxyPort);
if (proxyUser != null) {
getLog().debug("Using proxy user: " + proxyUser);
client.getState().setProxyCredentials(new AuthScope(null, AuthScope.ANY_PORT, null, AuthScope.ANY_SCHEME), new UsernamePasswordCredentials(proxyUser, proxyPass));
}
}
}
use of org.apache.commons.httpclient.auth.AuthScope in project zaproxy by zaproxy.
the class HttpMethodDirector method authenticateProxy.
private void authenticateProxy(final HttpMethod method) throws AuthenticationException {
// Clean up existing authentication headers
boolean userDefinedAuthenticationHeaders = !cleanAuthHeaders(method, PROXY_AUTH_RESP);
if (userDefinedAuthenticationHeaders) {
if (LOG.isDebugEnabled()) {
LOG.debug("User defined '" + PROXY_AUTH_RESP + "' headers present in the request.");
}
}
AuthState authstate = method.getProxyAuthState();
AuthScheme authscheme = authstate.getAuthScheme();
if (authscheme == null) {
return;
}
if (authstate.isAuthRequested() || !authscheme.isConnectionBased()) {
AuthScope authscope = new AuthScope(conn.getProxyHost(), conn.getProxyPort(), authscheme.getRealm(), authscheme.getSchemeName());
if (LOG.isDebugEnabled()) {
LOG.debug("Authenticating with " + authscope);
}
Credentials credentials = this.state.getProxyCredentials(authscope);
if (credentials != null) {
if (userDefinedAuthenticationHeaders) {
if (!method.getParams().getBooleanParameter(PARAM_REMOVE_USER_DEFINED_AUTH_HEADERS, false)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Ignoring proxy authentication, user defined '" + PROXY_AUTH_RESP + "' headers present in the request.");
}
return;
}
method.removeRequestHeader(PROXY_AUTH_RESP);
if (LOG.isDebugEnabled()) {
LOG.debug("Removed user defined '" + PROXY_AUTH_RESP + "' headers.");
}
}
String authstring = authscheme.authenticate(credentials, method);
if (authstring != null) {
method.addRequestHeader(new Header(PROXY_AUTH_RESP, authstring, true));
}
} else {
if (LOG.isWarnEnabled()) {
LOG.warn("Required proxy credentials not available for " + authscope);
if (method.getProxyAuthState().isPreemptive()) {
LOG.warn("Preemptive authentication requested but no default " + "proxy credentials available");
}
}
}
}
}
use of org.apache.commons.httpclient.auth.AuthScope in project zaproxy by zaproxy.
the class HttpMethodDirector method processProxyAuthChallenge.
private boolean processProxyAuthChallenge(final HttpMethod method) throws MalformedChallengeException, AuthenticationException {
AuthState authstate = method.getProxyAuthState();
Map<?, ?> proxyChallenges = AuthChallengeParser.parseChallenges(method.getResponseHeaders(PROXY_AUTH_CHALLENGE));
if (proxyChallenges.isEmpty()) {
LOG.debug("Proxy authentication challenge(s) not found");
return false;
}
AuthScheme authscheme = null;
try {
authscheme = this.authProcessor.processChallenge(authstate, proxyChallenges);
} catch (AuthChallengeException e) {
if (LOG.isWarnEnabled()) {
LOG.warn(e.getMessage());
}
}
if (authscheme == null) {
return false;
}
AuthScope authscope = new AuthScope(conn.getProxyHost(), conn.getProxyPort(), authscheme.getRealm(), authscheme.getSchemeName());
if (LOG.isDebugEnabled()) {
LOG.debug("Proxy authentication scope: " + authscope);
}
if (authstate.isAuthAttempted() && authscheme.isComplete()) {
// Already tried and failed
Credentials credentials = promptForProxyCredentials(authscheme, method.getParams(), authscope);
if (credentials == null) {
if (LOG.isInfoEnabled()) {
LOG.info("Failure authenticating with " + authscope);
}
return false;
} else {
return true;
}
} else {
authstate.setAuthAttempted(true);
Credentials credentials = this.state.getProxyCredentials(authscope);
if (credentials == null) {
credentials = promptForProxyCredentials(authscheme, method.getParams(), authscope);
}
if (credentials == null) {
if (LOG.isInfoEnabled()) {
LOG.info("No credentials available for " + authscope);
}
return false;
} else {
return true;
}
}
}
Aggregations