use of org.apache.commons.httpclient.HttpState in project zm-mailbox by Zimbra.
the class TestCookieReuse method testReuseAdminCookieWithCsrf.
/**
* Verify that we CAN make an admin GET request by reusing a valid csrf-enabled cookie
*/
@Test
public void testReuseAdminCookieWithCsrf() throws Exception {
AuthToken at = AuthProvider.getAdminAuthToken();
at.setCsrfTokenEnabled(true);
int port = 7071;
try {
port = Provisioning.getInstance().getLocalServer().getIntAttr(Provisioning.A_zimbraAdminPort, 0);
} catch (ServiceException e) {
ZimbraLog.test.error("Unable to get admin SOAP port", e);
}
String host = Provisioning.getInstance().getLocalServer().getName();
String getServerConfigURL = "https://localhost:" + port + "/service/collectconfig/?host=" + host;
HttpClient eve = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
HttpState state = new HttpState();
at.encode(state, true, "localhost");
eve.setState(state);
GetMethod get = new GetMethod(getServerConfigURL);
int statusCode = HttpClientUtil.executeMethod(eve, get);
Assert.assertEquals("This request should succeed. Getting status code " + statusCode, HttpStatus.SC_OK, statusCode);
}
use of org.apache.commons.httpclient.HttpState in project zm-mailbox by Zimbra.
the class ZMailbox method getHttpClient.
public HttpClient getHttpClient(URI uri) {
boolean isAdmin = uri.getPort() == LC.zimbra_admin_service_port.intValue();
HttpState initialState = HttpClientUtil.newHttpState(getAuthToken(), uri.getHost(), isAdmin);
HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
client.setState(initialState);
client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
return client;
}
use of org.apache.commons.httpclient.HttpState in project maven-plugins by apache.
the class ClassicJiraDownloader method doExecute.
/**
* Execute the query on the JIRA server.
*
* @throws Exception on error
*/
public void doExecute() throws Exception {
try {
HttpClient client = new HttpClient();
// MCHANGES-89 Allow circular redirects
HttpClientParams clientParams = client.getParams();
clientParams.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
// MCHANGES-237
clientParams.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
HttpState state = new HttpState();
HostConfiguration hc = new HostConfiguration();
client.setHostConfiguration(hc);
client.setState(state);
String baseUrl = JiraHelper.getBaseUrl(project.getIssueManagement().getUrl());
getLog().debug("JIRA lives at: " + baseUrl);
// Here we only need the host part of the URL
determineProxy(baseUrl, client);
prepareBasicAuthentication(client);
boolean jiraAuthenticationSuccessful = false;
if (isJiraAuthenticationConfigured()) {
// Here we only need the parts up to and including the host part of the URL
jiraAuthenticationSuccessful = doJiraAuthentication(client, baseUrl);
}
if ((isJiraAuthenticationConfigured() && jiraAuthenticationSuccessful) || !isJiraAuthenticationConfigured()) {
String fullUrl;
if (useJql) {
fullUrl = getJqlQueryURL();
} else {
fullUrl = getParameterBasedQueryURL(client);
}
if (log.isDebugEnabled()) {
log.debug("download jira issues from url " + fullUrl);
}
// execute the GET
download(client, fullUrl);
}
} catch (Exception e) {
if (project.getIssueManagement() != null) {
getLog().error("Error accessing " + project.getIssueManagement().getUrl(), e);
} else {
getLog().error("Error accessing mock project issues", e);
}
}
}
Aggregations