@Override public void apply() throws ConfigurationException { List<X509Certificate> existing = myTrustManager.getCertificates(); Set<X509Certificate> added = new HashSet<X509Certificate>(myCertificates); added.removeAll(existing); Set<X509Certificate> removed = new HashSet<X509Certificate>(existing); removed.removeAll(myCertificates); for (X509Certificate certificate : added) { if (!myTrustManager.addCertificate(certificate)) { throw new ConfigurationException( "Cannot add certificate for " + getCommonName(certificate), "Cannot Add Certificate"); } } for (X509Certificate certificate : removed) { if (!myTrustManager.removeCertificate(certificate)) { throw new ConfigurationException( "Cannot remove certificate for " + getCommonName(certificate), "Cannot Remove Certificate"); } } CertificateManager.Config state = CertificateManager.getInstance().getState(); state.ACCEPT_AUTOMATICALLY = myAcceptAutomatically.isSelected(); state.CHECK_HOSTNAME = myCheckHostname.isSelected(); state.CHECK_VALIDITY = myCheckValidityPeriod.isSelected(); }
@Override public void reset() { List<X509Certificate> original = myTrustManager.getCertificates(); myTreeBuilder.reset(original); myCertificates.clear(); myCertificates.addAll(original); myDetailsPanel.removeAll(); myDetailsPanel.add(myEmptyPanel, EMPTY_PANEL); // fill lower panel with cards for (X509Certificate certificate : original) { addCertificatePanel(certificate); } if (!myCertificates.isEmpty()) { myTreeBuilder.selectFirstCertificate(); } CertificateManager.Config state = CertificateManager.getInstance().getState(); myAcceptAutomatically.setSelected(state.ACCEPT_AUTOMATICALLY); myCheckHostname.setSelected(state.CHECK_HOSTNAME); myCheckValidityPeriod.setSelected(state.CHECK_VALIDITY); }
@Override public boolean isModified() { CertificateManager.Config state = CertificateManager.getInstance().getState(); return myAcceptAutomatically.isSelected() != state.ACCEPT_AUTOMATICALLY || myCheckHostname.isSelected() != state.CHECK_HOSTNAME || myCheckValidityPeriod.isSelected() != state.CHECK_VALIDITY || !myCertificates.equals(new HashSet<X509Certificate>(myTrustManager.getCertificates())); }