Example usage for org.apache.maven.settings.crypto SettingsDecryptionResult getServer

List of usage examples for org.apache.maven.settings.crypto SettingsDecryptionResult getServer

Introduction

In this page you can find the example usage for org.apache.maven.settings.crypto SettingsDecryptionResult getServer.

Prototype

Server getServer();

Source Link

Document

Gets the decrypted server.

Usage

From source file:com.basistech.ReleaseNoteMojo.java

License:Open Source License

private boolean getAuthFromSettings(Client client) throws MojoExecutionException {
    if (serverId == null) {
        return false;
    }/*  w w w  .  jav  a 2  s  .c om*/
    Server server = getServer(settings, serverId);
    if (server == null) {
        throw new MojoExecutionException(
                MessageFormat.format("Server ''{0}'' not found in settings", serverId));
    }

    getLog().debug(MessageFormat.format("Using ''{0}'' server credentials", serverId));

    try {
        SettingsDecrypter settingsDecrypter = container.lookup(SettingsDecrypter.class);
        SettingsDecryptionResult result = settingsDecrypter
                .decrypt(new DefaultSettingsDecryptionRequest(server));
        server = result.getServer();
    } catch (ComponentLookupException cle) {
        throw new MojoExecutionException("Unable to lookup SettingsDecrypter: " + cle.getMessage(), cle);
    }

    String serverUsername = server.getUsername();
    String serverPassword = server.getPassword();

    if (serverUsername != null && serverUsername.length() > 0 && serverPassword != null
            && serverPassword.length() > 0) {
        getLog().debug("Using basic authentication with username: " + serverUsername);
        setupBasicAuthentication(client, serverUsername, serverPassword);
        return true;
    }

    // A server password without a username is assumed to be an OAuth2 token
    if (serverPassword != null && serverPassword.length() > 0) {
        getLog().debug("Using OAuth2 access token authentication");
        setupOauth2(client, serverPassword);
        return true;
    }

    getLog().debug(MessageFormat.format("Server ''{0}'' is missing username/password credentials", serverId));
    return false;
}

From source file:com.goodformobile.build.mobile.RIMSigningMojo.java

License:Apache License

public void execute() throws MojoExecutionException {

    getLog().info("RIMSigningMojo.execute()");

    if (skipSigning) {
        getLog().info("Skipping signing.");
        return;//from   w w w  . j a v a2  s. c o  m
    }

    Settings settings = this.settings;
    Server server = settings.getServer(signingCredentialsServerId);
    if (server == null) {
        throw new MojoExecutionException("Unable to find server with the id[" + signingCredentialsServerId
                + "].  Please configure this in your settings.xml");
    }
    String password = server.getPassword();
    if (StringUtils.isEmpty(password)) {
        throw new MojoExecutionException("Unable to find password in settings.xml for server with the id["
                + signingCredentialsServerId + "].");
    }

    if (password.contains("{")) {
        SettingsDecryptionRequest settingsDecryptionRequest = new DefaultSettingsDecryptionRequest(server);
        SettingsDecryptionResult result = settingsDecrypter.decrypt(settingsDecryptionRequest);
        if (result.getProblems() != null && result.getProblems().size() > 0) {
            throw new MojoExecutionException(
                    "Unable to decrypt password:" + result.getProblems().get(0).toString(),
                    result.getProblems().get(0).getException());
        }
        password = result.getServer().getPassword();
    }

    File deliverablesDirectory = new File(project.getBuild().getDirectory() + File.separator + "deliverables");

    if (signaturePath == null) {
        throw new MojoExecutionException(
                "signaturePath is null.  Please specify the <signature.path> property pointing to the directory with your signatureTools.jar");
    }

    Commandline commandLine = new Commandline("java -jar " + signaturePath.getAbsolutePath() + File.separator
            + "SignatureTool.jar -a -C -s -p " + password + " -r " + deliverablesDirectory.getAbsolutePath());

    commandLine.setWorkingDirectory(project.getBasedir());

    executeCommandLineToLogger(commandLine);

    String inputClassesDirectory = project.getBuild().getOutputDirectory();

    if (bundleCodsInOutputJar) {
        try {
            FileUtils.copyDirectory(
                    new File(project.getBuild().getDirectory() + File.separator + "deliverables"),
                    new File(inputClassesDirectory), "*.cod", "");
        } catch (IOException e) {
            throw new MojoExecutionException("Error copying files.", e);
        }
    }
}

From source file:de.jutzig.github.release.plugin.UploadMojo.java

