public static void main(String[] args) { // register the auth scheme AuthPolicy.registerAuthScheme(SecretAuthScheme.NAME, SecretAuthScheme.class); // include the scheme in the AuthPolicy.AUTH_SCHEME_PRIORITY preference, // this can be done on a per-client or per-method basis but we'll do it // globally for this example HttpParams params = DefaultHttpParams.getDefaultParams(); ArrayList schemes = new ArrayList(); schemes.add(SecretAuthScheme.NAME); schemes.addAll((Collection) params.getParameter(AuthPolicy.AUTH_SCHEME_PRIORITY)); params.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, schemes); // now that our scheme has been registered we can execute methods against // servers that require "Secret" authentication... }
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); }
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 } }
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 } }
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 } }
public static void enableAuth(HttpClient client, Keychain keychain, KeyId keyId) { Signer signer = new Signer(keychain, keyId); CredentialsProvider credProvider = (CredentialsProvider) client.getParams() .getParameter(CredentialsProvider.PROVIDER); CredentialsProvider newProvider; if (credProvider instanceof SignerCredentialsProvider) { newProvider = new SignerCredentialsProvider(signer, ((SignerCredentialsProvider) credProvider).getDelegatee()); } else { newProvider = new SignerCredentialsProvider(signer, credProvider); } client.getParams().setParameter(CredentialsProvider.PROVIDER, newProvider); AuthPolicy.registerAuthScheme(Constants.SCHEME, Http3SignatureAuthScheme.class); List<String> schemes = new ArrayList<String>(); schemes.add(Constants.SCHEME); Collection authSchemePriority = (Collection) DefaultHttpParams.getDefaultParams().getParameter(AuthPolicy.AUTH_SCHEME_PRIORITY); if (authSchemePriority != null) { schemes.addAll(authSchemePriority); } client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, schemes); }
public void init() { this.sslKeyStore = new AlfrescoKeyStoreImpl(sslEncryptionParameters.getKeyStoreParameters(), keyResourceLoader); this.sslTrustStore = new AlfrescoKeyStoreImpl(sslEncryptionParameters.getTrustStoreParameters(), keyResourceLoader); this.sslSocketFactory = new AuthSSLProtocolSocketFactory(sslKeyStore, sslTrustStore, keyResourceLoader); // Setup the Apache httpclient library to use our concurrent HttpParams factory DefaultHttpParams.setHttpParamsFactory(new NonBlockingHttpParamsFactory()); }
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")); }
public static void main(String[] args) { // register the auth scheme AuthPolicy.registerAuthScheme("Negotiate", NegotiateScheme.class); // include the scheme in the AuthPolicy.AUTH_SCHEME_PRIORITY preference ArrayList schemes = new ArrayList(); schemes.add("Negotiate"); HttpParams params = DefaultHttpParams.getDefaultParams(); params.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, schemes); // now that our scheme has been registered we can execute methods against // servers that require "Negotiate" authentication... HttpClient client = new HttpClient(); // The Negotiate scheme uses JAAS as credential provider but the // httpclient api require us to supply cred anyway. // a work around is to provide an empty set of creds. Credentials use_jaas_creds = new Credentials() {}; client.getState().setCredentials( new AuthScope(null, -1, null), use_jaas_creds); GetMethod httpget = new GetMethod(args[0]); try { client.executeMethod(httpget); //System.out.println(httpget.getStatusLine()); //System.out.println(httpget.getResponseBodyAsString()); } catch (Exception e) { e.printStackTrace(); } finally { // release any connection resources used by the method httpget.releaseConnection(); } }
@Override public void setup(OperatorContext context) { url = prepareURL(); client = new HttpClient(); method = new GetMethod(url); DefaultHttpParams.getDefaultParams().setParameter("http.protocol.cookie-policy", CookiePolicy.BROWSER_COMPATIBILITY); }