Search in sources :

Example 1 with SecDispatcherException

use of org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException in project fabric8 by jboss-fuse.

the class MavenSecurityDispatcher method decrypt.

@Override
public String decrypt(String str) throws SecDispatcherException {
    if (!isEncryptedString(str)) {
        return str;
    }
    String bare = null;
    try {
        bare = cipher.unDecorate(str);
    } catch (PlexusCipherException e1) {
        throw new SecDispatcherException(e1);
    }
    Map<String, String> attr = stripAttributes(bare);
    String res = null;
    if (attr == null || attr.get("type") == null) {
        String master = getMaster();
        try {
            res = cipher.decrypt(bare, master);
        } catch (PlexusCipherException e) {
            throw new SecDispatcherException("Unable to decrypt encrypted string", e);
        }
    } else {
        String type = (String) attr.get(TYPE_ATTR);
        throw new UnsupportedOperationException("Unable to lookup security dispatched of type " + type);
    }
    return res;
}
Also used : SecDispatcherException(org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException) PlexusCipherException(org.sonatype.plexus.components.cipher.PlexusCipherException)

Example 2 with SecDispatcherException

use of org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException in project fabric8 by jboss-fuse.

the class MavenPasswordAction method findMasterMavenPassword.

/**
 * Searches for master Maven password configured in <code>settings-security.xml</code>
 * @param securitySettingsInMavenConfig
 * @param securitySettingsInAgentConfig
 * @param securitySettingsInPaxConfig
 * @param securitySettingsInImplicitLocation
 * @return
 */
private String findMasterMavenPassword(String securitySettingsInMavenConfig, String securitySettingsInAgentConfig, String securitySettingsInPaxConfig, String securitySettingsInImplicitLocation) throws SecDispatcherException, PlexusCipherException {
    if (command.cipher == null) {
        System.out.println("Can't decrypt Maven master password: " + command.cipherInitializationProblem);
        return null;
    }
    for (String loc : new String[] { securitySettingsInMavenConfig, securitySettingsInAgentConfig, securitySettingsInPaxConfig, securitySettingsInImplicitLocation }) {
        if (loc == null) {
            continue;
        }
        System.out.print("Looking up master Maven password in " + loc + "...");
        if (new File(loc).isFile()) {
            String decrypted = null;
            try {
                SettingsSecurity settingsSecurity = SecUtil.read(loc, true);
                decrypted = command.cipher.decryptDecorated(settingsSecurity.getMaster(), DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION);
                System.out.println(" Done!");
                return decrypted;
            } catch (Exception e) {
                System.out.println(" Failure! (" + e.getMessage() + ")");
            }
        } else {
            System.out.println(" Not found.");
        }
    }
    return null;
}
Also used : SettingsSecurity(org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity) File(java.io.File) IOException(java.io.IOException) PlexusCipherException(org.sonatype.plexus.components.cipher.PlexusCipherException) SecDispatcherException(org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException)

Example 3 with SecDispatcherException

use of org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException in project fabric8 by jboss-fuse.

the class MavenSettingsDecrypter method decrypt.

public SettingsDecryptionResult decrypt(SettingsDecryptionRequest request) {
    List<SettingsProblem> problems = new ArrayList<SettingsProblem>();
    List<Server> servers = new ArrayList<Server>();
    for (Server server : request.getServers()) {
        server = server.clone();
        servers.add(server);
        try {
            server.setPassword(decrypt(server.getPassword()));
        } catch (SecDispatcherException e) {
            problems.add(new DefaultSettingsProblem("Failed to decrypt password for server " + server.getId() + ": " + e.getMessage(), Severity.ERROR, "server: " + server.getId(), -1, -1, e));
        }
        try {
            server.setPassphrase(decrypt(server.getPassphrase()));
        } catch (SecDispatcherException e) {
            problems.add(new DefaultSettingsProblem("Failed to decrypt passphrase for server " + server.getId() + ": " + e.getMessage(), Severity.ERROR, "server: " + server.getId(), -1, -1, e));
        }
    }
    List<Proxy> proxies = new ArrayList<Proxy>();
    for (Proxy proxy : request.getProxies()) {
        proxy = proxy.clone();
        proxies.add(proxy);
        try {
            proxy.setPassword(decrypt(proxy.getPassword()));
        } catch (SecDispatcherException e) {
            problems.add(new DefaultSettingsProblem("Failed to decrypt password for proxy " + proxy.getId() + ": " + e.getMessage(), Severity.ERROR, "proxy: " + proxy.getId(), -1, -1, e));
        }
    }
    return new MavenSettingsDecryptionResult(servers, proxies, problems);
}
Also used : DefaultSettingsProblem(org.apache.maven.settings.building.DefaultSettingsProblem) Proxy(org.apache.maven.settings.Proxy) Server(org.apache.maven.settings.Server) ArrayList(java.util.ArrayList) SecDispatcherException(org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException) SettingsProblem(org.apache.maven.settings.building.SettingsProblem) DefaultSettingsProblem(org.apache.maven.settings.building.DefaultSettingsProblem)

Aggregations

SecDispatcherException (org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException)3 PlexusCipherException (org.sonatype.plexus.components.cipher.PlexusCipherException)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Proxy (org.apache.maven.settings.Proxy)1 Server (org.apache.maven.settings.Server)1 DefaultSettingsProblem (org.apache.maven.settings.building.DefaultSettingsProblem)1 SettingsProblem (org.apache.maven.settings.building.SettingsProblem)1 SettingsSecurity (org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity)1