Search in sources :

Example 11 with AuthScope

use of org.apache.commons.httpclient.auth.AuthScope in project ecf by eclipse.

the class TestHttpState method testWrongRealmCredentials.

public void testWrongRealmCredentials() throws Exception {
    HttpState state = new HttpState();
    Credentials cred = new UsernamePasswordCredentials("name", "pass");
    state.setCredentials(new AuthScope("host", AuthScope.ANY_PORT, "realm1"), cred);
    Credentials got = state.getCredentials(new AuthScope("host", AuthScope.ANY_PORT, "realm2"));
    assertNotSame(cred, got);
}
Also used : AuthScope(org.apache.commons.httpclient.auth.AuthScope)

Example 12 with AuthScope

use of org.apache.commons.httpclient.auth.AuthScope in project lobcder by skoulouzis.

the class TestREST method setUp.

@Before
public void setUp() throws Exception {
    // String propBasePath = System.getProperty("user.home") + File.separator
    // + "workspace" + File.separator + "lobcder-tests"
    // + File.separator + "etc" + File.separator + "test.properties";
    String propBasePath = "etc" + File.separator + "test.properties";
    Properties prop = TestSettings.getTestProperties(propBasePath);
    String testURL = prop.getProperty("webdav.test.url", "http://localhost:8080/lobcder/dav");
    assertTrue(testURL != null);
    if (!testURL.endsWith("/")) {
        testURL = testURL + "/";
    }
    this.uri = URI.create(testURL);
    this.root = this.uri.toASCIIString();
    if (!this.root.endsWith("/")) {
        this.root += "/";
    }
    this.username = prop.getProperty(("webdav.test.username1"), "user");
    assertTrue(username != null);
    this.password = prop.getProperty(("webdav.test.password1"), "token0");
    assertTrue(password != null);
    int port = uri.getPort();
    if (port == -1) {
        port = 443;
    }
    ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
    Protocol https = new Protocol("https", socketFactory, port);
    Protocol.registerProtocol("https", https);
    this.client = new HttpClient();
    this.client.getState().setCredentials(new AuthScope(this.uri.getHost(), this.uri.getPort()), new UsernamePasswordCredentials(this.username, this.password));
    restURL = prop.getProperty(("rest.test.url"), "http://localhost:8080/lobcder/rest/");
    // testResourceId = "testResourceId";
    // testcol = this.root + testResourceId + "/";
    translatorURL = prop.getProperty(("translator.test.url"), "http://localhost:8080/lobcder/urest/");
    mrURL = prop.getProperty(("metadata.repository.url"), "http://vphshare.atosresearch.eu/metadata-extended/rest/metadata");
    quckTest = Boolean.valueOf(prop.getProperty(("test.quick"), "true"));
    ClientConfig clientConfig = configureClient();
    // SSLContext ctx = SSLContext.getInstance("SSL");
    // clientConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hostnameVerifier, ctx));
    clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
    restClient = Client.create(clientConfig);
    restClient.addFilter(new com.sun.jersey.api.client.filter.HTTPBasicAuthFilter(username, password));
    utils = new Utils(client);
}
Also used : Properties(java.util.Properties) HTTPSProperties(com.sun.jersey.client.urlconnection.HTTPSProperties) EasySSLProtocolSocketFactory(org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) EasySSLProtocolSocketFactory(org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory) ProtocolSocketFactory(org.apache.commons.httpclient.protocol.ProtocolSocketFactory) HttpClient(org.apache.commons.httpclient.HttpClient) AuthScope(org.apache.commons.httpclient.auth.AuthScope) Protocol(org.apache.commons.httpclient.protocol.Protocol) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) Before(org.junit.Before)

Example 13 with AuthScope

use of org.apache.commons.httpclient.auth.AuthScope in project lobcder by skoulouzis.

the class TestWebWAVFS method testUploadFileOnRootWithoutAdminRole.

@Test
public void testUploadFileOnRootWithoutAdminRole() throws IOException, DavException {
    System.err.println("testUploadFileOnRootWithoutAdminRole");
    String uname = prop.getProperty(("webdav.test.non.admin.username1"), "nonAdmin");
    assertNotNull(uname);
    String pass = prop.getProperty(("webdav.test.non.admin.password1"), "secret");
    assertNotNull(pass);
    HttpClient client = new HttpClient();
    assertNotNull(uri.getHost());
    assertNotNull(uri.getPort());
    assertNotNull(client);
    client.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(uname, pass));
    String testFileURI1 = this.uri.toASCIIString() + TestSettings.TEST_FILE_NAME1 + ".txt";
    PutMethod put = new PutMethod(testFileURI1);
    put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
    int status = client.executeMethod(put);
    assertEquals(HttpStatus.SC_UNAUTHORIZED, status);
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.commons.httpclient.HttpClient) AuthScope(org.apache.commons.httpclient.auth.AuthScope) PutMethod(org.apache.jackrabbit.webdav.client.methods.PutMethod) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Test(org.junit.Test)

Example 14 with AuthScope

use of org.apache.commons.httpclient.auth.AuthScope in project lobcder by skoulouzis.

