/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008-2010 Sun Microsystems, Inc.
* Portions Copyright 2013 ForgeRock AS
*/
/**
* This class is a dialog that appears when the user wants to configure
* security parameters for the new OpenDS instance.
*/
{
private boolean isCanceled = true;
private boolean certificateHasAlias;
/**
* Constructor of the SecurityOptionsDialog.
* @param parent the parent frame for this dialog.
* @param options the SecurityOptions used to populate this dialog.
* @throws IllegalArgumentException if options is null.
*/
throws IllegalArgumentException
{
super(parent);
pack();
minHeight));
{
public void windowClosing(WindowEvent e)
{
}
});
}
/**
* Returns <CODE>true</CODE> if the user clicked on cancel and
* <CODE>false</CODE> otherwise.
* @return <CODE>true</CODE> if the user clicked on cancel and
* <CODE>false</CODE> otherwise.
*/
public boolean isCanceled()
{
return isCanceled;
}
/**
* Displays this dialog and populates its contents with the provided
* SecurityOptions object.
* @param options the SecurityOptions used to populate this dialog.
* @throws IllegalArgumentException if options is null.
*/
{
{
throw new IllegalArgumentException("options parameter cannot be null.");
}
isCanceled = true;
setVisible(true);
}
/**
* Returns the security options object representing the input of the user
* in this panel.
* @return the security options object representing the input of the user
* in this panel.
*/
{
if (enableSSL || enableStartTLS)
{
int sslPort = -1;
try
{
}
catch (Throwable t)
{
}
{
}
else if (rbJKS.isSelected())
{
}
else if (rbJCEKS.isSelected())
{
}
else if (rbPKCS11.isSelected())
{
}
else if (rbPKCS12.isSelected())
{
}
else
{
throw new IllegalStateException("No certificate options selected.");
}
}
else
{
}
return ops;
}
/**
* Creates and returns the panel of the dialog.
* @return the panel of the dialog.
*/
{
return contentPanel;
}
/**
* Creates and returns the title sub panel.
* @return the title sub panel.
*/
{
titlePanel.setOpaque(false);
JLabel l =
l.setOpaque(false);
return titlePanel;
}
/**
* Creates and returns the instructions sub panel.
* @return the instructions sub panel.
*/
{
instructionsPane.setOpaque(false);
instructionsPane.setEditable(false);
return instructionsPane;
}
/**
* Creates and returns the input sub panel: the panel with all the widgets
* that are used to define the security options.
* @return the input sub panel.
*/
{
inputPanel.setOpaque(false);
ActionListener l = new ActionListener()
{
{
}
};
if (port > 0)
{
}
lKeystoreType.setOpaque(false);
lKeystorePath.setOpaque(false);
this);
lKeystorePwd.setOpaque(false);
gbc);
gbc);
return inputPanel;
}
/**
*/
{
buttonsPanel.setOpaque(false);
okButton =
{
{
okClicked();
}
});
{
{
}
});
return buttonsPanel;
}
/**
* Method called when user clicks on cancel.
*
*/
private void cancelClicked()
{
isCanceled = true;
dispose();
}
/**
* Method called when user clicks on OK.
*
*/
private void okClicked()
{
{
{
return errorMsgs;
}
{
{
// Bug
INFO_ERROR_TITLE.get());
cancelButton.setEnabled(true);
okButton.setEnabled(true);
}
else
{
cancelButton.setEnabled(true);
okButton.setEnabled(true);
{
INFO_ERROR_TITLE.get());
}
else
{
if (rbUseExistingCertificate.isSelected() &&
{
if (!certificateHasAlias)
{
isCanceled = false;
dispose();
}
{
{
}
if (!aliasDlg.isCanceled())
{
isCanceled = false;
dispose();
}
}
else
{
isCanceled = false;
dispose();
}
}
else
{
isCanceled = false;
dispose();
}
}
}
}
};
cancelButton.setEnabled(false);
okButton.setEnabled(false);
}
/**
* Displays an error message dialog.
*
* @param msg
* the error message.
* @param title
* the title for the dialog.
*/
{
toFront();
}
/**
* Updates the widgets on the dialog with the contents of the securityOptions
* object.
*
*/
private void updateContents()
{
if (securityOptions.getEnableSSL())
{
if (port > 0)
{
}
}
switch (securityOptions.getCertificateType())
{
case NO_CERTIFICATE:
// Nothing else to do
break;
case SELF_SIGNED_CERTIFICATE:
break;
case JKS:
rbJKS.setSelected(true);
break;
case JCEKS:
rbJCEKS.setSelected(true);
break;
case PKCS11:
rbPKCS11.setSelected(true);
break;
case PKCS12:
rbPKCS12.setSelected(true);
break;
default:
throw new IllegalStateException("Unknown certificate type.");
}
}
/**
* the user selected.
*/
private void updateEnablingState()
{
{
}
{
rbJKS.setSelected(true);
}
}
/**
* Returns the port help message that we display when we cannot use the
* default port (636).
* @return the port help message that we display when we cannot use the
* default port (636).
*/
{
{
}
return s;
}
/**
* Checks the port.
* @return the error messages found while checking the port.
*/
{
if (cbEnableSSL.isSelected())
{
/* Check the port. */
int port = -1;
try
{
{
}
{
{
}
else
{
}
}
}
catch (NumberFormatException nfe)
{
}
}
return errorMsgs;
}
/**
* Checks the existing keystore parameters.
* @return the error messages found while checking existing keystore
* parameters.
*/
{
boolean pathValid = true;
boolean pwdValid = true;
if (rbUseExistingCertificate.isSelected() &&
{
{
/* Check the path */
{
}
else
{
if (!f.exists())
{
}
else if (!f.isFile())
{
}
}
}
if (pathValid)
{
try
{
if (rbJKS.isSelected())
{
certManager = new CertificateManager(
path,
pwd);
}
else if (rbJCEKS.isSelected())
{
certManager = new CertificateManager(
path,
pwd);
}
else if (rbPKCS12.isSelected())
{
certManager = new CertificateManager(
path,
pwd);
}
else if (rbPKCS11.isSelected())
{
certManager = new CertificateManager(
pwd);
}
else
{
throw new IllegalStateException("No keystore type selected.");
}
{
// Could not retrieve any certificate
if (rbPKCS11.isSelected())
{
}
else
{
if (rbJKS.isSelected())
{
}
else if (rbJCEKS.isSelected())
{
}
else
{
}
pathValid = false;
}
}
else
{
}
}
catch (KeyStoreException ke)
{
// issue OPENDJ-18, related to JDK bug
if (StaticUtils
{
}
else
{
pwdValid = false;
if (!rbPKCS11.isSelected())
{
pathValid = false;
}
// Could not access to the keystore: because the password is
// no good, because the provided file is not a valid keystore, etc.
if (rbPKCS11.isSelected())
{
}
else
{
if (rbJKS.isSelected())
{
}
else if (rbJCEKS.isSelected())
{
}
else
{
}
pathValid = false;
}
}
}
}
}
return errorMsgs;
}
/**
* Method that updates the text style of a provided component by calling
* SwingUtilities.invokeLater. This method is aimed to be called outside
* the event thread (calling it from the event thread will also work though).
* @param comp the component to be updated.
* @param valid whether to use a TextStyle to mark the component as valid
* or as invalid.
*/
{
{
public void run()
{
}
});
}
/**
* Method written for testing purposes.
* @param args the arguments to be passed to the test program.
*/
{
try
{
// UIFactory.initialize();
dlg.setVisible(true);
{
}
}
}