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.permissions.PermissionsFilterTest.java
License:asdf
@org.junit.Test public void test_Path_Credentials_no_permission() { /*//w w w . ja v a 2 s . c o m * Error accessing to a user collection beginning with same user name from a * external user */ GetMethod err_access = new GetMethod(SLING_URL + ERROR1_URL); err_access.setDoAuthentication(true); defaultcreds = new UsernamePasswordCredentials("tests", "tests"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(err_access); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals(401, err_access.getStatusCode()); err_access.releaseConnection(); }
From source file:org.iavante.sling.permissions.PermissionsFilterTest.java
License:asdf
@org.junit.Test public void test_Path_Credentials_user_no_authenticated() { /*//from w w w. j a v a 2 s . co m * Error accessing to a user collection beginning with same user name */ GetMethod err_access = new GetMethod(SLING_URL + ERROR3_URL); err_access.setDoAuthentication(true); defaultcreds = new UsernamePasswordCredentials("asdadsa", "dasdasdfa"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(err_access); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertTrue(err_access.getStatusCode() == 401 || err_access.getStatusCode() == 403); err_access.releaseConnection(); }
From source file:org.iavante.sling.permissions.PermissionsFilterTest.java
License:asdf
@org.junit.Test public void test_Search_OK() { GetMethod err_access = new GetMethod(SLING_URL + SEARCH_URL_OK); err_access.setDoAuthentication(true); defaultcreds = new UsernamePasswordCredentials("tests", "tests"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try {// w w w.ja v a 2 s . co m client.executeMethod(err_access); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals("Search OK test", 200, err_access.getStatusCode()); err_access.releaseConnection(); }
From source file:org.iavante.sling.permissions.PermissionsFilterTest.java
License:asdf
@org.junit.Test public void test_Search_Fail() { GetMethod err_access = new GetMethod(SLING_URL + SEARCH_URL_FAIL); err_access.setDoAuthentication(true); defaultcreds = new UsernamePasswordCredentials("tests", "tests"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try {/*w ww. j a va 2 s. com*/ client.executeMethod(err_access); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals("Search FAIL test", 401, err_access.getStatusCode()); err_access.releaseConnection(); }
From source file:org.iavante.sling.permissions.PermissionsFilterTest.java
License:asdf
@org.junit.Test public void test_CrossDomainAccess() { GetMethod cross_access = new GetMethod(SLING_URL + CROSSDOMAIN_URL); cross_access.setDoAuthentication(true); defaultcreds = new UsernamePasswordCredentials("tests", "tests"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try {/*from w ww .ja v a 2s. c o m*/ client.executeMethod(cross_access); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals("Crossdomain access", 200, cross_access.getStatusCode()); cross_access.releaseConnection(); }
From source file:org.iavante.sling.permissions.ValidationFilterIT.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;//from w w w.ja va 2 s .c o m } } if (hashost == false) SLING_URL = SLING_URL + HOSTPREDEF; client = new HttpClient(); title = "Test case content"; schema = "default"; slug_content = "test_case_content"; slug_collection = "admin"; authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); defaultcreds = new UsernamePasswordCredentials("admin", "admin"); anonymouscreds = new UsernamePasswordCredentials("anonymous", "anonymous"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); 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), 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(); } // Collection created post_create_col.releaseConnection(); }
From source file:org.iavante.sling.s3backend.S3BackendTestIT.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 ww.ja v a 2s . 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); createTest3(); try { uploadContent(); } catch (FileNotFoundException e) { log.info("ERROR uploading File: " + e.toString()); e.printStackTrace(); } createContent(); }
From source file:org.iavante.sling.searcher.SearcherServiceTestIT.java
@org.junit.BeforeClass static public void initialize() { try {//from ww w . jav a 2s .co m Thread.sleep(3000); } catch (InterruptedException e1) { e1.printStackTrace(); } /* get env params */ 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.compareToIgnoreCase(HOSTVAR) == 0) { SLING_URL = SLING_URL + (String) envs.get(key); hashost = true; break; } } if (hashost == false) SLING_URL = SLING_URL + HOSTPREDEF; /* make http connection */ client = new HttpClient(); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); defaultcreds = new UsernamePasswordCredentials("admin", "admin"); PostMethod post_create_col; /* tests if the collection exists */ GetMethod get_create_col = new GetMethod(SLING_URL + COLLECTIONS_URL + "/" + COLLECTION); get_create_col.setDoAuthentication(true); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(get_create_col); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } if (get_create_col.getStatusCode() != 404) { deletecontent(); } /* create a collection */ post_create_col = new PostMethod(SLING_URL + COLLECTIONS_URL + "/*"); post_create_col.setDoAuthentication(true); NameValuePair[] data_create_col = { new NameValuePair("sling:resourceType", "gad/collection"), new NameValuePair("title", COLLECTION), 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); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(post_create_col); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals("Creando la coleccion", 201, post_create_col.getStatusCode()); post_create_col.releaseConnection(); // collection created // Get the content try { Thread.sleep(3000); } catch (InterruptedException e1) { e1.printStackTrace(); } /* create a content */ post_create_col = new PostMethod(SLING_URL + COLLECTIONS_URL + "/" + COLLECTION + "/contents/*"); post_create_col.setDoAuthentication(true); NameValuePair[] data_create_col_content = { new NameValuePair("sling:resourceType", "gad/content"), new NameValuePair("title", TITLE_CONTENT), new NameValuePair("author", "test_autor@tests.com"), new NameValuePair("schema", SCHEMA), new NameValuePair("description", DESCRIPTION), new NameValuePair("origin", "final cut"), new NameValuePair("lang", "es"), new NameValuePair("tags", "recetas equilibradas"), new NameValuePair("tags@TypeHint", "String[]"), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create_col.setRequestBody(data_create_col_content); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(post_create_col); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals("Creando contenido", 201, post_create_col.getStatusCode()); post_create_col.releaseConnection(); // Content created // Get the content try { Thread.sleep(3000); } catch (InterruptedException e1) { e1.printStackTrace(); } /* create a source */ post_create_col = new PostMethod( SLING_URL + COLLECTIONS_URL + "/" + COLLECTION + "/contents/tests_search_title/sources/*"); post_create_col.setDoAuthentication(true); NameValuePair[] data_create_col_source = { new NameValuePair("sling:resourceType", "gad/source"), new NameValuePair("title", SOURCE_TITLE), new NameValuePair("author", "test_autor@tests.com"), new NameValuePair("schema", SCHEMA), new NameValuePair("description", DESCRIPTION), new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") }; post_create_col.setRequestBody(data_create_col_source); // post.setDoAuthentication(true); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(post_create_col); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Get the content assertEquals("Creando fuente", 201, post_create_col.getStatusCode()); post_create_col.releaseConnection(); // Source created /* send to review */ try { Thread.sleep(3000); } catch (InterruptedException e1) { e1.printStackTrace(); } post_create_col = new PostMethod( SLING_URL + COLLECTIONS_URL + "/" + COLLECTION + "/contents/" + TITLE_CONTENT); post_create_col.setDoAuthentication(true); NameValuePair[] data_send_review = { new NameValuePair(":operation", "copy"), new NameValuePair(":dest", "/content/catalogo/pendientes/"), new NameValuePair("replace", "true") }; post_create_col.setRequestBody(data_send_review); // post.setDoAuthentication(true); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(post_create_col); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // test if sent assertEquals("Mandando a revision", 201, post_create_col.getStatusCode()); post_create_col.releaseConnection(); // send to review finished }
From source file:org.iavante.sling.searcher.SearcherServiceTestIT.java
@org.junit.AfterClass static public void deletecontent() { try {//from w ww . j a v a2 s . c om Thread.sleep(3000); } catch (InterruptedException e1) { e1.printStackTrace(); } /* delete collection */ PostMethod post_create_col = new PostMethod(SLING_URL + COLLECTIONS_URL + "/" + COLLECTION); post_create_col.setDoAuthentication(true); NameValuePair[] data_create_col = { new NameValuePair(":operation", "delete"), }; post_create_col.setRequestBody(data_create_col); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(post_create_col); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals("Deleting content", 200, post_create_col.getStatusCode()); post_create_col.releaseConnection(); try { Thread.sleep(3000); } catch (InterruptedException e1) { e1.printStackTrace(); } }
From source file:org.iavante.sling.searcher.SearcherServiceTestIT.java
@org.junit.Test public void test_emptySearchAscii() { // Empty search String param = "?key=jasndkjasjkdn897hdioa"; String body = null;//from ww w . j a v a2s .c o m GetMethod empty_search = new GetMethod(SLING_URL + SEARCH_URL + param); empty_search.setDoAuthentication(true); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); try { client.executeMethod(empty_search); } catch (HttpException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } assertEquals("emptySearchAscii", 200, empty_search.getStatusCode()); try { body = empty_search.getResponseBodyAsString(); assertTrue("emptySearch", body.contains("[]")); } catch (IOException e) { assert false; e.printStackTrace(); } empty_search.releaseConnection(); }