try
{
result = helper.invokeConfigureServer(args);
if (result != 0)
{
ae = new ApplicationException(
ReturnCode.CONFIGURATION_ERROR,
INFO_ERROR_CONFIGURING.get(), null);
}
else
{
if (getUserData().getNewSuffixOptions().getBaseDns().isEmpty())
{
helper.deleteBackend(getBackendName());
}
}
} catch (ApplicationException aex)
{
ae = aex;
} catch (Throwable t)
{
ae = new ApplicationException(
ReturnCode.CONFIGURATION_ERROR,
getThrowableMsg(INFO_ERROR_CONFIGURING.get(), t), t);
}
finally
{
setNotifyListeners(true);
}
isOver = true;
}
@Override
public void abort()
{
// TODO: implement the abort
}
};
invokeLongOperation(thread);
notifyListeners(getFormattedDoneWithLineBreak());
checkAbort();
try
{
SecurityOptions.CertificateType certType = sec.getCertificateType();
if (certType != SecurityOptions.CertificateType.NO_CERTIFICATE)
{
notifyListeners(getFormattedWithPoints(
INFO_PROGRESS_UPDATING_CERTIFICATES.get()));
}
CertificateManager certManager;
CertificateManager trustManager;
File f;
switch (certType)
{
case NO_CERTIFICATE:
// Nothing to do
break;
case SELF_SIGNED_CERTIFICATE:
String pwd = getSelfSignedCertificatePwd();
certManager = new CertificateManager(
getSelfSignedKeystorePath(),
CertificateManager.KEY_STORE_TYPE_JKS,
pwd);
certManager.generateSelfSignedCertificate(SELF_SIGNED_CERT_ALIAS,
getSelfSignedCertificateSubjectDN(),
getSelfSignedCertificateValidity());
SetupUtils.exportCertificate(certManager, SELF_SIGNED_CERT_ALIAS,
getTemporaryCertificatePath());
trustManager = new CertificateManager(
getTrustManagerPath(),
CertificateManager.KEY_STORE_TYPE_JKS,
pwd);
trustManager.addCertificate(SELF_SIGNED_CERT_ALIAS,
new File(getTemporaryCertificatePath()));
createProtectedFile(getKeystorePinPath(), pwd);
f = new File(getTemporaryCertificatePath());
f.delete();
break;
case JKS:
certManager = new CertificateManager(
sec.getKeystorePath(),
CertificateManager.KEY_STORE_TYPE_JKS,
sec.getKeystorePassword());
if (aliasInKeyStore != null)
{
SetupUtils.exportCertificate(certManager, aliasInKeyStore,
getTemporaryCertificatePath());
}
else
{
SetupUtils.exportCertificate(certManager,
getTemporaryCertificatePath());
}
trustManager = new CertificateManager(
getTrustManagerPath(),
CertificateManager.KEY_STORE_TYPE_JKS,
sec.getKeystorePassword());
trustManager.addCertificate(aliasInTrustStore,
new File(getTemporaryCertificatePath()));
createProtectedFile(getKeystorePinPath(), sec.getKeystorePassword());
f = new File(getTemporaryCertificatePath());
f.delete();
break;
case JCEKS:
certManager = new CertificateManager(
sec.getKeystorePath(),
CertificateManager.KEY_STORE_TYPE_JCEKS,
sec.getKeystorePassword());
if (aliasInKeyStore != null)
{
SetupUtils.exportCertificate(certManager, aliasInKeyStore,
getTemporaryCertificatePath());
}
else
{
SetupUtils.exportCertificate(certManager,
getTemporaryCertificatePath());
}
trustManager = new CertificateManager(
getTrustManagerPath(),
CertificateManager.KEY_STORE_TYPE_JCEKS,
sec.getKeystorePassword());
trustManager.addCertificate(aliasInTrustStore,
new File(getTemporaryCertificatePath()));
createProtectedFile(getKeystorePinPath(), sec.getKeystorePassword());
f = new File(getTemporaryCertificatePath());
f.delete();
break;
case PKCS12:
certManager = new CertificateManager(
sec.getKeystorePath(),
CertificateManager.KEY_STORE_TYPE_PKCS12,
sec.getKeystorePassword());
if (aliasInKeyStore != null)
{
SetupUtils.exportCertificate(certManager, aliasInKeyStore,
getTemporaryCertificatePath());
}
else
{
SetupUtils.exportCertificate(certManager,
getTemporaryCertificatePath());
}
trustManager = new CertificateManager(
getTrustManagerPath(),
CertificateManager.KEY_STORE_TYPE_JKS,
sec.getKeystorePassword());
trustManager.addCertificate(aliasInTrustStore,
new File(getTemporaryCertificatePath()));
createProtectedFile(getKeystorePinPath(), sec.getKeystorePassword());
f = new File(getTemporaryCertificatePath());
f.delete();
break;
case PKCS11:
certManager = new CertificateManager(
CertificateManager.KEY_STORE_PATH_PKCS11,
CertificateManager.KEY_STORE_TYPE_PKCS11,
sec.getKeystorePassword());
if (aliasInKeyStore != null)
{
SetupUtils.exportCertificate(certManager, aliasInKeyStore,
getTemporaryCertificatePath());
}
else
{
SetupUtils.exportCertificate(certManager,
getTemporaryCertificatePath());
}
trustManager = new CertificateManager(
getTrustManagerPath(),
CertificateManager.KEY_STORE_TYPE_JKS,
sec.getKeystorePassword());
trustManager.addCertificate(aliasInTrustStore,
new File(getTemporaryCertificatePath()));
createProtectedFile(getKeystorePinPath(), sec.getKeystorePassword());
break;
default:
throw new IllegalStateException("Unknown certificate type: "+certType);
}
if (certType != SecurityOptions.CertificateType.NO_CERTIFICATE)
{
notifyListeners(getFormattedDoneWithLineBreak());
}
}
catch (Throwable t)
{
LOG.log(Level.SEVERE, "Error configuring certificate: "+t, t);
throw new ApplicationException(
ReturnCode.CONFIGURATION_ERROR,
getThrowableMsg(INFO_ERROR_CONFIGURING_CERTIFICATE.get(),
t), t);
}
}