Search in sources :

Example 1 with DefaultPlexusCipher

use of org.sonatype.plexus.components.cipher.DefaultPlexusCipher in project flyway by flyway.

the class AbstractFlywayMojo method loadCredentialsFromSettings.

/**
     * Load username password from settings
     *
     * @throws FlywayException when the credentials could not be loaded.
     */
private void loadCredentialsFromSettings() throws FlywayException {
    final Server server = settings.getServer(serverId);
    if (user == null) {
        if (server != null) {
            user = server.getUsername();
            try {
                SecDispatcher secDispatcher = new DefaultSecDispatcher() {

                    {
                        _cipher = new DefaultPlexusCipher();
                    }
                };
                password = secDispatcher.decrypt(server.getPassword());
            } catch (SecDispatcherException e) {
                throw new FlywayException("Unable to decrypt password", e);
            } catch (PlexusCipherException e) {
                throw new FlywayException("Unable to initialize password decryption", e);
            }
        }
    } else if (server != null) {
        throw new FlywayException("You specified credentials both in the Flyway config and settings.xml. Use either one or the other");
    }
}
Also used : FlywayException(org.flywaydb.core.api.FlywayException) Server(org.apache.maven.settings.Server) SecDispatcher(org.sonatype.plexus.components.sec.dispatcher.SecDispatcher) DefaultSecDispatcher(org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher) DefaultPlexusCipher(org.sonatype.plexus.components.cipher.DefaultPlexusCipher) DefaultSecDispatcher(org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher) SecDispatcherException(org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException) PlexusCipherException(org.sonatype.plexus.components.cipher.PlexusCipherException)

Aggregations

Server (org.apache.maven.settings.Server)1 FlywayException (org.flywaydb.core.api.FlywayException)1 DefaultPlexusCipher (org.sonatype.plexus.components.cipher.DefaultPlexusCipher)1 PlexusCipherException (org.sonatype.plexus.components.cipher.PlexusCipherException)1 DefaultSecDispatcher (org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher)1 SecDispatcher (org.sonatype.plexus.components.sec.dispatcher.SecDispatcher)1 SecDispatcherException (org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException)1