Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPARK-1944 #346

Merged
merged 6 commits into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,31 @@
import static java.awt.GridBagConstraints.WEST;
import static java.awt.GridBagConstraints.BOTH;
import static java.awt.GridBagConstraints.NONE;
import static java.awt.GridBagConstraints.CENTER;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;

import org.jivesoftware.resource.Res;
import org.jivesoftware.spark.util.ResourceUtils;
import org.jivesoftware.sparkimpl.certificates.CertificateController;
import org.jivesoftware.sparkimpl.certificates.CertificateModel;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;

Expand All @@ -39,24 +45,27 @@ public class CertificateDialog extends JDialog implements ActionListener {
private final static Insets DEFAULT_INSETS = new Insets(5, 5, 5, 5);
private final LocalPreferences localPreferences;
private CertificateModel cert;
private CertificateController certControll;
private boolean addInfo;

private JScrollPane scrollPane;
private JPanel panel = new JPanel();
private JPanel buttonPanel = new JPanel();

private JTextField versionField = new JTextField();
private JTextField serialNumberField = new JTextField();
private JTextArea versionField = new JTextArea();
private JTextArea serialNumberField = new JTextArea();
private JTextArea signatureValueField = new JTextArea();
private JTextField signatureAlgorithmField = new JTextField();
private JTextField issuerField = new JTextField();
private JTextField subjectField = new JTextField();
private JTextField notBeforeField = new JTextField();
private JTextField notAfterField = new JTextField();
private JTextArea signatureAlgorithmField = new JTextArea();
private JTextArea issuerField = new JTextArea();
private JTextArea subjectField = new JTextArea();
private JTextArea notBeforeField = new JTextArea();
private JTextArea notAfterField = new JTextArea();
private JTextArea publicKeyField = new JTextArea();
private JTextField publicKeyAlgorithmField = new JTextField();
private JTextField issuerUniqueIDField = new JTextField();
private JTextField subjectUniqueIDField = new JTextField();
private JTextArea publicKeyAlgorithmField = new JTextArea();
private JTextArea issuerUniqueIDField = new JTextArea();
private JTextArea subjectUniqueIDField = new JTextArea();

private JLabel infoLabel = new JLabel();
private JLabel versionLabel = new JLabel();
private JLabel serialNumberLabel = new JLabel();
private JLabel signatureValueLabel = new JLabel();
Expand All @@ -74,11 +83,14 @@ public class CertificateDialog extends JDialog implements ActionListener {
private JRadioButton distrust = new JRadioButton();
private JButton checkValidity = new JButton();
private JButton okButton = new JButton();
private JButton cancelButton = new JButton();

public CertificateDialog(LocalPreferences localPreferences, CertificateModel cert) {
public CertificateDialog(LocalPreferences localPreferences, CertificateModel cert,
CertificateController certificateController, boolean addInfo) {
if (localPreferences == null || cert == null) {
throw new IllegalArgumentException();
}
certControll = certificateController;
this.localPreferences = localPreferences;
this.cert = cert;
setTitle(Res.getString("title.certificate"));
Expand All @@ -89,6 +101,7 @@ public CertificateDialog(LocalPreferences localPreferences, CertificateModel cer
setModal(true);
setLayout(new GridBagLayout());
isAlwaysOnTop();
setResizable(false);

setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

Expand All @@ -105,13 +118,26 @@ public CertificateDialog(LocalPreferences localPreferences, CertificateModel cer
issuerUniqueIDField.setText(cert.getIssuerUniqueID());
subjectUniqueIDField.setText(cert.getSubjectUniqueID());

versionField.setLineWrap(true);
serialNumberField.setLineWrap(true);
signatureValueField.setLineWrap(true);
signatureAlgorithmField.setLineWrap(true);
issuerField.setLineWrap(true);
subjectField.setLineWrap(true);
notBeforeField.setLineWrap(true);
notAfterField.setLineWrap(true);
publicKeyField.setLineWrap(true);
publicKeyAlgorithmField.setLineWrap(true);
issuerUniqueIDField.setLineWrap(true);
subjectUniqueIDField.setLineWrap(true);


ButtonGroup radioGroup = new ButtonGroup();
radioGroup.add(distrust);
radioGroup.add(trust);

okButton.addActionListener(this);
cancelButton.addActionListener(this);

ResourceUtils.resLabel(versionLabel, versionField, Res.getString("label.certificate.version"));
ResourceUtils.resLabel(serialNumberLabel, serialNumberField, Res.getString("label.certificate.serial.number"));
Expand All @@ -134,6 +160,8 @@ public CertificateDialog(LocalPreferences localPreferences, CertificateModel cer
ResourceUtils.resButton(distrust, Res.getString("radio.certificate.distrust"));
ResourceUtils.resButton(checkValidity, Res.getString("button.check.validity"));
ResourceUtils.resButton(okButton, Res.getString("ok"));
ResourceUtils.resButton(cancelButton, Res.getString("cancel"));
infoLabel.setText(Res.getString("dialog.certificate.show"));

panel.setLayout(new GridBagLayout());
buttonPanel.setLayout(new GridBagLayout());
Expand Down Expand Up @@ -178,29 +206,59 @@ public CertificateDialog(LocalPreferences localPreferences, CertificateModel cer
panel.add(subjectUniqueIDField,
new GridBagConstraints(2, 11, 6, 1, 1.0, 0.0, WEST, HORIZONTAL, DEFAULT_INSETS, 0, 0));

buttonPanel.add(trust, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, WEST, HORIZONTAL, DEFAULT_INSETS, 0, 0));
buttonPanel.add(distrust, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, WEST, HORIZONTAL, DEFAULT_INSETS, 0, 0));
buttonPanel.add(trust, new GridBagConstraints(0, 0, 1, 1, 0.2, 0.0, WEST, HORIZONTAL, DEFAULT_INSETS, 0, 0));
buttonPanel.add(distrust, new GridBagConstraints(1, 0, 1, 1, 0.1, 0.0, WEST, HORIZONTAL, DEFAULT_INSETS, 0, 0));
buttonPanel.add(checkValidity, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0, WEST, NONE, DEFAULT_INSETS, 0, 0));
buttonPanel.add(okButton, new GridBagConstraints(2, 2, 2, 1, 0.0, 0.0, WEST, NONE, new Insets(5, 5, 5, 200), 60, 0));
buttonPanel.add(okButton, new GridBagConstraints(1, 2, 1, 1, 0.2, 0.0, CENTER, HORIZONTAL, new Insets(5, 100, 5, 5), 0, 0));
buttonPanel.add(cancelButton, new GridBagConstraints(2, 2, 1, 1, 0.2, 0.0, CENTER, HORIZONTAL, new Insets(5, 5, 5, 100), 0, 0));

trust.setSelected(cert.isValid() || cert.isExempted());
distrust.setSelected(!cert.isValid() && !cert.isExempted());


scrollPane = new JScrollPane(panel);
scrollPane.setMinimumSize(new Dimension(250, 500));
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

add(scrollPane, new GridBagConstraints(0, 0, 4, 1, 1.0, 1.0, WEST, BOTH, DEFAULT_INSETS, 0, 0));
add(buttonPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, WEST, HORIZONTAL, DEFAULT_INSETS, 0, 0));

scrollPane.setVisible(true);

if (addInfo) {
add(infoLabel, new GridBagConstraints(0, 0, 4, 1, 1.0, 0.0, WEST, BOTH, DEFAULT_INSETS, 0, 0));
}

add(scrollPane, new GridBagConstraints(0, 1, 4, 1, 1.0, 1.0, WEST, BOTH, DEFAULT_INSETS, 0, 0));
add(buttonPanel, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0, WEST, HORIZONTAL, DEFAULT_INSETS, 0, 0));

SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
//scrolls scrollPane to top
panel.scrollRectToVisible(versionField.getBounds());

//info that certificate is distrusted
if(addInfo && !cert.isValid()){
JOptionPane.showMessageDialog(null, Res.getString("dialog.certificate.is.distrusted"));
}
}
});

setVisible(true);

scrollPane.getVerticalScrollBar().setValue(0);
scrollPane.repaint();
repaint();
}

public CertificateDialog(LocalPreferences localPreferences, CertificateModel certificateModel) {
this(localPreferences, certificateModel, null, false);
}

@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == okButton){
//controller should be passed to this class only if there is need to modification content of Keystore.
if (certControll != null) {
certControll.setAddToKeystore(true);
}
this.dispose();
}else if(e.getSource() == cancelButton){
if (certControll != null) {
certControll.setAddToKeystore(false);
}
this.dispose();
}
}
Expand Down
Loading