You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2015/02/23 11:10:20 UTC
[45/54] [partial] incubator-taverna-engine git commit: Revert
"temporarily empty repository"
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/PossibleURILookupsTest.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/PossibleURILookupsTest.java b/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/PossibleURILookupsTest.java
new file mode 100644
index 0000000..1cf20ff
--- /dev/null
+++ b/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/PossibleURILookupsTest.java
@@ -0,0 +1,254 @@
+/*******************************************************************************
+ * Copyright (C) 2008-2010 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.security.credentialmanager.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Random;
+
+import net.sf.taverna.t2.security.credentialmanager.CMException;
+import net.sf.taverna.t2.security.credentialmanager.JavaTruststorePasswordProvider;
+import net.sf.taverna.t2.security.credentialmanager.MasterPasswordProvider;
+import net.sf.taverna.t2.security.credentialmanager.ServiceUsernameAndPasswordProvider;
+import net.sf.taverna.t2.security.credentialmanager.TrustConfirmationProvider;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ * @author Stian Soiland-Reyes
+ * @author Alex Nenadic
+ *
+ */
+public class PossibleURILookupsTest {
+ private static final String SIMPLE_URI = "http://www.taverna.org.uk/filename.html";
+ private static final String ROOT_URI = "http://www.taverna.org.uk/";
+ private static final String NAIVE_ROOT_URI = "http://www.taverna.org.uk";
+
+ private static final String NASTY_URI = "http://www.taverna.org.uk/path1/path2/path3/filename.html?query=1&query2=2";
+
+ private static final String NASTY_URI_FRAGMENT = "http://www.taverna.org.uk/path1/path2/path3/filename.html?query=1&query2=2#frag1337";
+
+ private static final String NASTY_URI_PARENT = "http://www.taverna.org.uk/path1/path2/path3/";
+
+ private static final String NASTY_DOT_DOT_URI = "http://www.taverna.org.uk/path1/path2/path3/path4/../fish.html";
+
+ private static CredentialManagerImpl credentialManager;
+ private static File credentialManagerDirectory;
+ private static DummyMasterPasswordProvider masterPasswordProvider;
+ private static HTTPAuthenticatorServiceUsernameAndPasswordProvider httpAuthProvider;
+
+ @BeforeClass
+ public static void setUp() throws CMException, IOException {
+
+ try {
+ credentialManager = new CredentialManagerImpl();
+ } catch (CMException e) {
+ System.out.println(e.getStackTrace());
+ }
+ Random randomGenerator = new Random();
+ String credentialManagerDirectoryPath = System
+ .getProperty("java.io.tmpdir")
+ + System.getProperty("file.separator")
+ + "taverna-security-"
+ + randomGenerator.nextInt(1000000);
+ System.out.println("Credential Manager's directory path: "
+ + credentialManagerDirectoryPath);
+ credentialManagerDirectory = new File(credentialManagerDirectoryPath);
+ try {
+ credentialManager
+ .setConfigurationDirectoryPath(credentialManagerDirectory);
+ } catch (CMException e) {
+ System.out.println(e.getStackTrace());
+ }
+
+ // Create the dummy master password provider
+ masterPasswordProvider = new DummyMasterPasswordProvider();
+ /* Short password to avoid issues with key sizes and Java strong crypto policy*/
+ masterPasswordProvider.setMasterPassword("uber");
+ List<MasterPasswordProvider> masterPasswordProviders = new ArrayList<MasterPasswordProvider>();
+ masterPasswordProviders.add(masterPasswordProvider);
+ credentialManager.setMasterPasswordProviders(masterPasswordProviders);
+
+ // Put our HTTP authenticator in the list of service username and password providers
+ httpAuthProvider = new HTTPAuthenticatorServiceUsernameAndPasswordProvider();
+ ArrayList<ServiceUsernameAndPasswordProvider> serviceUsernameAndPasswordProviders = new ArrayList<ServiceUsernameAndPasswordProvider>();
+ serviceUsernameAndPasswordProviders.add(httpAuthProvider);
+ credentialManager.setServiceUsernameAndPasswordProviders(serviceUsernameAndPasswordProviders);
+
+ // These can be empty
+ credentialManager.setJavaTruststorePasswordProviders(new ArrayList<JavaTruststorePasswordProvider>());
+ credentialManager.setTrustConfirmationProviders(new ArrayList<TrustConfirmationProvider>());
+ }
+
+ @AfterClass
+ // Clean up the credentialManagerDirectory we created for testing
+ public static void cleanUp(){
+
+ if (credentialManagerDirectory.exists()){
+ try {
+ FileUtils.deleteDirectory(credentialManagerDirectory);
+ System.out.println("Deleting Credential Manager's directory: "
+ + credentialManagerDirectory.getAbsolutePath());
+ } catch (IOException e) {
+ System.out.println(e.getStackTrace());
+ }
+ }
+ }
+
+ @Test
+ public void possibleLookupsNoRecursion() throws Exception {
+ URI uri = URI.create(NASTY_URI);
+ LinkedHashSet<URI> lookups = credentialManager.getPossibleServiceURIsToLookup(uri,
+ false);
+ assertTrue("Did not contain " + uri, lookups.remove(uri));
+ assertTrue("Unexpected lookups:" + lookups, lookups.isEmpty());
+ }
+
+ @Test
+ public void possibleLookupsDotDot() throws Exception {
+ URI uri = URI.create(NASTY_DOT_DOT_URI);
+ List<URI> expected = Arrays
+ .asList(
+ URI.create("http://www.taverna.org.uk/path1/path2/path3/fish.html"),
+ URI.create("http://www.taverna.org.uk/path1/path2/path3/"),
+ URI.create("http://www.taverna.org.uk/path1/path2/"),
+ URI.create("http://www.taverna.org.uk/path1/"),
+ URI.create("http://www.taverna.org.uk/"));
+
+ ArrayList<URI> lookups = new ArrayList<URI>(credentialManager
+ .getPossibleServiceURIsToLookup(uri, true));
+
+ assertEquals("Did not match expected URIs", expected, lookups);
+ }
+
+ @Test
+ public void possibleLookups() throws Exception {
+ URI uri = URI.create(NASTY_URI);
+ List<URI> expected = Arrays
+ .asList(
+ URI.create("http://www.taverna.org.uk/path1/path2/path3/filename.html?query=1&query2=2"),
+ URI.create("http://www.taverna.org.uk/path1/path2/path3/filename.html"),
+ URI.create("http://www.taverna.org.uk/path1/path2/path3/"),
+ URI.create("http://www.taverna.org.uk/path1/path2/"),
+ URI.create("http://www.taverna.org.uk/path1/"), URI
+ .create("http://www.taverna.org.uk/"));
+
+ ArrayList<URI> lookups = new ArrayList<URI>(credentialManager
+ .getPossibleServiceURIsToLookup(uri, true));
+
+ assertEquals("Did not match expected URIs", expected, lookups);
+ }
+
+
+ @Test
+ public void possibleLookupsWithFragment() throws Exception {
+ URI uri = URI.create(NASTY_URI_FRAGMENT);
+ List<URI> expected = Arrays
+ .asList(
+ URI.create("http://www.taverna.org.uk/path1/path2/path3/filename.html?query=1&query2=2#frag1337"),
+ URI.create("http://www.taverna.org.uk/path1/path2/path3/filename.html#frag1337"),
+ URI.create("http://www.taverna.org.uk/path1/path2/path3/#frag1337"),
+ URI.create("http://www.taverna.org.uk/path1/path2/#frag1337"),
+ URI.create("http://www.taverna.org.uk/path1/#frag1337"), URI
+ .create("http://www.taverna.org.uk/#frag1337"),
+ // And then again without fragment
+ URI.create("http://www.taverna.org.uk/path1/path2/path3/filename.html?query=1&query2=2"),
+ URI.create("http://www.taverna.org.uk/path1/path2/path3/filename.html"),
+ URI.create("http://www.taverna.org.uk/path1/path2/path3/"),
+ URI.create("http://www.taverna.org.uk/path1/path2/"),
+ URI.create("http://www.taverna.org.uk/path1/"), URI
+ .create("http://www.taverna.org.uk/")
+
+ );
+
+ ArrayList<URI> lookups = new ArrayList<URI>(credentialManager
+ .getPossibleServiceURIsToLookup(uri, true));
+
+ assertEquals("Did not match expected URIs", expected, lookups);
+ }
+
+ @Test
+ public void possibleLookupDirectory() throws Exception {
+ URI uri = URI.create(NASTY_URI_PARENT);
+ List<URI> expected = Arrays.asList(URI
+ .create("http://www.taverna.org.uk/path1/path2/path3/"), URI
+ .create("http://www.taverna.org.uk/path1/path2/"), URI
+ .create("http://www.taverna.org.uk/path1/"), URI
+ .create("http://www.taverna.org.uk/"));
+
+ ArrayList<URI> lookups = new ArrayList<URI>(credentialManager
+ .getPossibleServiceURIsToLookup(uri, true));
+
+ assertEquals("Did not match expected URIs", expected, lookups);
+ }
+
+ @Test
+ public void possibleLookupSimple() throws Exception {
+ URI uri = URI.create(SIMPLE_URI);
+ List<URI> expected = Arrays.asList(URI
+ .create("http://www.taverna.org.uk/filename.html"), URI
+ .create("http://www.taverna.org.uk/"));
+
+ ArrayList<URI> lookups = new ArrayList<URI>(credentialManager
+ .getPossibleServiceURIsToLookup(uri, true));
+
+ assertEquals("Did not match expected URIs", expected, lookups);
+ }
+
+ @Test
+ public void possibleLookupRoot() throws Exception {
+ URI uri = URI.create(ROOT_URI);
+ List<URI> expected = Arrays.asList(URI
+ .create("http://www.taverna.org.uk/"));
+
+ ArrayList<URI> lookups = new ArrayList<URI>(credentialManager
+ .getPossibleServiceURIsToLookup(uri, true));
+
+ assertEquals("Did not match expected URIs", expected, lookups);
+ }
+
+ @Test
+ public void possibleLookupNaiveRoot() throws Exception {
+ URI uri = URI.create(NAIVE_ROOT_URI);
+ List<URI> expected = Arrays.asList(URI
+ .create("http://www.taverna.org.uk"), URI
+ .create("http://www.taverna.org.uk/"));
+
+ ArrayList<URI> lookups = new ArrayList<URI>(credentialManager
+ .getPossibleServiceURIsToLookup(uri, true));
+
+ assertEquals("Did not match expected URIs", expected, lookups);
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/TrustAlwaysTrustConfirmationProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/TrustAlwaysTrustConfirmationProvider.java b/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/TrustAlwaysTrustConfirmationProvider.java
new file mode 100644
index 0000000..bae9e54
--- /dev/null
+++ b/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/TrustAlwaysTrustConfirmationProvider.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (C) 2008-2010 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.security.credentialmanager.impl;
+
+import java.security.cert.X509Certificate;
+
+import net.sf.taverna.t2.security.credentialmanager.TrustConfirmationProvider;
+
+public class TrustAlwaysTrustConfirmationProvider implements TrustConfirmationProvider{
+
+ @Override
+ public Boolean shouldTrustCertificate(X509Certificate[] chain) {
+
+ // Always trust
+ return Boolean.TRUE;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/TrustNeverTrustConfimationProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/TrustNeverTrustConfimationProvider.java b/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/TrustNeverTrustConfimationProvider.java
new file mode 100644
index 0000000..f7e0aee
--- /dev/null
+++ b/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/TrustNeverTrustConfimationProvider.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (C) 2008-2010 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.security.credentialmanager.impl;
+
+import java.security.cert.X509Certificate;
+
+import net.sf.taverna.t2.security.credentialmanager.TrustConfirmationProvider;
+
+public class TrustNeverTrustConfimationProvider implements TrustConfirmationProvider{
+
+ @Override
+ public Boolean shouldTrustCertificate(X509Certificate[] chain) {
+
+ // Never trust
+ return Boolean.FALSE;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager-impl/src/test/resources/html/test.html
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/test/resources/html/test.html b/taverna-credential-manager-impl/src/test/resources/html/test.html
new file mode 100644
index 0000000..aca08e6
--- /dev/null
+++ b/taverna-credential-manager-impl/src/test/resources/html/test.html
@@ -0,0 +1,5 @@
+<html>
+ <body>
+ Hello!
+ </body>
+</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager-impl/src/test/resources/security/google-trusted-certificate.pem
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/test/resources/security/google-trusted-certificate.pem b/taverna-credential-manager-impl/src/test/resources/security/google-trusted-certificate.pem
new file mode 100644
index 0000000..803d7db
--- /dev/null
+++ b/taverna-credential-manager-impl/src/test/resources/security/google-trusted-certificate.pem
@@ -0,0 +1,29 @@
+-----BEGIN CERTIFICATE-----
+MIIFCDCCBHGgAwIBAgIKYaLlHAADAAAtEDANBgkqhkiG9w0BAQUFADBGMQswCQYD
+VQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIElu
+dGVybmV0IEF1dGhvcml0eTAeFw0xMTA3MjcxMDExNTlaFw0xMjA3MjcxMDIxNTla
+MGYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1N
+b3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgSW5jMRUwEwYDVQQDFAwqLmdv
+b2dsZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANCK/ZK6aQGxkbxJ
+BQavVU11O36JxAWwHSw1d5pNFS4FKUZSWAQrde2PEaGO3q/lezcK1Fef/ldZIu0M
+ZHYCdKoP5Axd8znIuJhbHw3xwnEi5V0gMINENEMcxdBsUCZiPTWFDI3v45bPYit3
+0wud8eBR94SAUfF27djcyGHq4VunAgMBAAGjggLbMIIC1zAdBgNVHQ4EFgQUflky
+CQk5VOPCyPDf6uPwmRDiB44wHwYDVR0jBBgwFoAUv8Aw6/VDET5nup6R+/xq2uNr
+EiQwWwYDVR0fBFQwUjBQoE6gTIZKaHR0cDovL3d3dy5nc3RhdGljLmNvbS9Hb29n
+bGVJbnRlcm5ldEF1dGhvcml0eS9Hb29nbGVJbnRlcm5ldEF1dGhvcml0eS5jcmww
+ZgYIKwYBBQUHAQEEWjBYMFYGCCsGAQUFBzAChkpodHRwOi8vd3d3LmdzdGF0aWMu
+Y29tL0dvb2dsZUludGVybmV0QXV0aG9yaXR5L0dvb2dsZUludGVybmV0QXV0aG9y
+aXR5LmNydDAhBgkrBgEEAYI3FAIEFB4SAFcAZQBiAFMAZQByAHYAZQByMIIBqwYD
+VR0RBIIBojCCAZ6CDCouZ29vZ2xlLmNvbYIKZ29vZ2xlLmNvbYILKi5hdGdnbC5j
+b22CDSoueW91dHViZS5jb22CC3lvdXR1YmUuY29tggsqLnl0aW1nLmNvbYIPKi5n
+b29nbGUuY29tLmJygg4qLmdvb2dsZS5jby5pboILKi5nb29nbGUuZXOCDiouZ29v
+Z2xlLmNvLnVrggsqLmdvb2dsZS5jYYILKi5nb29nbGUuZnKCCyouZ29vZ2xlLnB0
+ggsqLmdvb2dsZS5pdIILKi5nb29nbGUuZGWCCyouZ29vZ2xlLmNsggsqLmdvb2ds
+ZS5wbIILKi5nb29nbGUubmyCDyouZ29vZ2xlLmNvbS5hdYIOKi5nb29nbGUuY28u
+anCCCyouZ29vZ2xlLmh1gg8qLmdvb2dsZS5jb20ubXiCDyouZ29vZ2xlLmNvbS5h
+coIPKi5nb29nbGUuY29tLmNvgg8qLmdvb2dsZS5jb20udm6CDyouZ29vZ2xlLmNv
+bS50coINKi5hbmRyb2lkLmNvbYIUKi5nb29nbGVjb21tZXJjZS5jb20wDQYJKoZI
+hvcNAQEFBQADgYEAF9+a/uwn7VpDIF0jqn6oNRNwbBnfwxvr2Kilxe2BpBDEzq3a
+ELLK6eozpR8LAM7uLzGyIdTIBOvYH2HKjmLZ/fdaARoXnk7xSspOs/DRZ3inh2d/
+KwDcKoeS49p53dpUZ5805fUqY/v9yiEvhAwpaJrGRaS6YCsFTYFVE0+awYo=
+-----END CERTIFICATE-----
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager-impl/src/test/resources/security/t2keystore.ubr
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/test/resources/security/t2keystore.ubr b/taverna-credential-manager-impl/src/test/resources/security/t2keystore.ubr
new file mode 100644
index 0000000..474ad77
Binary files /dev/null and b/taverna-credential-manager-impl/src/test/resources/security/t2keystore.ubr differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager-impl/src/test/resources/security/t2truststore.ubr
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/test/resources/security/t2truststore.ubr b/taverna-credential-manager-impl/src/test/resources/security/t2truststore.ubr
new file mode 100644
index 0000000..15d38f2
Binary files /dev/null and b/taverna-credential-manager-impl/src/test/resources/security/t2truststore.ubr differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager-impl/src/test/resources/security/test-private-key-cert.p12
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/test/resources/security/test-private-key-cert.p12 b/taverna-credential-manager-impl/src/test/resources/security/test-private-key-cert.p12
new file mode 100644
index 0000000..6f298c5
Binary files /dev/null and b/taverna-credential-manager-impl/src/test/resources/security/test-private-key-cert.p12 differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager-impl/src/test/resources/security/tomcat_heater_certificate.pem
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/test/resources/security/tomcat_heater_certificate.pem b/taverna-credential-manager-impl/src/test/resources/security/tomcat_heater_certificate.pem
new file mode 100644
index 0000000..c729258
--- /dev/null
+++ b/taverna-credential-manager-impl/src/test/resources/security/tomcat_heater_certificate.pem
@@ -0,0 +1,20 @@
+-----BEGIN CERTIFICATE-----
+MIIDyDCCArCgAwIBAgIETlYTBzANBgkqhkiG9w0BAQUFADCBpTELMAkGA1UEBhMCVUsxGzAZBgNV
+BAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjETMBEGA1UEBxMKTWFuY2hlc3RlcjEhMB8GA1UEChMYVW5p
+dmVyc2l0eSBvZiBNYW5jaGVzdGVyMSMwIQYDVQQLExpTY2hvb2wgb2YgQ29tcHV0ZXIgU2NpZW5j
+ZTEcMBoGA1UEAxMTaGVhdGVyLmNzLm1hbi5hYy51azAeFw0xMTA4MjUwOTE2NTVaFw0yMTA4MjIw
+OTE2NTVaMIGlMQswCQYDVQQGEwJVSzEbMBkGA1UECBMSR3JlYXRlciBNYW5jaGVzdGVyMRMwEQYD
+VQQHEwpNYW5jaGVzdGVyMSEwHwYDVQQKExhVbml2ZXJzaXR5IG9mIE1hbmNoZXN0ZXIxIzAhBgNV
+BAsTGlNjaG9vbCBvZiBDb21wdXRlciBTY2llbmNlMRwwGgYDVQQDExNoZWF0ZXIuY3MubWFuLmFj
+LnVrMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1/TuezSNYFpD2NTtw5UGECCPwClV
+Om08Nca1aanOVxv5rcn4eUVbu6Btm/dqgiCeV8nCyu7nEPvWP+Kvktseikx3LZ08qKdDRLpNa68/
+WrjcbS6ICs2hphhqftHSpl0OPnWkQicbI7Z4uUdqmF6DsLDOLpRfiYhh9lZ0FM7PD3yt42GR5E2B
+j465IJQweZxLCsRKwuZlvOsWJxnx1MHVj7ZFBYl7HSBfEpvThyqKL5R7FOZW0zpG3+Y+S9HmfQYk
+BipXrrNS1+lsIwPU8jD31PBzVPBNxIeKYHxXCKLf+EBah/tAKSxIzUihxhh1pdNEPvUyy2zY9vyv
+1PfXd8Uk0wIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQAtiPDBRlmjhFd9DP1NvbyfMApdjLufMLvr
+mzze3W6A4XUZj+kXR/Z3KYj84pWOnhe+Benvw5bIf2JM+sqIiSUA+TB8losx+SeY5hZ3lqEFY1wZ
+1qy47hH3rY98RdSAXlAhvGCEL/CktvIEHgaSlCmrOvK76ySwRCTYA9DJTWeB81R7bP7le2ewSg5c
+MY/Hy3VBkMGbVnZQoHhkUd7TIsPqD1SvYQDCug49JFsKsyrfep3nANAQO7uR8FYrCYtXj66z9ziO
+m0gZm+h/Rq8StgMrNwmi+3mGAgRJ6JKj4vAWJfyUSaOjLLf9u3BvrxVtQKCMSDGx25dBFlZXHIhE
+rONf
+-----END CERTIFICATE-----
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-credential-manager/pom.xml b/taverna-credential-manager/pom.xml
new file mode 100644
index 0000000..e8b967a
--- /dev/null
+++ b/taverna-credential-manager/pom.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.taverna.engine</groupId>
+ <artifactId>taverna-engine</artifactId>
+ <version>3.1.0-incubating-SNAPSHOT</version>
+ </parent>
+ <artifactId>taverna-credential-manager</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Taverna Credential manager</name>
+ <dependencies>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>taverna-observer</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.taverna.osgi</groupId>
+ <artifactId>taverna-app-configuration-api</artifactId>
+ <version>${taverna.osgi.version}</version>
+ </dependency>
+ <!-- <dependency>
+ <groupId>org.bouncycastle</groupId>
+ <artifactId>com.springsource.org.bouncycastle.jce</artifactId>
+ <version>1.39.0</version>
+ </dependency> -->
+ <dependency>
+ <groupId>org.bouncycastle</groupId>
+ <artifactId>bcprov-jdk16</artifactId>
+ <version>${bcprov.jdk16.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>${log4j.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>${commons.io.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>${jetty.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/CMException.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/CMException.java b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/CMException.java
new file mode 100644
index 0000000..a18e39b
--- /dev/null
+++ b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/CMException.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.security.credentialmanager;
+
+/**
+ * Represents a (cryptographic or any other) exception thrown by Credential
+ * Manager.
+ *
+ * @author Alexandra Nenadic
+ */
+public class CMException extends Exception {
+
+ private static final long serialVersionUID = 3885885604048806903L;
+
+ /**
+ * Creates a new CMException.
+ */
+ public CMException() {
+ super();
+ }
+
+ /**
+ * Creates a new CMException with the specified message.
+ */
+ public CMException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new CMException with the specified message and cause.
+ *
+ */
+ public CMException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Creates a new CMException with the specified cause throwable.
+ */
+ public CMException(Throwable cause) {
+ super(cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/CMNotInitialisedException.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/CMNotInitialisedException.java b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/CMNotInitialisedException.java
new file mode 100644
index 0000000..aa978fc
--- /dev/null
+++ b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/CMNotInitialisedException.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.security.credentialmanager;
+
+/**
+ * Represents an exception thrown by Credential Manager if an application tries
+ * to invoke certain methods on it before it has been initialised.
+ *
+ * @author Alex Nenadic
+ */
+public class CMNotInitialisedException extends Exception {
+ private static final long serialVersionUID = 6041577726294822985L;
+
+ /**
+ * Creates a new CMNotInitialisedException.
+ */
+ public CMNotInitialisedException() {
+ super();
+ }
+
+ /**
+ * Creates a new CMNotInitialisedException with the specified message.
+ */
+ public CMNotInitialisedException(String message) {
+ super(message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/CredentialManager.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/CredentialManager.java b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/CredentialManager.java
new file mode 100644
index 0000000..808dd65
--- /dev/null
+++ b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/CredentialManager.java
@@ -0,0 +1,415 @@
+/*******************************************************************************
+ * Copyright (C) 2008-2014 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.security.credentialmanager;
+
+import java.io.File;
+import java.net.Authenticator;
+import java.net.URI;
+import java.security.Key;
+import java.security.KeyStore;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.net.ssl.SSLSocketFactory;
+
+import net.sf.taverna.t2.lang.observer.Observer;
+
+/**
+ * Provides a wrapper for Taverna's Keystore and Truststore and implements
+ * methods for managing user's credentials (passwords, private/proxy key pairs)
+ * and credentials of trusted services and CAs' (i.e. their public key
+ * certificates).
+ * <p>
+ * Keystore and Truststore are Bouncy Castle UBER-type keystores saved as files
+ * called "taverna-keystore.ubr" and "taverna-truststore.ubr" respectively. In
+ * the case of the Workbench, they are located in a directory called "security"
+ * inside the taverna.home directory. This location can be changed, e.g. in the
+ * case of the server and command line tool you may want to pass in the location
+ * of the Credential Manager's files.
+ *
+ * @author Alex Nenadic
+ * @author Stian Soiland-Reyes
+ */
+public interface CredentialManager {
+
+ public static final String KEYSTORE_FILE_NAME = "taverna-keystore.ubr";
+ public static final String TRUSTSTORE_FILE_NAME = "taverna-truststore.ubr";
+
+ public static final String UTF_8 = "UTF-8";
+
+ public static final String PROPERTY_TRUSTSTORE = "javax.net.ssl.trustStore";
+ public static final String PROPERTY_TRUSTSTORE_PASSWORD = "javax.net.ssl.trustStorePassword";
+ public static final String PROPERTY_KEYSTORE = "javax.net.ssl.keyStore";
+ public static final String PROPERTY_KEYSTORE_PASSWORD = "javax.net.ssl.keyStorePassword";
+ public static final String PROPERTY_KEYSTORE_TYPE = "javax.net.ssl.keyStoreType";
+ public static final String PROPERTY_KEYSTORE_PROVIDER = "javax.net.ssl.keyStoreProvider";
+ public static final String PROPERTY_TRUSTSTORE_TYPE = "javax.net.ssl.trustStoreType";
+ public static final String PROPERTY_TRUSTSTORE_PROVIDER = "javax.net.ssl.trustStoreProvider";
+
+ // Existence of the file with this name in the Credential Manager folder
+ // indicates the we have deleted the revoked certificates from some of our services -
+ // BioCatalogue, BiodiversityCatalogue, heater.
+ public static final String CERTIFICATES_REVOKED_INDICATOR_FILE_NAME = "certificates_revoked";
+
+ /*
+ * ASCII NUL character - for separating the username from the rest of the
+ * string when saving it in the Keystore. Seems like a good separator as it
+ * will highly unlikely feature in a username.
+ */
+ public static final char USERNAME_AND_PASSWORD_SEPARATOR_CHARACTER = '\u0000';
+
+ /*
+ * Constants denoting which of the two Credential Manager's keystores
+ * (Keystore or Truststore) we are currently performing an operation on (in
+ * cases when the same operation can be done on both).
+ */
+ public static enum KeystoreType {
+ KEYSTORE, TRUSTSTORE
+ };
+
+ /*
+ * Existence of this file in the Credential Manager folder indicates the
+ * user has set the master password so do not use the default password
+ */
+ public static final String USER_SET_MASTER_PASSWORD_INDICATOR_FILE_NAME = "user_set_master_password";
+
+ /*
+ * Default password for Truststore - needed as the Truststore needs to be
+ * populated before the Workbench starts up to initiate the SSLSocketFactory
+ * and to avoid popping up a dialog to ask the user for it.
+ */
+ // private static final String TRUSTSTORE_PASSWORD = "Tu/Ap%2_$dJt6*+Rca9v";
+
+ /**
+ * Set the directory where Credential Manager's Keystore and Truststore
+ * files will be read from. If this method is not used, the directory will
+ * default to <TAVERNA_HOME>/security somewhere in user's home directory.
+ *
+ * If you want to use this method to change the location of Credential
+ * Manager's configuration directory then make sure you call it before any
+ * other method on Credential Manager.
+ *
+ * @param credentialManagerDirectory
+ * @throws CMException
+ */
+ void setConfigurationDirectoryPath(File credentialManagerDirectory)
+ throws CMException;
+
+ /**
+ * Checks if the Keystore contains a username and password for the given
+ * service URI.
+ */
+ boolean hasUsernamePasswordForService(URI serviceURI) throws CMException;
+
+ /**
+ * Get a username and password pair for the given service's URI, or null if
+ * it does not exit.
+ * <p>
+ * If the username and password are not available in the Keystore, it will
+ * invoke implementations of the {@link ServiceUsernameAndPasswordProvider}
+ * interface asking the user (typically through the UI) or resolving
+ * hard-coded credentials.
+ * <p>
+ * If the parameter <code>useURIPathRecursion</code> is true, then the
+ * Credential Manager will also attempt to look for stored credentials for
+ * each of the parent fragments of the URI.
+ *
+ * @param serviceURI
+ * The URI of the service for which we are providing the username
+ * and password
+ *
+ * @param useURIPathRecursion
+ * Whether to look for any username and passwords stored in the
+ * Keystore for the parent fragments of the service URI (for
+ * example, we are looking for the credentials for service
+ * http://somehost/some-fragment but we already have credentials
+ * stored for http://somehost which can be reused)
+ *
+ * @param requestingMessage
+ * The message to be presented to the user when asking for the
+ * username and password, normally useful for UI providers that
+ * pop up dialogs, can be ignored otherwise
+ *
+ * @return username and password pair for the given service
+ *
+ * @throws CMException
+ * if anything goes wrong during Keystore lookup, etc.
+ */
+ UsernamePassword getUsernameAndPasswordForService(URI serviceURI,
+ boolean useURIPathRecursion, String requestingMessage)
+ throws CMException;
+
+ /**
+ * Insert a username and password pair for the given service URI in the
+ * Keystore.
+ * <p>
+ * Effectively, this method inserts a new secret key entry in the Keystore,
+ * where key contains <USERNAME>"\000"<PASSWORD> string, i.e. password is
+ * prepended with the username and separated by a \000 character (which
+ * hopefully will not appear in the username).
+ * <p>
+ * Username and password string is saved in the Keystore as byte array using
+ * SecretKeySpec (which constructs a secret key from the given byte array
+ * but does not check if the given bytes indeed specify a secret key of the
+ * specified algorithm).
+ * <p>
+ * An alias used to identify the username and password entry is constructed
+ * as "password#"<SERVICE_URL> using the service URL this username/password
+ * pair is to be used for.
+ *
+ * @param usernamePassword
+ * The {@link UsernamePassword} to store
+ * @param serviceURI
+ * The (possibly normalized) URI to store the credentials under
+ * @return TODO
+ * @throws CMException
+ * If the credentials could not be stored
+ *
+ * @return the alias under which this username and password entry was saved
+ * in the Keystore
+ */
+ String addUsernameAndPasswordForService(UsernamePassword usernamePassword,
+ URI serviceURI) throws CMException;
+
+ /**
+ * Delete a username and password pair for the given service URI from the
+ * Keystore.
+ */
+ void deleteUsernameAndPasswordForService(URI serviceURI) throws CMException;
+
+ /**
+ * Checks if the Keystore contains the given key pair entry (private key and
+ * its corresponding public key certificate chain).
+ */
+ public boolean hasKeyPair(Key privateKey, Certificate[] certs)
+ throws CMException;
+
+ /**
+ * Insert a new key entry containing private key and the corresponding
+ * public key certificate chain in the Keystore.
+ *
+ * An alias used to identify the keypair entry is constructed as:
+ * "keypair#"<CERT_SUBJECT_COMMON_NAME>"#"<CERT_ISSUER_COMMON_NAME>"#"<
+ * CERT_SERIAL_NUMBER>
+ *
+ * @return the alias under which this key entry was saved in the Keystore
+ */
+ String addKeyPair(Key privateKey, Certificate[] certs) throws CMException;
+
+ /**
+ * Delete a key pair entry from the Keystore given its alias.
+ */
+ void deleteKeyPair(String alias) throws CMException;
+
+ /**
+ * Delete a key pair entry from the Keystore given its private and public
+ * key parts.
+ */
+ void deleteKeyPair(Key privateKey, Certificate[] certs) throws CMException;
+
+ /**
+ * Create a Keystore alias that would be used for adding the given key pair
+ * (private and public key) entry to the Keystore. The alias is cretaed as
+ * "keypair#"<CERT_SUBJECT_COMMON_NAME>"#"<CERT_ISSUER_COMMON_NAME>"#"<
+ * CERT_SERIAL_NUMBER>
+ *
+ * @param privateKey
+ * private key
+ * @param certs
+ * public key's certificate chain
+ * @return
+ */
+ String createKeyPairAlias(Key privateKey, Certificate certs[]);
+
+ /**
+ * Export a key entry containing private key and public key certificate
+ * chain from the Keystore to a PKCS #12 file.
+ */
+ void exportKeyPair(String alias, File exportFile, String pkcs12Password)
+ throws CMException;
+
+ /**
+ * Get certificate entry from the Keystore or Truststore. If the given alias
+ * name identifies a trusted certificate entry, the certificate associated
+ * with that entry is returned from the Truststore. If the given alias name
+ * identifies a key pair entry, the first element of the certificate chain
+ * of that entry is returned from the Keystore.
+ */
+ Certificate getCertificate(KeystoreType ksType, String alias)
+ throws CMException;
+
+ /**
+ * Get certificate chain for the key pair entry from the Keystore given its
+ * alias.
+ * <p>
+ * This method works for the Keystore only as the Truststore does not
+ * contain key pair entries, but trusted certificate entries only.
+ */
+ Certificate[] getKeyPairsCertificateChain(String alias) throws CMException;
+
+ /**
+ * Get the private key part of a key pair entry from the Keystore given its
+ * alias.
+ * <p>
+ * This method works for the Keystore only as the Truststore does not
+ * contain key pair entries, but trusted certificate entries only.
+ */
+ Key getKeyPairsPrivateKey(String alias) throws CMException;
+
+ /**
+ * Checks if the Truststore contains the given public key certificate.
+ */
+ boolean hasTrustedCertificate(Certificate cert) throws CMException;
+
+ /**
+ * Insert a trusted certificate entry in the Truststore with an alias
+ * constructed as:
+ *
+ * "trustedcert#<CERT_SUBJECT_COMMON_NAME>"#"<CERT_ISSUER_COMMON_NAME>"#
+ * "<CERT_SERIAL_NUMBER>
+ *
+ * @return the alias under which this trusted certificate entry was saved in
+ * the Keystore
+ */
+ String addTrustedCertificate(X509Certificate cert) throws CMException;
+
+ /**
+ * Delete a trusted certificate entry from the Truststore given its alias.
+ */
+ void deleteTrustedCertificate(String alias) throws CMException;
+
+ /**
+ * Delete a trusted certificate entry from the Truststore given the
+ * certificate.
+ */
+ void deleteTrustedCertificate(X509Certificate cert) throws CMException;
+
+ /**
+ * Create a Truststore alias that would be used for adding the given trusted
+ * X509 certificate to the Truststore. The alias is cretaed as
+ * "trustedcert#"<CERT_SUBJECT_COMMON_NAME>"#"<CERT_ISSUER_COMMON_NAME>"#"<
+ * CERT_SERIAL_NUMBER>
+ *
+ * @param cert
+ * certificate to generate the alias for
+ * @return the alias for the given certificate
+ */
+ String createTrustedCertificateAlias(X509Certificate cert);
+
+ /**
+ * Check if the given alias identifies a key entry in the Keystore.
+ */
+ boolean isKeyEntry(String alias) throws CMException;
+
+ /**
+ * Check if the Keystore/Truststore contains an entry with the given alias.
+ */
+ boolean hasEntryWithAlias(KeystoreType ksType, String alias)
+ throws CMException;
+
+ /**
+ * Get all the aliases from the Keystore/Truststore or null if there was
+ * some error while accessing it.
+ */
+ ArrayList<String> getAliases(KeystoreType ksType) throws CMException;
+
+ /**
+ * Get service URIs associated with all username/password pairs currently in
+ * the Keystore.
+ *
+ * @see #hasUsernamePasswordForService(URI)
+ */
+ List<URI> getServiceURIsForAllUsernameAndPasswordPairs() throws CMException;
+
+ /**
+ * Load a PKCS12-type keystore from a file using the supplied password.
+ */
+ KeyStore loadPKCS12Keystore(File pkcs12File, String pkcs12Password)
+ throws CMException;
+
+ /**
+ * Add an observer of the changes to the Keystore or Truststore.
+ */
+ void addObserver(Observer<KeystoreChangedEvent> observer);
+
+ /**
+ * Get all current observers of changes to the Keystore or Truststore.
+ */
+ List<Observer<KeystoreChangedEvent>> getObservers();
+
+ /**
+ * Remove an observer of the changes to the Keystore or Truststore.
+ */
+ void removeObserver(Observer<KeystoreChangedEvent> observer);
+
+ /**
+ * Checks if Keystore's master password is the same as the one provided.
+ *
+ * @param password
+ * @return
+ * @throws CMException
+ */
+ boolean confirmMasterPassword(String password) throws CMException;
+
+ /**
+ * Change the Keystore and the Truststore's master password to the one
+ * provided. The Keystore and Truststore both use the same password.
+ */
+ void changeMasterPassword(String newPassword) throws CMException;
+
+ /**
+ * Reset the JVMs cache for authentication like HTTP Basic Auth.
+ * <p>
+ * Note that this method uses undocumented calls to
+ * <code>sun.net.www.protocol.http.AuthCacheValue</code> which might not be
+ * valid in virtual machines other than Sun Java 6. If these calls fail,
+ * this method will log the error and return <code>false</code>.
+ *
+ * @return <code>true</code> if the VMs cache could be reset, or
+ * <code>false</code> otherwise.
+ */
+ boolean resetAuthCache();
+
+ /**
+ * Set the default SSLContext to use Credential Manager's Keystore and
+ * Truststore for managing SSL connections from Taverna and also set
+ * HttpsURLConnection's default SSLSocketFactory to use the one from the
+ * just configured SSLContext, i.e. backed by Credential Manager's Keystore
+ * and Truststore.
+ *
+ * @throws CMException
+ */
+ void initializeSSL() throws CMException;
+
+ /**
+ * Get Taverna's SSLSocketFactory backed by Credential Manager's Keystore
+ * and Truststore.
+ *
+ * @return
+ * @throws CMException
+ */
+ SSLSocketFactory getTavernaSSLSocketFactory() throws CMException;
+
+ public Authenticator getAuthenticator();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/DistinguishedNameParser.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/DistinguishedNameParser.java b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/DistinguishedNameParser.java
new file mode 100644
index 0000000..eb1d171
--- /dev/null
+++ b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/DistinguishedNameParser.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (C) 2014 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.security.credentialmanager;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import uk.org.taverna.configuration.app.ApplicationConfiguration;
+
+/**
+ * Methods for parsing Distinguished Names and various associated utility methods.
+ *
+ * @author Alex Nenadic
+ * @author Stian Soiland-Reyes
+ * @author Christian Brenninkmeijer
+ */
+public interface DistinguishedNameParser {
+
+ /**
+ * Parses a DN string and fills in fields with DN parts.
+ */
+ public ParsedDistinguishedName parseDN(String DNstr);
+
+ public String getMessageDigestAsFormattedString(byte[] certBinaryEncoding, String shA1);
+
+ /**
+ * Convert the certificate object into an X509Certificate object.
+ */
+ public X509Certificate convertCertificate(Certificate certificate) throws CMException;
+
+ public URI setUserInfoForURI(URI uri, String userinfo) throws URISyntaxException;
+
+ public URI setFragmentForURI(URI uri, String userinfo) throws URISyntaxException;
+
+ /**
+ * Get the configuration directory where the security stuff will be/is saved
+ * to.
+ */
+ public File getCredentialManagerDefaultDirectory(ApplicationConfiguration applicationConfiguration);
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/JavaTruststorePasswordProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/JavaTruststorePasswordProvider.java b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/JavaTruststorePasswordProvider.java
new file mode 100644
index 0000000..7da73ca
--- /dev/null
+++ b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/JavaTruststorePasswordProvider.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (C) 2008-2010 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.security.credentialmanager;
+
+/**
+ * Defines an interface for providing a password for Java's default truststore
+ * located in JAVA_HOME/lib/security/cacerts.
+ * <p>
+ * Used by Credential Manager when trying to copy the trusted certificates from the
+ * Java's default truststore into the Credential Manageger's own Truststore. It will
+ * first try the default Java passwords and then if they do not work - it will loop
+ * through all the providers until one can provide the password. If none
+ * can, the certificates will not be copied.
+ * <p>
+ * A typical implementation of this class would pop up a dialog
+ * and ask the user for the password. Such providers should check
+ * {@link GraphicsEnvironment#isHeadless()} before returning to avoid
+ * attempts to pop up dialogues on server/headless installations.
+ * <p>
+ * It is safe to return <code>null</code> if the provider does not have an
+ * opinion.
+ *
+ * @see CredentialManagerOld
+ * @author Alex Nenadic
+ * @author Stian Soiland-Reyes
+ *
+ */
+public interface JavaTruststorePasswordProvider {
+
+ /**
+ * Get the Java truststore password.
+ * <p>
+ * This method will only be called if the provider returned
+ * <code>true</code> from {@link #canProvideJavaTruststorePassword()}.
+ * <p>
+ * This method will be called when initialising the Credential Manager
+ * for the first time, in the cases where the Java truststore password has
+ * been changed from the VM default. The Credential Manager will need this
+ * password to unlock the Java truststore and copy the trusted certificate
+ * into the Credential Managers's own Truststore.
+ * <p>
+ * Generally only advanced users would change this password.
+ *
+ * @return The Java truststore password, or <code>null</code> if not
+ * available (for instance if user action was cancelled).
+ */
+ public String getJavaTruststorePassword();
+
+ /**
+ * Set the Java truststore password.
+ * @param password to set
+ */
+ public void setJavaTruststorePassword(String password);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/KeystoreChangedEvent.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/KeystoreChangedEvent.java b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/KeystoreChangedEvent.java
new file mode 100644
index 0000000..de20a5a
--- /dev/null
+++ b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/KeystoreChangedEvent.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.security.credentialmanager;
+
+import net.sf.taverna.t2.security.credentialmanager.CredentialManager.KeystoreType;
+
+/**
+ * An event given to {@link CredentialManagerOld} observers registered using
+ * {@link Observable#addObserver(net.sf.taverna.t2.lang.observer.Observer)} to
+ * let them know the Keystore or Truststore have been changed.
+ *
+ * @author Alex Nenadic
+ */
+public class KeystoreChangedEvent {
+ // Whether the change is on the Keystore or the Truststore
+ public final KeystoreType keystoreType;
+
+ public KeystoreChangedEvent(KeystoreType keystoreType) {
+ this.keystoreType = keystoreType;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/MasterPasswordProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/MasterPasswordProvider.java b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/MasterPasswordProvider.java
new file mode 100644
index 0000000..83aaf7f
--- /dev/null
+++ b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/MasterPasswordProvider.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (C) 2008-2010 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.security.credentialmanager;
+
+import java.util.Comparator;
+
+/**
+ * Defines an interface for providing a master password for the Credential
+ * Manager. This master password is used to encrypt/decrypt the Credential
+ * Manager's Keystore/Truststore.
+ * <p>
+ * A typical implementation of this class would pop up a dialog to ask the user
+ * for the master password. Such providers should check
+ * {@link GraphicsEnvironment#isHeadless()} before returning, to avoid attempts
+ * to pop up dialogues on server/headless installations.
+ * <p>
+ * Another example may be to read the master password from a file or from
+ * command line parameters.
+ *
+ * @see CredentialManager
+ * @author Alex Nenadic
+ * @author Stian Soiland-Reyes
+ */
+public interface MasterPasswordProvider {
+
+ /**
+ * Get the master password for the Credential Manager.
+ * <p>
+ * This method will only be called if the provider returned
+ * <code>true</code> from {@link #canProvideMasterPassword()}.
+ * <p>
+ * If the parameter <code>firstTime</code> is <code>true</code>, this is a
+ * request for <em>setting</em> the master password, as the Keystore and
+ * Truststore have not been created yet.
+ *
+ * @see #canProvideMasterPassword()
+ * @param firstTime
+ * <code>true</code> if this is the first time the keystore is
+ * accessed, in which case the returned password will be used to
+ * encrypt the keystore. If <code>false</code>, the returned
+ * password will be used to decrypt (unlock) the keystore.
+ * @return The master password, or <code>null</code> if not available (user
+ * cancelled, etc.)
+ */
+ public String getMasterPassword(boolean firstTime);
+
+ /**
+ * Set the master password.
+ *
+ * @param password
+ * to set
+ */
+ public void setMasterPassword(String password);
+
+ /**
+ * Get the priority of this provider.
+ * <p>
+ * The providers with highest priority will be asked first, lower-priority
+ * providers will be asked only if the higher ones either return
+ * <code>false</code> on the canProvideMasterPassword() method, or return
+ * <code>null</code> on the corresponding actual request.
+ * <p>
+ * It is undetermined who will be asked first if providers have the same
+ * priority.
+ * <p>
+ * A typical priority for UI providers that pop up a dialog to as the user
+ * could be <code>100</code>, allowing server-side providers to override
+ * with priorities like <code>500</code>, or fall-back providers (say by
+ * reading system properties) to have a priority of <code>10</code>.
+ *
+ * @return The priority of this provider. Higher number means higher
+ * priority.
+ */
+ public int getProviderPriority();
+
+ /**
+ * Set the provider's priority that determines the order in which various
+ * master password providers will be invoked.
+ *
+ * @param priority
+ * provider's priority
+ */
+ // public void setProviderPriority(int priority);
+
+ public class ProviderComparator implements
+ Comparator<MasterPasswordProvider> {
+ @Override
+ public int compare(MasterPasswordProvider provider1,
+ MasterPasswordProvider provider2) {
+ return provider1.getProviderPriority()
+ - provider2.getProviderPriority();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/ParsedDistinguishedName.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/ParsedDistinguishedName.java b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/ParsedDistinguishedName.java
new file mode 100644
index 0000000..f484493
--- /dev/null
+++ b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/ParsedDistinguishedName.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (C) 2014 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.security.credentialmanager;
+
+
+/**
+ * A parsed Distinguished Name with getters for parts.
+ *
+ * @author Alex Nenadic
+ * @author Stian Soiland-Reyes
+ * @author Christian Brenninkmeijer
+ */
+public interface ParsedDistinguishedName {
+
+ /**
+ *
+ * @return The common name
+ */
+ public String getCN();
+
+ /**
+ *
+ * @return The Email address
+ */
+ public String getEmailAddress();
+
+ /**
+ *
+ * @return The organizational unit name
+ */
+ public String getOU();
+
+ /**
+ *
+ * @return The organization name
+ */
+ public String getO();
+
+ /**
+ *
+ * @return The locality name
+ */
+ public String getL();
+
+ /**
+ *
+ * @return The state or province name
+ */
+ public String getST();
+
+ /**
+ *
+ * @return The country name
+ */
+ public String getC();
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/ServiceUsernameAndPasswordProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/ServiceUsernameAndPasswordProvider.java b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/ServiceUsernameAndPasswordProvider.java
new file mode 100644
index 0000000..5a0835a
--- /dev/null
+++ b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/ServiceUsernameAndPasswordProvider.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (C) 2008-2010 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.security.credentialmanager;
+
+import java.net.URI;
+
+/**
+ * Defines an interface for providing a username and password for a service to
+ * be invoked as part of a workflow run.
+ * <p>
+ * Used by Credential Manager when looking up the username and password for the
+ * service in its Keystore - if it cannot find anything it will loop through all
+ * providers until one can provide them. If none can, the service invocation
+ * will (most probably) fail.
+ * <p>
+ * A typical implementation of this class would pop up a dialog and ask the user
+ * for the password. Such providers should check
+ * {@link GraphicsEnvironment#isHeadless()} before returning to avoid attempts
+ * to pop up dialogues on server/headless installations.
+ *
+ * @see CredentialManager
+ * @author Alex Nenadic
+ * @author Stian Soiland-Reyes
+ */
+public interface ServiceUsernameAndPasswordProvider {
+ /**
+ * Get the username and password pair for the given service URI.
+ *
+ * @param serviceURI
+ * The service we are looking username and password for
+ * @param requestMessage
+ * The message to be presented to the user when asking for the
+ * username and password, normally useful for UI providers that
+ * pop up dialogs, can be ignored otherwise
+ * @return the username and password pair for the given service URI, or
+ * <tt>null</tt> if the provider does not know for this URI.
+ */
+ UsernamePassword getServiceUsernameAndPassword(URI serviceURI,
+ String requestMessage);
+
+ /**
+ * Set the username and password pair for the given service URI.
+ */
+ void setServiceUsernameAndPassword(URI serviceURI,
+ UsernamePassword usernamePassword);
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/TrustConfirmationProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/TrustConfirmationProvider.java b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/TrustConfirmationProvider.java
new file mode 100644
index 0000000..ca6af82
--- /dev/null
+++ b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/TrustConfirmationProvider.java
@@ -0,0 +1,56 @@
+package net.sf.taverna.t2.security.credentialmanager;
+
+import java.security.cert.X509Certificate;
+
+/**
+ * Defines an interface for providing ways to confirm/decline trust in a given
+ * service (i.e. its public key certificate).
+ * <p>
+ * Used by Credential Manager when looking up the username and password for the
+ * service in its Keystore - if it cannot find anything it will loop through all
+ * providers until one can provide them. If none can, the service invocation
+ * will (most probably) fail.
+ * <p>
+ * A typical implementation of this class would pop up a dialog and ask the user
+ * for the password. Such providers should check
+ * {@link GraphicsEnvironment#isHeadless()} before returning to avoid attempts
+ * to pop up dialogues on server/headless installations.
+ * <p>
+ * It is safe to return <code>null</code> if the provider does not have an
+ * opinion.
+ *
+ * @see CredentialManager
+ * @author Alex Nenadic
+ * @author Stian Soiland-Reyes
+ *
+ */
+public interface TrustConfirmationProvider {
+ /**
+ * If the given public key certificate should be trusted or not.
+ * <p>
+ * This method is called when a SSL connection is attempted to a service
+ * which certificate could not be confirmed using the Credential Manager's
+ * Truststore (i.e. it could not be found there).
+ * <p>
+ * A typical implementation of this class would pop up a dialog and ask the
+ * user if they want to trust the service. Such providers should check
+ * {@link GraphicsEnvironment#isHeadless()} before returning to avoid
+ * attempts to pop up dialogues on server/headless installations.
+ * <p>
+ * The provider can return <code>null</code> if it does not have an opinion
+ * whether the certificate should be trusted or not (in which case other
+ * providers will be asked), or an instance of {@link TrustConfirmation}
+ * confirming or denying if the certificate is to be trusted.
+ * <p>
+ * If the provider returns <code>true</code>, the Credential Manager will
+ * also save the first certificate of the certificate chain (chain[0]) in
+ * its Truststore so the user will not be asked next time.
+ *
+ * @param chain
+ * X509 certificate chain to confirm whether it is trusted or not
+ * @return <code>null</code> if the provider does not have an opinion,
+ * <code>true</code> if certificate is to be trusted and
+ * <code>false</code> if not.
+ */
+ public Boolean shouldTrustCertificate(X509Certificate[] chain);
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/UsernamePassword.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/UsernamePassword.java b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/UsernamePassword.java
new file mode 100644
index 0000000..a5ee1a7
--- /dev/null
+++ b/taverna-credential-manager/src/main/java/net/sf/taverna/t2/security/credentialmanager/UsernamePassword.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.security.credentialmanager;
+
+import java.util.Arrays;
+
+/**
+ *
+ * @author Stian Soiland-Reyes
+ */
+public class UsernamePassword {
+ private char[] password;
+ private boolean shouldSave = false;
+ private String username;
+
+ @Override
+ public UsernamePassword clone() {
+ UsernamePassword up = new UsernamePassword();
+ up.setUsername(getUsername());
+ up.setPassword(getPassword().clone());
+ up.setShouldSave(isShouldSave());
+ return up;
+ }
+
+ public UsernamePassword() {
+ }
+
+ public UsernamePassword(String username, String password) {
+ this.username = username;
+ this.password = password.toCharArray();
+ }
+
+ public char[] getPassword() {
+ return password;
+ }
+
+ public String getPasswordAsString() {
+ return String.valueOf(password);
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public boolean isShouldSave() {
+ return shouldSave;
+ }
+
+ public void resetPassword() {
+ if (this.password == null)
+ return;
+ Arrays.fill(this.password, '\u0000');
+ }
+
+ public void setPassword(char[] password) {
+ resetPassword();
+ this.password = password;
+ }
+
+ public void setShouldSave(boolean shouldSave) {
+ this.shouldSave = shouldSave;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ resetPassword();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager/src/main/resources/META-INF/services/net.sf.taverna.t2.security.credentialmanager.CredentialProviderSPI
----------------------------------------------------------------------
diff --git a/taverna-credential-manager/src/main/resources/META-INF/services/net.sf.taverna.t2.security.credentialmanager.CredentialProviderSPI b/taverna-credential-manager/src/main/resources/META-INF/services/net.sf.taverna.t2.security.credentialmanager.CredentialProviderSPI
new file mode 100644
index 0000000..9ff33f1
--- /dev/null
+++ b/taverna-credential-manager/src/main/resources/META-INF/services/net.sf.taverna.t2.security.credentialmanager.CredentialProviderSPI
@@ -0,0 +1 @@
+net.sf.taverna.t2.security.credentialmanager.DefaultMasterPasswordProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager/src/test/resources/html/test.html
----------------------------------------------------------------------
diff --git a/taverna-credential-manager/src/test/resources/html/test.html b/taverna-credential-manager/src/test/resources/html/test.html
new file mode 100644
index 0000000..5e45661
--- /dev/null
+++ b/taverna-credential-manager/src/test/resources/html/test.html
@@ -0,0 +1,5 @@
+<html>
+ <body>
+ Hello!
+ </body>
+</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-credential-manager/src/test/resources/realm.properties
----------------------------------------------------------------------
diff --git a/taverna-credential-manager/src/test/resources/realm.properties b/taverna-credential-manager/src/test/resources/realm.properties
new file mode 100644
index 0000000..2561568
--- /dev/null
+++ b/taverna-credential-manager/src/test/resources/realm.properties
@@ -0,0 +1 @@
+test: test, user
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-database-configuration-api/.project
----------------------------------------------------------------------
diff --git a/taverna-database-configuration-api/.project b/taverna-database-configuration-api/.project
new file mode 100644
index 0000000..dfcb96a
--- /dev/null
+++ b/taverna-database-configuration-api/.project
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>taverna-database-configuration-api</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-database-configuration-api/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-database-configuration-api/pom.xml b/taverna-database-configuration-api/pom.xml
new file mode 100644
index 0000000..01d000f
--- /dev/null
+++ b/taverna-database-configuration-api/pom.xml
@@ -0,0 +1,18 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.taverna.engine</groupId>
+ <artifactId>taverna-engine</artifactId>
+ <version>3.1.0-incubating-SNAPSHOT</version>
+ </parent>
+ <artifactId>taverna-database-configuration-api</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Taverna Database Configuration API</name>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.taverna.osgi</groupId>
+ <artifactId>taverna-configuration-api</artifactId>
+ <version>${taverna.osgi.version}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-database-configuration-api/src/main/java/uk/org/taverna/configuration/database/DatabaseConfiguration.java
----------------------------------------------------------------------
diff --git a/taverna-database-configuration-api/src/main/java/uk/org/taverna/configuration/database/DatabaseConfiguration.java b/taverna-database-configuration-api/src/main/java/uk/org/taverna/configuration/database/DatabaseConfiguration.java
new file mode 100644
index 0000000..ba3ebd2
--- /dev/null
+++ b/taverna-database-configuration-api/src/main/java/uk/org/taverna/configuration/database/DatabaseConfiguration.java
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ * Copyright (C) 2012 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package uk.org.taverna.configuration.database;
+
+import java.util.Map;
+
+import uk.org.taverna.configuration.Configurable;
+
+/**
+ *
+ *
+ * @author David Withers
+ */
+public interface DatabaseConfiguration extends Configurable {
+
+ public static final String IN_MEMORY = "in_memory";
+ public static final String ENABLE_PROVENANCE = "provenance";
+ public static final String CONNECTOR_TYPE = "connector";
+ public static final String PORT = "port";
+ public static final String CURRENT_PORT = "current_port";
+ public static final String REFERENCE_SERVICE_CONTEXT = "referenceService.context";
+ public static final String IN_MEMORY_CONTEXT = "inMemoryReferenceServiceContext.xml";
+ public static final String HIBERNATE_CONTEXT = "hibernateReferenceServiceContext.xml";
+ public static final String HIBERNATE_DIALECT = "dialect";
+ public static final String START_INTERNAL_DERBY = "start_derby";
+ public static final String POOL_MAX_ACTIVE = "pool_max_active";
+ public static final String POOL_MIN_IDLE = "pool_min_idle";
+ public static final String POOL_MAX_IDLE = "pool_max_idle";
+ public static final String DRIVER_CLASS_NAME = "driver";
+ public static final String JDBC_URI = "jdbcuri";
+ public static final String USERNAME = "username";
+ public static final String PASSWORD = "password";
+ public static final String EXPOSE_DATANATURE = "taverna.exposedatanature";
+ // FIXME: these should me just mysql & derby - but build & dependency issues
+ // is causing the provenance to expect these values:
+ public static final String CONNECTOR_MYSQL = "mysql";
+ public static final String CONNECTOR_DERBY = "derby";
+ public static final String JNDI_NAME = "jdbc/taverna";
+
+ public boolean isAutoSave();
+
+ public void enableAutoSave();
+
+ public void disableAutoSave();
+
+ public boolean isInMemory();
+
+ public void setInMemory(boolean value);
+
+ public boolean isExposeDatanature();
+
+ public void setExposeDatanature(boolean exposeDatanature);
+
+ public String getDatabaseContext();
+
+ public void setPort(int port);
+
+ public void setPort(String port);
+
+ public void setDriverClassName(String driverClassName);
+
+ public String getDriverClassName();
+
+ public boolean isProvenanceEnabled();
+
+ public void setProvenanceEnabled(boolean value);
+
+ public void setStartInternalDerbyServer(boolean value);
+
+ public boolean getStartInternalDerbyServer();
+
+ public int getPort();
+
+ public void setCurrentPort(int port);
+
+ public int getCurrentPort();
+
+ public int getPoolMaxActive();
+
+ public int getPoolMinIdle();
+
+ public int getPoolMaxIdle();
+
+ public String getCategory();
+
+ public Map<String, String> getDefaultPropertyMap();
+
+ public String getHibernateDialect();
+
+ public String getDisplayName();
+
+ public String getFilePrefix();
+
+ public String getUUID();
+
+ public String getConnectorType();
+
+ public String getJDBCUri();
+
+ public void setJDBCUri(String uri);
+
+ public String getUsername();
+
+ public String getPassword();
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-database-configuration-api/src/main/java/uk/org/taverna/configuration/database/DatabaseManager.java
----------------------------------------------------------------------
diff --git a/taverna-database-configuration-api/src/main/java/uk/org/taverna/configuration/database/DatabaseManager.java b/taverna-database-configuration-api/src/main/java/uk/org/taverna/configuration/database/DatabaseManager.java
new file mode 100644
index 0000000..c7e6641
--- /dev/null
+++ b/taverna-database-configuration-api/src/main/java/uk/org/taverna/configuration/database/DatabaseManager.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (C) 2012 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package uk.org.taverna.configuration.database;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+
+/**
+ *
+ *
+ * @author David Withers
+ */
+public interface DatabaseManager {
+
+ public Connection getConnection() throws SQLException;
+
+ public DataSource getDataSource();
+
+ public void startDerbyNetworkServer();
+
+ public void stopDerbyNetworkServer();
+
+ public boolean isRunning();
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-database-configuration-impl/.project
----------------------------------------------------------------------
diff --git a/taverna-database-configuration-impl/.project b/taverna-database-configuration-impl/.project
new file mode 100644
index 0000000..bac6198
--- /dev/null
+++ b/taverna-database-configuration-impl/.project
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>taverna-database-configuration-impl</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/246a16e2/taverna-database-configuration-impl/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-database-configuration-impl/pom.xml b/taverna-database-configuration-impl/pom.xml
new file mode 100644
index 0000000..07bd9b7
--- /dev/null
+++ b/taverna-database-configuration-impl/pom.xml
@@ -0,0 +1,78 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.taverna.engine</groupId>
+ <artifactId>taverna-engine</artifactId>
+ <version>3.1.0-incubating-SNAPSHOT</version>
+ </parent>
+ <artifactId>taverna-database-configuration-impl</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Taverna Database Configuration implementation</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ uk.org.taverna.configuration.database;provide:=true,
+ org.apache.derby.jdbc, *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>taverna-database-configuration-api</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.taverna.osgi</groupId>
+ <artifactId>taverna-app-configuration-api</artifactId>
+ <version>${taverna.osgi.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.taverna.osgi</groupId>
+ <artifactId>taverna-configuration-api</artifactId>
+ <version>${taverna.osgi.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>com.springsource.org.apache.derby</artifactId>
+ <version>${derby.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>com.springsource.org.apache.derby.client</artifactId>
+ <version>${derbyclient.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>com.springsource.org.apache.derby.drda</artifactId>
+ <version>${derbynet.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ <version>${commons.dbcp.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>${log4j.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>