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);
}
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);
}
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);
}
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);
}
}
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);
}
Aggregations