org.apache.maven.settings.crypto.SettingsDecrypter Java Examples

The following examples show how to use org.apache.maven.settings.crypto.SettingsDecrypter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MojoUtils.java    From frontend-maven-plugin with Apache License 2.0 6 votes vote down vote up
static ProxyConfig getProxyConfig(MavenSession mavenSession, SettingsDecrypter decrypter) {
    if (mavenSession == null ||
            mavenSession.getSettings() == null ||
            mavenSession.getSettings().getProxies() == null ||
            mavenSession.getSettings().getProxies().isEmpty()) {
        return new ProxyConfig(Collections.<ProxyConfig.Proxy>emptyList());
    } else {
        final List<Proxy> mavenProxies = mavenSession.getSettings().getProxies();

        final List<ProxyConfig.Proxy> proxies = new ArrayList<ProxyConfig.Proxy>(mavenProxies.size());

        for (Proxy mavenProxy : mavenProxies) {
            if (mavenProxy.isActive()) {
                mavenProxy = decryptProxy(mavenProxy, decrypter);
                proxies.add(new ProxyConfig.Proxy(mavenProxy.getId(), mavenProxy.getProtocol(), mavenProxy.getHost(),
                        mavenProxy.getPort(), mavenProxy.getUsername(), mavenProxy.getPassword(), mavenProxy.getNonProxyHosts()));
            }
        }

        LOGGER.info("Found proxies: {}", proxies);
        return new ProxyConfig(proxies);
    }
}
 
Example #2
Source File: MojoUtils.java    From wisdom with Apache License 2.0 6 votes vote down vote up
public static ProxyConfig getProxyConfig(MavenSession mavenSession, SettingsDecrypter decrypter) {
    if (mavenSession == null ||
            mavenSession.getSettings() == null ||
            mavenSession.getSettings().getProxies() == null ||
            mavenSession.getSettings().getProxies().isEmpty()) {
        return new ProxyConfig(Collections.<ProxyConfig.Proxy>emptyList());
    } else {
        final List<Proxy> mavenProxies = mavenSession.getSettings().getProxies();

        final List<ProxyConfig.Proxy> proxies = new ArrayList<>(mavenProxies.size());

        for (Proxy mavenProxy : mavenProxies) {
            if (mavenProxy.isActive()) {
                mavenProxy = decryptProxy(mavenProxy, decrypter);
                proxies.add(new ProxyConfig.Proxy(mavenProxy.getId(), mavenProxy.getProtocol(), mavenProxy.getHost(),
                        mavenProxy.getPort(), mavenProxy.getUsername(), mavenProxy.getPassword(), mavenProxy.getNonProxyHosts()));
            }
        }

        return new ProxyConfig(proxies);
    }
}
 
Example #3
Source File: CatalogRepoProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public List<Archetype> getArchetypes() {
    File root = Places.getCacheSubdirectory("mavenarchetypes"); //NOI18N
    ArrayList<Archetype> toRet = new ArrayList<Archetype>();
    MavenEmbedder embedder = EmbedderFactory.getOnlineEmbedder();
    SettingsDecryptionResult settings = embedder.lookupComponent(SettingsDecrypter.class).decrypt(new DefaultSettingsDecryptionRequest(embedder.getSettings()));
    
    for (RepositoryInfo info : RepositoryPreferences.getInstance().getRepositoryInfos()) {
        if (info.isRemoteDownloadable()) {
            File catalog = new File(new File( root, info.getId()), "archetype-catalog.xml"); //NOI18N
            boolean download = false;
            if (!catalog.exists()) {
                download = true;
            } else {
                long lastM = catalog.lastModified();
                if (lastM == 0) {
                    download = true;
                } else if (lastM - System.currentTimeMillis() > ARCHETYPE_TIMEOUT) {
                    download = true;
                }
            }
            
            if (download) {
                download(info.getId(), info.getRepositoryUrl(), catalog, settings, embedder);
            }
            
            if (catalog.exists()) {
                try {
                    toRet.addAll(CatalogRepoProvider.getArchetypes(Utilities.toURI(catalog).toURL(), info.getRepositoryUrl()));
                } catch (MalformedURLException ex) {
                    LOG.log(Level.INFO, null, ex);
                }
            }
        }
    }
    
    return toRet;
}
 
