List of usage examples for org.apache.commons.httpclient.auth AuthPolicy DIGEST
String DIGEST
To view the source code for org.apache.commons.httpclient.auth AuthPolicy DIGEST.
Click Source Link
From source file:org.fao.geonet.lib.NetLib.java
/** Setup proxy for http client *//* www. j a v a 2 s .com*/ public void setupProxy(SettingManager sm, HttpClient client) { boolean enabled = sm.getValueAsBool(ENABLED, false); String host = sm.getValue(HOST); String port = sm.getValue(PORT); String username = sm.getValue(USERNAME); String password = sm.getValue(PASSWORD); if (enabled) { if (!Lib.type.isInteger(port)) { Log.error(Geonet.GEONETWORK, "Proxy port is not an integer : " + port); } else { HostConfiguration config = client.getHostConfiguration(); if (config == null) config = new HostConfiguration(); config.setProxy(host, Integer.parseInt(port)); client.setHostConfiguration(config); if (username.trim().length() != 0) { Credentials cred = new UsernamePasswordCredentials(username, password); AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM); client.getState().setProxyCredentials(scope, cred); } List authPrefs = new ArrayList(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); // This will exclude the NTLM authentication scheme client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); } } }
From source file:org.iavante.sling.authentication.AuthenticationFilterIT.java
@org.junit.Test public void test_get_authenticated() { // Try to get a collection authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC);//from ww w . j a v a 2 s. c o m defaultcreds = new UsernamePasswordCredentials("admin", "admin"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); HttpMethod get = new GetMethod(SLING_URL + GET_URL); try { client.executeMethod(get); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } assertEquals(get.getStatusCode(), 404); }
From source file:org.iavante.sling.authentication.AuthenticationFilterIT.java
@org.junit.Test public void test_get_not_authenticated() { // Try to get a collection authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC);//w w w . j a v a 2 s. c om defaultcreds = new UsernamePasswordCredentials("noauthenticated", "noauthenticated"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); HttpMethod get = new GetMethod(SLING_URL + GET_URL); try { client.executeMethod(get); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } assertEquals(get.getStatusCode(), 403); }
From source file:org.iavante.sling.authentication.AuthenticationFilterIT.java
@org.junit.Test public void test_admin_url() { // Try to get a collection authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC);//ww w . j ava 2 s . com defaultcreds = new UsernamePasswordCredentials("noauthenticated", "noauthenticated"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); HttpMethod get = new GetMethod(SLING_URL + ADMIN_URL); try { client.executeMethod(get); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } assertTrue((get.getStatusCode() != 403)); }
From source file:org.iavante.sling.authentication.AuthenticationFilterIT.java
@org.junit.Test public void test_downloader_url() { // Try to get a collection authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC);//from w w w. j av a 2s. c o m defaultcreds = new UsernamePasswordCredentials("noauthenticated", "noauthenticated"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); HttpMethod get = new GetMethod(SLING_URL + DOWNLOADER_URL); try { client.executeMethod(get); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } assertTrue((get.getStatusCode() != 403)); }
From source file:org.iavante.sling.commons.services.CopyAndRenameOperationIT.java
protected void setUp() { Map<String, String> envs = System.getenv(); Set<String> keys = envs.keySet(); Iterator<String> it = keys.iterator(); boolean hashost = false; while (it.hasNext()) { String key = (String) it.next(); if (key.compareTo(HOSTVAR) == 0) { SLING_URL = SLING_URL + (String) envs.get(key); hashost = true;/*ww w . j a va2s .co m*/ } } if (hashost == false) SLING_URL = SLING_URL + HOSTPREDEF; client = new HttpClient(); title_col = "Title collection"; title1 = "Test case content 1"; title2 = "Test case content 2"; source_file = "test.avi"; source_mime = "video/avi"; source_dest_slug = "fuente_default"; source_dest_title = "Fuente por defecto"; description1 = "Description 1"; description2 = "Description 2"; schema = "default"; slug_collection = "admin"; slug_content1 = "it_content_1"; slug_content2 = "it_content_2"; authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); defaultcreds = new UsernamePasswordCredentials("admin", "admin"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); // Create collection PostMethod post_create_col = new PostMethod(SLING_URL + COLLECTIONS_URL + slug_collection); post_create_col.setDoAuthentication(true); NameValuePair[] data_create_col = { new NameValuePair("sling:resourceType", "gad/collection"), new NameValuePair("title", title_col), new NameValuePair("subtitle", ""), new NameValuePair("schema", schema), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create_col.setRequestBody(data_create_col); try { client.executeMethod(post_create_col); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } post_create_col.releaseConnection(); // Create content in collection try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } PostMethod post_create = new PostMethod( SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/" + slug_content1); post_create.setDoAuthentication(true); NameValuePair[] data_create = { new NameValuePair("sling:resourceType", "gad/content"), new NameValuePair("title", title1), new NameValuePair("schema", schema), new NameValuePair("description", description1), new NameValuePair("author", "Test case"), new NameValuePair("origin", "Test case"), new NameValuePair("lang", "es"), new NameValuePair("tags@TypeHint", "String[]"), new NameValuePair("state", "pending"), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", ""), new NameValuePair("_charset_", "utf-8") }; post_create.setRequestBody(data_create); try { client.executeMethod(post_create); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } post_create.releaseConnection(); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } // Create the source PostMethod post_create_source = new PostMethod( SLING_URL + COLLECTIONS_URL + slug_collection + "/" + SOURCES_FOLDER + "/" + source_title); post_create.setDoAuthentication(true); NameValuePair[] data_create_source = { new NameValuePair("sling:resourceType", "gad/source"), new NameValuePair("title", source_dest_title), new NameValuePair("file", source_file), new NameValuePair("mimetype", source_mime), new NameValuePair("text_encoding", ""), new NameValuePair("lang", ""), new NameValuePair("length", ""), new NameValuePair("size", ""), new NameValuePair("type", ""), new NameValuePair("bitrate", ""), new NameValuePair("tracks_number", ""), new NameValuePair("track_1_type", ""), new NameValuePair("track_1_encoding", ""), new NameValuePair("track_1_features", ""), new NameValuePair("track_2_type", ""), new NameValuePair("track_2_encoding", ""), new NameValuePair("track_2_features", ""), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create_source.setRequestBody(data_create_source); try { client.executeMethod(post_create_source); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(201, post_create_source.getStatusCode()); post_create_source.releaseConnection(); }
From source file:org.iavante.sling.commons.services.DistributionServerTestIT.java
@org.junit.Before public void setUp() { Map<String, String> envs = System.getenv(); Set<String> keys = envs.keySet(); Iterator<String> it = keys.iterator(); boolean hashost = false; while (it.hasNext()) { String key = (String) it.next(); if (key.compareTo(HOSTVAR) == 0) { SLING_URL = SLING_URL + (String) envs.get(key); hashost = true;// w w w . ja v a2 s .c o m } } if (hashost == false) SLING_URL = SLING_URL + HOSTPREDEF; client = new HttpClient(); title = "Test case content"; schema = "default"; slug = "test_case_contents3"; authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); defaultcreds = new UsernamePasswordCredentials("admin", "admin"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); //tearDown(); createTest3(); try { uploadContent(); } catch (FileNotFoundException e) { e.printStackTrace(); } createContent(); }
From source file:org.iavante.sling.commons.services.LDAPConnectorTest.java
@org.junit.Before public void setUp() { Map<String, String> envs = System.getenv(); Set<String> keys = envs.keySet(); Iterator<String> it = keys.iterator(); boolean hashost = false; while (it.hasNext()) { String key = (String) it.next(); if (key.compareTo(HOSTVAR) == 0) { SLING_URL = SLING_URL + (String) envs.get(key); hashost = true;/*www. j a v a 2s . c o m*/ } } if (hashost == false) { SLING_URL = SLING_URL + HOSTPREDEF; } client = new HttpClient(); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); }
From source file:org.iavante.sling.gad.administration.impl.AbstractHttpOperation.java
/** Execute a POST request and check status */ protected Header[] assertAuthenticatedPostStatus(Credentials creds, String url, List<String> expectedStatusCode, List<NameValuePair> postParams, String assertMessage) throws IOException { Header[] headers = null;//from w w w.ja v a2s . c o m URL baseUrl = new URL(HTTP_BASE_URL); List authPrefs = new ArrayList(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); HttpClient httpClient = new HttpClient(); httpClient.getParams().setAuthenticationPreemptive(true); httpClient.getState().setCredentials(AuthScope.ANY, creds); httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); PostMethod post = new PostMethod(url); post.setFollowRedirects(false); post.setDoAuthentication(true); try { if (postParams != null) { final NameValuePair[] nvp = {}; post.setRequestBody(postParams.toArray(nvp)); } final int status = httpClient.executeMethod(post); if (!expectedStatusCode.contains("" + status)) { log.error("ResponseCode: " + status + " isn't in " + expectedStatusCode.toString()); throw new IOException("ResponseCode: " + status + " isn't in " + expectedStatusCode.toString()); } headers = post.getResponseHeaders(); } finally { post.releaseConnection(); } return headers; }
From source file:org.iavante.sling.gad.administration.impl.AbstractHttpOperation.java
/** Execute a POST request and check status */ protected Header[] assertAuthenticatedPostMultipartStatus(Credentials creds, String url, List<String> expectedStatusCode, Part[] parts, String assertMessage) throws IOException { Header[] headers = null;/* w w w .j a v a 2 s . co m*/ URL baseUrl = new URL(HTTP_BASE_URL); List authPrefs = new ArrayList(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); HttpClient httpClient = new HttpClient(); httpClient.getParams().setAuthenticationPreemptive(true); httpClient.getState().setCredentials(AuthScope.ANY, creds); httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); PostMethod post = new PostMethod(url); post.setFollowRedirects(false); post.setDoAuthentication(true); try { if (parts != null) { post.setRequestEntity((RequestEntity) new MultipartRequestEntity(parts, post.getParams())); } final int status = httpClient.executeMethod(post); if (!expectedStatusCode.contains("" + status)) { log.error("ResponseCode: " + status + " isn't in " + expectedStatusCode.toString()); throw new IOException("ResponseCode: " + status + " isn't in " + expectedStatusCode.toString()); } headers = post.getResponseHeaders(); } finally { post.releaseConnection(); } return headers; }