the class TestWebWAVFS method testMultiThread.

@Test
public void testMultiThread() throws IOException, DavException {
    System.err.println("testMultiThread");
    try {
        Thread userThread1 = new UserThread(client1, uri.toASCIIString(), 1);
        userThread1.setName("T1");
        client2.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username1, password1));
        Thread userThread2 = new UserThread(client2, uri.toASCIIString(), 2);
        userThread2.setName("T2");
        userThread1.start();
        userThread2.start();
        userThread1.join();
        userThread2.join();
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
        Logger.getLogger(TestWebWAVFS.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : AuthScope(org.apache.commons.httpclient.auth.AuthScope) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Test(org.junit.Test)

Example 15 with AuthScope

use of org.apache.commons.httpclient.auth.AuthScope in project lobcder by skoulouzis.

the class TestWebWAVFS method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    String propBasePath = "etc" + File.separator + "test.properties";
    prop = TestSettings.getTestProperties(propBasePath);
    String testURL = prop.getProperty("webdav.test.url");
    // Some problem with the pom.xml. The properties are set but System.getProperty gets null
    if (testURL == null) {
        testURL = "http://localhost:8080/lobcder-1.0-SNAPSHOT/";
    }
    assertTrue(testURL != null);
    if (!testURL.endsWith("/")) {
        testURL = testURL + "/";
    }
    uri = URI.create(testURL);
    root = uri.toASCIIString();
    if (!root.endsWith("/")) {
        root += "/";
    }
    username1 = prop.getProperty(("webdav.test.username1"), "");
    if (username1 == null) {
        username1 = "user1";
    }
    assertTrue(username1 != null);
    password1 = prop.getProperty(("webdav.test.password1"), "");
    if (password1 == null) {
        password1 = "passwd1";
    }
    assertTrue(password1 != null);
    username2 = prop.getProperty(("webdav.test.username2"), "user2");
    assertTrue(username2 != null);
    password2 = prop.getProperty(("webdav.test.password2"), "passwd2");
    assertTrue(password2 != null);
    quckTest = Boolean.valueOf(prop.getProperty(("test.quick"), "true"));
    client1 = new HttpClient();
    HttpClientParams params = new HttpClientParams();
    params.setParameter("http.protocol.handle-redirects", false);
    client1.setParams(params);
    assertNotNull(uri.getHost());
    assertNotNull(uri.getPort());
    assertNotNull(client1);
    int port = uri.getPort();
    if (port == -1) {
        port = 443;
    }
    ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
    Protocol https = new Protocol("https", socketFactory, port);
    Protocol.registerProtocol("https", https);
    client1.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username1, password1));
    httpclient = new DefaultHttpClient();
    org.apache.http.auth.Credentials defaultcreds = new org.apache.http.auth.UsernamePasswordCredentials(username1, password1);
    httpclient.getCredentialsProvider().setCredentials(org.apache.http.auth.AuthScope.ANY, (org.apache.http.auth.Credentials) defaultcreds);
    // httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    client2 = new HttpClient();
    assertNotNull(uri.getHost());
    assertNotNull(uri.getPort());
    assertNotNull(client2);
    client2.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username2, password2));
    ClientConfig clientConfig = new DefaultClientConfig();
    clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
    restClient = Client.create(clientConfig);
    restClient.addFilter(new com.sun.jersey.api.client.filter.HTTPBasicAuthFilter(username1, password1));
    restURL = prop.getProperty(("rest.test.url"), "http://localhost:8080/lobcder-2.0-SNAPSHOT/rest/");
    utils = new Utils(client1);
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) EasySSLProtocolSocketFactory(org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) EasySSLProtocolSocketFactory(org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory) ProtocolSocketFactory(org.apache.commons.httpclient.protocol.ProtocolSocketFactory) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.commons.httpclient.HttpClient) HttpClientParams(org.apache.commons.httpclient.params.HttpClientParams) AuthScope(org.apache.commons.httpclient.auth.AuthScope) Protocol(org.apache.commons.httpclient.protocol.Protocol) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) BeforeClass(org.junit.BeforeClass)

Aggregations

AuthScope (org.apache.commons.httpclient.auth.AuthScope)52 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)34 Credentials (org.apache.commons.httpclient.Credentials)19 GetMethod (org.apache.commons.httpclient.methods.GetMethod)12 HttpClient (org.apache.commons.httpclient.HttpClient)11 URL (java.net.URL)10 IOException (java.io.IOException)5 NTCredentials (org.apache.commons.httpclient.NTCredentials)5 Protocol (org.apache.commons.httpclient.protocol.Protocol)5 ProtocolSocketFactory (org.apache.commons.httpclient.protocol.ProtocolSocketFactory)5 Header (org.apache.commons.httpclient.Header)4 AuthScheme (org.apache.commons.httpclient.auth.AuthScheme)4 AuthState (org.apache.commons.httpclient.auth.AuthState)4 EasySSLProtocolSocketFactory (org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory)4 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)3 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)3 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 URISyntaxException (java.net.URISyntaxException)3 ArrayList (java.util.ArrayList)3