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

The following examples show how to use org.apache.maven.settings.crypto.SettingsDecryptionResult. 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: SingerMojo.java    From component-runtime with Apache License 2.0 6 votes vote down vote up
private void doExecute() throws MojoExecutionException {
    try (final JibHelper jibHelper = new JibHelper(getLog(), project.getBuild().getDirectory(),
            layersCacheDirectory, repository, dockerEnvironment, dockerExecutable, laggyPushWorkaround)) {
        jibHelper
                .prepare(project.getArtifactId(), project.getVersion(), project.getProperties(), fromImage, toImage,
                        creationTime, workingDirectory,
                        () -> "/opt/talend/singer/component/" + project.getArtifactId(), environment, labels);

        configure(jibHelper);

        getLog().info("Creating the image (can be long)");

        jibHelper
                .build("Talend Singer Maven Plugin",
                        () -> ofNullable(session.getSettings().getServer(repository))
                                .map(it -> settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(it)))
                                .map(SettingsDecryptionResult::getServer)
                                .orElse(null));

        if (versionProperty != null) {
            jibHelper.setProperties(project, versionProperty);
        }
    } catch (final Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
 
Example #2
Source File: MavenRegistryAuthSupplier.java    From dockerfile-maven with Apache License 2.0 6 votes vote down vote up
private RegistryAuth createRegistryAuth(Server server) throws DockerException {
  SettingsDecryptionRequest decryptionRequest = new DefaultSettingsDecryptionRequest(server);
  SettingsDecryptionResult decryptionResult = settingsDecrypter.decrypt(decryptionRequest);

  if (decryptionResult.getProblems().isEmpty()) {
    log.debug("Successfully decrypted Maven server password");
  } else {
    for (SettingsProblem problem : decryptionResult.getProblems()) {
      log.error("Settings problem for server {}: {}", server.getId(), problem);
    }

    throw new DockerException("Failed to decrypt Maven server password");
  }

  return RegistryAuth.builder()
          .username(server.getUsername())
          .password(decryptionResult.getServer().getPassword())
          .build();
}
 
Example #3
Source File: MavenSettings.java    From spring-init with Apache License 2.0 5 votes vote down vote up
private AuthenticationSelector createAuthenticationSelector(
		SettingsDecryptionResult decryptedSettings) {
	DefaultAuthenticationSelector selector = new DefaultAuthenticationSelector();
	for (Server server : decryptedSettings.getServers()) {
		AuthenticationBuilder auth = new AuthenticationBuilder();
		auth.addUsername(server.getUsername()).addPassword(server.getPassword());
		auth.addPrivateKey(server.getPrivateKey(), server.getPassphrase());
		selector.add(server.getId(), auth.build());
	}
	return new ConservativeAuthenticationSelector(selector);
}
 
Example #4
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 #5
Source File: MavenSettingsReader.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
public MavenSettings readSettings() {
	Settings settings = loadSettings();
	SettingsDecryptionResult decrypted = decryptSettings(settings);
	if (!decrypted.getProblems().isEmpty()) {
		log.error(
				"Maven settings decryption failed. Some Maven repositories may be inaccessible");
		// Continue - the encrypted credentials may not be used
	}
	return new MavenSettings(settings, decrypted);
}
 
Example #6
Source File: MavenSettings.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
private ProxySelector createProxySelector(
		SettingsDecryptionResult decryptedSettings) {
	DefaultProxySelector selector = new DefaultProxySelector();
	for (Proxy proxy : decryptedSettings.getProxies()) {
		Authentication authentication = new AuthenticationBuilder()
				.addUsername(proxy.getUsername()).addPassword(proxy.getPassword())
				.build();
		selector.add(
				new org.eclipse.aether.repository.Proxy(proxy.getProtocol(),
						proxy.getHost(), proxy.getPort(), authentication),
				proxy.getNonProxyHosts());
	}
	return selector;
}
 
Example #7
Source File: MavenSettings.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
private AuthenticationSelector createAuthenticationSelector(
		SettingsDecryptionResult decryptedSettings) {
	DefaultAuthenticationSelector selector = new DefaultAuthenticationSelector();
	for (Server server : decryptedSettings.getServers()) {
		AuthenticationBuilder auth = new AuthenticationBuilder();
		auth.addUsername(server.getUsername()).addPassword(server.getPassword());
		auth.addPrivateKey(server.getPrivateKey(), server.getPassphrase());
		selector.add(server.getId(), auth.build());
	}
	return new ConservativeAuthenticationSelector(selector);
}
 
Example #8
Source File: MavenSettings.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new {@link MavenSettings} instance.
 * @param settings the source settings
 * @param decryptedSettings the decrypted settings
 */
public MavenSettings(Settings settings, SettingsDecryptionResult decryptedSettings) {
	this.offline = settings.isOffline();
	this.mirrorSelector = createMirrorSelector(settings);
	this.authenticationSelector = createAuthenticationSelector(decryptedSettings);
	this.proxySelector = createProxySelector(decryptedSettings);
	this.localRepository = settings.getLocalRepository();
	this.activeProfiles = determineActiveProfiles(settings);
}
 
Example #9
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 #10
Source File: MavenSettingsReader.java    From spring-init with Apache License 2.0 5 votes vote down vote up
public MavenSettings readSettings() {
	Settings settings = loadSettings();
	SettingsDecryptionResult decrypted = decryptSettings(settings);
	if (!decrypted.getProblems().isEmpty()) {
		log.error(
				"Maven settings decryption failed. Some Maven repositories may be inaccessible");
		// Continue - the encrypted credentials may not be used
	}
	return new MavenSettings(settings, decrypted);
}
 
Example #11
Source File: MavenSettings.java    From spring-init with Apache License 2.0 5 votes vote down vote up
private ProxySelector createProxySelector(
		SettingsDecryptionResult decryptedSettings) {
	DefaultProxySelector selector = new DefaultProxySelector();
	for (Proxy proxy : decryptedSettings.getProxies()) {
		Authentication authentication = new AuthenticationBuilder()
				.addUsername(proxy.getUsername()).addPassword(proxy.getPassword())
				.build();
		selector.add(
				new org.eclipse.aether.repository.Proxy(proxy.getProtocol(),
						proxy.getHost(), proxy.getPort(), authentication),
				proxy.getNonProxyHosts());
	}
	return selector;
}
 
Example #12
Source File: MavenSettings.java    From spring-init with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new {@link MavenSettings} instance.
 * @param settings the source settings
 * @param decryptedSettings the decrypted settings
 */
public MavenSettings(Settings settings, SettingsDecryptionResult decryptedSettings) {
	this.offline = settings.isOffline();
	this.mirrorSelector = createMirrorSelector(settings);
	this.authenticationSelector = createAuthenticationSelector(decryptedSettings);
	this.proxySelector = createProxySelector(decryptedSettings);
	this.localRepository = settings.getLocalRepository();
	this.activeProfiles = determineActiveProfiles(settings);
}
 
Example #13
Source File: WebsiteBuilderMojo.java    From component-runtime with Apache License 2.0 4 votes vote down vote up
private void pulishGhPages(final Path root) {
    final Server server = session.getSettings().getServer(githubPagesServerId);
    final Server decryptedServer = ofNullable(server)
            .map(s -> settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(s)))
            .map(SettingsDecryptionResult::getServer)
            .orElse(server);

    final Path gitCloneBase =
            mkdirs(PathFactory.get(project.getBuild().getDirectory()).resolve(UUID.randomUUID().toString()));
    final UsernamePasswordCredentialsProvider credentialsProvider =
            new UsernamePasswordCredentialsProvider(decryptedServer.getUsername(), decryptedServer.getPassword());
    try (final Git git = Git
            .cloneRepository()
            .setCredentialsProvider(credentialsProvider)
            .setURI(githubPagesUrl)
            .setDirectory(gitCloneBase.toFile())
            .setBranchesToClone(singleton(githubPagesBranch))
            .setBranch(githubPagesBranch)
            .call()) {

        // clean up repo
        deleteFolder(gitCloneBase);

        // copy new files
        Files.walkFileTree(root, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
                final String relative = root.relativize(file).toString();
                final Path target = gitCloneBase.resolve(relative);
                mkdirs(target.getParent());
                Files.copy(file, target);
                return super.visitFile(file, attrs);
            }
        });

        final String message =
                "Updating the website with version " + project.getVersion() + " // " + new Date().toString();
        git.add().addFilepattern(".").call();
        git.commit().setAll(true).setMessage(message).call();
        git.status().call();
        git.push().setCredentialsProvider(credentialsProvider).add(githubPagesBranch).call();
        getLog().info("Updated the website on " + ZonedDateTime.now());
    } catch (final GitAPIException | IOException e) {
        throw new IllegalStateException(e);
    }
}
 
Example #14
Source File: MavenSettingsReader.java    From spring-init with Apache License 2.0 4 votes vote down vote up
private SettingsDecryptionResult decryptSettings(Settings settings) {
	DefaultSettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(
			settings);

	return createSettingsDecrypter().decrypt(request);
}
 
Example #15
Source File: MavenSettingsReader.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
private SettingsDecryptionResult decryptSettings(Settings settings) {
	DefaultSettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(
			settings);

	return createSettingsDecrypter().decrypt(request);
}
 
Example #16
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 #17
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();
}