Search in sources :

Example 1 with PlexusCipherException

use of org.sonatype.plexus.components.cipher.PlexusCipherException 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 PlexusCipherException

use of org.sonatype.plexus.components.cipher.PlexusCipherException 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)

Aggregations

PlexusCipherException (org.sonatype.plexus.components.cipher.PlexusCipherException)2 SecDispatcherException (org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException)2 File (java.io.File)1 IOException (java.io.IOException)1 SettingsSecurity (org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity)1