use of org.gridlab.gat.security.PasswordSecurityContext in project compss by bsc-wdc.
the class FileAdaptorTest method test.
public AdaptorTestResult test(String adaptor, String host) {
run(host, "adaptor-test-init.sh");
AdaptorTestResult adaptorTestResult = new AdaptorTestResult(adaptor, host);
GATContext gatContext = new GATContext();
PasswordSecurityContext password = new PasswordSecurityContext("username", "TeMpPaSsWoRd");
password.addNote("adaptors", "ftp");
gatContext.addSecurityContext(password);
// CertificateSecurityContext ctxt = new CertificateSecurityContext(null, null, "username", "passphrase");
// gatContext.addSecurityContext(ctxt);
Preferences preferences = new Preferences();
preferences.put("file.adaptor.name", adaptor + ",local");
adaptorTestResult.put("exists: absolute existing file", existTest(gatContext, preferences, host, "/tmp/JavaGAT-test-exists-file", 0, true));
adaptorTestResult.put("exists: absolute existing dir", existTest(gatContext, preferences, host, "/tmp/JavaGAT-test-exists-dir", 0, true));
adaptorTestResult.put("exists: absolute non-existing file", existTest(gatContext, preferences, host, "/tmp/JavaGAT-test-exists-fake", 0, false));
adaptorTestResult.put("exists: relative existing file", existTest(gatContext, preferences, host, "JavaGAT-test-exists-file", 1, true));
adaptorTestResult.put("exists: relative existing dir", existTest(gatContext, preferences, host, "JavaGAT-test-exists-dir", 1, true));
adaptorTestResult.put("exists: relative non-existing file", existTest(gatContext, preferences, host, "JavaGAT-test-exists-fake", 1, false));
adaptorTestResult.put("mkdir: absolute non-existing dir", mkdirTest(gatContext, preferences, host, "/tmp/JavaGAT-test-mkdir-dir", 0, true));
adaptorTestResult.put("mkdir: absolute existing dir", mkdirTest(gatContext, preferences, host, "/tmp/JavaGAT-test-mkdir-dir", 0, false));
adaptorTestResult.put("mkdir: relative non-existing dir", mkdirTest(gatContext, preferences, host, "JavaGAT-test-mkdir-dir", 1, true));
adaptorTestResult.put("mkdir: relative existing dir", mkdirTest(gatContext, preferences, host, "JavaGAT-test-mkdir-dir", 1, false));
adaptorTestResult.put("mkdirs: absolute non-existing dir", mkdirsTest(gatContext, preferences, host, "/tmp/JavaGAT-test-mkdirs/1/2/3", 0, true));
adaptorTestResult.put("mkdirs: absolute existing dir", mkdirsTest(gatContext, preferences, host, "/tmp/JavaGAT-test-mkdirs/1/2/3", 0, false));
adaptorTestResult.put("mkdirs: relative non-existing dir", mkdirsTest(gatContext, preferences, host, "JavaGAT-test-mkdirs/1/2/3", 0, true));
adaptorTestResult.put("mkdirs: relative existing dir", mkdirsTest(gatContext, preferences, host, "JavaGAT-test-mkdirs/1/2/3", 0, false));
adaptorTestResult.put("delete: absolute existing file", deleteTest(gatContext, preferences, host, "/tmp/JavaGAT-test-delete-file", 0, true));
adaptorTestResult.put("delete: absolute non-existing file", deleteTest(gatContext, preferences, host, "/tmp/JavaGAT-test-delete-file", 0, false));
adaptorTestResult.put("delete: absolute existing dir", deleteTest(gatContext, preferences, host, "/tmp/JavaGAT-test-delete-dir/", 0, true));
adaptorTestResult.put("delete: absolute non-existing dir", deleteTest(gatContext, preferences, host, "/tmp/JavaGAT-test-delete-fake", 0, false));
adaptorTestResult.put("delete: relative existing file", deleteTest(gatContext, preferences, host, "JavaGAT-test-delete-file", 0, true));
adaptorTestResult.put("delete: relative non-existing file", deleteTest(gatContext, preferences, host, "JavaGAT-test-delete-file", 0, false));
adaptorTestResult.put("delete: relative existing dir", deleteTest(gatContext, preferences, host, "JavaGAT-test-delete-dir", 1, true));
adaptorTestResult.put("delete: relative non-existing dir", deleteTest(gatContext, preferences, host, "JavaGAT-test-delete-dir", 1, false));
adaptorTestResult.put("isFile: existing dir", isFileTest(gatContext, preferences, host, "JavaGAT-test-filedir-dir", 0, false));
adaptorTestResult.put("isFile: existing file", isFileTest(gatContext, preferences, host, "JavaGAT-test-filedir-file", 0, true));
adaptorTestResult.put("isFile: non-existing file", isFileTest(gatContext, preferences, host, "JavaGAT-test-filedir-fake", 0, false));
adaptorTestResult.put("isDirectory: existing dir", isDirectoryTest(gatContext, preferences, host, "JavaGAT-test-filedir-dir", 0, true));
adaptorTestResult.put("isDirectory: existing file", isDirectoryTest(gatContext, preferences, host, "JavaGAT-test-filedir-file", 0, false));
adaptorTestResult.put("isDirectory: non-existing file", isDirectoryTest(gatContext, preferences, host, "JavaGAT-test-filedir-fake", 0, false));
adaptorTestResult.put("canRead: readable file", canReadTest(gatContext, preferences, host, "JavaGAT-test-mode-readable", 0, true));
adaptorTestResult.put("canRead: non-readable file", canReadTest(gatContext, preferences, host, "JavaGAT-test-mode-unreadable", 0, false));
adaptorTestResult.put("canRead: non-existent file", canReadTest(gatContext, preferences, host, "JavaGAT-test-mode-does-not-exist", 0, false));
adaptorTestResult.put("canWrite: writable file", canWriteTest(gatContext, preferences, host, "JavaGAT-test-mode-writable", 0, true));
adaptorTestResult.put("canWrite: non-writable file", canWriteTest(gatContext, preferences, host, "JavaGAT-test-mode-unwritable", 0, false));
adaptorTestResult.put("canWrite: non-existent file", canWriteTest(gatContext, preferences, host, "JavaGAT-test-mode-does-not-exist", 0, false));
adaptorTestResult.put("length, existing file:", lengthTest(gatContext, preferences, host, "JavaGAT-test-length", 1, 6));
adaptorTestResult.put("length, non-existent file:", lengthTest(gatContext, preferences, host, "JavaGAT-test-length-nonexistent", 1, 0));
adaptorTestResult.put("list:", listTest(gatContext, preferences, host, "JavaGAT-test-list", 2, "file1", "file2", "dir1"));
adaptorTestResult.put("lastModified, existent file:", lastModifiedTest(gatContext, preferences, host, "JavaGAT-test-last-modified", 0, 458258400000L));
adaptorTestResult.put("lastModified, non-existent file:", lastModifiedTest(gatContext, preferences, host, "JavaGAT-test-last-modified-nonexist", 0, 0L));
adaptorTestResult.put("createNewFile: non-existent file", createNewFileTest(gatContext, preferences, host, "JavaGAT-test-new-file", 1, true));
adaptorTestResult.put("createNewFile: existent file", createNewFileTest(gatContext, preferences, host, "JavaGAT-test-new-file", 1, false));
adaptorTestResult.put("copy: small relative file", copyFileTest(gatContext, preferences, host, "JavaGAT-test-copy-small", 1, true));
adaptorTestResult.put("copy: large relative file", copyFileTest(gatContext, preferences, host, "JavaGAT-test-copy-large", 1, true));
adaptorTestResult.put("copy: small absolute file", copyFileTest(gatContext, preferences, host, "/tmp/JavaGAT-test-copy-small", 1, true));
adaptorTestResult.put("copy: large absolute file", copyFileTest(gatContext, preferences, host, "/tmp/JavaGAT-test-copy-large", 1, true));
run(host, "adaptor-test-clean.sh");
return adaptorTestResult;
}
use of org.gridlab.gat.security.PasswordSecurityContext in project compss by bsc-wdc.
the class FileOutputStreamAdaptorTest method test.
public AdaptorTestResult test(String adaptor, String host) {
AdaptorTestResult adaptorTestResult = new AdaptorTestResult(adaptor, host);
GATContext gatContext = new GATContext();
PasswordSecurityContext password = new PasswordSecurityContext("username", "TeMpPaSsWoRd");
password.addNote("adaptors", "ftp");
gatContext.addSecurityContext(password);
// CertificateSecurityContext ctxt = new CertificateSecurityContext(null, null, "username", "passphrase");
// gatContext.addSecurityContext(ctxt);
Preferences preferences = new Preferences();
preferences.put("fileoutputstream.adaptor.name", adaptor);
FileOutputStream out = null;
try {
out = GAT.createFileOutputStream(gatContext, preferences, "any://" + host + "/JavaGAT-test-fileoutputstream");
} catch (GATObjectCreationException e) {
adaptorTestResult.put("create ", new AdaptorTestResultEntry(false, 0, e));
run(host, "fileoutputstream-adaptor-test-clean.sh");
return adaptorTestResult;
}
byte[] large = new byte[10 * 1024 * 1024];
for (int i = 0; i < large.length; i++) {
large[i] = 'a';
}
adaptorTestResult.put("write (small)", writeTest(out, "test\n"));
adaptorTestResult.put("write (large)", writeTest(out, new String(large)));
adaptorTestResult.put("flush ", flushTest(out));
adaptorTestResult.put("close ", closeTest(out));
run(host, "fileoutputstream-adaptor-test-clean.sh");
return adaptorTestResult;
}
use of org.gridlab.gat.security.PasswordSecurityContext in project compss by bsc-wdc.
the class FileInputStreamAdaptorTest method test.
public AdaptorTestResult test(String adaptor, String host) {
run(host, "fileinputstream-adaptor-test-init.sh");
AdaptorTestResult adaptorTestResult = new AdaptorTestResult(adaptor, host);
GATContext gatContext = new GATContext();
PasswordSecurityContext password = new PasswordSecurityContext("username", "TeMpPaSsWoRd");
password.addNote("adaptors", "ftp");
gatContext.addSecurityContext(password);
// CertificateSecurityContext ctxt = new CertificateSecurityContext(null, null, "username", "passphrase");
// gatContext.addSecurityContext(ctxt);
Preferences preferences = new Preferences();
preferences.put("fileinputstream.adaptor.name", adaptor);
FileInputStream in = null;
try {
in = GAT.createFileInputStream(gatContext, preferences, "any://" + host + "/JavaGAT-test-fileinputstream");
} catch (GATObjectCreationException e) {
adaptorTestResult.put("create ", new AdaptorTestResultEntry(false, 0, e));
run(host, "fileinputstream-adaptor-test-clean.sh");
return adaptorTestResult;
}
adaptorTestResult.put("markSupported ", markSupportedTest(in));
adaptorTestResult.put("available: ", availableTest(in, 0, true));
adaptorTestResult.put("read: single char a", readTest(in, 'a', true));
adaptorTestResult.put("read: single char b", readTest(in, 'b', true));
adaptorTestResult.put("read: single char c", readTest(in, 'c', true));
adaptorTestResult.put("read: single char !d", readTest(in, 'q', false));
adaptorTestResult.put("read: small ", readTest(in, "efg".getBytes(), true));
byte[] bytes = new byte[1024 * 1024 * 10];
byte current = 'h';
for (int i = 0; i < bytes.length; i++) {
bytes[i] = current;
if (current == 'z') {
current = '\n';
} else if (current == '\n') {
current = 'a';
} else {
current++;
}
}
adaptorTestResult.put("read: large ", readTest(in, bytes, true));
adaptorTestResult.put("skip: small ", skipTest(in, 100));
adaptorTestResult.put("skip: large ", skipTest(in, 10 * 1024 * 1024));
adaptorTestResult.put("close ", closeTest(in));
run(host, "fileinputstream-adaptor-test-clean.sh");
return adaptorTestResult;
}
use of org.gridlab.gat.security.PasswordSecurityContext in project compss by bsc-wdc.
the class SecurityExample method main.
/**
* This example shows the use of the SecurityContext objects in JavaGAT.
*
* This example will attach various security contexts to a GATContext. Then
* it will try to create the same file with and without this GATContext.
* Note that you've to replace the arguments of the methods with values that
* are suitable for your environment. Please don't put passwords and
* passphrases directly in the source code, but try to retrieve by having
* the user to type it.
*
* @param args
* a String representation of a valid JavaGAT uri that points
* to a file
*/
public static void main(String[] args) {
GATContext context = new GATContext();
try {
// create a certificate security context
CertificateSecurityContext globusSecurityContext = new CertificateSecurityContext(new URI("userkey.pem"), new URI("usercert.pem"), "grid-proxy-init passphrase");
// add a note to this security context; it's only to be used for the
// globus and wsgt4new adaptors
globusSecurityContext.addNote("adaptors", "globus,wsgt4new");
context.addSecurityContext(globusSecurityContext);
} catch (URISyntaxException e) {
// ignore
}
// create a password security context
PasswordSecurityContext ftpSecurityContext = new PasswordSecurityContext(System.getProperty("user.name"), "ftp password");
// add a note to this security context; it's only to be used for ftp and
// only for two hosts, host1 and host2:21
ftpSecurityContext.addNote("adaptors", "ftp");
ftpSecurityContext.addNote("hosts", "host1,host2:21");
context.addSecurityContext(ftpSecurityContext);
PasswordSecurityContext sshSecurityContext = new PasswordSecurityContext(System.getProperty("user.name"), "ssh password");
// add a note to this security context; it's only to be used for
// sshtrilead and commandlinessh and only for one host, host3
sshSecurityContext.addNote("adaptors", "sshtrilead,commandlinessh");
sshSecurityContext.addNote("hosts", "host3");
context.addSecurityContext(sshSecurityContext);
// contexts attached
try {
File file = GAT.createFile(context, new URI(args[0]));
System.out.println(args[0] + " exists: " + file.exists());
} catch (Exception e) {
System.err.println("Failed to check whether '" + args[0] + "' exists: " + e);
}
// contexts.
try {
File file2 = GAT.createFile(new URI(args[0]));
System.out.println(args[0] + " exists: " + file2.exists());
} catch (Exception e) {
System.err.println("Failed to check whether '" + args[0] + "' exists: " + e);
}
}
Aggregations