You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by re...@apache.org on 2015/03/20 16:47:29 UTC
[4/8] incubator-taverna-engine git commit: package names changed to
org.apache.taverna.*
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/55900be9/taverna-credential-manager-impl/src/main/java/org/apache/taverna/security/credentialmanager/impl/DefaultMasterPasswordProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/main/java/org/apache/taverna/security/credentialmanager/impl/DefaultMasterPasswordProvider.java b/taverna-credential-manager-impl/src/main/java/org/apache/taverna/security/credentialmanager/impl/DefaultMasterPasswordProvider.java
new file mode 100644
index 0000000..3f7cc59
--- /dev/null
+++ b/taverna-credential-manager-impl/src/main/java/org/apache/taverna/security/credentialmanager/impl/DefaultMasterPasswordProvider.java
@@ -0,0 +1,70 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.security.credentialmanager.impl;
+
+import static org.apache.taverna.security.credentialmanager.CredentialManager.USER_SET_MASTER_PASSWORD_INDICATOR_FILE_NAME;
+
+import java.io.File;
+
+import org.apache.taverna.security.credentialmanager.MasterPasswordProvider;
+import uk.org.taverna.configuration.app.ApplicationConfiguration;
+
+//import org.apache.log4j.Logger;
+
+public class DefaultMasterPasswordProvider implements MasterPasswordProvider {
+ /**
+ * Default master password for Credential Manager - used by default and
+ * ignored if user sets their own
+ */
+ private final String DEFAULT_MASTER_PASSWORD = "taverna";
+ private ApplicationConfiguration appConfig;
+
+ @Override
+ public int getProviderPriority() {
+ // Higher priority then the UI provider so this one will be tried first
+ return 101;
+ }
+
+ /**
+ * Sets the applicationConfiguration.
+ *
+ * @param applicationConfiguration
+ * the new value of applicationConfiguration
+ */
+ public void setApplicationConfiguration(
+ ApplicationConfiguration applicationConfiguration) {
+ appConfig = applicationConfiguration;
+ }
+
+ @Override
+ public String getMasterPassword(boolean firstTime) {
+ File cmDir = DistinguishedNameParserImpl.getTheCredentialManagerDefaultDirectory(appConfig);
+ File flagFile = new File(cmDir,
+ USER_SET_MASTER_PASSWORD_INDICATOR_FILE_NAME);
+ if (flagFile.exists())
+ return null;
+ return DEFAULT_MASTER_PASSWORD;
+ }
+
+ @Override
+ public void setMasterPassword(String password) {
+ // We always ignore this; we're never changing our password
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/55900be9/taverna-credential-manager-impl/src/main/java/org/apache/taverna/security/credentialmanager/impl/DistinguishedNameParserImpl.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/main/java/org/apache/taverna/security/credentialmanager/impl/DistinguishedNameParserImpl.java b/taverna-credential-manager-impl/src/main/java/org/apache/taverna/security/credentialmanager/impl/DistinguishedNameParserImpl.java
new file mode 100644
index 0000000..a993720
--- /dev/null
+++ b/taverna-credential-manager-impl/src/main/java/org/apache/taverna/security/credentialmanager/impl/DistinguishedNameParserImpl.java
@@ -0,0 +1,196 @@
+/*******************************************************************************
+ * 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 org.apache.taverna.security.credentialmanager.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.math.BigInteger;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.Certificate;
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+
+import org.apache.taverna.security.credentialmanager.CMException;
+import org.apache.taverna.security.credentialmanager.DistinguishedNameParser;
+
+import org.apache.log4j.Logger;
+
+import uk.org.taverna.configuration.app.ApplicationConfiguration;
+
+/**
+ * Utility methods for Credential Manager and security-related stuff.
+ *
+ * @author Alex Nenadic
+ * @author Stian Soiland-Reyes
+ * @author Christian Brenninkmeijer
+ */
+public class DistinguishedNameParserImpl implements DistinguishedNameParser{
+ private static Logger logger = Logger.getLogger(DistinguishedNameParserImpl.class);
+
+ public DistinguishedNameParserImpl(){
+ }
+
+ /**
+ * Get the configuration directory where the security stuff will be/is saved
+ * to.
+ */
+ public static File getTheCredentialManagerDefaultDirectory(
+ ApplicationConfiguration applicationConfiguration) {
+ File home = applicationConfiguration.getApplicationHomeDir();
+ File secConfigDirectory = new File(home, "security");
+ if (!secConfigDirectory.exists())
+ secConfigDirectory.mkdir();
+ return secConfigDirectory;
+ }
+
+ @Override
+ public final File getCredentialManagerDefaultDirectory(
+ ApplicationConfiguration applicationConfiguration) {
+ return getTheCredentialManagerDefaultDirectory(applicationConfiguration);
+ }
+
+ static URI resolveUriFragment(URI uri, String realm)
+ throws URISyntaxException {
+ /*
+ * Little hack to encode the fragment correctly - why does not
+ * java.net.URI expose this quoting or have setFragment()?
+ */
+ URI fragment = new URI("http", "localhost", "/", realm);
+ fragment = fragment.resolve(fragment.getPath()).relativize(fragment);
+ return uri.resolve(fragment);
+ }
+
+ @Override
+ public final URI setFragmentForURI(URI uri, String fragment)
+ throws URISyntaxException {
+ return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(),
+ uri.getPort(), uri.getPath(), uri.getQuery(), fragment);
+ }
+
+ @Override
+ public final URI setUserInfoForURI(URI uri, String userinfo)
+ throws URISyntaxException {
+ return new URI(uri.getScheme(), userinfo, uri.getHost(), uri.getPort(),
+ uri.getPath(), uri.getQuery(), uri.getFragment());
+ }
+
+ @Override
+ public final X509Certificate convertCertificate(Certificate cert)
+ throws CMException {
+ try {
+ // Get the factory for X509 certificates
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ // Get the encoded (binary) form of the certificate.
+ // For an X509 certificate the encoding will be DER.
+ ByteArrayInputStream bais = new ByteArrayInputStream(
+ cert.getEncoded());
+ // Create the X509 certificate object from the stream
+ return (X509Certificate) cf.generateCertificate(bais);
+ } catch (CertificateException ex) {
+ throw new CMException(
+ "Failed to convert the certificate object into X.509 certificate.",
+ ex);
+ }
+ }
+
+ /**
+ * Get the message digest of the given byte array as a string of hexadecimal
+ * characters in the form XX:XX:XX... using the given digest algorithm.
+ */
+ public String getMessageDigestAsFormattedString(byte[] messageBytes,
+ String digestAlgorithm) {
+
+ MessageDigest messageDigest;
+ byte[] digestBytes;
+ try {
+ messageDigest = MessageDigest.getInstance(digestAlgorithm);
+ digestBytes = messageDigest.digest(messageBytes);
+ } catch (NoSuchAlgorithmException ex) {
+ logger.error("Failed to create message digest.", ex);
+ return "";
+ }
+
+ // Create the integer value from the digest bytes
+ BigInteger number = new BigInteger(1, digestBytes);
+ // Convert the integer from decimal to hexadecimal representation
+ String hexValueString = number.toString(16).toUpperCase();
+
+ StringBuffer strBuff = new StringBuffer(hexValueString);
+ // If the hex number contains odd number of characters -
+ // insert a padding "0" at the front of the string
+ if ((strBuff.length() % 2) != 0)
+ strBuff.insert(0, '0');
+
+ // Insert colons after every two hex characters - start form the end of
+ // the hex string
+ if (strBuff.length() > 2)
+ for (int i = 2; i < strBuff.length(); i += 3)
+ strBuff.insert(i, ':');
+
+ return strBuff.toString();
+ }
+
+
+ private String emailAddress; // not from RFC 2253, yet some certificates
+ // contain this field
+
+ private String CN;
+ private String L;
+ private String ST;
+ private String C;
+ private String O;
+ private String OU;
+
+ /**
+ * Parses a DN string and fills in fields with DN parts. Heavily based on
+ * uk.ac.omii.security.utils.DNParser class from omii-security-utils
+ * library.
+ *
+ * http://maven.omii.ac.uk/maven2/repository/omii/omii-security-utils/
+ */
+ public ParsedDistinguishedNameImpl parseDN(String DNstr) {
+ return new ParsedDistinguishedNameImpl(DNstr);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/55900be9/taverna-credential-manager-impl/src/main/java/org/apache/taverna/security/credentialmanager/impl/ParsedDistinguishedNameImpl.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/main/java/org/apache/taverna/security/credentialmanager/impl/ParsedDistinguishedNameImpl.java b/taverna-credential-manager-impl/src/main/java/org/apache/taverna/security/credentialmanager/impl/ParsedDistinguishedNameImpl.java
new file mode 100644
index 0000000..6fe09b3
--- /dev/null
+++ b/taverna-credential-manager-impl/src/main/java/org/apache/taverna/security/credentialmanager/impl/ParsedDistinguishedNameImpl.java
@@ -0,0 +1,263 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.taverna.security.credentialmanager.impl;
+
+import java.util.ArrayList;
+import org.apache.taverna.security.credentialmanager.ParsedDistinguishedName;
+import org.apache.log4j.Logger;
+
+/**
+ * Parses a Distinguished Name and stores the parts for retreival.
+ *
+ * @author Alex Nenadic
+ * @author Stian Soiland-Reyes
+ * @author Christian Brenninkmeijer
+ */
+public class ParsedDistinguishedNameImpl implements ParsedDistinguishedName{
+ private static final Logger logger = Logger.getLogger(ParsedDistinguishedNameImpl.class);
+
+ private String emailAddress; // not from RFC 2253, yet some certificates
+ // contain this field
+ private String CN;
+ private String L;
+ private String ST;
+ private String C;
+ private String O;
+ private String OU;
+
+ // /**
+ // * Gets the intended certificate uses, i.e. Netscape Certificate Type
+ // * extension (2.16.840.1.113730.1.1) as a string.
+ // */
+ // // From openssl's documentation: "The [above] extension is non standard,
+ // Netscape
+ // // specific and largely obsolete. Their use in new applications is
+ // discouraged."
+ // // TODO replace with "basicConstraints, keyUsage and extended key usage
+ // extensions
+ // // which are now used instead."
+ // public static String getIntendedCertificateUses(byte[] value) {
+ //
+ // // Netscape Certificate Types (2.16.840.1.113730.1.1) denoting the
+ // // intended uses of a certificate
+ // int[] INTENDED_USES = new int[] { NetscapeCertType.sslClient,
+ // NetscapeCertType.sslServer, NetscapeCertType.smime,
+ // NetscapeCertType.objectSigning, NetscapeCertType.reserved,
+ // NetscapeCertType.sslCA, NetscapeCertType.smimeCA,
+ // NetscapeCertType.objectSigningCA, };
+ //
+ // // Netscape Certificate Type strings (2.16.840.1.113730.1.1)
+ // HashMap<String, String> INTENDED_USES_STRINGS = new HashMap<String,
+ // String>();
+ // INTENDED_USES_STRINGS.put("128", "SSL Client");
+ // INTENDED_USES_STRINGS.put("64", "SSL Server");
+ // INTENDED_USES_STRINGS.put("32", "S/MIME");
+ // INTENDED_USES_STRINGS.put("16", "Object Signing");
+ // INTENDED_USES_STRINGS.put("8", "Reserved");
+ // INTENDED_USES_STRINGS.put("4", "SSL CA");
+ // INTENDED_USES_STRINGS.put("2", "S/MIME CA");
+ // INTENDED_USES_STRINGS.put("1", "Object Signing CA");
+ //
+ // // Get DER octet string from extension value
+ // ASN1OctetString derOctetString = new DEROctetString(value);
+ // byte[] octets = derOctetString.getOctets();
+ // // Get DER bit string
+ // DERBitString derBitString = new DERBitString(octets);
+ // int val = new NetscapeCertType(derBitString).intValue();
+ // StringBuffer strBuff = new StringBuffer();
+ // for (int i = 0, len = INTENDED_USES.length; i < len; i++) {
+ // int use = INTENDED_USES[i];
+ // if ((val & use) == use) {
+ // strBuff.append(INTENDED_USES_STRINGS.get(String.valueOf(use))
+ // + ", \n");
+ // }
+ // }
+ // // remove the last ", \n" from the end of the buffer
+ // String str = strBuff.toString();
+ // str = str.substring(0, str.length() - 3);
+ // return str;
+ // }
+
+ // FROM RFC 2253:
+ // CN commonName
+ // L localityName
+ // ST stateOrProvinceName
+ // O organizationName
+ // OU organizationalUnitName
+ // C countryName
+ // STREET streetAddress
+ // DC domainComponent
+ // UID userid
+
+ /**
+ * Parses a DN string and fills in fields with DN parts. Heavily based on
+ * uk.ac.omii.security.utils.DNParser class from omii-security-utils
+ * library.
+ *
+ * http://maven.omii.ac.uk/maven2/repository/omii/omii-security-utils/
+ */
+ public ParsedDistinguishedNameImpl(String DNstr) {
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////
+ // Parse the DN String and put into variables. First, tokenise using a
+ // "," character as a delimiter
+ // UNLESS escaped with a "\" character. Put the tokens into an
+ // ArrayList. These should be name value pairs
+ // separated by "=". Tokenise these using a StringTokenizer class, test
+ // for the name, and if one of the
+ // recognised names, copy into the correct variable. The reason
+ // StringTokenizer is not used for the major
+ // token list is that the StringTokenizer class does not handle escaped
+ // delimiters so an escaped delimiter
+ // in the code would be treated as a valid one.
+
+ int i = 0;
+
+ char majorListDelimiter = ',';
+ char majorListEscapeChar = '\\';
+
+ // String minorListDelimiter = "=";
+
+ String DNchars = DNstr;
+
+ int startIndex = 0;
+ int endIndex = 0;
+ boolean ignoreThisChar = false;
+
+ boolean inQuotes = false;
+
+ ArrayList<String> majorTokenList = new ArrayList<String>();
+
+ for (i = 0; i < DNchars.length(); i++) {
+ if (ignoreThisChar == true) {
+ ignoreThisChar = false;
+ } else if ((inQuotes == false) && (DNchars.charAt(i) == '\"')) {
+ inQuotes = true;
+ } else if ((inQuotes == true) && (DNchars.charAt(i) == '\"')) {
+ inQuotes = false;
+ } else if (inQuotes == true) {
+ continue;
+ } else if (DNchars.charAt(i) == majorListEscapeChar) {
+ ignoreThisChar = true;
+ } else if ((DNchars.charAt(i) == majorListDelimiter)
+ && (ignoreThisChar == false)) {
+ endIndex = i;
+ majorTokenList.add(DNchars.substring(startIndex, endIndex));
+ startIndex = i + 1;
+ }
+ }
+
+ // Add last token - after the last delimiter
+ endIndex = DNchars.length();
+ majorTokenList.add(DNchars.substring(startIndex, endIndex));
+
+ for (String currentToken : majorTokenList) {
+ currentToken = currentToken.trim();
+
+ // split on first equals only, as value can contain an equals char
+ String[] minorTokenList = currentToken.split("=", 2);
+
+ if (minorTokenList.length == 2) {
+ // there had better be a key and a value only
+ String DNTokenName = minorTokenList[0].toUpperCase();
+ String DNTokenValue = minorTokenList[1];
+
+ if (DNTokenName.equals("CN")
+ || DNTokenName.equals("COMMONNAME")) {
+ CN = DNTokenValue;
+ } else if (DNTokenName.equals("EMAIL")
+ || DNTokenName.equals("EMAILADDRESS")) {
+ emailAddress = DNTokenValue;
+ } else if (DNTokenName.equals("OU")
+ || DNTokenName.equals("ORGANIZATIONALUNITNAME")) {
+ OU = DNTokenValue;
+ } else if (DNTokenName.equals("O")
+ || DNTokenName.equals("ORGANIZATIONNAME")) {
+ O = DNTokenValue;
+ } else if (DNTokenName.equals("L")
+ || DNTokenName.equals("LOCALITYNAME")) {
+ L = DNTokenValue;
+ } else if (DNTokenName.equals("ST")
+ || DNTokenName.equals("STATEORPROVINCENAME")) {
+ ST = DNTokenValue;
+ } else if (DNTokenName.equals("C")
+ || DNTokenName.equals("COUNTRYNAME")) {
+ C = DNTokenValue;
+ }
+ }
+ // else we have a key with no value, so skip processing the key
+ }
+
+ if (CN == null)
+ CN = "none";
+
+ if (emailAddress == null)
+ emailAddress = "none";
+
+ if (OU == null)
+ OU = "none";
+
+ if (O == null)
+ O = "none";
+
+ if (L == null)
+ L = "none";
+
+ if (ST == null)
+ ST = "none";
+
+ if (C == null)
+ C = "none";
+ }
+
+ @Override
+ public String getCN() {
+ return CN;
+ }
+
+ @Override
+ public String getEmailAddress() {
+ return emailAddress;
+ }
+
+ @Override
+ public String getOU() {
+ return OU;
+ }
+
+ @Override
+ public String getO() {
+ return O;
+ }
+
+ @Override
+ public String getL() {
+ return L;
+ }
+
+ @Override
+ public String getST() {
+ return ST;
+ }
+
+ @Override
+ public String getC() {
+ return C;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/55900be9/taverna-credential-manager-impl/src/main/resources/META-INF/spring/credential-manager-impl-context-osgi.xml
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/main/resources/META-INF/spring/credential-manager-impl-context-osgi.xml b/taverna-credential-manager-impl/src/main/resources/META-INF/spring/credential-manager-impl-context-osgi.xml
index 3c59bf6..813cc31 100644
--- a/taverna-credential-manager-impl/src/main/resources/META-INF/spring/credential-manager-impl-context-osgi.xml
+++ b/taverna-credential-manager-impl/src/main/resources/META-INF/spring/credential-manager-impl-context-osgi.xml
@@ -7,25 +7,25 @@
http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<service ref="credentialManager"
- interface="net.sf.taverna.t2.security.credentialmanager.CredentialManager" />
+ interface="org.apache.taverna.security.credentialmanager.CredentialManager" />
<service ref="defaultMasterPassword"
- interface="net.sf.taverna.t2.security.credentialmanager.MasterPasswordProvider" />
+ interface="org.apache.taverna.security.credentialmanager.MasterPasswordProvider" />
<service ref="distinguishedNameParser"
- interface="net.sf.taverna.t2.security.credentialmanager.DistinguishedNameParser" />
+ interface="org.apache.taverna.security.credentialmanager.DistinguishedNameParser" />
<reference id="applicationConfiguration"
interface="uk.org.taverna.configuration.app.ApplicationConfiguration" />
<list id="masterPasswordProviders"
- interface="net.sf.taverna.t2.security.credentialmanager.MasterPasswordProvider"
+ interface="org.apache.taverna.security.credentialmanager.MasterPasswordProvider"
cardinality="0..N" comparator-ref="MasterPasswordProviderComparator" />
<list id="javaTruststorePasswordProviders"
- interface="net.sf.taverna.t2.security.credentialmanager.JavaTruststorePasswordProvider"
+ interface="org.apache.taverna.security.credentialmanager.JavaTruststorePasswordProvider"
cardinality="0..N" />
<list id="serviceUsernameAndPasswordProviders"
- interface="net.sf.taverna.t2.security.credentialmanager.ServiceUsernameAndPasswordProvider"
+ interface="org.apache.taverna.security.credentialmanager.ServiceUsernameAndPasswordProvider"
cardinality="0..N" />
<list id="trustConfirmationProviders"
- interface="net.sf.taverna.t2.security.credentialmanager.TrustConfirmationProvider"
+ interface="org.apache.taverna.security.credentialmanager.TrustConfirmationProvider"
cardinality="0..N" />
</beans:beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/55900be9/taverna-credential-manager-impl/src/main/resources/META-INF/spring/credential-manager-impl-context.xml
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/main/resources/META-INF/spring/credential-manager-impl-context.xml b/taverna-credential-manager-impl/src/main/resources/META-INF/spring/credential-manager-impl-context.xml
index d1531e1..170c3ca 100644
--- a/taverna-credential-manager-impl/src/main/resources/META-INF/spring/credential-manager-impl-context.xml
+++ b/taverna-credential-manager-impl/src/main/resources/META-INF/spring/credential-manager-impl-context.xml
@@ -14,12 +14,12 @@
</bean>
<bean id="MasterPasswordProviderComparator"
- class="net.sf.taverna.t2.security.credentialmanager.MasterPasswordProvider$ProviderComparator" />
+ class="org.apache.taverna.security.credentialmanager.MasterPasswordProvider$ProviderComparator" />
<bean id="distinguishedNameParser"
- class="net.sf.taverna.t2.security.credentialmanager.impl.DistinguishedNameParserImpl" />
+ class="org.apache.taverna.security.credentialmanager.impl.DistinguishedNameParserImpl" />
<bean id="defaultMasterPassword"
- class="net.sf.taverna.t2.security.credentialmanager.impl.DefaultMasterPasswordProvider">
+ class="org.apache.taverna.security.credentialmanager.impl.DefaultMasterPasswordProvider">
<property name="applicationConfiguration" ref="applicationConfiguration" />
</bean>
</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/55900be9/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/CredentialManagerImplIT.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/CredentialManagerImplIT.java b/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/CredentialManagerImplIT.java
deleted file mode 100644
index 593e223..0000000
--- a/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/CredentialManagerImplIT.java
+++ /dev/null
@@ -1,339 +0,0 @@
-/*******************************************************************************
- * 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.*;
-
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.security.Key;
-import java.security.KeyStore;
-import java.security.Security;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Random;
-
-import javax.net.ssl.HttpsURLConnection;
-
-import net.sf.taverna.t2.lang.observer.Observable;
-import net.sf.taverna.t2.lang.observer.Observer;
-import net.sf.taverna.t2.security.credentialmanager.CMException;
-import net.sf.taverna.t2.security.credentialmanager.KeystoreChangedEvent;
-import net.sf.taverna.t2.security.credentialmanager.MasterPasswordProvider;
-import net.sf.taverna.t2.security.credentialmanager.TrustConfirmationProvider;
-import net.sf.taverna.t2.security.credentialmanager.UsernamePassword;
-
-import org.apache.commons.io.FileUtils;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-/**
- * Tests here require Java strong/unlimited cryptography policy to be installed
- * so they are part of integration tests.
- *
- * Java strong/unlimited cryptography policy is required to use the Credential Manager and
- * the full security capabilities in Taverna. Java by default comes with the weak policy
- * that disables the use of certain cryto algorithms and bigger key sizes. Although
- * it is claimed that as of Java 6 the default policy is strong, we have seen otherwise,
- * so make sure you install it.
- *
- * For Java 6, strong/unlimited cryptography policy can be downloaded
- * (together with the installation instructions) from:
- * http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html
- *
- * These tests use an existing keystore (in resources/security/t2keystore.ubr) and
- * truststore (in resources/security/t2truststore.ubr) that are not empty.
- *
- * @author Alex Nenadic
- *
- */
-public class CredentialManagerImplIT {
-
- private static CredentialManagerImpl credentialManager;
- // Master password for Credential Manager's Keystore and Truststore
- private static String masterPassword = "(cl%ZDxu66AN/{vNXbLF";
- private static DummyMasterPasswordProvider masterPasswordProvider;
- private static File credentialManagerDirectory;
-
- private static UsernamePassword usernamePassword;
- private static URI serviceURI;
- private static UsernamePassword usernamePassword2;
- private static URI serviceURI2;
- private static UsernamePassword usernamePassword3;
- private static URI serviceURI3;
-
- private static Key privateKey;
- private static Certificate[] privateKeyCertChain;
- private static URL privateKeyFileURL = CredentialManagerImplTest.class.getResource(
- "/security/test-private-key-cert.p12");
- private static final String privateKeyAndPKCS12KeystorePassword = "test"; // password for the test PKCS#12 keystore in resources
-
- private static X509Certificate trustedCertficateGoogle;
- private static URL trustedCertficateGoogleFileURL = CredentialManagerImplTest.class.getResource(
- "/security/google-trusted-certificate.pem");
- private static X509Certificate trustedCertficateHeater;
- private static URL trustedCertficateHeaterFileURL = CredentialManagerImplTest.class.getResource(
- "/security/tomcat_heater_certificate.pem");
-
- private static Observer<KeystoreChangedEvent> keystoreChangedObserver;
-
- /**
- * @throws java.lang.Exception
- */
- @BeforeClass
- @Ignore
- public static void setUpBeforeCLass() throws Exception {
-
- Security.addProvider(new BouncyCastleProvider());
-
- // Create some test username and passwords for services
- serviceURI = new URI("http://someservice");
- usernamePassword = new UsernamePassword("testuser", "testpasswd");
- serviceURI2 = new URI("http://someservice2");
- usernamePassword2 = new UsernamePassword("testuser2", "testpasswd2");
- serviceURI3 = new URI("http://someservice3");
- usernamePassword3 = new UsernamePassword("testuser3", "testpasswd3");
-
- // Load the test private key and its certificate
- File privateKeyCertFile = new File(privateKeyFileURL.getPath());
- KeyStore pkcs12Keystore = java.security.KeyStore.getInstance("PKCS12", "BC"); // We have to use the BC provider here as the certificate chain is not loaded if we use whichever provider is first in Java!!!
- FileInputStream inStream = new FileInputStream(privateKeyCertFile);
- pkcs12Keystore.load(inStream, privateKeyAndPKCS12KeystorePassword.toCharArray());
- // KeyStore pkcs12Keystore = credentialManager.loadPKCS12Keystore(privateKeyCertFile, privateKeyPassword);
- Enumeration<String> aliases = pkcs12Keystore.aliases();
- while (aliases.hasMoreElements()) {
- // The test-private-key-cert.p12 file contains only one private key
- // and corresponding certificate entry
- String alias = aliases.nextElement();
- if (pkcs12Keystore.isKeyEntry(alias)) { // is it a (private) key entry?
- privateKey = pkcs12Keystore.getKey(alias,
- privateKeyAndPKCS12KeystorePassword.toCharArray());
- privateKeyCertChain = pkcs12Keystore.getCertificateChain(alias);
- break;
- }
- }
- inStream.close();
-
- // Load the test trusted certificate (belonging to *.Google.com)
- File trustedCertFile = new File(trustedCertficateGoogleFileURL.getPath());
- inStream = new FileInputStream(trustedCertFile);
- CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
- trustedCertficateGoogle = (X509Certificate) certFactory.generateCertificate(inStream);
- try{
- inStream.close();
- }
- catch (Exception e) {
- // Ignore
- }
- // Load the test trusted certificate (belonging to heater.cs.man.ac.uk)
- File trustedCertFile2 = new File(trustedCertficateHeaterFileURL.getPath());
- inStream = new FileInputStream(trustedCertFile2);
- trustedCertficateHeater = (X509Certificate) certFactory.generateCertificate(inStream);
- try{
- inStream.close();
- }
- catch (Exception e) {
- // Ignore
- }
-
- credentialManager = new CredentialManagerImpl();
-
-// // The code below sets up the Keystore and Truststore files and loads some data into them
-// // and saves them into a temp directory. These files can later be used for testing the Credential
-// // Manager with non-empty keystores.
-// 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);
-// credentialManager.setConfigurationDirectoryPath(credentialManagerDirectory);
-//
-// // Create the dummy master password provider
-// masterPasswordProvider = new DummyMasterPasswordProvider();
-// masterPasswordProvider.setMasterPassword(masterPassword);
-// List<MasterPasswordProvider> masterPasswordProviders = new ArrayList<MasterPasswordProvider>();
-// masterPasswordProviders.add(masterPasswordProvider);
-// credentialManager.setMasterPasswordProviders(masterPasswordProviders);
-//
-// // Add some stuff into Credential Manager
-// credentialManager.addUsernameAndPasswordForService(usernamePassword, serviceURI);
-// credentialManager.addUsernameAndPasswordForService(usernamePassword2, serviceURI2);
-// credentialManager.addUsernameAndPasswordForService(usernamePassword3, serviceURI3);
-// credentialManager.addKeyPair(privateKey, privateKeyCertChain);
-// credentialManager.addTrustedCertificate(trustedCertficate);
-
-
- // Set up a random temp directory and copy the test keystore files
- // from resources/security
- 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);
- if (!credentialManagerDirectory.exists()) {
- credentialManagerDirectory.mkdir();
- }
- URL keystoreFileURL = CredentialManagerImplIT.class
- .getResource("/security/t2keystore.ubr");
- File keystoreFile = new File(keystoreFileURL.getPath());
- File keystoreDestFile = new File(credentialManagerDirectory,
- "taverna-keystore.ubr");
- URL truststroreFileURL = CredentialManagerImplIT.class
- .getResource("/security/t2truststore.ubr");
- File truststoreFile = new File(truststroreFileURL.getPath());
- File truststoreDestFile = new File(credentialManagerDirectory,
- "taverna-truststore.ubr");
- FileUtils.copyFile(keystoreFile, keystoreDestFile);
- FileUtils.copyFile(truststoreFile, truststoreDestFile);
- credentialManager.setConfigurationDirectoryPath(credentialManagerDirectory);
-
- // Create the dummy master password provider
- masterPasswordProvider = new DummyMasterPasswordProvider();
- masterPasswordProvider.setMasterPassword(masterPassword);
- List<MasterPasswordProvider> masterPasswordProviders = new ArrayList<MasterPasswordProvider>();
- masterPasswordProviders.add(masterPasswordProvider);
- credentialManager.setMasterPasswordProviders(masterPasswordProviders);
-
- // Set an empty list for trust confirmation providers
- credentialManager.setTrustConfirmationProviders(new ArrayList<TrustConfirmationProvider>());
-
- keystoreChangedObserver = new Observer<KeystoreChangedEvent>() {
- @Override
- public void notify(Observable<KeystoreChangedEvent> sender,
- KeystoreChangedEvent message) throws Exception {
- // TODO Auto-generated method stub
- }
- };
- credentialManager.addObserver(keystoreChangedObserver);
- }
-
- @AfterClass
- @Ignore
- // 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
- @Ignore
- public void testCredentialManager() throws CMException, URISyntaxException, IOException{
-
- // There are 3 service username and password entries in the Keystore
- List<URI> serviceList = credentialManager.getServiceURIsForAllUsernameAndPasswordPairs();
- assertTrue(serviceList.size() == 3);
- System.out.println();
- assertTrue(serviceList.contains(serviceURI2));
-
- credentialManager.deleteUsernameAndPasswordForService(serviceURI3);
- assertFalse(credentialManager.hasUsernamePasswordForService(serviceURI3));
-
- // There are 2 private/public key pair entries in the Keystore
- credentialManager.hasKeyPair(privateKey, privateKeyCertChain);
-
- // There are Google's and heater.cs.man.ac's trusted certificates in the Truststore
- credentialManager.hasTrustedCertificate(trustedCertficateGoogle);
- // Open a HTTPS connection to Google
- URL url = new URL("https://code.google.com/p/taverna/");
- HttpsURLConnection conn;
- conn = (HttpsURLConnection) url.openConnection();
- // This should work
- conn.connect();
- assertEquals("HTTP/1.1 200 OK", conn.getHeaderField(0));
- conn.disconnect();
-
- credentialManager.hasTrustedCertificate(trustedCertficateHeater);
- // Open a HTTPS connection to heater
- url = new URL("https://heater.cs.man.ac.uk:7443/");
- conn = (HttpsURLConnection) url.openConnection();
- // This should work
- conn.connect();
- assertEquals("HTTP/1.1 200 OK", conn.getHeaderField(0));
- conn.disconnect();
-
- }
-
- public void generateKeystores() throws Exception{
-
- setUpBeforeCLass();
-
- // The code below sets up the Keystore and Truststore files and loads some data into them
- // and saves them into a temp directory. These files can later be used for testing the Credential
- // Manager with non-empty keystores.
- 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 Keystore and Truststore will be saved to: "
- + credentialManagerDirectoryPath);
- credentialManagerDirectory = new File(credentialManagerDirectoryPath);
- credentialManager.setConfigurationDirectoryPath(credentialManagerDirectory);
-
- // Create the dummy master password provider
- masterPasswordProvider = new DummyMasterPasswordProvider();
-// masterPasswordProvider.setMasterPassword(masterPassword);
- masterPasswordProvider.setMasterPassword("uber");
- List<MasterPasswordProvider> masterPasswordProviders = new ArrayList<MasterPasswordProvider>();
- masterPasswordProviders.add(masterPasswordProvider);
- credentialManager.setMasterPasswordProviders(masterPasswordProviders);
-
- // Add some stuff into Credential Manager
- credentialManager.addUsernameAndPasswordForService(usernamePassword, new URI("http://heater.cs.man.ac.uk:7070/axis/services/HelloService-PlaintextPassword?wsdl"));
-
-// credentialManager.addUsernameAndPasswordForService(usernamePassword, serviceURI);
-// credentialManager.addUsernameAndPasswordForService(usernamePassword2, serviceURI2);
-// credentialManager.addUsernameAndPasswordForService(usernamePassword3, serviceURI3);
-// credentialManager.addKeyPair(privateKey, privateKeyCertChain);
- credentialManager.addTrustedCertificate(trustedCertficateHeater);
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/55900be9/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/CredentialManagerImplTest.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/CredentialManagerImplTest.java b/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/CredentialManagerImplTest.java
deleted file mode 100644
index 931fa07..0000000
--- a/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/CredentialManagerImplTest.java
+++ /dev/null
@@ -1,872 +0,0 @@
-/*******************************************************************************
- * 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.*;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.security.Key;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.Security;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Random;
-
-import javax.net.ssl.SSLSocketFactory;
-
-import net.sf.taverna.t2.lang.observer.Observable;
-import net.sf.taverna.t2.lang.observer.Observer;
-import net.sf.taverna.t2.security.credentialmanager.CMException;
-import net.sf.taverna.t2.security.credentialmanager.CredentialManager;
-import net.sf.taverna.t2.security.credentialmanager.CredentialManager.KeystoreType;
-import net.sf.taverna.t2.security.credentialmanager.JavaTruststorePasswordProvider;
-import net.sf.taverna.t2.security.credentialmanager.KeystoreChangedEvent;
-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 net.sf.taverna.t2.security.credentialmanager.UsernamePassword;
-
-import org.apache.commons.io.FileUtils;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Tests here should not require Java strong/unlimited cryptography policy to be installed,
- * although if something goes wrong that is the first thing to be checked for.
- *
- * Java by default comes with the weak policy
- * that disables the use of certain cryto algorithms and bigger key sizes. Although
- * it is claimed that as of Java 6 the default policy is strong, we have seen otherwise,
- * so make sure you install it.
- *
- * For Java 6, strong/unlimited cryptography policy can be downloaded
- * (together with the installation instructions) from:
- * http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html
- *
- * An empty Keystore/Truststore is created before each test so we always start afresh
- * (see the setUp() method).
- * s
- * @author Alex Nenadic
- *
- */
-public class CredentialManagerImplTest {
-
- private CredentialManagerImpl credentialManager;
- private String masterPassword = "uber";
- private DummyMasterPasswordProvider masterPasswordProvider;
- private File credentialManagerDirectory;
-
- private static UsernamePassword usernamePassword;
- private static URI serviceURI;
-
- private static Key privateKey;
- private static Certificate[] privateKeyCertChain;
- private static URL privateKeyFileURL = CredentialManagerImplTest.class.getResource(
- "/security/test-private-key-cert.p12");
- private static final String privateKeyAndPKCS12KeystorePassword = "test"; // password for the test PKCS#12 keystore in resources
-
- private static X509Certificate trustedCertficate;
- private static URL trustedCertficateFileURL = CredentialManagerImplTest.class.getResource(
- "/security/google-trusted-certificate.pem");
-
- private static Observer<KeystoreChangedEvent> keystoreChangedObserver;
-
- /**
- * @throws java.lang.Exception
- */
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
-
- // Just in case, add the BouncyCastle provider
- // It gets added from the CredentialManagerImpl constructor as well
- // but we may need some crypto operations before we invoke the Cred. Manager
- Security.addProvider(new BouncyCastleProvider());
-
- // Create a test username and password for a service
- serviceURI = new URI("http://someservice");
- usernamePassword = new UsernamePassword("testuser", "testpasswd");
-
- // Load the test private key and its certificate
- File privateKeyCertFile = new File(privateKeyFileURL.getPath());
- KeyStore pkcs12Keystore = java.security.KeyStore.getInstance("PKCS12", "BC"); // We have to use the BC provider here as the certificate chain is not loaded if we use whichever provider is first in Java!!!
- FileInputStream inStream = new FileInputStream(privateKeyCertFile);
- pkcs12Keystore.load(inStream, privateKeyAndPKCS12KeystorePassword.toCharArray());
- // KeyStore pkcs12Keystore = credentialManager.loadPKCS12Keystore(privateKeyCertFile, privateKeyPassword);
- Enumeration<String> aliases = pkcs12Keystore.aliases();
- while (aliases.hasMoreElements()) {
- // The test-private-key-cert.p12 file contains only one private key
- // and corresponding certificate entry
- String alias = aliases.nextElement();
- if (pkcs12Keystore.isKeyEntry(alias)) { // is it a (private) key entry?
- privateKey = pkcs12Keystore.getKey(alias,
- privateKeyAndPKCS12KeystorePassword.toCharArray());
- privateKeyCertChain = pkcs12Keystore.getCertificateChain(alias);
- break;
- }
- }
- inStream.close();
-
- // Load the test trusted certificate (belonging to *.Google.com)
- File trustedCertFile = new File(trustedCertficateFileURL.getPath());
- inStream = new FileInputStream(trustedCertFile);
- CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
- trustedCertficate = (X509Certificate) certFactory.generateCertificate(inStream);
- try{
- inStream.close();
- }
- catch (Exception e) {
- // Ignore
- }
-
- keystoreChangedObserver = new Observer<KeystoreChangedEvent>() {
-
- @Override
- public void notify(Observable<KeystoreChangedEvent> sender,
- KeystoreChangedEvent message) throws Exception {
- // TODO Auto-generated method stub
-
- }
- };
- }
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
-
- 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();
- masterPasswordProvider.setMasterPassword(masterPassword);
- List<MasterPasswordProvider> masterPasswordProviders = new ArrayList<MasterPasswordProvider>();
- masterPasswordProviders.add(masterPasswordProvider);
- credentialManager.setMasterPasswordProviders(masterPasswordProviders);
-
- // Set an empty list for service username and password providers
- credentialManager.setServiceUsernameAndPasswordProviders(new ArrayList<ServiceUsernameAndPasswordProvider>());
-
- credentialManager.setJavaTruststorePasswordProviders(new ArrayList<JavaTruststorePasswordProvider>());
-
- credentialManager.setTrustConfirmationProviders(new ArrayList<TrustConfirmationProvider>());
-
- }
-
- @After
- // Clean up the credentialManagerDirectory we created for testing
- public void cleanUp(){
-// assertTrue(credentialManagerDirectory.exists());
-// assertFalse(credentialManagerDirectory.listFiles().length == 0); // something was created there
-
- 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 method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#CredentialManagerImpl()}.
- * @throws CMException
- */
- @Test
- public void testCredentialManagerImpl() throws CMException {
- new CredentialManagerImpl();
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#getUsernameAndPasswordForService(java.net.URI, boolean, java.lang.String)}.
- * @throws URISyntaxException
- * @throws CMException
- */
- @Test
- public void testGetUsernameAndPasswordForServiceURI() throws URISyntaxException, CMException {
- // The Credential Manage's Keystore is empty so we should not be able to find anything initially
- assertNull(credentialManager.getUsernameAndPasswordForService(serviceURI, false, ""));
-
- credentialManager.addUsernameAndPasswordForService(usernamePassword,serviceURI);
-
- UsernamePassword testUsernamePassword = credentialManager.getUsernameAndPasswordForService(serviceURI, false, "");
- assertNotNull(testUsernamePassword);
- assertTrue(Arrays.equals(usernamePassword.getPassword(), testUsernamePassword.getPassword()));
- assertTrue(usernamePassword.getUsername().equals(testUsernamePassword.getUsername()));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#addUsernameAndPasswordForService(net.sf.taverna.t2.security.credentialmanager.UsernamePassword, java.net.URI)}.
- * @throws URISyntaxException
- * @throws CMException
- */
- @Test
- public void testAddUsernameAndPasswordForService() throws CMException, URISyntaxException {
-
- String alias = credentialManager.addUsernameAndPasswordForService(usernamePassword,serviceURI);
-
- UsernamePassword testUsernamePassword = credentialManager.getUsernameAndPasswordForService(serviceURI, false, "");
- assertNotNull(testUsernamePassword);
- assertTrue(credentialManager.hasEntryWithAlias(CredentialManager.KeystoreType.KEYSTORE, alias));
- assertTrue(Arrays.equals(usernamePassword.getPassword(), testUsernamePassword.getPassword()));
- assertTrue(usernamePassword.getUsername().equals(testUsernamePassword.getUsername()));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#hasUsernamePasswordForService(java.net.URI)}.
- * @throws CMException
- */
- @Test
- public void testHasUsernamePasswordForService() throws CMException {
-
- UsernamePassword testUsernamePassword = credentialManager.getUsernameAndPasswordForService(serviceURI, false, "");
- assertNull(testUsernamePassword);
-
- String alias = credentialManager.addUsernameAndPasswordForService(usernamePassword,serviceURI);
- testUsernamePassword = credentialManager.getUsernameAndPasswordForService(serviceURI, false, "");
- assertNotNull(testUsernamePassword);
- assertTrue(credentialManager.hasEntryWithAlias(CredentialManager.KeystoreType.KEYSTORE, alias));
- assertTrue(Arrays.equals(usernamePassword.getPassword(), testUsernamePassword.getPassword()));
- assertTrue(usernamePassword.getUsername().equals(testUsernamePassword.getUsername()));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#deleteUsernameAndPasswordForService(java.net.URI)}.
- * @throws URISyntaxException
- * @throws CMException
- */
- @Test
- public void testDeleteUsernameAndPasswordForServiceURI() throws URISyntaxException, CMException {
-
- // The Credential Manage's Keystore is empty initially so this should
- // have no effect apart from initializing the Keystore/Truststore
- credentialManager.deleteUsernameAndPasswordForService(serviceURI);
-
- credentialManager.addUsernameAndPasswordForService(usernamePassword,serviceURI);
- credentialManager.deleteUsernameAndPasswordForService(serviceURI);
-
- assertNull(credentialManager.getUsernameAndPasswordForService(serviceURI, false, ""));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#addKeyPair(java.security.Key, java.security.cert.Certificate[])}.
- * @throws CMException
- * @throws KeyStoreException
- * @throws NoSuchAlgorithmException
- * @throws UnrecoverableKeyException
- * @throws IOException
- * @throws FileNotFoundException
- * @throws CertificateException
- */
- @Test
- public void testAddKeyPair() throws CMException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException {
-
- String alias = credentialManager.addKeyPair(privateKey, privateKeyCertChain);
- assertTrue(credentialManager.hasKeyPair(privateKey, privateKeyCertChain));
- assertTrue(credentialManager.hasEntryWithAlias(CredentialManager.KeystoreType.KEYSTORE, alias));
-
- credentialManager.deleteKeyPair(alias);
- assertFalse(credentialManager.hasKeyPair(privateKey, privateKeyCertChain));
- assertFalse(credentialManager.hasEntryWithAlias(CredentialManager.KeystoreType.KEYSTORE, alias));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#hasKeyPair(java.security.Key, java.security.cert.Certificate[])}.
- * @throws CMException
- * @throws KeyStoreException
- * @throws NoSuchAlgorithmException
- * @throws UnrecoverableKeyException
- * @throws IOException
- * @throws FileNotFoundException
- * @throws CertificateException
- */
- @Test
- public void testHasKeyPair() throws CMException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException {
- assertFalse(credentialManager.hasKeyPair(privateKey, privateKeyCertChain));
- credentialManager.addKeyPair(privateKey, privateKeyCertChain);
- assertTrue(credentialManager.hasKeyPair(privateKey, privateKeyCertChain));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#deleteKeyPair(java.lang.String)}.
- * @throws CMException
- * @throws KeyStoreException
- * @throws NoSuchAlgorithmException
- * @throws UnrecoverableKeyException
- * @throws IOException
- * @throws FileNotFoundException
- * @throws CertificateException
- */
- @Test
- public void testDeleteKeyPair() throws CMException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException {
- // The Credential Manage's Keystore is empty initially so this should
- // have no effect apart from initializing the Keystore/Truststore
- credentialManager.deleteKeyPair("somealias");
-
- String alias = credentialManager.addKeyPair(privateKey, privateKeyCertChain);
- credentialManager.deleteKeyPair(alias);
- assertFalse(credentialManager.hasEntryWithAlias(CredentialManager.KeystoreType.KEYSTORE, alias));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#deleteKeyPair(Key, Certificate[])}.
- * @throws CMException
- */
- @Test
- public void testDeleteKeyPair2() throws CMException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException {
- credentialManager.addKeyPair(privateKey, privateKeyCertChain);
- assertTrue(credentialManager.hasKeyPair(privateKey, privateKeyCertChain));
- credentialManager.deleteKeyPair(privateKey, privateKeyCertChain);
- assertFalse(credentialManager.hasKeyPair(privateKey, privateKeyCertChain));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#exportKeyPair(java.lang.String, java.io.File, java.lang.String)}.
- * @throws CMException
- * @throws KeyStoreException
- * @throws NoSuchAlgorithmException
- * @throws UnrecoverableKeyException
- */
- @Test
- public void testExportKeyPair() throws CMException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException {
- String alias = credentialManager.addKeyPair(privateKey, privateKeyCertChain);
- File fileToExportTo = new File(credentialManagerDirectory, "test-export-key.p12");
- credentialManager.exportKeyPair(alias, fileToExportTo, privateKeyAndPKCS12KeystorePassword);
- assertTrue(fileToExportTo.exists());
- // Load it back from the file we just saved
- KeyStore ks = credentialManager.loadPKCS12Keystore(fileToExportTo, privateKeyAndPKCS12KeystorePassword);
- Enumeration<String> aliases = ks.aliases();
- Key newPrivateKey = null;
- Certificate[] newPrivateKeyCerts = null;
- while (aliases.hasMoreElements()) {
- // The test-private-key-cert.p12 file contains only one private key
- // and corresponding certificate entry
- alias = aliases.nextElement();
- if (ks.isKeyEntry(alias)) { // is it a (private) key entry?
- newPrivateKey = ks.getKey(alias,
- privateKeyAndPKCS12KeystorePassword.toCharArray());
- newPrivateKeyCerts = ks.getCertificateChain(alias);
- break;
- }
- }
- assertNotNull(newPrivateKey);
- assertNotNull(newPrivateKeyCerts);
- //assertTrue(Arrays.equals(newPrivateKey.getEncoded(), privateKey.getEncoded()));
- assertTrue(newPrivateKey.equals(privateKey));
- assertTrue(Arrays.equals(newPrivateKeyCerts, privateKeyCertChain));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#getCertificate(java.lang.String, java.lang.String)}.
- * @throws CMException
- */
- @Test
- public void testGetCertificate() throws CMException {
- String alias = credentialManager.addKeyPair(privateKey, privateKeyCertChain);
- // Get certificate from the Keystore associated with the private key we just inserted
- Certificate privateKeyCertificate = credentialManager.getCertificate(CredentialManager.KeystoreType.KEYSTORE, alias);
- assertNotNull(privateKeyCertificate);
- assertTrue(privateKeyCertChain[0].equals(privateKeyCertificate));
-
- // We should also have some trusted certificates in the Truststore
- // Need to get their aliases
- ArrayList<String> truststoreAliases = credentialManager.getAliases(CredentialManager.KeystoreType.TRUSTSTORE);
- assertTrue(!truststoreAliases.isEmpty());
- // Just get the first one
- Certificate trustedCertificate = credentialManager.getCertificate(CredentialManager.KeystoreType.TRUSTSTORE, truststoreAliases.get(0));
- assertNotNull(trustedCertificate);
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#getKeyPairsCertificateChain(java.lang.String)}.
- * @throws CMException
- */
- @Test
- public void testGetKeyPairCertificateChain() throws CMException {
- String alias = credentialManager.addKeyPair(privateKey, privateKeyCertChain);
- Certificate[] keyPairCertificateChain = credentialManager.getKeyPairsCertificateChain(alias);
- assertNotNull(keyPairCertificateChain);
- assertTrue(Arrays.equals(privateKeyCertChain, keyPairCertificateChain));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#getKeyPairsPrivateKey(java.lang.String)}.
- * @throws CMException
- */
- @Test
- public void testGetKeyPairsPrivateKey() throws CMException {
- String alias = credentialManager.addKeyPair(privateKey, privateKeyCertChain);
- Key prvKey = credentialManager.getKeyPairsPrivateKey(alias);
- assertNotNull(prvKey);
- assertEquals(privateKey, prvKey);
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#addTrustedCertificate(java.security.cert.X509Certificate)}.
- * @throws CMException
- */
- @Test
- public void testAddTrustedCertificate() throws CMException {
-
- String alias = credentialManager.addTrustedCertificate(trustedCertficate);
- assertTrue(credentialManager.hasTrustedCertificate(trustedCertficate));
- assertTrue(credentialManager.hasEntryWithAlias(CredentialManager.KeystoreType.TRUSTSTORE, alias));
-
- credentialManager.deleteTrustedCertificate(alias);
- assertFalse(credentialManager.hasTrustedCertificate(trustedCertficate));
- assertFalse(credentialManager.hasEntryWithAlias(CredentialManager.KeystoreType.TRUSTSTORE, alias));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#createTrustedCertificateAlias(java.security.cert.X509Certificate)}.
- * @throws CMException
- */
- @Test
- public void testGetX509CertificateAlias() throws CMException {
-
- String alias = credentialManager.createTrustedCertificateAlias(trustedCertficate);
- String alias2 = credentialManager.addTrustedCertificate(trustedCertficate);
- assertEquals(alias, alias2);
-
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#deleteTrustedCertificate(java.lang.String)}.
- * @throws CMException
- */
- @Test
- public void testDeleteTrustedCertificate() throws CMException {
- // The Credential Manage's Truststore is empty initially so this should
- // have no effect apart from initializing the Keystore/Truststore
- credentialManager.deleteTrustedCertificate("somealias");
-
- String alias = credentialManager.addTrustedCertificate(trustedCertficate);
- assertTrue(credentialManager.hasEntryWithAlias(CredentialManager.KeystoreType.TRUSTSTORE, alias));
- credentialManager.deleteTrustedCertificate(alias);
- assertFalse(credentialManager.hasTrustedCertificate(trustedCertficate));
- assertFalse(credentialManager.hasEntryWithAlias(CredentialManager.KeystoreType.TRUSTSTORE, alias));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#deleteTrustedCertificate(X509Certificate)}.
- * @throws CMException
- */
- @Test
- public void testDeleteTrustedCertificate2() throws CMException {
-
- credentialManager.addTrustedCertificate(trustedCertficate);
- assertTrue(credentialManager.hasTrustedCertificate(trustedCertficate));
- credentialManager.deleteTrustedCertificate(trustedCertficate);
- assertFalse(credentialManager.hasTrustedCertificate(trustedCertficate));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#isKeyEntry(java.lang.String)}.
- * @throws CMException
- */
- @Test
- public void testIsKeyEntry() throws CMException {
- // The Credential Manage's Keystore/Truststore is empty initially so this should
- // have no effect apart from initializing them
- // This should throw an exception
- assertFalse(credentialManager.isKeyEntry("somealias"));
-
- String aliasPassword = credentialManager.addUsernameAndPasswordForService(usernamePassword, serviceURI);
- String aliasKeyPair = credentialManager.addKeyPair(privateKey, privateKeyCertChain);
- String aliasTrustedCert = credentialManager.addTrustedCertificate(trustedCertficate);
-
- assertTrue(credentialManager.isKeyEntry(aliasPassword)); // passwords are saves as symmetric key entries
- assertTrue(credentialManager.isKeyEntry(aliasKeyPair));
- assertFalse(credentialManager.isKeyEntry(aliasTrustedCert));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#hasEntryWithAlias(java.lang.String, java.lang.String)}.
- * @throws CMException
- */
- @Test
- public void testHasEntryWithAlias() throws CMException {
-
- String aliasTrustedCert = credentialManager.createTrustedCertificateAlias(trustedCertficate);
- assertFalse(credentialManager.hasEntryWithAlias(KeystoreType.TRUSTSTORE, aliasTrustedCert));
-
- String aliasTrustedCert2 = credentialManager.addTrustedCertificate(trustedCertficate);
- assertTrue(credentialManager.hasEntryWithAlias(KeystoreType.TRUSTSTORE, aliasTrustedCert2));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#getAliases(net.sf.taverna.t2.security.credentialmanager.CredentialManager.KeystoreType)}.
- * @throws CMException
- */
- @Test
- public void testGetAliases() throws CMException {
-
- ArrayList<String> keystoreAliases = credentialManager.getAliases(KeystoreType.KEYSTORE);
- ArrayList<String> truststoreAliases = credentialManager.getAliases(KeystoreType.TRUSTSTORE);
-
- // Initially Keystore/Truststore is empty
- assertTrue(keystoreAliases.isEmpty());
-
- String aliasPassword = credentialManager.addUsernameAndPasswordForService(usernamePassword, serviceURI);
- String aliasKeyPair = credentialManager.addKeyPair(privateKey, privateKeyCertChain);
- String aliasTrustedCert = credentialManager.addTrustedCertificate(trustedCertficate);
-
- keystoreAliases = credentialManager.getAliases(KeystoreType.KEYSTORE);
- truststoreAliases = credentialManager.getAliases(KeystoreType.TRUSTSTORE);
-
- assertTrue(keystoreAliases.size() == 2);
- assertTrue(truststoreAliases.size() >= 1); // we at least have the one we inserted but could be more copied from Java's defauls truststore
-
- assertTrue(keystoreAliases.contains(aliasPassword));
- assertTrue(keystoreAliases.contains(aliasKeyPair));
- assertTrue(truststoreAliases.contains(aliasTrustedCert));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#getServiceURIsForAllUsernameAndPasswordPairs()}.
- * @throws CMException
- * @throws URISyntaxException
- */
- @Test
- public void testGetServiceURIsForAllUsernameAndPasswordPairs() throws CMException, URISyntaxException {
- // Initially empty so this
- assertTrue(credentialManager.getServiceURIsForAllUsernameAndPasswordPairs().isEmpty());
-
- credentialManager.addUsernameAndPasswordForService(usernamePassword, serviceURI);
-
- URI serviceURI2 = new URI("http://someservice2");
- UsernamePassword usernamePassword2 = new UsernamePassword("testuser2", "testpasswd2");
- credentialManager.addUsernameAndPasswordForService(usernamePassword2, serviceURI2);
-
- List<URI> serviceURIs = credentialManager.getServiceURIsForAllUsernameAndPasswordPairs();
- assertTrue(credentialManager.getServiceURIsForAllUsernameAndPasswordPairs().size() == 2);
- assertTrue(serviceURIs.contains(serviceURI));
- assertTrue(serviceURIs.contains(serviceURI2));
-
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#loadPKCS12Keystore(java.io.File, java.lang.String)}.
- * @throws CMException
- * @throws KeyStoreException
- * @throws NoSuchAlgorithmException
- * @throws UnrecoverableKeyException
- */
- @Test
- public void testLoadPKCS12Keystore() throws CMException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException {
- KeyStore pkcs12Keystore = credentialManager.loadPKCS12Keystore(new File(privateKeyFileURL.getPath()), privateKeyAndPKCS12KeystorePassword);
-
- Key privateKey2 = null;
- Certificate[] privateKeyCertChain2 = null;
-
- Enumeration<String> aliases = pkcs12Keystore.aliases();
- while (aliases.hasMoreElements()) {
- // The test-private-key-cert.p12 file contains only one private key
- // and corresponding certificate entry
- String alias = aliases.nextElement();
- if (pkcs12Keystore.isKeyEntry(alias)) { // is it a (private) key entry?
- privateKey2 = pkcs12Keystore.getKey(alias,
- privateKeyAndPKCS12KeystorePassword.toCharArray());
- privateKeyCertChain2 = pkcs12Keystore.getCertificateChain(alias);
- break;
- }
- }
- assertNotNull(privateKey2);
- assertNotNull(privateKeyCertChain2);
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#addObserver(net.sf.taverna.t2.lang.observer.Observer)}.
- */
- @Test
- public void testAddObserver() {
-
- credentialManager.addObserver(keystoreChangedObserver);
- assertEquals(keystoreChangedObserver, credentialManager.getObservers().get(0));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#getObservers()}.
- */
- @Test
- public void testGetObservers() {
- // Initially there are no observers
- assertTrue(credentialManager.getObservers().isEmpty());
-
- credentialManager.addObserver(keystoreChangedObserver);
-
- assertEquals(keystoreChangedObserver, credentialManager.getObservers().get(0));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#removeObserver(net.sf.taverna.t2.lang.observer.Observer)}.
- */
- @Test
- public void testRemoveObserver() {
- credentialManager.addObserver(keystoreChangedObserver);
- assertTrue(credentialManager.getObservers().size() == 1);
- credentialManager.removeObserver(keystoreChangedObserver);
- assertTrue(credentialManager.getObservers().size() == 0);
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#confirmMasterPassword(java.lang.String)}.
- * @throws CMException
- */
- @Test
- public void testConfirmMasterPassword() throws CMException {
- credentialManager.confirmMasterPassword("uber");
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#changeMasterPassword(java.lang.String)}.
- * @throws CMException
- */
- @Test
- public void testChangeMasterPassword() throws CMException {
- // Test the changeMasterPassword() method first to see if
- // it will initialize Credential Manager properly
- credentialManager.changeMasterPassword("blah");
- credentialManager.confirmMasterPassword("blah");
-
- // Add new stuff - key pair and password entries - under the new master password
- String keyPairAlias = credentialManager.addKeyPair(privateKey, privateKeyCertChain);
- credentialManager.addUsernameAndPasswordForService(usernamePassword, serviceURI);
-
- // Change the master password again and try to retrieve the private key and password
- credentialManager.changeMasterPassword("hlab");
- assertArrayEquals(credentialManager.getUsernameAndPasswordForService(serviceURI, false, "").getPassword(), usernamePassword.getPassword());
- assertEquals(privateKey, credentialManager.getKeyPairsPrivateKey(keyPairAlias));
- assertTrue(Arrays.equals(privateKeyCertChain, credentialManager.getKeyPairsCertificateChain(keyPairAlias)));
-
- // Load the Credential Manager back from the saved file to see of entries will be picked up properly
- CredentialManagerImpl credentialManagerNew = null;
- try {
- credentialManagerNew = new CredentialManagerImpl();
- } catch (CMException e) {
- System.out.println(e.getStackTrace());
- }
- try {
- credentialManagerNew
- .setConfigurationDirectoryPath(credentialManagerDirectory);
- } catch (CMException e) {
- System.out.println(e.getStackTrace());
- }
-
- // Create the dummy master password provider
- masterPasswordProvider = new DummyMasterPasswordProvider();
- masterPasswordProvider.setMasterPassword("hlab");
- List<MasterPasswordProvider> masterPasswordProviders = new ArrayList<MasterPasswordProvider>();
- masterPasswordProviders.add(masterPasswordProvider);
- credentialManager.setMasterPasswordProviders(masterPasswordProviders);
-
- // Set an empty list for service username and password providers
- credentialManagerNew.setServiceUsernameAndPasswordProviders(new ArrayList<ServiceUsernameAndPasswordProvider>());
-
- credentialManager.setJavaTruststorePasswordProviders(new ArrayList<JavaTruststorePasswordProvider>());
-
- credentialManager.setTrustConfirmationProviders(new ArrayList<TrustConfirmationProvider>());
-
- assertArrayEquals(credentialManager.getUsernameAndPasswordForService(serviceURI, false, "").getPassword(), usernamePassword.getPassword());
- assertEquals(privateKey, credentialManager.getKeyPairsPrivateKey(keyPairAlias));
- assertTrue(Arrays.equals(privateKeyCertChain, credentialManager.getKeyPairsCertificateChain(keyPairAlias)));
-
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#initializeSSL()}.
- * @throws CMException
- */
- @Test
- public void testInitializeSSL() throws CMException {
- //credentialManager.initializeSSL();
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#getTavernaSSLSocketFactory()}.
- * @throws CMException
- */
- @Test
- public void testGetTavernaSSLSocketFactory() throws CMException {
- SSLSocketFactory sslSocketFactory = credentialManager.getTavernaSSLSocketFactory();
- assertNotNull(sslSocketFactory);
-
- // This should also create Taverna's SSLSocketFactory backed by Credential Manager's Keystore and Truststore
- // if not already created
- credentialManager.initializeSSL();
- assertEquals(sslSocketFactory, credentialManager.getTavernaSSLSocketFactory());
-
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#setMasterPasswordProviders(java.util.List)}.
- */
- @Test
- public void testSetMasterPasswordProviders() {
-
- List<MasterPasswordProvider> masterPasswordProviders = new ArrayList<MasterPasswordProvider>();
- masterPasswordProviders.add(masterPasswordProvider);
-
- credentialManager.setMasterPasswordProviders(masterPasswordProviders);
-
- assertTrue(credentialManager.getMasterPasswordProviders().contains(masterPasswordProvider));
-
- // Set it to null and see what happens
- credentialManager.setMasterPasswordProviders(null);
- assertNull(credentialManager.getMasterPasswordProviders());
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#getMasterPasswordProviders()}.
- */
- @Test
- public void testGetMasterPasswordProviders() {
-
- assertFalse(credentialManager.getMasterPasswordProviders().isEmpty());
- assertTrue(credentialManager.getMasterPasswordProviders().contains(masterPasswordProvider));
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#setJavaTruststorePasswordProviders(java.util.List)}.
- */
- @Test
- public void testSetJavaTruststorePasswordProviders() {
-
- List<JavaTruststorePasswordProvider> javaTruststorePasswordProviders = new ArrayList<JavaTruststorePasswordProvider>();
- JavaTruststorePasswordProvider javaTruststorePasswordProvider = new DummyJavaTruststorePasswordProvider();
- javaTruststorePasswordProvider.setJavaTruststorePassword("blah");
- javaTruststorePasswordProviders.add(javaTruststorePasswordProvider);
-
- credentialManager.setJavaTruststorePasswordProviders(javaTruststorePasswordProviders);
-
- assertTrue(credentialManager.getJavaTruststorePasswordProviders().contains(javaTruststorePasswordProvider));
-
- // Set it to null and see what happens
- credentialManager.setJavaTruststorePasswordProviders(null);
- assertNull(credentialManager.getJavaTruststorePasswordProviders());
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#getJavaTruststorePasswordProviders()}.
- */
- @Test
- public void testGetJavaTruststorePasswordProviders() {
-
- assertTrue(credentialManager.getJavaTruststorePasswordProviders().isEmpty());
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#setServiceUsernameAndPasswordProviders(java.util.List)}.
- * @throws URISyntaxException
- */
- @Test
- public void testSetServiceUsernameAndPasswordProviders() throws URISyntaxException {
-
- List<ServiceUsernameAndPasswordProvider> serviceUsernameAndPasswordProviders = new ArrayList<ServiceUsernameAndPasswordProvider>();
- ServiceUsernameAndPasswordProvider serviceUsernameAndPasswordProvider = new DummyServiceUsernameAndPasswordProvider();
- serviceUsernameAndPasswordProvider.setServiceUsernameAndPassword(new URI("http://someservice"), new UsernamePassword("blah", "blah"));
- serviceUsernameAndPasswordProviders.add(serviceUsernameAndPasswordProvider);
-
- credentialManager.setServiceUsernameAndPasswordProviders(serviceUsernameAndPasswordProviders);
-
- assertTrue(credentialManager.getServiceUsernameAndPasswordProviders().contains(serviceUsernameAndPasswordProvider));
-
- // Set it to null and see what happens
- credentialManager.setServiceUsernameAndPasswordProviders(null);
- assertNull(credentialManager.getServiceUsernameAndPasswordProviders());
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#getServiceUsernameAndPasswordProviders()}.
- */
- @Test
- public void testGetServiceUsernameAndPasswordProviders() {
-
- assertTrue(credentialManager.getServiceUsernameAndPasswordProviders().isEmpty());
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#setTrustConfirmationProviders(java.util.List)}.
- * @throws IOException
- */
- @Test
- public void testSetTrustConfirmationProviders() throws IOException {
- List<TrustConfirmationProvider> trustConfirmationProviders = new ArrayList<TrustConfirmationProvider>();
- TrustConfirmationProvider trustConfirmationProvider = new TrustAlwaysTrustConfirmationProvider();
- trustConfirmationProviders.add(trustConfirmationProvider);
-
- credentialManager.setTrustConfirmationProviders(trustConfirmationProviders);
-
- assertTrue(credentialManager.getTrustConfirmationProviders().contains(trustConfirmationProvider));
-
- // Set it to null and see what happens
- credentialManager.setTrustConfirmationProviders(null);
- assertNull(credentialManager.getTrustConfirmationProviders());
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#getTrustConfirmationProviders()}.
- */
- @Test
- public void testGetTrustConfirmationProviders() {
-
- assertTrue(credentialManager.getTrustConfirmationProviders().isEmpty());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/55900be9/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/DummyJavaTruststorePasswordProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/DummyJavaTruststorePasswordProvider.java b/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/DummyJavaTruststorePasswordProvider.java
deleted file mode 100644
index 6a1b9dc..0000000
--- a/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/DummyJavaTruststorePasswordProvider.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * 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 net.sf.taverna.t2.security.credentialmanager.JavaTruststorePasswordProvider;
-
-public class DummyJavaTruststorePasswordProvider implements JavaTruststorePasswordProvider{
-
- String javaTruststorePassword;
-
- @Override
- public String getJavaTruststorePassword() {
- return javaTruststorePassword;
- }
-
- @Override
- public void setJavaTruststorePassword(String password) {
- javaTruststorePassword = password;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/55900be9/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/DummyMasterPasswordProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/DummyMasterPasswordProvider.java b/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/DummyMasterPasswordProvider.java
deleted file mode 100644
index ddcd7e6..0000000
--- a/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/DummyMasterPasswordProvider.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*******************************************************************************
- * 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 net.sf.taverna.t2.security.credentialmanager.MasterPasswordProvider;
-
-public class DummyMasterPasswordProvider implements MasterPasswordProvider{
-
- private String masterPassword;
- private int priority = 0;
-
- @Override
- public String getMasterPassword(boolean firstTime) {
- return masterPassword;
- }
-
- @Override
- public int getProviderPriority() {
- return priority;
- }
-
- @Override
- public void setMasterPassword(String password) {
- masterPassword = password;
- }
-
-// @Override
-// public void setProviderPriority(int priority) {
-// this.priority = priority;
-// }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-engine/blob/55900be9/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/DummyServiceUsernameAndPasswordProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/DummyServiceUsernameAndPasswordProvider.java b/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/DummyServiceUsernameAndPasswordProvider.java
deleted file mode 100644
index f2227fc..0000000
--- a/taverna-credential-manager-impl/src/test/java/net/sf/taverna/t2/security/credentialmanager/impl/DummyServiceUsernameAndPasswordProvider.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*******************************************************************************
- * 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.net.URI;
-
-import net.sf.taverna.t2.security.credentialmanager.ServiceUsernameAndPasswordProvider;
-import net.sf.taverna.t2.security.credentialmanager.UsernamePassword;
-
-public class DummyServiceUsernameAndPasswordProvider implements ServiceUsernameAndPasswordProvider{
-
- private UsernamePassword usernamePassword;
- private URI serviceURI;
- private String requestingMessage;
-
- @Override
- public UsernamePassword getServiceUsernameAndPassword(URI serviceURI,
- String requestingMessage) {
- this.requestingMessage = requestingMessage;
- this.serviceURI = serviceURI;
- return usernamePassword;
- }
-
- @Override
- public void setServiceUsernameAndPassword(URI serviceURI,
- UsernamePassword usernamePassword) {
-
- //this.serviceURI = serviceURI;
- this.usernamePassword = usernamePassword;
- }
-
-}