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/26 19:52:20 UTC
[31/51] [partial] incubator-taverna-workbench git commit: all
packages are moved to org.apache.taverna.*
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/TrustedCertsTableModel.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/TrustedCertsTableModel.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/TrustedCertsTableModel.java
new file mode 100644
index 0000000..489d7b2
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/TrustedCertsTableModel.java
@@ -0,0 +1,215 @@
+/*
+* 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.workbench.ui.credentialmanager;
+
+import static javax.swing.JOptionPane.ERROR_MESSAGE;
+import static javax.swing.JOptionPane.showMessageDialog;
+import static org.apache.taverna.security.credentialmanager.CredentialManager.KeystoreType.TRUSTSTORE;
+import static org.apache.taverna.workbench.ui.credentialmanager.CMStrings.ERROR_TITLE;
+import static org.apache.taverna.workbench.ui.credentialmanager.CredentialManagerUI.TRUST_CERT_ENTRY_TYPE;
+
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.swing.JFrame;
+import javax.swing.table.AbstractTableModel;
+
+import org.apache.taverna.lang.observer.Observable;
+import org.apache.taverna.lang.observer.Observer;
+import org.apache.taverna.security.credentialmanager.CMException;
+import org.apache.taverna.security.credentialmanager.CredentialManager;
+import org.apache.taverna.security.credentialmanager.KeystoreChangedEvent;
+
+import org.apache.log4j.Logger;
+
+/**
+ * The table model used to display the Keystore's trusted certificate entries.
+ *
+ * @author Alex Nenadic
+ */
+@SuppressWarnings("serial")
+public class TrustedCertsTableModel extends AbstractTableModel implements
+ Observer<KeystoreChangedEvent> {
+ private static final Logger logger = Logger
+ .getLogger(TrustedCertsTableModel.class);
+
+ // Column names
+ private String[] columnNames;
+ // Table data
+ private Object[][] data;
+ private CredentialManager credManager;
+
+ public TrustedCertsTableModel(CredentialManager credentialManager) {
+ credManager = credentialManager;
+ if (credentialManager == null) {
+ // Failed to instantiate Credential Manager - warn the user and exit
+ String sMessage = "Failed to instantiate Credential Manager. ";
+ logger.error("CM GUI: "+ sMessage);
+ showMessageDialog(new JFrame(), sMessage, ERROR_TITLE,
+ ERROR_MESSAGE);
+ return;
+ }
+
+ data = new Object[0][0];
+ columnNames = new String[] {
+ "Entry Type", // type of the Keystore entry
+ "Owner", // owner's common name
+ "Issuer", // issuer's common name
+ "Serial Number", // public key certificate's serial number
+ "Last Modified", // last modified date of the entry
+ "Alias" // the invisible column holding the actual alias in the Keystore
+ };
+
+ try {
+ load();
+ } catch (CMException cme) {
+ String sMessage = "Failed to load trusted certificates";
+ logger.error(sMessage);
+ showMessageDialog(new JFrame(), sMessage, ERROR_TITLE,
+ ERROR_MESSAGE);
+ return;
+ }
+
+ // Start observing changes to the Keystore
+ credManager.addObserver(this);
+ }
+
+ /**
+ * Load the TrustCertsTableModel with trusted certificate entries from the Keystore.
+ */
+ public void load() throws CMException {
+ /*
+ * Place trusted certificate entries' aliases in a tree map to sort them
+ */
+ Set<String> aliases = new TreeSet<>();
+ for (String alias : credManager.getAliases(TRUSTSTORE))
+ /*
+ * We are only interested in trusted certificate entries here. Alias
+ * for such entries is constructed as
+ * "trustedcert#<CERT_SERIAL_NUMBER>#<CERT_COMMON_NAME>"
+ */
+ if (alias.startsWith("trustedcert#"))
+ aliases.add(alias);
+
+ /*
+ * Create one table row for each trusted certificate entry Each row has
+ * 4 fields - type, owner name, last modified data and the invisible
+ * alias
+ */
+ data = new Object[aliases.size()][6];
+
+ /*
+ * Iterate through the sorted aliases, retrieving the trusted
+ * certificate entries and populating the table model
+ */
+ int i = 0;
+ for (String alias : aliases) {
+ /*
+ * Populate the type column - it is set with an integer but a custom
+ * cell renderer will cause a suitable icon to be displayed
+ */
+ data[i][0] = TRUST_CERT_ENTRY_TYPE;
+
+ /*
+ * Split the alias string to extract owner, issuer and serial number
+ * alias =
+ * "trustedcert#<CERT_SUBJECT_COMMON_NAME>"#"<CERT_ISSUER_COMMON_NAME>"
+ * #"<CERT_SERIAL_NUMBER>
+ */
+ String[] aliasComponents = alias.split("#");
+
+ // Populate the owner column extracted from the alias
+ data[i][1] = aliasComponents[1];
+
+ // Populate the issuer column extracted from the alias
+ data[i][2] = aliasComponents[2];
+
+ // Populate the serial number column extracted from the alias
+ data[i][3] = aliasComponents[3];
+
+ // Populate the modified date column
+ //data[iCnt][4] = credManager.getEntryCreationDate(CredentialManager.TRUSTSTORE, alias);
+
+ // Populate the invisible alias column
+ data[i][5] = alias;
+
+ i++;
+ }
+
+ fireTableDataChanged();
+ }
+
+ /**
+ * Get the number of columns in the table.
+ */
+ @Override
+ public int getColumnCount() {
+ return columnNames.length;
+ }
+
+ /**
+ * Get the number of rows in the table.
+ */
+ @Override
+ public int getRowCount() {
+ return data.length;
+ }
+
+ /**
+ * Get the name of the column at the given position.
+ */
+ @Override
+ public String getColumnName(int iCol) {
+ return columnNames[iCol];
+ }
+
+ /**
+ * Get the cell value at the given row and column position.
+ */
+ @Override
+ public Object getValueAt(int iRow, int iCol) {
+ return data[iRow][iCol];
+ }
+
+ /**
+ * Get the class at of the cells at the given column position.
+ */
+ @Override
+ public Class<? extends Object> getColumnClass(int iCol) {
+ return getValueAt(0, iCol).getClass();
+ }
+
+ /**
+ * Is the cell at the given row and column position editable?
+ */
+ @Override
+ public boolean isCellEditable(int iRow, int iCol) {
+ // The table is always read-only
+ return false;
+ }
+
+ @Override
+ public void notify(Observable<KeystoreChangedEvent> sender,
+ KeystoreChangedEvent message) throws Exception {
+ // reload the table
+ if (message.keystoreType.equals(TRUSTSTORE))
+ load();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/ViewCertDetailsDialog.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/ViewCertDetailsDialog.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/ViewCertDetailsDialog.java
new file mode 100644
index 0000000..ee6f1a7
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/ViewCertDetailsDialog.java
@@ -0,0 +1,508 @@
+/*
+* 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.workbench.ui.credentialmanager;
+
+import static java.awt.BorderLayout.CENTER;
+import static java.awt.BorderLayout.NORTH;
+import static java.awt.BorderLayout.SOUTH;
+import static java.awt.Font.BOLD;
+import static java.awt.Font.PLAIN;
+import static java.awt.GridBagConstraints.LINE_START;
+import static javax.security.auth.x500.X500Principal.RFC2253;
+import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
+import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
+import static javax.swing.SwingUtilities.invokeLater;
+
+import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.math.BigInteger;
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+
+import javax.swing.DefaultListModel;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.EtchedBorder;
+
+import org.apache.taverna.security.credentialmanager.CMException;
+import org.apache.taverna.security.credentialmanager.DistinguishedNameParser;
+import org.apache.taverna.security.credentialmanager.ParsedDistinguishedName;
+import org.apache.taverna.workbench.helper.NonBlockedHelpEnabledDialog;
+
+/**
+ * Displays the details of a X.509 certificate.
+ *
+ * Inspired by the Portlecle tool (http://portecle.sourceforge.net/). and the
+ * view certificate dialog from Firefox's Certificate Manager.
+ */
+@SuppressWarnings("serial")
+public class ViewCertDetailsDialog extends NonBlockedHelpEnabledDialog {
+ // Logger
+ //private static Logger logger = Logger.getLogger(ViewCertDetailsDialog.class);
+
+ /** Stores certificate to display*/
+ private X509Certificate cert;
+ /** Stores list of serviceURLs to display*/
+ private ArrayList<String> serviceURLs;
+ private final DistinguishedNameParser dnParser;
+
+ /**
+ * Creates new ViewCertDetailsDialog dialog where the parent is a frame.
+ */
+ public ViewCertDetailsDialog(JFrame parent, String title, boolean modal,
+ X509Certificate crt, ArrayList<String> serviceURLs,
+ DistinguishedNameParser dnParser) throws CMException {
+ super(parent, title, modal);
+ this.cert = crt;
+ this.serviceURLs = serviceURLs;
+ this.dnParser = dnParser;
+ initComponents();
+ }
+
+ /**
+ * Creates new ViewCertDetailsDialog dialog where the parent is a dialog.
+ */
+ public ViewCertDetailsDialog(JDialog parent, String title, boolean modal,
+ X509Certificate crt, ArrayList<String> urlList,
+ DistinguishedNameParser dnParser) throws CMException {
+ super(parent, title, modal);
+ cert = crt;
+ serviceURLs = urlList;
+ this.dnParser = dnParser;
+ initComponents();
+ }
+
+ /**
+ * Initialise the dialog's GUI components.
+ *
+ * @throws CMException
+ * A problem was encountered getting the certificates' details
+ */
+ private void initComponents() throws CMException {
+ // Certificate details:
+
+ // Grid Bag Constraints templates for labels (column 1) and
+ // values (column 2) of certificate details
+ GridBagConstraints gbcLabel = new GridBagConstraints();
+ gbcLabel.gridx = 0;
+ gbcLabel.ipadx = 20;
+ gbcLabel.gridwidth = 1;
+ gbcLabel.gridheight = 1;
+ gbcLabel.insets = new Insets(2, 15, 2, 2);
+ gbcLabel.anchor = LINE_START;
+
+ GridBagConstraints gbcValue = new GridBagConstraints();
+ gbcValue.gridx = 1;
+ gbcValue.gridwidth = 1;
+ gbcValue.gridheight = 1;
+ gbcValue.insets = new Insets(2, 5, 2, 2);
+ gbcValue.anchor = LINE_START;
+
+ /*
+ * Netscape Certificate Type non-critical extension (if any) defines the
+ * intended uses of the certificate - to make it look like firefox's
+ * view certificate dialog. 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."
+ */
+// byte[] intendedUses = cert.getExtensionValue("2.16.840.1.113730.1.1"); //Netscape Certificate Type OID/*
+// JLabel jlIntendedUses = null;
+// JTextField jtfIntendedUsesValue = null;
+// JPanel jpUses = null;
+// GridBagConstraints gbc_jpUses = null;
+// if (intendedUses != null)
+// {
+// jlIntendedUses = new JLabel("This certificate has been approved for the following uses:");
+// jlIntendedUses.setFont(new Font(null, Font.BOLD, 11));
+// jlIntendedUses.setBorder(new EmptyBorder(5,5,5,5));
+//
+// jtfIntendedUsesValue = new JTextField(45);
+// jtfIntendedUsesValue.setText(CMUtils.getIntendedCertificateUses(intendedUses));
+// jtfIntendedUsesValue.setEditable(false);
+// jtfIntendedUsesValue.setFont(new Font(null, Font.PLAIN, 11));
+//
+// jpUses = new JPanel(new BorderLayout());
+// jpUses.add(jlIntendedUses, BorderLayout.NORTH);
+// jpUses.add(jtfIntendedUsesValue, BorderLayout.CENTER);
+// JSeparator jsp = new JSeparator(JSeparator.HORIZONTAL);
+// jpUses.add(jsp, BorderLayout.SOUTH);
+//
+// gbc_jpUses = (GridBagConstraints) gbcLabel.clone();
+// gbc_jpUses.gridy = 0;
+// gbc_jpUses.gridwidth = 2; //takes two columns
+// gbc_jpUses.insets = new Insets(5, 5, 5, 5);//has slightly bigger insets
+//
+// }
+
+ //Issued To
+ JLabel jlIssuedTo = new JLabel("Issued To");
+ jlIssuedTo.setFont(new Font(null, Font.BOLD, 11));
+ GridBagConstraints gbc_jlIssuedTo = (GridBagConstraints) gbcLabel.clone();
+ gbc_jlIssuedTo.gridy = 1;
+ gbc_jlIssuedTo.gridwidth = 2; //takes two columns
+ gbc_jlIssuedTo.insets = new Insets(5, 5, 5, 5);//has slightly bigger insets
+
+ // Distinguished Name (DN)
+ String sDN = cert.getSubjectX500Principal().getName(RFC2253);
+ ParsedDistinguishedName parsedDN = dnParser.parseDN(sDN);
+ // Extract the CN, O, OU and EMAILADDRESS fields
+ String sCN = parsedDN.getCN();
+ String sOrg = parsedDN.getO();
+ String sOU = parsedDN.getOU();
+ //String sEMAILADDRESS = CMX509Util.getEmilAddress();
+
+ // Common Name (CN)
+ JLabel jlCN = new JLabel("Common Name (CN)");
+ jlCN.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlCN = (GridBagConstraints) gbcLabel.clone();
+ gbc_jlCN.gridy = 2;
+ JLabel jlCNValue = new JLabel(sCN);
+ jlCNValue.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlCNValue = (GridBagConstraints) gbcValue.clone();
+ gbc_jlCNValue.gridy = 2;
+
+ // Organisation (O)
+ JLabel jlOrg = new JLabel("Organisation (O)");
+ jlOrg.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlOrg = (GridBagConstraints) gbcLabel.clone();
+ gbc_jlOrg.gridy = 3;
+ JLabel jlOrgValue = new JLabel(sOrg);
+ jlOrgValue.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlOrgValue = (GridBagConstraints) gbcValue.clone();
+ gbc_jlOrgValue.gridy = 3;
+
+ // Organisation Unit (OU)
+ JLabel jlOU = new JLabel("Organisation Unit (OU)");
+ jlOU.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlOU = (GridBagConstraints) gbcLabel.clone();
+ gbc_jlOU.gridy = 4;
+ JLabel jlOUValue = new JLabel(sOU);
+ jlOUValue.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlOUValue = (GridBagConstraints) gbcValue.clone();
+ gbc_jlOUValue.gridy = 4;
+
+ // E-mail Address
+ //JLabel jlEmail = new JLabel("E-mail Address");
+ //jlEmail.setFont(new Font(null, PLAIN, 11));
+ //GridBagConstraints gbc_jlEmail = (GridBagConstraints) gbcLabel.clone();
+ //gbc_jlEmail.gridy = 5;
+ //JLabel jlEmailValue = new JLabel(sEMAILADDRESS);
+ //jlEmailValue.setFont(new Font(null, PLAIN, 11));
+ //GridBagConstraints gbc_jlEmailValue = (GridBagConstraints) gbcValue.clone();
+ //gbc_jlEmailValue.gridy = 5;
+
+ // Serial Number
+ JLabel jlSN = new JLabel("Serial Number");
+ jlSN.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlSN = (GridBagConstraints) gbcLabel.clone();
+ gbc_jlSN.gridy = 6;
+ JLabel jlSNValue = new JLabel();
+ // Get the hexadecimal serial number
+ StringBuilder strBuff = new StringBuilder(new BigInteger(1,
+ cert.getSerialNumber().toByteArray()).toString(16).toUpperCase());
+ // Place colons at every two hexadecimal characters
+ if (strBuff.length() > 2)
+ for (int iCnt = 2; iCnt < strBuff.length(); iCnt += 3)
+ strBuff.insert(iCnt, ':');
+ jlSNValue.setText(strBuff.toString());
+ jlSNValue.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlSNValue = (GridBagConstraints) gbcValue.clone();
+ gbc_jlSNValue.gridy = 6;
+
+ // Version
+ JLabel jlVersion = new JLabel("Version");
+ jlVersion.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlVersion = (GridBagConstraints) gbcLabel.clone();
+ gbc_jlVersion.gridy = 7;
+ JLabel jlVersionValue = new JLabel(Integer.toString(cert.getVersion()));
+ jlVersionValue.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlVersionValue = (GridBagConstraints) gbcValue.clone();
+ gbc_jlVersionValue.gridy = 7;
+
+ // Issued By
+ JLabel jlIssuedBy = new JLabel("Issued By");
+ jlIssuedBy.setFont(new Font(null, BOLD, 11));
+ GridBagConstraints gbc_jlIssuedBy = (GridBagConstraints) gbcLabel.clone();
+ gbc_jlIssuedBy.gridy = 8;
+ gbc_jlIssuedBy.gridwidth = 2; //takes two columns
+ gbc_jlIssuedBy.insets = new Insets(5, 5, 5, 5);//has slightly bigger insets
+
+ // Distinguished Name (DN)
+ String iDN = cert.getIssuerX500Principal().getName(RFC2253);
+ parsedDN = dnParser.parseDN(iDN);
+ // Extract the CN, O and OU fields
+ String iCN = parsedDN.getCN();
+ String iOrg = parsedDN.getO();
+ String iOU = parsedDN.getOU();
+
+ // Common Name (CN)
+ JLabel jlICN = new JLabel("Common Name (CN)");
+ jlICN.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlICN = (GridBagConstraints) gbcLabel.clone();
+ gbc_jlICN.gridy = 9;
+ JLabel jlICNValue = new JLabel(iCN);
+ jlICNValue.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlICNValue = (GridBagConstraints) gbcValue
+ .clone();
+ gbc_jlICNValue.gridy = 9;
+
+ // Organisation (O)
+ JLabel jlIOrg = new JLabel("Organisation (O)");
+ jlIOrg.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlIOrg = (GridBagConstraints) gbcLabel.clone();
+ gbc_jlIOrg.gridy = 10;
+ JLabel jlIOrgValue = new JLabel(iOrg);
+ jlIOrgValue.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlIOrgValue = (GridBagConstraints) gbcValue
+ .clone();
+ gbc_jlIOrgValue.gridy = 10;
+
+ // Organisation Unit (OU)
+ JLabel jlIOU = new JLabel("Organisation Unit (OU)");
+ jlIOU.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlIOU = (GridBagConstraints) gbcLabel.clone();
+ gbc_jlIOU.gridy = 11;
+ JLabel jlIOUValue = new JLabel(iOU);
+ jlIOUValue.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlIOUValue = (GridBagConstraints) gbcValue
+ .clone();
+ gbc_jlIOUValue.gridy = 11;
+
+ // Validity
+ JLabel jlValidity = new JLabel("Validity");
+ jlValidity.setFont(new Font(null, BOLD, 11));
+ GridBagConstraints gbc_jlValidity = (GridBagConstraints) gbcLabel
+ .clone();
+ gbc_jlValidity.gridy = 12;
+ gbc_jlValidity.gridwidth = 2; // takes two columns
+ gbc_jlValidity.insets = new Insets(5, 5, 5, 5);// has slightly bigger insets
+
+ // Issued On
+ JLabel jlIssuedOn = new JLabel("Issued On");
+ jlIssuedOn.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlIssuedOn = (GridBagConstraints) gbcLabel
+ .clone();
+ gbc_jlIssuedOn.gridy = 13;
+ JLabel jlIssuedOnValue = new JLabel(cert.getNotBefore().toString());
+ jlIssuedOnValue.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlIssuedOnValue = (GridBagConstraints) gbcValue
+ .clone();
+ gbc_jlIssuedOnValue.gridy = 13;
+
+ // Expires On
+ JLabel jlExpiresOn = new JLabel("Expires On");
+ jlExpiresOn.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlExpiresOn = (GridBagConstraints) gbcLabel
+ .clone();
+ gbc_jlExpiresOn.gridy = 14;
+ JLabel jlExpiresOnValue = new JLabel(cert.getNotAfter().toString());
+ jlExpiresOnValue.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlExpiresOnValue = (GridBagConstraints) gbcValue
+ .clone();
+ gbc_jlExpiresOnValue.gridy = 14;
+
+ // Fingerprints
+ byte[] certBinaryEncoding;
+ try {
+ certBinaryEncoding = cert.getEncoded();
+ } catch (CertificateEncodingException ex) {
+ throw new CMException(
+ "Could not get the encoded form of the certificate.", ex);
+ }
+ JLabel jlFingerprints = new JLabel("Fingerprints");
+ jlFingerprints.setFont(new Font(null, BOLD, 11));
+ GridBagConstraints gbc_jlFingerprints = (GridBagConstraints) gbcLabel.clone();
+ gbc_jlFingerprints.gridy = 15;
+ gbc_jlFingerprints.gridwidth = 2; //takes two columns
+ gbc_jlFingerprints.insets = new Insets(5, 5, 5, 5);//has slightly bigger insets
+
+ // SHA-1 Fingerprint
+ JLabel jlSHA1Fingerprint = new JLabel("SHA1 Fingerprint");
+ jlSHA1Fingerprint.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlSHA1Fingerprint = (GridBagConstraints) gbcLabel.clone();
+ gbc_jlSHA1Fingerprint.gridy = 16;
+ JLabel jlSHA1FingerprintValue = new JLabel(dnParser.getMessageDigestAsFormattedString(certBinaryEncoding, "SHA1"));
+ jlSHA1FingerprintValue.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlSHA1FingerprintValue = (GridBagConstraints) gbcValue.clone();
+ gbc_jlSHA1FingerprintValue.gridy = 16;
+
+ // MD5 Fingerprint
+ JLabel jlMD5Fingerprint = new JLabel("MD5 Fingerprint");
+ jlMD5Fingerprint.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlMD5Fingerprint = (GridBagConstraints) gbcLabel.clone();
+ gbc_jlMD5Fingerprint.gridy = 17;
+ JLabel jlMD5FingerprintValue = new JLabel(dnParser.getMessageDigestAsFormattedString(certBinaryEncoding, "MD5"));
+ jlMD5FingerprintValue.setFont(new Font(null, PLAIN, 11));
+ GridBagConstraints gbc_jlMD5FingerprintValue = (GridBagConstraints) gbcValue.clone();
+ gbc_jlMD5FingerprintValue.gridy = 17;
+
+ /*
+ * Empty label to add a bit space at the bottom of the panel to make it
+ * look like firefox's view certificate dialog
+ */
+ JLabel jlEmpty = new JLabel("");
+ GridBagConstraints gbc_jlEmpty = (GridBagConstraints) gbcLabel.clone();
+ gbc_jlEmpty.gridy = 18;
+ gbc_jlEmpty.gridwidth = 2; // takes two columns
+ gbc_jlEmpty.ipady = 40;
+
+ JPanel jpCertificate = new JPanel(new GridBagLayout());
+ jpCertificate.setBorder(new CompoundBorder(new EmptyBorder(15, 15, 15,
+ 15), new EtchedBorder()));
+
+// if (intendedUses != null){
+// jpCertificate.add(jpUses, gbc_jpUses);
+// }
+ jpCertificate.add(jlIssuedTo, gbc_jlIssuedTo); // Issued To
+ jpCertificate.add(jlCN, gbc_jlCN);
+ jpCertificate.add(jlCNValue, gbc_jlCNValue);
+ jpCertificate.add(jlOrg, gbc_jlOrg);
+ jpCertificate.add(jlOrgValue, gbc_jlOrgValue);
+ jpCertificate.add(jlOU, gbc_jlOU);
+ jpCertificate.add(jlOUValue, gbc_jlOUValue);
+ //jpCertificate.add(jlEmail, gbc_jlEmail);
+ //jpCertificate.add(jlEmailValue, gbc_jlEmailValue);
+ jpCertificate.add(jlSN, gbc_jlSN);
+ jpCertificate.add(jlSNValue, gbc_jlSNValue);
+ jpCertificate.add(jlVersion, gbc_jlVersion);
+ jpCertificate.add(jlVersionValue, gbc_jlVersionValue);
+ jpCertificate.add(jlIssuedBy, gbc_jlIssuedBy); //Issued By
+ jpCertificate.add(jlICN, gbc_jlICN);
+ jpCertificate.add(jlICNValue, gbc_jlICNValue);
+ jpCertificate.add(jlIOrg, gbc_jlIOrg);
+ jpCertificate.add(jlIOrgValue, gbc_jlIOrgValue);
+ jpCertificate.add(jlIOU, gbc_jlIOU);
+ jpCertificate.add(jlIOUValue, gbc_jlIOUValue);
+ jpCertificate.add(jlValidity, gbc_jlValidity); //Validity
+ jpCertificate.add(jlIssuedOn, gbc_jlIssuedOn);
+ jpCertificate.add(jlIssuedOnValue, gbc_jlIssuedOnValue);
+ jpCertificate.add(jlExpiresOn, gbc_jlExpiresOn);
+ jpCertificate.add(jlExpiresOnValue, gbc_jlExpiresOnValue);
+ jpCertificate.add(jlFingerprints, gbc_jlFingerprints); //Fingerprints
+ jpCertificate.add(jlSHA1Fingerprint, gbc_jlSHA1Fingerprint);
+ jpCertificate.add(jlSHA1FingerprintValue, gbc_jlSHA1FingerprintValue);
+ jpCertificate.add(jlMD5Fingerprint, gbc_jlMD5Fingerprint);
+ jpCertificate.add(jlMD5FingerprintValue, gbc_jlMD5FingerprintValue);
+ jpCertificate.add(jlEmpty, gbc_jlEmpty); //Empty label to get some vertical space on the frame
+
+ // List of serviceURLs
+ JPanel jpURLs = null; // Panel to hold the URL list
+ if (serviceURLs != null) { //if service serviceURLs are not null (even if empty - show empty list)
+
+ jpURLs = new JPanel(new BorderLayout());
+ jpURLs.setBorder(new CompoundBorder(
+ new EmptyBorder(0, 15, 0, 15), new EtchedBorder()));
+ // Label
+ JLabel jlServiceURLs = new JLabel ("Service URLs this key pair will be used for:");
+ jlServiceURLs.setFont(new Font(null, Font.BOLD, 11));
+ jlServiceURLs.setBorder(new EmptyBorder(5,5,5,5));
+
+ // New empty service serviceURLs list
+ DefaultListModel<String> jltModel = new DefaultListModel<>();
+ JList<String> jltServiceURLs = new JList<>(jltModel);
+ for (String url : serviceURLs)
+ jltModel.addElement(url);
+ // don't show more than 5 otherwise the window is too big
+ jltServiceURLs.setVisibleRowCount(5);
+
+ // Scroll pane for service serviceURLs
+ JScrollPane jspServiceURLs = new JScrollPane(jltServiceURLs,
+ VERTICAL_SCROLLBAR_AS_NEEDED,
+ HORIZONTAL_SCROLLBAR_AS_NEEDED);
+ jspServiceURLs.getViewport().setBackground(
+ jltServiceURLs.getBackground());
+
+ jpURLs.add(jlServiceURLs, NORTH);
+ jpURLs.add(jspServiceURLs, CENTER);
+
+ // Put it on the main content pane
+ getContentPane().add(jpURLs, CENTER);
+ }
+
+ // OK button
+ JPanel jpOK = new JPanel(new FlowLayout(FlowLayout.CENTER));
+
+ final JButton jbOK = new JButton("OK");
+ jbOK.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ okPressed();
+ }
+ });
+
+ jpOK.add(jbOK);
+
+ /*
+ * Put it all together (panel with URL list is already added, if it was
+ * not null)
+ */
+ getContentPane().add(jpCertificate, NORTH);
+ getContentPane().add(jpOK, SOUTH);
+
+ // Resizing wreaks havoc
+ setResizable(false);
+
+ addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent evt) {
+ closeDialog();
+ }
+ });
+
+ getRootPane().setDefaultButton(jbOK);
+
+ pack();
+
+ invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ jbOK.requestFocus();
+ }
+ });
+ }
+
+ private void okPressed() {
+ closeDialog();
+ }
+
+ private void closeDialog() {
+ setVisible(false);
+ dispose();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/ViewUsernamePasswordEntryDialog.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/ViewUsernamePasswordEntryDialog.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/ViewUsernamePasswordEntryDialog.java
new file mode 100644
index 0000000..a9f1847
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/ViewUsernamePasswordEntryDialog.java
@@ -0,0 +1,198 @@
+/*
+* 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.workbench.ui.credentialmanager;
+
+import static java.awt.BorderLayout.CENTER;
+import static java.awt.BorderLayout.SOUTH;
+import static java.awt.GridBagConstraints.HORIZONTAL;
+import static java.awt.GridBagConstraints.NONE;
+import static java.awt.GridBagConstraints.WEST;
+
+import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.EtchedBorder;
+
+import org.apache.taverna.workbench.helper.NonBlockedHelpEnabledDialog;
+
+/**
+ * Dialog used for viewing service URL, username and password.
+ *
+ * @author Alex Nenadic
+ */
+@SuppressWarnings("serial")
+public class ViewUsernamePasswordEntryDialog extends
+ NonBlockedHelpEnabledDialog {
+ /** Service URL field */
+ private JTextField serviceURLField;
+ /** Username field */
+ private JTextField usernameField;
+ /** Password field */
+ private JTextField passwordField;
+ /** Service URL value */
+ private String serviceURL;
+ /** Service username value */
+ private String username;
+ /** Service password value */
+ private String password;
+
+ public ViewUsernamePasswordEntryDialog(JFrame parent, String currentURL,
+ String currentUsername, String currentPassword) {
+ super(parent, "View username and password for a service", true);
+ serviceURL = currentURL;
+ username = currentUsername;
+ password = currentPassword;
+ initComponents();
+ }
+
+ public ViewUsernamePasswordEntryDialog(JDialog parent, String currentURL,
+ String currentUsername, String currentPassword) {
+ super(parent, "View username and password for a service", true);
+ serviceURL = currentURL;
+ username = currentUsername;
+ password = currentPassword;
+ initComponents();
+ }
+
+ private void initComponents() {
+ getContentPane().setLayout(new BorderLayout());
+
+ JLabel serviceURLLabel = new JLabel("Service URL");
+ serviceURLLabel.setBorder(new EmptyBorder(0, 5, 0, 0));
+ JLabel usernameLabel = new JLabel("Username");
+ usernameLabel.setBorder(new EmptyBorder(0, 5, 0, 0));
+ JLabel passwordLabel = new JLabel("Password");
+ passwordLabel.setBorder(new EmptyBorder(0, 5, 0, 0));
+
+ // Populate the fields with values and disable user input
+ serviceURLField = new JTextField();
+ serviceURLField.setText(serviceURL);
+ serviceURLField.setEditable(false);
+
+ usernameField = new JTextField(15);
+ usernameField.setText(username);
+ usernameField.setEditable(false);
+
+ passwordField = new JTextField(15);
+ passwordField.setText(password);
+ passwordField.setEditable(false);
+
+ JButton okButton = new JButton("OK");
+ okButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ closeDialog();
+ }
+ });
+
+ JPanel fieldsPanel = new JPanel(new GridBagLayout());
+
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.weighty = 0.0;
+
+ gbc.weightx = 0.0;
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.fill = NONE;
+ gbc.anchor = WEST;
+ gbc.insets = new Insets(5, 10, 0, 0);
+ fieldsPanel.add(serviceURLLabel, gbc);
+
+ gbc.weightx = 1.0;
+ gbc.gridx = 1;
+ gbc.gridy = 0;
+ gbc.fill = HORIZONTAL;
+ gbc.anchor = WEST;
+ gbc.insets = new Insets(5, 10, 0, 5);
+ fieldsPanel.add(serviceURLField, gbc);
+
+ gbc.weightx = 0.0;
+ gbc.gridx = 0;
+ gbc.gridy = 1;
+ gbc.fill = NONE;
+ gbc.anchor = WEST;
+ gbc.insets = new Insets(5, 10, 0, 0);
+ fieldsPanel.add(usernameLabel, gbc);
+
+ gbc.weightx = 1.0;
+ gbc.gridx = 1;
+ gbc.gridy = 1;
+ gbc.fill = HORIZONTAL;
+ gbc.anchor = WEST;
+ gbc.insets = new Insets(5, 10, 0, 5);
+ fieldsPanel.add(usernameField, gbc);
+
+ gbc.weightx = 0.0;
+ gbc.gridx = 0;
+ gbc.gridy = 2;
+ gbc.fill = NONE;
+ gbc.anchor = WEST;
+ gbc.insets = new Insets(5, 10, 0, 0);
+ fieldsPanel.add(passwordLabel, gbc);
+
+ gbc.weightx = 1.0;
+ gbc.gridx = 1;
+ gbc.gridy = 2;
+ gbc.fill = HORIZONTAL;
+ gbc.anchor = WEST;
+ gbc.insets = new Insets(5, 10, 0, 5);
+ fieldsPanel.add(passwordField, gbc);
+
+ fieldsPanel.setBorder(new CompoundBorder(
+ new EmptyBorder(10, 10, 10, 10), new EtchedBorder()));
+
+ JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
+ buttonsPanel.add(okButton);
+
+ getContentPane().add(fieldsPanel, CENTER);
+ getContentPane().add(buttonsPanel, SOUTH);
+
+ addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent evt) {
+ closeDialog();
+ }
+ });
+
+ // setResizable(false);
+ getRootPane().setDefaultButton(okButton);
+ pack();
+ }
+
+ private void closeDialog() {
+ setVisible(false);
+ dispose();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/WarnUserAboutJCEPolicyDialog.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/WarnUserAboutJCEPolicyDialog.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/WarnUserAboutJCEPolicyDialog.java
new file mode 100644
index 0000000..1bdf288
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/WarnUserAboutJCEPolicyDialog.java
@@ -0,0 +1,222 @@
+/*
+* 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.workbench.ui.credentialmanager;
+
+import static java.awt.BorderLayout.CENTER;
+import static java.awt.BorderLayout.SOUTH;
+import static java.awt.Desktop.getDesktop;
+import static javax.swing.border.EtchedBorder.LOWERED;
+import static javax.swing.event.HyperlinkEvent.EventType.ACTIVATED;
+import static org.apache.commons.io.FileUtils.touch;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.GraphicsEnvironment;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.IOException;
+
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JEditorPane;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.EtchedBorder;
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.event.HyperlinkListener;
+import javax.swing.text.Document;
+import javax.swing.text.html.HTMLEditorKit;
+import javax.swing.text.html.StyleSheet;
+
+import org.apache.taverna.security.credentialmanager.DistinguishedNameParser;
+import org.apache.taverna.workbench.helper.NonBlockedHelpEnabledDialog;
+
+import org.apache.log4j.Logger;
+
+import uk.org.taverna.configuration.app.ApplicationConfiguration;
+
+/**
+ * Dialog that warns user that they need to install unlimited cryptography
+ * strength policy for Java.
+ *
+ * @author Alex Nenadic
+ */
+@SuppressWarnings("serial")
+public class WarnUserAboutJCEPolicyDialog extends NonBlockedHelpEnabledDialog {
+ private static final Logger logger = Logger
+ .getLogger(WarnUserAboutJCEPolicyDialog.class);
+
+ private JCheckBox doNotWarnMeAgainCheckBox;
+ private final ApplicationConfiguration applicationConfiguration;
+ private final DistinguishedNameParser dnParser;
+
+ public WarnUserAboutJCEPolicyDialog(
+ ApplicationConfiguration applicationConfiguration,
+ DistinguishedNameParser dnParser) {
+ super((Frame) null,
+ "Java Unlimited Strength Cryptography Policy Warning", true);
+ this.applicationConfiguration = applicationConfiguration;
+ this.dnParser = dnParser;
+ initComponents();
+ }
+
+ // For testing
+ public static void main(String[] args) {
+ WarnUserAboutJCEPolicyDialog dialog = new WarnUserAboutJCEPolicyDialog(
+ null, null);
+ dialog.setVisible(true);
+ }
+
+ private void initComponents() {
+ // Base font for all components on the form
+ Font baseFont = new JLabel("base font").getFont().deriveFont(11f);
+
+ // Message saying that updates are available
+ JPanel messagePanel = new JPanel(new BorderLayout());
+ messagePanel.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10,
+ 10), new EtchedBorder(LOWERED)));
+
+ JEditorPane message = new JEditorPane();
+ message.setEditable(false);
+ message.setBackground(this.getBackground());
+ message.setFocusable(false);
+ HTMLEditorKit kit = new HTMLEditorKit();
+ message.setEditorKit(kit);
+ StyleSheet styleSheet = kit.getStyleSheet();
+ //styleSheet.addRule("body {font-family:"+baseFont.getFamily()+"; font-size:"+baseFont.getSize()+";}"); // base font looks bigger when rendered as HTML
+ styleSheet.addRule("body {font-family:" + baseFont.getFamily()
+ + "; font-size:10px;}");
+ Document doc = kit.createDefaultDocument();
+ message.setDocument(doc);
+ message.setText("<html><body>In order for Taverna's security features to function properly - you need to install<br>"
+ + "'Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy'. <br><br>"
+ + "If you do not already have it, for <b>Java 6</b> you can get it from:<br>"
+ + "<a href=\"http://www.oracle.com/technetwork/java/javase/downloads/index.html\">http://www.oracle.com/technetwork/java/javase/downloads/index.html</a><br<br>"
+ + "Installation instructions are contained in the bundle you download."
+ + "</body><html>");
+ message.addHyperlinkListener(new HyperlinkListener() {
+ @Override
+ public void hyperlinkUpdate(HyperlinkEvent he) {
+ HyperlinkEvent.EventType type = he.getEventType();
+ if (type == ACTIVATED)
+ // Open a Web browser
+ try {
+ getDesktop().browse(he.getURL().toURI());
+// BrowserLauncher launcher = new BrowserLauncher();
+// launcher.openURLinBrowser(he.getURL().toString());
+ } catch (Exception ex) {
+ logger.error("Failed to launch browser to fetch JCE "
+ + he.getURL());
+ }
+ }
+ });
+ message.setBorder(new EmptyBorder(5, 5, 5, 5));
+ messagePanel.add(message, CENTER);
+
+ doNotWarnMeAgainCheckBox = new JCheckBox("Do not warn me again");
+ doNotWarnMeAgainCheckBox.setFont(baseFont.deriveFont(12f));
+ messagePanel.add(doNotWarnMeAgainCheckBox, SOUTH);
+
+ // Buttons
+ JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
+ JButton okButton = new JButton("OK");
+ okButton.setFont(baseFont);
+ okButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ okPressed();
+ }
+ });
+
+ buttonsPanel.add(okButton);
+
+ getContentPane().setLayout(new BorderLayout());
+ getContentPane().add(messagePanel, CENTER);
+ getContentPane().add(buttonsPanel, SOUTH);
+
+ pack();
+ setResizable(false);
+ // Center the dialog on the screen (we do not have the parent)
+ Dimension dimension = getToolkit().getScreenSize();
+ Rectangle abounds = getBounds();
+ setLocation((dimension.width - abounds.width) / 2,
+ (dimension.height - abounds.height) / 2);
+ setSize(getPreferredSize());
+ }
+
+ private static final String DO_NOT_WARN_ABOUT_JCE_POLICY = "do_not_warn_about_JCE_policy";
+ public static boolean warnedUser = false; // have we already warned user for
+ // this run
+
+ /**
+ * Warn user that they need to install Java Cryptography Extension (JCE)
+ * Unlimited Strength Jurisdiction Policy if they want Credential Manager to
+ * function properly.
+ */
+ public static void warnUserAboutJCEPolicy(
+ ApplicationConfiguration applicationConfiguration,
+ DistinguishedNameParser dnParser) {
+ /*
+ * Do not pop up a dialog if we are running headlessly. If we have
+ * warned the user and they do not want us to remind them again - exit.
+ */
+ if (warnedUser || GraphicsEnvironment.isHeadless()
+ || doNotWarnFile(applicationConfiguration, dnParser).exists())
+ return;
+
+ WarnUserAboutJCEPolicyDialog warnDialog = new WarnUserAboutJCEPolicyDialog(
+ applicationConfiguration, dnParser);
+ warnDialog.setVisible(true);
+ warnedUser = true;
+ }
+
+ private static File doNotWarnFile(
+ ApplicationConfiguration applicationConfiguration,
+ DistinguishedNameParser dnParser) {
+ return new File(
+ dnParser.getCredentialManagerDefaultDirectory(applicationConfiguration),
+ DO_NOT_WARN_ABOUT_JCE_POLICY);
+ }
+
+ protected void okPressed() {
+ try {
+ if (doNotWarnMeAgainCheckBox.isSelected())
+ touch(doNotWarnFile(applicationConfiguration, dnParser));
+ } catch (IOException e) {
+ logger.error(
+ "Failed to touch the 'Do not want me about JCE unilimited security policy' file.",
+ e);
+ }
+ closeDialog();
+ }
+
+ private void closeDialog() {
+ setVisible(false);
+ dispose();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/action/CredentialManagerAction.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/action/CredentialManagerAction.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/action/CredentialManagerAction.java
new file mode 100644
index 0000000..038f69a
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/action/CredentialManagerAction.java
@@ -0,0 +1,67 @@
+/*
+* 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.workbench.ui.credentialmanager.action;
+
+import static javax.swing.SwingUtilities.invokeLater;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.ImageIcon;
+
+import org.apache.taverna.security.credentialmanager.CredentialManager;
+import org.apache.taverna.security.credentialmanager.DistinguishedNameParser;
+import org.apache.taverna.workbench.ui.credentialmanager.CredentialManagerUI;
+
+//import javax.swing.SwingUtilities;
+
+@SuppressWarnings("serial")
+public class CredentialManagerAction extends AbstractAction {
+ private static ImageIcon ICON = new ImageIcon(
+ CredentialManagerAction.class
+ .getResource("/images/cred_manager16x16.png"));
+
+ private CredentialManagerUI cmUI;
+ private final CredentialManager credentialManager;
+ private final DistinguishedNameParser dnParser;
+
+ public CredentialManagerAction(CredentialManager credentialManager,
+ DistinguishedNameParser dnParser) {
+ super("Credential Manager", ICON);
+ this.credentialManager = credentialManager;
+ this.dnParser = dnParser;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (cmUI != null) {
+ cmUI.setVisible(true);
+ return;
+ }
+
+ invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ cmUI = new CredentialManagerUI(credentialManager, dnParser);
+ cmUI.setVisible(true);
+ }
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/menu/CredentialManagerMenu.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/menu/CredentialManagerMenu.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/menu/CredentialManagerMenu.java
new file mode 100644
index 0000000..eb6cd88
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/menu/CredentialManagerMenu.java
@@ -0,0 +1,69 @@
+/*
+* 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.workbench.ui.credentialmanager.menu;
+
+import java.net.URI;
+
+import javax.swing.Action;
+
+//import org.apache.log4j.Logger;
+
+import org.apache.taverna.security.credentialmanager.CredentialManager;
+import org.apache.taverna.security.credentialmanager.DistinguishedNameParser;
+import org.apache.taverna.ui.menu.AbstractMenuAction;
+import org.apache.taverna.workbench.ui.credentialmanager.action.CredentialManagerAction;
+
+public class CredentialManagerMenu extends AbstractMenuAction {
+ private static final String MENU_URI = "http://taverna.sf.net/2008/t2workbench/menu#advanced";
+
+ private CredentialManager credentialManager;
+ private DistinguishedNameParser dnParser;
+
+ // private static Logger logger = Logger.getLogger(CredentialManagerMenu.class);
+
+ public CredentialManagerMenu() {
+ super(URI.create(MENU_URI), 60);
+ /* This is now done in the initialise SSL startup hook - no need to do it here.
+ // Force initialisation at startup
+ try {
+ CredentialManager.getInstance();
+ } catch (CMException e) {
+ logger.error("Could not initialise SSL properties for SSL connections from Taverna.", e);
+ }
+ */
+ }
+
+ @Override
+ protected Action createAction() {
+ return new CredentialManagerAction(credentialManager, dnParser);
+ }
+
+ public void setCredentialManager(CredentialManager credentialManager) {
+ this.credentialManager = credentialManager;
+ }
+
+ /**
+ * @param dnParser
+ * the dnParser to set
+ */
+ public void setDistinguishedNameParser(DistinguishedNameParser dnParser) {
+ this.dnParser = dnParser;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserJavaTruststorePasswordProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserJavaTruststorePasswordProvider.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserJavaTruststorePasswordProvider.java
new file mode 100644
index 0000000..4d0cc03
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserJavaTruststorePasswordProvider.java
@@ -0,0 +1,45 @@
+/*
+* 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.workbench.ui.credentialmanager.password;
+
+import org.apache.taverna.security.credentialmanager.JavaTruststorePasswordProvider;
+
+/**
+ * An implementation of the {@link JavaTruststorePasswordProvider} that pops up a
+ * dialog and asks the user to provide the password.
+ *
+ * @author Alex Nenadic
+ *
+ */
+public class AskUserJavaTruststorePasswordProvider implements JavaTruststorePasswordProvider{
+
+ @Override
+ public String getJavaTruststorePassword() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setJavaTruststorePassword(String password) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserMasterPasswordProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserMasterPasswordProvider.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserMasterPasswordProvider.java
new file mode 100644
index 0000000..fc62f51
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserMasterPasswordProvider.java
@@ -0,0 +1,54 @@
+/*
+* 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.workbench.ui.credentialmanager.password;
+
+import org.apache.taverna.security.credentialmanager.MasterPasswordProvider;
+
+public class AskUserMasterPasswordProvider implements MasterPasswordProvider{
+
+// @Override
+// public boolean canProvideMasterPassword() {
+// // TODO Auto-generated method stub
+// return false;
+// }
+ private int priority = 100;
+
+ @Override
+ public String getMasterPassword(boolean firstTime) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int getProviderPriority() {
+ return priority;
+ }
+
+ @Override
+ public void setMasterPassword(String password) {
+ // TODO Auto-generated method stub
+ }
+
+// @Override
+// public void setProviderPriority(int priority) {
+// this.priority = priority;
+// }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserServiceUsernameAndPasswordProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserServiceUsernameAndPasswordProvider.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserServiceUsernameAndPasswordProvider.java
new file mode 100644
index 0000000..4c6f046
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserServiceUsernameAndPasswordProvider.java
@@ -0,0 +1,42 @@
+/*
+* 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.workbench.ui.credentialmanager.password;
+
+import java.net.URI;
+
+import org.apache.taverna.security.credentialmanager.ServiceUsernameAndPasswordProvider;
+import org.apache.taverna.security.credentialmanager.UsernamePassword;
+
+public class AskUserServiceUsernameAndPasswordProvider implements ServiceUsernameAndPasswordProvider{
+
+ @Override
+ public UsernamePassword getServiceUsernameAndPassword(URI serviceURI, String requestMessage) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setServiceUsernameAndPassword(URI serviceURI,
+ UsernamePassword usernamePassword) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserTrustConfirmationProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserTrustConfirmationProvider.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserTrustConfirmationProvider.java
new file mode 100644
index 0000000..8523207
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/AskUserTrustConfirmationProvider.java
@@ -0,0 +1,34 @@
+/*
+* 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.workbench.ui.credentialmanager.password;
+
+import java.security.cert.X509Certificate;
+
+import org.apache.taverna.security.credentialmanager.TrustConfirmationProvider;
+
+public class AskUserTrustConfirmationProvider implements TrustConfirmationProvider {
+
+ @Override
+ public Boolean shouldTrustCertificate(X509Certificate[] chain) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/GetPasswordDialog.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/GetPasswordDialog.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/GetPasswordDialog.java
new file mode 100644
index 0000000..74b1446
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/GetPasswordDialog.java
@@ -0,0 +1,227 @@
+/*
+* 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.workbench.ui.credentialmanager.password;
+
+import static java.awt.BorderLayout.CENTER;
+import static java.awt.BorderLayout.NORTH;
+import static java.awt.BorderLayout.SOUTH;
+import static java.awt.FlowLayout.LEFT;
+import static java.awt.FlowLayout.RIGHT;
+import static javax.swing.JOptionPane.WARNING_MESSAGE;
+import static javax.swing.JOptionPane.showMessageDialog;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JPasswordField;
+import javax.swing.JTextField;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.EtchedBorder;
+
+import org.apache.taverna.workbench.helper.NonBlockedHelpEnabledDialog;
+
+/**
+ * Dialog for entering user's username and password.
+ *
+ * @author Alex Nenadic
+ */
+@SuppressWarnings("serial")
+public class GetPasswordDialog extends NonBlockedHelpEnabledDialog {
+ /**
+ * Whether we should ask user to save their username and password using
+ * Credential Manager
+ */
+ private boolean shouldAskUserToSave;
+ /** Username field */
+ private JTextField usernameField;
+ /** Password field */
+ private JPasswordField passwordField;
+ /**
+ * Whether user wished to save the username and password using Credential
+ * Manager
+ */
+ private JCheckBox saveCheckBox;
+ /** The entered username */
+ private String username;
+ /** The entered password */
+ private String password;
+ /** Instructions to the user */
+ private String instructions;
+
+ public GetPasswordDialog(String instructions, boolean shouldAskUserToSave) {
+ super((Frame) null, "Enter username and password", true);
+ this.instructions = instructions;
+ this.shouldAskUserToSave = shouldAskUserToSave;
+ initComponents();
+ }
+
+ private void initComponents() {
+ getContentPane().setLayout(new BorderLayout());
+
+ JLabel instructionsLabel = new JLabel(instructions);
+ instructionsLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
+ JPanel jpInstructions = new JPanel(new FlowLayout(LEFT));
+ jpInstructions.add(instructionsLabel);
+
+ JLabel usernameLabel = new JLabel("Username");
+ usernameLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
+ JLabel passwordLabel = new JLabel("Password");
+ passwordLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
+
+ usernameField = new JTextField(15);
+ passwordField = new JPasswordField(15);
+
+ JButton okButton = new JButton("OK");
+ okButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ okPressed();
+ }
+ });
+
+ JButton cancelButton = new JButton("Cancel");
+ cancelButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ cancelPressed();
+ }
+ });
+
+ // Central panel with username/password fields and a "Do you want to Save?" checkbox
+ JPanel mainPanel = new JPanel(new BorderLayout());
+
+ JPanel passwordPanel = new JPanel(new GridLayout(2, 2, 5, 5));
+ passwordPanel.add(usernameLabel);
+ passwordPanel.add(usernameField);
+ passwordPanel.add(passwordLabel);
+ passwordPanel.add(passwordField);
+ mainPanel.add(passwordPanel, CENTER);
+
+ // If user wants to save this username and password
+ saveCheckBox = new JCheckBox();
+ saveCheckBox.setBorder(new EmptyBorder(5, 5, 5, 5));
+ saveCheckBox.setSelected(true);
+ saveCheckBox
+ .setText("Use Credential Manager to save this username and password");
+ if (shouldAskUserToSave) {
+ JPanel jpSaveCheckBox = new JPanel(new FlowLayout(LEFT));
+ jpSaveCheckBox.add(saveCheckBox);
+ mainPanel.add(jpSaveCheckBox, SOUTH);
+ }
+
+ passwordPanel.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10,
+ 10), new EtchedBorder()));
+
+ JPanel buttonsPanel = new JPanel(new FlowLayout(RIGHT));
+ buttonsPanel.add(okButton);
+ buttonsPanel.add(cancelButton);
+
+ passwordPanel.setMinimumSize(new Dimension(300, 100));
+
+ getContentPane().add(jpInstructions, NORTH);
+ getContentPane().add(mainPanel, CENTER);
+ getContentPane().add(buttonsPanel, SOUTH);
+
+ addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent evt) {
+ closeDialog();
+ }
+ });
+
+ setResizable(false);
+ getRootPane().setDefaultButton(okButton);
+ pack();
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * Check if user wishes to save username and pasword using the Credential
+ * Manager.
+ */
+ public boolean shouldSaveUsernameAndPassword() {
+ return saveCheckBox.isSelected();
+ }
+
+ private boolean checkControls() {
+ username = usernameField.getText();
+ if (username.length() == 0) {
+ showMessageDialog(this, "Username cannot be empty", "Warning",
+ WARNING_MESSAGE);
+ return false;
+ }
+
+ password = new String(passwordField.getPassword());
+ if (password.length() == 0) { // password empty
+ showMessageDialog(this, "Password cannot be empty", "Warning",
+ WARNING_MESSAGE);
+
+ return false;
+ }
+
+ return true;
+ }
+
+ private void okPressed() {
+ if (checkControls())
+ closeDialog();
+ }
+
+ private void cancelPressed() {
+ // Set all fields to null to indicate that cancel button was pressed
+ username = null;
+ password = null;
+ closeDialog();
+ }
+
+ private void closeDialog() {
+ setVisible(false);
+ dispose();
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ usernameField.setText(username);
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ passwordField.setText(password);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/SimpleMasterPasswordProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/SimpleMasterPasswordProvider.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/SimpleMasterPasswordProvider.java
new file mode 100644
index 0000000..0b04984
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/SimpleMasterPasswordProvider.java
@@ -0,0 +1,53 @@
+/*
+* 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.workbench.ui.credentialmanager.password;
+
+import org.apache.taverna.security.credentialmanager.MasterPasswordProvider;
+
+/**
+ * A simple implementation of {@link MasterPasswordProvider} that just provides
+ * a master password that can be obtained and set from outside the provider.
+ *
+ * @author Alex Nenadic
+ */
+public class SimpleMasterPasswordProvider implements MasterPasswordProvider {
+ private String masterPassword;
+ private int priority = 200;
+
+ @Override
+ public String getMasterPassword(boolean firstTime) {
+ return masterPassword;
+ }
+
+ @Override
+ public void setMasterPassword(String masterPassword){
+ this.masterPassword = masterPassword;
+ }
+
+ @Override
+ public int getProviderPriority() {
+ return priority;
+ }
+
+// @Override
+// public void setProviderPriority(int priority) {
+// this.priority = priority;
+// }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/UIMasterPasswordProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/UIMasterPasswordProvider.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/UIMasterPasswordProvider.java
new file mode 100644
index 0000000..8f76a37
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/UIMasterPasswordProvider.java
@@ -0,0 +1,125 @@
+/*
+* 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.workbench.ui.credentialmanager.password;
+
+import java.awt.GraphicsEnvironment;
+
+import javax.swing.JFrame;
+import org.apache.taverna.security.credentialmanager.DistinguishedNameParser;
+
+import uk.org.taverna.configuration.app.ApplicationConfiguration;
+
+import org.apache.taverna.security.credentialmanager.JavaTruststorePasswordProvider;
+import org.apache.taverna.security.credentialmanager.MasterPasswordProvider;
+import org.apache.taverna.workbench.ui.credentialmanager.GetMasterPasswordDialog;
+import org.apache.taverna.workbench.ui.credentialmanager.SetMasterPasswordDialog;
+import org.apache.taverna.workbench.ui.credentialmanager.WarnUserAboutJCEPolicyDialog;
+
+/**
+ * A UI pop-up that asks user for a master password for Credential Manager.
+ *
+ * @author Alex Nenadic
+ * @author Stian Soiland-Reyes
+ *
+ */
+public class UIMasterPasswordProvider implements MasterPasswordProvider, JavaTruststorePasswordProvider {
+
+ private ApplicationConfiguration applicationConfiguration;
+
+ private DistinguishedNameParser dnParser;
+
+ @Override
+ public String getJavaTruststorePassword() {
+ if (GraphicsEnvironment.isHeadless()) {
+ return null;
+ }
+
+ GetMasterPasswordDialog getPasswordDialog = new GetMasterPasswordDialog(
+ "Credential Manager needs to copy certificates from Java truststore. "
+ + "Please enter your password.");
+ getPasswordDialog.setLocationRelativeTo(null);
+ getPasswordDialog.setVisible(true);
+ String javaTruststorePassword = getPasswordDialog.getPassword();
+ return javaTruststorePassword;
+ }
+
+ @Override
+ public void setJavaTruststorePassword(String password) {
+ }
+
+ @Override
+ public String getMasterPassword(boolean firstTime) {
+
+ // Check if this Taverna run is headless (i.e. Taverna Server or Taverna
+ // from command line) - do not do anything here if it is as we do not
+ // want
+ // any windows popping up even if they could
+ if (GraphicsEnvironment.isHeadless()) {
+ return null;
+ }
+
+ // Pop up a warning about Java Cryptography Extension (JCE)
+ // Unlimited Strength Jurisdiction Policy
+ WarnUserAboutJCEPolicyDialog.warnUserAboutJCEPolicy(applicationConfiguration, dnParser);
+
+ if (firstTime) {
+ // Ask user to set the master password for Credential Manager (only
+ // the first time)
+ SetMasterPasswordDialog setPasswordDialog = new SetMasterPasswordDialog(
+ (JFrame) null, "Set master password", true,
+ "Set master password for Credential Manager");
+ setPasswordDialog.setLocationRelativeTo(null);
+ setPasswordDialog.setVisible(true);
+ return setPasswordDialog.getPassword();
+ } else {
+ // Ask user to provide a master password for Credential Manager
+ GetMasterPasswordDialog getPasswordDialog = new GetMasterPasswordDialog(
+ "Enter master password for Credential Manager");
+ getPasswordDialog.setLocationRelativeTo(null);
+ getPasswordDialog.setVisible(true);
+ return getPasswordDialog.getPassword();
+ }
+ }
+
+ @Override
+ public void setMasterPassword(String password) {
+ }
+
+ @Override
+ public int getProviderPriority() {
+ return 100;
+ }
+
+ /**
+ * Sets the applicationConfiguration.
+ *
+ * @param applicationConfiguration the new value of applicationConfiguration
+ */
+ public void setApplicationConfiguration(ApplicationConfiguration applicationConfiguration) {
+ this.applicationConfiguration = applicationConfiguration;
+ }
+
+ /**
+ * @param dnParser the dnParser to set
+ */
+ public void setDistinguishedNameParser(DistinguishedNameParser dnParser) {
+ this.dnParser = dnParser;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/UIUsernamePasswordProvider.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/UIUsernamePasswordProvider.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/UIUsernamePasswordProvider.java
new file mode 100644
index 0000000..c92535c
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/password/UIUsernamePasswordProvider.java
@@ -0,0 +1,111 @@
+/*
+* 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.workbench.ui.credentialmanager.password;
+
+import static java.awt.GraphicsEnvironment.isHeadless;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.taverna.security.credentialmanager.DistinguishedNameParser;
+import org.apache.taverna.security.credentialmanager.ServiceUsernameAndPasswordProvider;
+import org.apache.taverna.security.credentialmanager.UsernamePassword;
+
+import org.apache.log4j.Logger;
+
+public class UIUsernamePasswordProvider implements
+ ServiceUsernameAndPasswordProvider {
+ private static final Logger logger = Logger
+ .getLogger(UIUsernamePasswordProvider.class);
+
+ private DistinguishedNameParser dnParser;
+
+ public boolean canProvideUsernamePassword(URI serviceURI) {
+ return !isHeadless();
+ }
+
+ @Override
+ public UsernamePassword getServiceUsernameAndPassword(URI serviceURI,
+ String requestingPrompt) {
+ URI displayURI = serviceURI;
+
+ try {
+ displayURI = dnParser.setFragmentForURI(displayURI, null);
+ displayURI = dnParser.setUserInfoForURI(displayURI, null);
+ } catch (URISyntaxException e) {
+ logger.warn("Could not strip fragment/userinfo from " + serviceURI,
+ e);
+ }
+
+ StringBuilder message = new StringBuilder();
+ message.append("<html><body>The Taverna Credential Manager could not find a ");
+ message.append("username and password for the service at:");
+ message.append("<br><br><code>");
+ message.append(displayURI);
+ message.append("</code>");
+ if (requestingPrompt != null && !requestingPrompt.isEmpty()) {
+ message.append("<p><i>");
+ message.append(requestingPrompt);
+ message.append("</i>");
+ }
+ message.append("<br><br>Please provide the username and password.</body></html>");
+
+ GetPasswordDialog getPasswordDialog = new GetPasswordDialog(
+ message.toString(), true);
+ getPasswordDialog.setLocationRelativeTo(null);
+ if (serviceURI.getRawUserInfo() != null
+ && serviceURI.getRawUserInfo().length() > 1) {
+ String userInfo = serviceURI.getRawUserInfo();
+ String[] userPassword = userInfo.split(":", 2);
+ if (userPassword.length == 2) {
+ getPasswordDialog.setUsername(userPassword[0]);
+ getPasswordDialog.setPassword(userPassword[1]);
+ }
+ }
+ getPasswordDialog.setVisible(true);
+
+ String username = getPasswordDialog.getUsername(); // get username
+ String password = getPasswordDialog.getPassword(); // get password
+ boolean shouldSaveUsernameAndPassword = getPasswordDialog
+ .shouldSaveUsernameAndPassword();
+ if (username == null || password == null)
+ // user cancelled - any of the above two variables is null
+ return null;
+
+ UsernamePassword credential = new UsernamePassword();
+ credential.setUsername(username);
+ credential.setPassword(password.toCharArray());
+ credential.setShouldSave(shouldSaveUsernameAndPassword);
+ return credential;
+ }
+
+ @Override
+ public void setServiceUsernameAndPassword(URI serviceURI,
+ UsernamePassword usernamePassword) {
+ }
+
+ /**
+ * @param dnParser
+ * the dnParser to set
+ */
+ public void setDistinguishedNameParser(DistinguishedNameParser dnParser) {
+ this.dnParser = dnParser;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/startup/InitialiseSSLStartupHook.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/startup/InitialiseSSLStartupHook.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/startup/InitialiseSSLStartupHook.java
new file mode 100644
index 0000000..6453556
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/startup/InitialiseSSLStartupHook.java
@@ -0,0 +1,63 @@
+/*
+* 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.workbench.ui.credentialmanager.startup;
+
+import org.apache.log4j.Logger;
+
+import org.apache.taverna.security.credentialmanager.CMException;
+import org.apache.taverna.security.credentialmanager.CredentialManager;
+import org.apache.taverna.workbench.StartupSPI;
+
+/**
+ *
+ * Startup hook to initialise SSL socket factory used by Taverna for creating
+ * HTTPS connections.
+ *
+ * @author Alex Nenadic
+ * @author Stian Soiland-Reyes
+ */
+public class InitialiseSSLStartupHook implements StartupSPI {
+ private static final Logger logger = Logger
+ .getLogger(InitialiseSSLStartupHook.class);
+
+ private CredentialManager credManager;
+
+ @Override
+ public int positionHint() {
+ return 25;
+ }
+
+ @Override
+ public boolean startup() {
+ logger.info("Initialising SSL socket factory for SSL connections from Taverna.");
+ try {
+ credManager.initializeSSL();
+ } catch (CMException e) {
+ logger.error(
+ "Could not initialise the SSL socket factory (for creating SSL connections)"
+ + " using Taverna's keystores.", e);
+ }
+ return true;
+ }
+
+ public void setCredentialManager(CredentialManager credManager) {
+ this.credManager = credManager;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/startup/SetCredManAuthenticatorStartupHook.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/startup/SetCredManAuthenticatorStartupHook.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/startup/SetCredManAuthenticatorStartupHook.java
new file mode 100644
index 0000000..23f006e
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/startup/SetCredManAuthenticatorStartupHook.java
@@ -0,0 +1,43 @@
+/*
+* 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.workbench.ui.credentialmanager.startup;
+
+import java.net.Authenticator;
+import org.apache.taverna.security.credentialmanager.CredentialManager;
+import org.apache.taverna.workbench.StartupSPI;
+
+public class SetCredManAuthenticatorStartupHook implements StartupSPI {
+ private CredentialManager credManager;
+
+ @Override
+ public int positionHint() {
+ return 50;
+ }
+
+ @Override
+ public boolean startup() {
+ Authenticator.setDefault(credManager.getAuthenticator());
+ return true;
+ }
+
+ public void setCredentialManager(CredentialManager credManager) {
+ this.credManager = credManager;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-workbench/blob/a9a52bd5/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/toolbar/CredentialManagerToolbarAction.java
----------------------------------------------------------------------
diff --git a/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/toolbar/CredentialManagerToolbarAction.java b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/toolbar/CredentialManagerToolbarAction.java
new file mode 100644
index 0000000..ca83468
--- /dev/null
+++ b/taverna-credential-manager-ui/src/main/java/org/apache/taverna/workbench/ui/credentialmanager/toolbar/CredentialManagerToolbarAction.java
@@ -0,0 +1,43 @@
+/*
+* 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.workbench.ui.credentialmanager.toolbar;
+
+import static org.apache.taverna.workbench.ui.credentialmanager.toolbar.CredentialManagerToolbarSection.CREDENTIAL_MANAGER_TOOLBAR_SECTION;
+
+import java.net.URI;
+
+import javax.swing.Action;
+
+import org.apache.taverna.ui.menu.AbstractMenuAction;
+import org.apache.taverna.workbench.ui.credentialmanager.action.CredentialManagerAction;
+
+public class CredentialManagerToolbarAction extends AbstractMenuAction {
+ private static final String ENTRY_URI = "http://taverna.sf.net/2008/t2workbench/toolbar#credentialManagerAction";
+
+ public CredentialManagerToolbarAction() {
+ super(CREDENTIAL_MANAGER_TOOLBAR_SECTION, 100, URI.create(ENTRY_URI));
+ }
+
+ @Override
+ protected Action createAction() {
+ // need to add CredentialManager if toolbar is ever used
+ return new CredentialManagerAction(null, null);
+ }
+}