/**
* {@inheritDoc}
*/
public boolean performOk()
{
PasswordsKeyStoreManager globalPasswordsKeyStoreManager = ConnectionCorePlugin.getDefault()
.getPasswordsKeyStoreManager();
if ( enableKeystoreCheckbox.getSelection() )
{
if ( passwordsKeyStoreManager.isLoaded() )
{
// First, let's save the temporary keystore manager
try
{
passwordsKeyStoreManager.save();
}
catch ( KeyStoreException e )
{
ConnectionUIPlugin
.getDefault()
.getLog()
.log(
new Status( Status.ERROR, ConnectionUIConstants.PLUGIN_ID, Status.ERROR,
"Couldn't save the temporary password keystore.", e ) ); //$NON-NLS-1$
}
// Now, let's copy the temporary keystore as the global keystore
try
{
FileUtils.copyFile( getTemporaryKeystoreFile(), ConnectionCorePlugin.getDefault()
.getPasswordsKeyStoreManager().getKeyStoreFile() );
}
catch ( IOException e )
{
ConnectionUIPlugin
.getDefault()
.getLog()
.log(
new Status( Status.ERROR, ConnectionUIConstants.PLUGIN_ID, Status.ERROR,
"Couldn't copy the temporary keystore as the global keystore.", e ) ); //$NON-NLS-1$
}
// Finally lets reload the global keystore
try
{
globalPasswordsKeyStoreManager.reload( passwordsKeyStoreManager.getMasterPassword() );
}
catch ( KeyStoreException e )
{
ConnectionUIPlugin
.getDefault()
.getLog()
.log(
new Status( Status.ERROR, ConnectionUIConstants.PLUGIN_ID, Status.ERROR,
"Couldn't reload the global keystore file.", e ) ); //$NON-NLS-1$
}
// Clearing each connection password
for ( Connection connection : connectionManager.getConnections() )
{
connection.getConnectionParameter().setBindPassword( null );
}
// Saving the connections
ConnectionCorePlugin.getDefault().getConnectionManager().saveConnections();
// Saving the value to the preferences
ConnectionCorePlugin.getDefault().getPluginPreferences()
.setValue( ConnectionCoreConstants.PREFERENCE_CONNECTIONS_PASSWORDS_KEYSTORE,
ConnectionCoreConstants.PREFERENCE_CONNECTIONS_PASSWORDS_KEYSTORE_ON );
}
}
else
{
// Reseting the global passwords keystore
globalPasswordsKeyStoreManager.reset();
// Looking for connections passwords in the list
if ( connectionsPasswordsBackup.size() > 0 )
{
// Adding them to the keystore