List of usage examples for org.apache.maven.settings.crypto SettingsDecryptionResult getServers
List<Server> getServers();
From source file:capsule.UserSettings.java
License:Open Source License
private UserSettings() { final DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); request.setUserSettingsFile(DEFAULT_LOCAL_MAVEN.resolve(SETTINGS_XML).toFile()); request.setGlobalSettingsFile(/* ww w . j a v a2 s . co m*/ MAVEN_HOME != null ? MAVEN_HOME.resolve("conf").resolve(SETTINGS_XML).toFile() : null); request.setSystemProperties(getSystemProperties()); try { this.settings = new DefaultSettingsBuilderFactory().newInstance().build(request).getEffectiveSettings(); final SettingsDecryptionResult result = newDefaultSettingsDecrypter() .decrypt(new DefaultSettingsDecryptionRequest(settings)); settings.setServers(result.getServers()); settings.setProxies(result.getProxies()); } catch (SettingsBuildingException e) { throw new RuntimeException(e); } }
From source file:com.isomorphic.maven.mojo.DeployMojo.java
License:Apache License
/** * Decrypt settings and return the server element with the given id. Useful for e.g., reading encrypted * user credentials.//w w w .j av a 2s .c o m * * @param id the id of the server to be decrypted * @return a Server with its protected elements decrypted, if one is found with the given id. Null otherwise. * * @see http://maven.apache.org/guides/mini/guide-encryption.html */ private Server getDecryptedServer(String id) { final SettingsDecryptionRequest settingsDecryptionRequest = new DefaultSettingsDecryptionRequest(); settingsDecryptionRequest.setServers(settings.getServers()); final SettingsDecryptionResult decrypt = settingsDecrypter.decrypt(settingsDecryptionRequest); List<Server> servers = decrypt.getServers(); for (Server server : servers) { if (server.getId().equals(id)) { return server; } } return null; }
From source file:com.mycila.maven.plugin.license.AbstractLicenseMojo.java
License:Apache License
/** * Returns the list of servers with decrypted passwords. * * @return list of servers with decrypted passwords. *///from w w w . j a v a 2 s.c o m List<Server> getDecryptedServers() { final SettingsDecryptionRequest settingsDecryptionRequest = new DefaultSettingsDecryptionRequest(); settingsDecryptionRequest.setServers(settings.getServers()); final SettingsDecryptionResult decrypt = settingsDecrypter.decrypt(settingsDecryptionRequest); return decrypt.getServers(); }
From source file:com.sap.research.maven.plugin.nwcloud.NWCloudGetPwd.java
License:Apache License
/** * Returns List of Server objects defined by Maven settings having the passwords decrypted. * @return List of Servers with decrypted passwords. *///from w w w.ja va2 s . c o m private List<Server> getDecryptedServers() { List<Server> result = null; if (settings != null) { result = settings.getServers(); if (result != null) { if (settingsDecrypter != null) { SettingsDecryptionRequest settingsDecryptionRequest = new DefaultSettingsDecryptionRequest(); settingsDecryptionRequest.setServers(result); SettingsDecryptionResult decrypt = settingsDecrypter.decrypt(settingsDecryptionRequest); result = decrypt.getServers(); } else { getLog().info( "Cannot decrypt the server settings as the SettingsDecrypter provided by Maven is null."); } } else { getLog().info("Servers defined in Maven settings are null."); } } else { getLog().info("Maven settings are null."); } return result; }
From source file:io.fabric8.maven.url.internal.AetherBasedResolver.java
License:Apache License
private void decryptSettings() { SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(m_settings); SettingsDecryptionResult result = decrypter.decrypt(request); m_settings.setProxies(result.getProxies()); m_settings.setServers(result.getServers()); }
From source file:io.fabric8.maven.util.MavenUtils.java
License:Apache License
public static synchronized Settings getSettings() { Settings settings = null;/*from w ww . j a v a 2 s.c o m*/ DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); File userSettingsFile = safeGetFile(USER_SETTINGS_FILE); File globalMavenSettingsFile = safeGetFile(GLOBAL_MAVEN_SETTINGS_FILE); if (globalMavenSettingsFile == null) { globalMavenSettingsFile = safeGetFile(GLOBAL_M2_SETTINGS_FILE); } if (userSettingsFile != null) { request.setUserSettingsFile(userSettingsFile); } if (globalMavenSettingsFile != null) { request.setGlobalSettingsFile(globalMavenSettingsFile); } request.setSystemProperties(System.getProperties()); try { settings = settingsBuilder.build(request).getEffectiveSettings(); } catch (SettingsBuildingException e) { LOGGER.warn("Could not process settings.xml: ", e); } try { SettingsDecrypter settingsDecrypter = createSettingsDecrypter(); SettingsDecryptionResult result = settingsDecrypter .decrypt(new DefaultSettingsDecryptionRequest(settings)); settings.setServers(result.getServers()); settings.setProxies(result.getProxies()); } catch (Exception ex) { LOGGER.warn("Failed to decrypt maven settings.", ex); } return settings; }
From source file:org.apache.karaf.maven.command.MavenConfigurationSupport.java
License:Apache License
/** * <p>Decrypts passwords inside correctly read <code>settings.xml</code>. Also tries to decrypt master password.</p> * <p>Not called implicitly for each action invocation.</p> *///from www.ja v a2s . co m private void decryptSettings() throws Exception { if (mavenSecuritySettings != null && mavenSettings != null) { masterPassword = cipher.decryptDecorated(mavenSecuritySettings.getMaster(), masterMasterPassword); DefaultSecDispatcher dispatcher = new DefaultSecDispatcher(); DefaultSettingsDecrypter decrypter = new DefaultSettingsDecrypter(); try { dispatcher.setConfigurationFile(securitySettings.value.getAbsolutePath()); Field f = dispatcher.getClass().getDeclaredField("_cipher"); f.setAccessible(true); f.set(dispatcher, cipher); f = decrypter.getClass().getDeclaredField("securityDispatcher"); f.setAccessible(true); f.set(decrypter, dispatcher); DefaultSettingsDecryptionRequest req = new DefaultSettingsDecryptionRequest(mavenSettings); SettingsDecryptionResult res = decrypter.decrypt(req); if (res.getProblems() != null && res.getProblems().size() > 0) { for (SettingsProblem sp : res.getProblems()) { System.err.println(sp); } } for (Proxy proxy : res.getProxies()) { if (!cipher.isEncryptedString(proxy.getPassword())) { proxyPasswords.put(proxy.getId(), proxy.getPassword()); } } for (Server server : res.getServers()) { if (!cipher.isEncryptedString(server.getPassword())) { serverPasswords.put(server.getId(), server.getPassword()); } } } catch (Throwable t) { LOG.warn("Can't decrypt " + securitySettings.value, t); } } }
From source file:org.debian.dependency.sources.SCMSourceRetrieval.java
License:Apache License
@Override public String retrieveSource(final Artifact artifact, final File directory, final MavenSession session) throws SourceRetrievalException { MavenProject project = findProjectRoot(constructProject(artifact, session)); Scm scm = project.getScm();/*from ww w. j av a 2 s. com*/ if (scm == null) { return null; } SettingsDecryptionResult decryptionResult = settingsDecrypter .decrypt(new DefaultSettingsDecryptionRequest(session.getSettings())); for (SettingsProblem problem : decryptionResult.getProblems()) { getLogger().warn("Error decrypting settings (" + problem.getLocation() + ") : " + problem.getMessage(), problem.getException()); } try { // first we check developer connection CheckOutScmResult checkoutResult = null; String connection = scm.getDeveloperConnection(); try { checkoutResult = performCheckout(connection, determineVersion(scm), directory, decryptionResult.getServers()); } catch (ScmException e) { // we don't really care about the exception here because we will try the regular connection next getLogger().debug( "Unable to checkout sources using developer connection, trying standard connection", e); } // now the regular connection if it wasn't successful if (checkoutResult == null || !checkoutResult.isSuccess()) { connection = scm.getConnection(); checkoutResult = performCheckout(connection, determineVersion(scm), directory, decryptionResult.getServers()); } if (checkoutResult == null) { throw new SourceRetrievalException("No scm information available"); } else if (!checkoutResult.isSuccess()) { getLogger().error("Provider Message:"); getLogger().error(StringUtils.defaultString(checkoutResult.getProviderMessage())); getLogger().error("Commandline:"); getLogger().error(StringUtils.defaultString(checkoutResult.getCommandOutput())); throw new SourceRetrievalException("Unable to checkout files: " + StringUtils.defaultString(checkoutResult.getProviderMessage())); } return connection; } catch (ScmException e) { throw new SourceRetrievalException("Unable to checkout project", e); } }
From source file:org.eclipse.aether.ant.AntRepoSys.java
License:Open Source License
private synchronized Settings getSettings() { if (settings == null) { DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest(); request.setUserSettingsFile(getUserSettings()); request.setGlobalSettingsFile(getGlobalSettings()); request.setSystemProperties(getSystemProperties()); request.setUserProperties(getUserProperties()); try {/* ww w. ja v a2 s .co m*/ settings = settingsBuilder.build(request).getEffectiveSettings(); } catch (SettingsBuildingException e) { project.log("Could not process settings.xml: " + e.getMessage(), e, Project.MSG_WARN); } SettingsDecryptionResult result = settingsDecrypter .decrypt(new DefaultSettingsDecryptionRequest(settings)); settings.setServers(result.getServers()); settings.setProxies(result.getProxies()); } return settings; }
From source file:org.jboss.shrinkwrap.resolver.impl.maven.bootstrap.MavenSettingsBuilder.java
License:Apache License
private Settings decryptPasswords(Settings settings) { File securitySettings = new File(DEFAULT_SETTINGS_SECURITY_PATH); String altSecuritySettings = SecurityActions.getProperty(ALT_SECURITY_SETTINGS_XML_LOCATION); String altSecuritySettingsDeprecated = SecurityActions .getProperty(ALT_SECURITY_SETTINGS_XML_LOCATION_DEPRECATED); // set alternate file if (altSecuritySettingsDeprecated != null && altSecuritySettingsDeprecated.length() > 0) { log.log(Level.WARNING,//from w w w .j av a 2 s . c o m "Maven settings-security.xml location ({0}) set via deprecated property \"{1}\", please use \"{2}\" instead", new Object[] { altSecuritySettingsDeprecated, ALT_SECURITY_SETTINGS_XML_LOCATION_DEPRECATED, ALT_SECURITY_SETTINGS_XML_LOCATION }); securitySettings = new File(altSecuritySettingsDeprecated); } // set alternate file if (altSecuritySettings != null && altSecuritySettings.length() > 0) { securitySettings = new File(altSecuritySettings); } SettingsDecrypter decrypter = new MavenSettingsDecrypter(securitySettings); SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(settings); SettingsDecryptionResult result = decrypter.decrypt(request); if (result.getProblems().size() > 0) { StringBuilder sb = new StringBuilder("Found ").append(result.getProblems().size()) .append(" problems while trying to decrypt settings configuration."); int counter = 1; for (SettingsProblem problem : result.getProblems()) { sb.append(counter++).append("/ ").append(problem).append("\n"); } throw new InvalidConfigurationFileException(sb.toString()); } settings.setProxies(result.getProxies()); settings.setServers(result.getServers()); return settings; }