Example #4
Source File: MavenEmbedder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
MavenEmbedder(EmbedderConfiguration configuration) throws ComponentLookupException {
    embedderConfiguration = configuration;
    plexus = configuration.getContainer();
    this.maven = (DefaultMaven) plexus.lookup(Maven.class);
    this.projectBuilder = plexus.lookup(ProjectBuilder.class);
    this.repositorySystem = plexus.lookup(RepositorySystem.class);
    this.settingsBuilder = plexus.lookup(SettingsBuilder.class);
    this.populator = plexus.lookup(MavenExecutionRequestPopulator.class);
    settingsDecrypter = plexus.lookup(SettingsDecrypter.class);
}
 
Example #5
Source File: GatewayAbstractMojo.java    From apigee-deploy-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void contextualize(Context context) throws ContextException {
	container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
	if (container.hasComponent(SettingsDecrypter.class)) {
		try {
			settingsDecrypter = container.lookup(SettingsDecrypter.class);
		} catch (ComponentLookupException e) {
			getLog().warn("Failed to lookup build in maven component session decrypter.", e);
		}
	}
}
 
Example #6
Source File: MojoUtils.java    From frontend-maven-plugin with Apache License 2.0 5 votes vote down vote up
static Server decryptServer(String serverId, MavenSession mavenSession, SettingsDecrypter decrypter) {
    if (StringUtils.isEmpty(serverId)) {
        return null;
    }
    Server server = mavenSession.getSettings().getServer(serverId);
    if (server != null) {
        final DefaultSettingsDecryptionRequest decryptionRequest = new DefaultSettingsDecryptionRequest(server);
        SettingsDecryptionResult decryptedResult = decrypter.decrypt(decryptionRequest);
        return decryptedResult.getServer();
    } else {
        LOGGER.warn("Could not find server '" + serverId + "' in settings.xml");
        return null;
    }
}
 
Example #7
Source File: MavenSettingsReader.java    From spring-init with Apache License 2.0 4 votes vote down vote up
private SettingsDecrypter createSettingsDecrypter() {
	SettingsDecrypter settingsDecrypter = new DefaultSettingsDecrypter();
	setField(DefaultSettingsDecrypter.class, "securityDispatcher", settingsDecrypter,
			new SpringBootSecDispatcher());
	return settingsDecrypter;
}
 
Example #8
Source File: MavenRegistryAuthSupplier.java    From dockerfile-maven with Apache License 2.0 4 votes vote down vote up
public MavenRegistryAuthSupplier(final Settings settings,
                                 final SettingsDecrypter settingsDecrypter) {
  this.settings = settings;
  this.settingsDecrypter = settingsDecrypter;
}
 
Example #9
Source File: MavenSettingsReader.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
private SettingsDecrypter createSettingsDecrypter() {
	SettingsDecrypter settingsDecrypter = new DefaultSettingsDecrypter();
	setField(DefaultSettingsDecrypter.class, "securityDispatcher", settingsDecrypter,
			new SpringBootSecDispatcher());
	return settingsDecrypter;
}
 
Example #10
Source File: MojoUtils.java    From frontend-maven-plugin with Apache License 2.0 4 votes vote down vote up
private static Proxy decryptProxy(Proxy proxy, SettingsDecrypter decrypter) {
    final DefaultSettingsDecryptionRequest decryptionRequest = new DefaultSettingsDecryptionRequest(proxy);
    SettingsDecryptionResult decryptedResult = decrypter.decrypt(decryptionRequest);
    return decryptedResult.getProxy();
}
 
Example #11
Source File: MojoUtils.java    From wisdom with Apache License 2.0 4 votes vote down vote up
private static Proxy decryptProxy(Proxy proxy, SettingsDecrypter decrypter) {
    final DefaultSettingsDecryptionRequest decryptionRequest =
            new DefaultSettingsDecryptionRequest(proxy);
    SettingsDecryptionResult decryptedResult = decrypter.decrypt(decryptionRequest);
    return decryptedResult.getProxy();
}