Search in sources :

Example 1 with FakeHttpMethod

use of org.apache.commons.httpclient.FakeHttpMethod in project ecf by eclipse.

the class TestDigestAuth method testDigestAuthentication.

public void testDigestAuthentication() throws Exception {
    String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
    UsernamePasswordCredentials cred = new UsernamePasswordCredentials("username", "password");
    FakeHttpMethod method = new FakeHttpMethod("/");
    AuthScheme authscheme = new DigestScheme();
    authscheme.processChallenge(challenge);
    String response = authscheme.authenticate(cred, method);
    Map table = AuthChallengeParser.extractParams(response);
    assertEquals("username", table.get("username"));
    assertEquals("realm1", table.get("realm"));
    assertEquals("/", table.get("uri"));
    assertEquals("f2a3f18799759d4f1a1c068b92b573cb", table.get("nonce"));
    assertEquals("e95a7ddf37c2eab009568b1ed134f89a", table.get("response"));
}
Also used : FakeHttpMethod(org.apache.commons.httpclient.FakeHttpMethod) Map(java.util.Map) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 2 with FakeHttpMethod

use of org.apache.commons.httpclient.FakeHttpMethod in project ecf by eclipse.

the class TestDigestAuth method testDigestAuthenticationWithDefaultCreds.

public void testDigestAuthenticationWithDefaultCreds() throws Exception {
    String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
    FakeHttpMethod method = new FakeHttpMethod("/");
    UsernamePasswordCredentials cred = new UsernamePasswordCredentials("username", "password");
    AuthScheme authscheme = new DigestScheme();
    authscheme.processChallenge(challenge);
    String response = authscheme.authenticate(cred, method);
    Map table = AuthChallengeParser.extractParams(response);
    assertEquals("username", table.get("username"));
    assertEquals("realm1", table.get("realm"));
    assertEquals("/", table.get("uri"));
    assertEquals("f2a3f18799759d4f1a1c068b92b573cb", table.get("nonce"));
    assertEquals("e95a7ddf37c2eab009568b1ed134f89a", table.get("response"));
}
Also used : FakeHttpMethod(org.apache.commons.httpclient.FakeHttpMethod) Map(java.util.Map) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 3 with FakeHttpMethod

use of org.apache.commons.httpclient.FakeHttpMethod in project ecf by eclipse.

the class TestNTLMAuth method testNTLMAuthenticationRetry.

public void testNTLMAuthenticationRetry() throws Exception {
    this.server.setHttpService(new NTLMAuthService());
    // configure the client
    this.client.getHostConfiguration().setHost(server.getLocalAddress(), server.getLocalPort(), Protocol.getProtocol("http"));
    this.client.getState().setCredentials(AuthScope.ANY, new NTCredentials("username", "password", "host", "domain"));
    FakeHttpMethod httpget = new FakeHttpMethod("/");
    try {
        client.executeMethod(httpget);
    } finally {
        httpget.releaseConnection();
    }
    assertNull(httpget.getResponseHeader("WWW-Authenticate"));
    assertEquals(200, httpget.getStatusCode());
}
Also used : FakeHttpMethod(org.apache.commons.httpclient.FakeHttpMethod) NTCredentials(org.apache.commons.httpclient.NTCredentials)

Example 4 with FakeHttpMethod

use of org.apache.commons.httpclient.FakeHttpMethod in project ecf by eclipse.

the class TestNTLMAuth method testNTLMAuthenticationResponse1.

// ---------------------------------
public void testNTLMAuthenticationResponse1() throws Exception {
    String challenge = "NTLM";
    String expected = "NTLM TlRMTVNTUAABAAAABlIAAAYABgAkAAAABAAEACAAAABIT" + "1NURE9NQUlO";
    NTCredentials cred = new NTCredentials("username", "password", "host", "domain");
    FakeHttpMethod method = new FakeHttpMethod();
    AuthScheme authscheme = new NTLMScheme(challenge);
    authscheme.processChallenge(challenge);
    String response = authscheme.authenticate(cred, method);
    assertEquals(expected, response);
    assertFalse(authscheme.isComplete());
}
Also used : FakeHttpMethod(org.apache.commons.httpclient.FakeHttpMethod) NTCredentials(org.apache.commons.httpclient.NTCredentials)

Example 5 with FakeHttpMethod

use of org.apache.commons.httpclient.FakeHttpMethod in project ecf by eclipse.

the class TestDigestAuth method testDigestAuthenticationWithMultipleRealms.

public void testDigestAuthenticationWithMultipleRealms() throws Exception {
    String challenge1 = "Digest realm=\"realm1\", nonce=\"abcde\"";
    String challenge2 = "Digest realm=\"realm2\", nonce=\"123546\"";
    UsernamePasswordCredentials cred = new UsernamePasswordCredentials("username", "password");
    UsernamePasswordCredentials cred2 = new UsernamePasswordCredentials("uname2", "password2");
    FakeHttpMethod method = new FakeHttpMethod("/");
    AuthScheme authscheme1 = new DigestScheme();
    authscheme1.processChallenge(challenge1);
    String response1 = authscheme1.authenticate(cred, method);
    Map table = AuthChallengeParser.extractParams(response1);
    assertEquals("username", table.get("username"));
    assertEquals("realm1", table.get("realm"));
    assertEquals("/", table.get("uri"));
    assertEquals("abcde", table.get("nonce"));
    assertEquals("786f500303eac1478f3c2865e676ed68", table.get("response"));
    AuthScheme authscheme2 = new DigestScheme();
    authscheme2.processChallenge(challenge2);
    String response2 = authscheme2.authenticate(cred2, method);
    table = AuthChallengeParser.extractParams(response2);
    assertEquals("uname2", table.get("username"));
    assertEquals("realm2", table.get("realm"));
    assertEquals("/", table.get("uri"));
    assertEquals("123546", table.get("nonce"));
    assertEquals("0283edd9ef06a38b378b3b74661391e9", table.get("response"));
}
Also used : FakeHttpMethod(org.apache.commons.httpclient.FakeHttpMethod) Map(java.util.Map) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Aggregations

FakeHttpMethod (org.apache.commons.httpclient.FakeHttpMethod)10 Map (java.util.Map)7 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)7 NTCredentials (org.apache.commons.httpclient.NTCredentials)3 HttpClient (org.apache.commons.httpclient.HttpClient)1 SimpleHttpServer (org.apache.commons.httpclient.server.SimpleHttpServer)1