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

The following examples show how to use org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest. 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: 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: GatewayAbstractMojo.java    From apigee-deploy-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Get the proxy configuration from the maven settings
 *
 * @param settings the maven settings
 * @param host     the host name of the apigee edge endpoint
 *
 * @return proxy or null if none was configured or the host was non-proxied
 */
protected Proxy getProxy(final Settings settings, final String host) {

	if (settings == null) {
		return null;
	}

	List<Proxy> proxies = settings.getProxies();

	if (proxies == null || proxies.isEmpty()) {
		return null;
	}

	String protocol = "https";
	String hostname = host;

	// check if protocol is present, if not assume https
	Matcher matcher = URL_PARSE_REGEX.matcher(host);
	if (matcher.matches()) {
		protocol = matcher.group(1);
		hostname = matcher.group(2);
	}

	// search active proxy
	for (Proxy proxy : proxies) {
		if (proxy.isActive() && protocol.equalsIgnoreCase(proxy.getProtocol()) && !matchNonProxy(proxy, hostname)) {
			if (settingsDecrypter != null) {
				return settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(proxy)).getProxy();
			} else {
				getLog().warn("Maven did not inject SettingsDecrypter, " +
						"proxy may contain an encrypted password, which cannot be " +
						"used to setup the REST client.");
				return proxy;
			}
		}
	}
	return null;
}
 
Example #5
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 #6
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 #7
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 #8
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 #9
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 #10
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();
}