List of usage examples for org.apache.commons.httpclient.auth AuthPolicy AUTH_SCHEME_PRIORITY
String AUTH_SCHEME_PRIORITY
To view the source code for org.apache.commons.httpclient.auth AuthPolicy AUTH_SCHEME_PRIORITY.
Click Source Link
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);// w w w. ja v a 2 s . c o m 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); 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);//from w ww. ja va2 s . co m authPrefs.add(AuthPolicy.BASIC); 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);//from w ww . j a v a2s. co m authPrefs.add(AuthPolicy.BASIC); 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);//ww w.ja va 2 s.co m authPrefs.add(AuthPolicy.BASIC); 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;/*from w w w .j av a 2 s.c o 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 ww . ja v a 2 s . com*/ } } 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.Test public void accessAuthorized1() { defaultcreds = new UsernamePasswordCredentials("tests", "tests"); GetMethod okaccess = new GetMethod(SLING_URL + OK1_URL); okaccess.setDoAuthentication(true);/*from w ww . j ava 2 s . com*/ client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(okaccess); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals("Access authorized", okaccess.getStatusCode(), 404); okaccess.releaseConnection(); }
From source file:org.iavante.sling.commons.services.LDAPConnectorTest.java
public void accessAuthorized2() { defaultcreds = new UsernamePasswordCredentials("tests", "tests"); GetMethod okaccess = new GetMethod(SLING_URL + OK2_URL); okaccess.setDoAuthentication(true);/*from w w w . ja v a2 s. c om*/ client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(okaccess); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals("Access authorized", okaccess.getStatusCode(), 404); okaccess.releaseConnection(); }
From source file:org.iavante.sling.commons.services.LDAPConnectorTest.java
public void accessAuthorized3() { defaultcreds = new UsernamePasswordCredentials("tests", "tests"); GetMethod okaccess = new GetMethod(SLING_URL + OK3_URL); okaccess.setDoAuthentication(true);//from w w w .ja va 2 s .c om client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(okaccess); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals("Access authorized", okaccess.getStatusCode(), 404); okaccess.releaseConnection(); }
From source file:org.iavante.sling.commons.services.LDAPConnectorTest.java
@org.junit.Test public void accessUnauthorized_bad_url() { defaultcreds = new UsernamePasswordCredentials("tests", "tests"); GetMethod okaccess = new GetMethod(SLING_URL + BAD_URL); okaccess.setDoAuthentication(true);/*from w ww. j av a 2s . c om*/ client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(okaccess); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertTrue("Access authorized", okaccess.getStatusCode() == 403 || okaccess.getStatusCode() == 401); okaccess.releaseConnection(); }