License:Apache License

public GitHub createGithub(String serverId) throws MojoExecutionException, IOException {
    String usernameProperty = System.getProperty("username");
    String passwordProperty = System.getProperty("password");
    if (usernameProperty != null && passwordProperty != null) {
        getLog().debug("Using server credentials from system properties 'username' and 'password'");
        return GitHub.connectUsingPassword(usernameProperty, passwordProperty);
    }//from  w w w .ja  v  a 2  s.c om

    Server server = getServer(settings, serverId);
    if (server == null)
        throw new MojoExecutionException(
                MessageFormat.format("Server ''{0}'' not found in settings", serverId));

    getLog().debug(MessageFormat.format("Using ''{0}'' server credentials", serverId));

    try {
        SettingsDecrypter settingsDecrypter = container.lookup(SettingsDecrypter.class);
        SettingsDecryptionResult result = settingsDecrypter
                .decrypt(new DefaultSettingsDecryptionRequest(server));
        server = result.getServer();
    } catch (ComponentLookupException cle) {
        throw new MojoExecutionException("Unable to lookup SettingsDecrypter: " + cle.getMessage(), cle);
    }

    String serverUsername = server.getUsername();
    String serverPassword = server.getPassword();
    String serverAccessToken = server.getPrivateKey();
    if (StringUtils.isNotEmpty(serverUsername) && StringUtils.isNotEmpty(serverPassword))
        return GitHub.connectUsingPassword(serverUsername, serverPassword);
    else if (StringUtils.isNotEmpty(serverAccessToken))
        return GitHub.connectUsingOAuth(serverAccessToken);
    else
        throw new MojoExecutionException("Configuration for server " + serverId + " has no login credentials");
}

From source file:org.eclipse.ebr.maven.EclipseIpLogUtil.java

License:Open Source License

private Server getServer(final String serverId, final Settings settings,
        final SettingsDecrypter settingsDecrypter) {
    for (Server server : settings.getServers()) {
        if (StringUtils.equals(server.getId(), serverId)) {
            final SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
            final SettingsDecryptionResult result = settingsDecrypter.decrypt(request);
            server = result.getServer();

            // log any detected problems
            for (final SettingsProblem problem : result.getProblems()) {
                getLog().warn(problem.getMessage(), problem.getException());
            }//from  w  w w  .  j a  v  a 2s  . c o m

            return server;
        }
    }

    return null;
}

From source file:org.eclipse.m2e.core.internal.embedder.MavenImpl.java

License:Open Source License

public Server decryptPassword(Server server) throws CoreException {
    SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
    SettingsDecryptionResult result = lookup(SettingsDecrypter.class).decrypt(request);
    for (SettingsProblem problem : result.getProblems()) {
        log.warn(problem.getMessage(), problem.getException());
    }/*w  w  w.j a v  a 2 s .  com*/
    return result.getServer();
}

From source file:org.jboss.as.plugin.common.AbstractServerMojo.java

License:Open Source License

private String decrypt(final Server server) {
    SettingsDecryptionResult decrypt = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(server));
    return decrypt.getServer().getPassword();
}

From source file:org.springframework.ide.vscode.commons.maven.MavenBridge.java

License:Open Source License

public Server decryptPassword(Server server) throws MavenException {
    SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
    SettingsDecryptionResult result = lookup(SettingsDecrypter.class).decrypt(request);
    for (SettingsProblem problem : result.getProblems()) {
        log.warn(problem.getMessage(), problem.getException());
    }/* w  ww  .ja  va 2  s  . com*/
    return result.getServer();
}

From source file:ph.samson.maven.cpages.DeployMojo.java

License:Apache License

private Server getServerSettings(String id) throws MojoExecutionException {
    SettingsDecryptionRequest sdr = new DefaultSettingsDecryptionRequest(settings.getServer(id));
    SettingsDecryptionResult decrypt = decrypter.decrypt(sdr);
    for (SettingsProblem problem : decrypt.getProblems()) {
        switch (problem.getSeverity()) {
        case WARNING:
            log.warn("{} ({})", problem.getMessage(), problem.getLocation());
            break;
        case ERROR:
            log.error("{} ({})", problem.getMessage(), problem.getLocation());
            break;
        case FATAL:
            log.error("{} ({})", problem.getMessage(), problem.getLocation());
            throw new MojoExecutionException(problem.getMessage());
        }/* w w w . ja  v  a  2s  . c om*/
    }
    return decrypt.getServer();
}