Search in sources :

Example 1 with DefaultHttpParams

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

the class TestChallengeProcessor method testUnsupportedChallenge.

public void testUnsupportedChallenge() throws Exception {
    List authPrefs = new ArrayList(3);
    authPrefs.add(AuthPolicy.NTLM);
    authPrefs.add(AuthPolicy.BASIC);
    authPrefs.add(AuthPolicy.DIGEST);
    HttpParams httpparams = new DefaultHttpParams();
    httpparams.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
    AuthChallengeProcessor processor = new AuthChallengeProcessor(httpparams);
    Map map = new HashMap();
    map.put("unsupported1", "unsupported1 realm=\"whatever\"");
    map.put("unsupported2", "unsupported2 realm=\"whatever\"");
    try {
        AuthScheme authscheme = processor.selectAuthScheme(map);
        fail("AuthChallengeException should have been thrown");
    } catch (AuthChallengeException e) {
    // expected
    }
}
Also used : DefaultHttpParams(org.apache.commons.httpclient.params.DefaultHttpParams) HttpParams(org.apache.commons.httpclient.params.HttpParams) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) DefaultHttpParams(org.apache.commons.httpclient.params.DefaultHttpParams) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with DefaultHttpParams

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

the class TestChallengeProcessor method testChallengeSelection.

public void testChallengeSelection() throws Exception {
    List authPrefs = new ArrayList(3);
    authPrefs.add(AuthPolicy.NTLM);
    authPrefs.add(AuthPolicy.DIGEST);
    authPrefs.add(AuthPolicy.BASIC);
    HttpParams httpparams = new DefaultHttpParams();
    httpparams.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
    AuthChallengeProcessor processor = new AuthChallengeProcessor(httpparams);
    Map map = new HashMap();
    map.put("unknown", "unknown realm=\"whatever\"");
    map.put("basic", "basic realm=\"whatever\"");
    AuthScheme authscheme = processor.selectAuthScheme(map);
    assertTrue(authscheme instanceof BasicScheme);
}
Also used : DefaultHttpParams(org.apache.commons.httpclient.params.DefaultHttpParams) HttpParams(org.apache.commons.httpclient.params.HttpParams) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) DefaultHttpParams(org.apache.commons.httpclient.params.DefaultHttpParams) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with DefaultHttpParams

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

the class TestChallengeProcessor method testChallengeProcessing.

public void testChallengeProcessing() throws Exception {
    HttpParams httpparams = new DefaultHttpParams();
    AuthChallengeProcessor processor = new AuthChallengeProcessor(httpparams);
    Map map = new HashMap();
    map.put("basic", "basic realm=\"whatever\", param=\"value\"");
    AuthState authstate = new AuthState();
    AuthScheme authscheme = processor.processChallenge(authstate, map);
    assertTrue(authscheme instanceof BasicScheme);
    assertEquals("whatever", authscheme.getRealm());
    assertEquals(authscheme, authstate.getAuthScheme());
    assertEquals("value", authscheme.getParameter("param"));
}
Also used : DefaultHttpParams(org.apache.commons.httpclient.params.DefaultHttpParams) HttpParams(org.apache.commons.httpclient.params.HttpParams) HashMap(java.util.HashMap) DefaultHttpParams(org.apache.commons.httpclient.params.DefaultHttpParams) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with DefaultHttpParams

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

the class TestChallengeProcessor method testInvalidChallenge.

public void testInvalidChallenge() throws Exception {
    List authPrefs = new ArrayList(3);
    authPrefs.add("unsupported1");
    authPrefs.add("unsupported2");
    HttpParams httpparams = new DefaultHttpParams();
    httpparams.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
    AuthChallengeProcessor processor = new AuthChallengeProcessor(httpparams);
    Map map = new HashMap();
    map.put("unsupported1", "unsupported1 realm=\"whatever\"");
    map.put("unsupported2", "unsupported2 realm=\"whatever\"");
    try {
        AuthScheme authscheme = processor.selectAuthScheme(map);
        fail("AuthChallengeException should have been thrown");
    } catch (AuthChallengeException e) {
    // ignore
    }
}
Also used : DefaultHttpParams(org.apache.commons.httpclient.params.DefaultHttpParams) HttpParams(org.apache.commons.httpclient.params.HttpParams) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) DefaultHttpParams(org.apache.commons.httpclient.params.DefaultHttpParams) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with DefaultHttpParams

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

the class TestChallengeProcessor method testInvalidChallengeProcessing.

public void testInvalidChallengeProcessing() throws Exception {
    HttpParams httpparams = new DefaultHttpParams();
    AuthChallengeProcessor processor = new AuthChallengeProcessor(httpparams);
    Map map = new HashMap();
    map.put("basic", "basic realm=\"whatever\", param=\"value\"");
    AuthState authstate = new AuthState();
    AuthScheme authscheme = processor.processChallenge(authstate, map);
    assertTrue(authscheme instanceof BasicScheme);
    assertEquals("whatever", authscheme.getRealm());
    assertEquals(authscheme, authstate.getAuthScheme());
    assertEquals("value", authscheme.getParameter("param"));
    Map map2 = new HashMap();
    map2.put("ntlm", "NTLM");
    try {
        // Basic authentication scheme expected
        authscheme = processor.processChallenge(authstate, map2);
        fail("AuthenticationException should have been thrown");
    } catch (AuthenticationException e) {
    // expected
    }
}
Also used : DefaultHttpParams(org.apache.commons.httpclient.params.DefaultHttpParams) HttpParams(org.apache.commons.httpclient.params.HttpParams) HashMap(java.util.HashMap) DefaultHttpParams(org.apache.commons.httpclient.params.DefaultHttpParams) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)6 DefaultHttpParams (org.apache.commons.httpclient.params.DefaultHttpParams)6 HttpParams (org.apache.commons.httpclient.params.HttpParams)6 Map (java.util.Map)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ReflectException (com.shulie.instrument.simulator.api.reflect.ReflectException)1