use of org.apache.commons.httpclient.FeedbackService in project ecf by eclipse.
the class TestBasicAuth method testBasicAuthenticationWithMutlipleRealms2.
public void testBasicAuthenticationWithMutlipleRealms2() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser2", "testpass2");
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test2"));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
HttpState state = new HttpState();
AuthScope realm1 = new AuthScope(this.server.getLocalAddress(), this.server.getLocalPort(), "test");
AuthScope realm2 = new AuthScope(this.server.getLocalAddress(), this.server.getLocalPort(), "test2");
state.setCredentials(realm1, new UsernamePasswordCredentials("testuser", "testpass"));
state.setCredentials(realm2, new UsernamePasswordCredentials("testuser2", "testpass2"));
this.client.setState(state);
this.server.setRequestHandler(handlerchain);
GetMethod httpget = new GetMethod("/test2/");
try {
this.client.executeMethod(httpget);
} finally {
httpget.releaseConnection();
}
assertNotNull(httpget.getStatusLine());
assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode());
Header auth = httpget.getRequestHeader("Authorization");
assertNotNull(auth);
String expected = "Basic " + EncodingUtil.getAsciiString(Base64.encodeBase64(EncodingUtil.getAsciiBytes("testuser2:testpass2")));
assertEquals(expected, auth.getValue());
AuthState authstate = httpget.getHostAuthState();
assertNotNull(authstate.getAuthScheme());
assertTrue(authstate.getAuthScheme() instanceof BasicScheme);
assertEquals("test2", authstate.getRealm());
}
use of org.apache.commons.httpclient.FeedbackService in project ecf by eclipse.
the class TestBasicAuth method testBasicAuthenticationWithMutlipleRealms1.
public void testBasicAuthenticationWithMutlipleRealms1() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
HttpState state = new HttpState();
AuthScope realm1 = new AuthScope(this.server.getLocalAddress(), this.server.getLocalPort(), "test");
AuthScope realm2 = new AuthScope(this.server.getLocalAddress(), this.server.getLocalPort(), "test2");
state.setCredentials(realm1, new UsernamePasswordCredentials("testuser", "testpass"));
state.setCredentials(realm2, new UsernamePasswordCredentials("testuser2", "testpass2"));
this.client.setState(state);
this.server.setRequestHandler(handlerchain);
GetMethod httpget = new GetMethod("/test/");
try {
this.client.executeMethod(httpget);
} finally {
httpget.releaseConnection();
}
assertNotNull(httpget.getStatusLine());
assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode());
Header auth = httpget.getRequestHeader("Authorization");
assertNotNull(auth);
String expected = "Basic " + EncodingUtil.getAsciiString(Base64.encodeBase64(EncodingUtil.getAsciiBytes("testuser:testpass")));
assertEquals(expected, auth.getValue());
AuthState authstate = httpget.getHostAuthState();
assertNotNull(authstate.getAuthScheme());
assertTrue(authstate.getAuthScheme() instanceof BasicScheme);
assertEquals("test", authstate.getRealm());
}
use of org.apache.commons.httpclient.FeedbackService in project ecf by eclipse.
the class TestBasicAuth method testBasicAuthenticationWithNoCredsRetry.
public void testBasicAuthenticationWithNoCredsRetry() throws IOException {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
GetMethod httpget = new GetMethod("/test/");
try {
this.client.executeMethod(httpget);
assertNotNull(httpget.getStatusLine());
assertEquals(HttpStatus.SC_UNAUTHORIZED, httpget.getStatusLine().getStatusCode());
AuthState authstate = httpget.getHostAuthState();
assertNotNull(authstate.getAuthScheme());
assertTrue(authstate.getAuthScheme() instanceof BasicScheme);
assertEquals("test", authstate.getRealm());
} finally {
httpget.releaseConnection();
}
// now try with credentials
httpget = new GetMethod("/test/");
try {
this.client.getState().setCredentials(AuthScope.ANY, creds);
this.client.executeMethod(httpget);
assertNotNull(httpget.getStatusLine());
assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode());
} finally {
httpget.releaseConnection();
}
}
use of org.apache.commons.httpclient.FeedbackService in project ecf by eclipse.
the class TestBasicAuth method testBasicAuthentication.
public void testBasicAuthentication() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
HttpState state = new HttpState();
AuthScope authscope = new AuthScope(this.server.getLocalAddress(), this.server.getLocalPort(), "test");
state.setCredentials(authscope, creds);
this.client.setState(state);
this.server.setRequestHandler(handlerchain);
GetMethod httpget = new GetMethod("/test/");
try {
this.client.executeMethod(httpget);
} finally {
httpget.releaseConnection();
}
assertNotNull(httpget.getStatusLine());
assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode());
Header auth = httpget.getRequestHeader("Authorization");
assertNotNull(auth);
String expected = "Basic " + EncodingUtil.getAsciiString(Base64.encodeBase64(EncodingUtil.getAsciiBytes("testuser:testpass")));
assertEquals(expected, auth.getValue());
AuthState authstate = httpget.getHostAuthState();
assertNotNull(authstate.getAuthScheme());
assertTrue(authstate.getAuthScheme() instanceof BasicScheme);
assertEquals("test", authstate.getRealm());
}
use of org.apache.commons.httpclient.FeedbackService in project ecf by eclipse.
the class TestBasicAuth method testPreemptiveAuthorizationTrueWithCreds.
public void testPreemptiveAuthorizationTrueWithCreds() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
HttpState state = new HttpState();
state.setCredentials(AuthScope.ANY, creds);
this.client.setState(state);
this.client.getParams().setAuthenticationPreemptive(true);
this.server.setRequestHandler(handlerchain);
GetMethod httpget = new GetMethod("/test/");
try {
this.client.executeMethod(httpget);
} finally {
httpget.releaseConnection();
}
assertNotNull(httpget.getStatusLine());
assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode());
Header auth = httpget.getRequestHeader("Authorization");
assertNotNull(auth);
String expected = "Basic " + EncodingUtil.getAsciiString(Base64.encodeBase64(EncodingUtil.getAsciiBytes("testuser:testpass")));
assertEquals(expected, auth.getValue());
AuthState authstate = httpget.getHostAuthState();
assertNotNull(authstate.getAuthScheme());
assertTrue(authstate.getAuthScheme() instanceof BasicScheme);
assertNull(authstate.getRealm());
assertTrue(authstate.isPreemptive());
}
Aggregations