org.apache.maven.settings.Server Java Examples
The following examples show how to use
org.apache.maven.settings.Server.
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: SqlExecMojoTest.java From sql-maven-plugin with Apache License 2.0 | 6 votes |
public void test002DefaultUsernamePassword() throws MojoExecutionException { Settings settings = new Settings(); Server server = new Server(); settings.addServer( server ); mojo.setSettings( settings ); // force a lookup of username mojo.setUsername( null ); mojo.setPassword( null ); mojo.execute(); assertEquals( "", mojo.getUsername() ); assertEquals( "", mojo.getPassword() ); }
Example #2
Source File: SqlExecMojoTest.java From sql-maven-plugin with Apache License 2.0 | 6 votes |
public void test003UsernamePasswordLookup() throws MojoExecutionException { Settings settings = new Settings(); Server server = new Server(); server.setId( "somekey" ); server.setUsername( "username" ); server.setPassword( "password" ); settings.addServer( server ); mojo.setSettings( settings ); // force a lookup of username mojo.setSettingsKey( "somekey" ); mojo.setUsername( null ); mojo.setPassword( null ); mojo.execute(); assertEquals( "username", mojo.getUsername() ); assertEquals( "password", mojo.getPassword() ); }
Example #3
Source File: InstallNodeAndYarnMojo.java From frontend-maven-plugin with Apache License 2.0 | 6 votes |
@Override public void execute(FrontendPluginFactory factory) throws InstallationException { ProxyConfig proxyConfig = MojoUtils.getProxyConfig(this.session, this.decrypter); Server server = MojoUtils.decryptServer(this.serverId, this.session, this.decrypter); if (null != server) { factory.getNodeInstaller(proxyConfig).setNodeDownloadRoot(this.nodeDownloadRoot) .setNodeVersion(this.nodeVersion).setPassword(server.getPassword()) .setUserName(server.getUsername()).install(); factory.getYarnInstaller(proxyConfig).setYarnDownloadRoot(this.yarnDownloadRoot) .setYarnVersion(this.yarnVersion).setUserName(server.getUsername()) .setPassword(server.getPassword()).install(); } else { factory.getNodeInstaller(proxyConfig).setNodeDownloadRoot(this.nodeDownloadRoot) .setNodeVersion(this.nodeVersion).install(); factory.getYarnInstaller(proxyConfig).setYarnDownloadRoot(this.yarnDownloadRoot) .setYarnVersion(this.yarnVersion).install(); } }
Example #4
Source File: AbstractScmMojo.java From buildnumber-maven-plugin with MIT License | 6 votes |
/** * Load username password from settings. */ private void loadInfosFromSettings( ScmProviderRepositoryWithHost repo ) { if ( username == null || password == null ) { String host = repo.getHost(); int port = repo.getPort(); if ( port > 0 ) { host += ":" + port; } Server server = this.settings.getServer( host ); if ( server != null ) { setPasswordIfNotEmpty( repo, decrypt( server.getPassword(), host ) ); setUserIfNotEmpty( repo, server.getUsername() ); } } }
Example #5
Source File: JibHelper.java From component-runtime with Apache License 2.0 | 6 votes |
public void build(final String toolName, final Supplier<Server> credentialsSupplier) throws InvalidImageReferenceException, InterruptedException, ExecutionException, IOException, CacheDirectoryCreationException, RegistryException, MojoExecutionException { if (builder == null) { throw new IllegalStateException("prepare had not been called"); } if (repository != null) { // push final Server credentials = credentialsSupplier.get(); if (laggyPushWorkaround > 0) { toLocalDocker(executor, builder, tag, imageName, toolName); hackyPush(tag, repository, imageName, credentials); } else { final RegistryImage registryImage = RegistryImage.named(imageName); if (credentials != null) { registryImage.addCredential(credentials.getUsername(), credentials.getPassword()); } builder .containerize(configureContainer(Containerizer.to(registryImage), executor, "Talend Singer Maven Plugin")); log.info("Pushed image='" + imageName + "', tag='" + tag + "'"); } } else { toLocalDocker(executor, builder, tag, imageName, toolName); } }
Example #6
Source File: JDOMSettingsConverter.java From pom-manipulation-ext with Apache License 2.0 | 6 votes |
/** * Method updateServer. * @param server * @param counter * @param element */ protected void updateServer( final Server server, final IndentationCounter counter, final Element element ) { final IndentationCounter innerCount = new IndentationCounter( counter.getDepth() + 1 ); findAndReplaceSimpleElement( innerCount, element, "username", server.getUsername(), null ); findAndReplaceSimpleElement( innerCount, element, "password", server.getPassword(), null ); findAndReplaceSimpleElement( innerCount, element, "privateKey", server.getPrivateKey(), null ); findAndReplaceSimpleElement( innerCount, element, "passphrase", server.getPassphrase(), null ); findAndReplaceSimpleElement( innerCount, element, "filePermissions", server.getFilePermissions(), null ); findAndReplaceSimpleElement( innerCount, element, "directoryPermissions", server.getDirectoryPermissions(), null ); findAndReplaceXpp3DOM( innerCount, element, "configuration", (Xpp3Dom) server.getConfiguration() ); findAndReplaceSimpleElement( innerCount, element, "id", server.getId(), "default" ); }
Example #7
Source File: AuthConfigFactory.java From docker-maven-plugin with Apache License 2.0 | 6 votes |
private AuthConfig getAuthConfigFromSettings(Settings settings, String user, String registry) throws MojoExecutionException { Server defaultServer = null; Server found; for (Server server : settings.getServers()) { String id = server.getId(); // Remember a default server without user as fallback for later if (defaultServer == null) { defaultServer = checkForServer(server, id, registry, null); } // Check for specific server with user part found = checkForServer(server, id, registry, user); if (found != null) { return createAuthConfigFromServer(found); } } return defaultServer != null ? createAuthConfigFromServer(defaultServer) : null; }
Example #8
Source File: RemoteExistsMojo.java From exists-maven-plugin with Apache License 2.0 | 6 votes |
AuthenticationInfo getAuthInfo(String serverId) throws SecDispatcherException { Server server = settings.getServer(serverId); if (server == null) { return null; } /* begin https://github.com/chonton/exists-maven-plugin/issues/22 */ if (securityDispatcher instanceof DefaultSecDispatcher) { ((DefaultSecDispatcher) securityDispatcher) .setConfigurationFile("~/.m2/settings-security.xml"); } /* end https://github.com/chonton/exists-maven-plugin/issues/22 */ AuthenticationInfo authInfo = new AuthenticationInfo(); authInfo.setUserName(server.getUsername()); authInfo.setPassword(securityDispatcher.decrypt(server.getPassword())); authInfo.setPassphrase(server.getPassphrase()); authInfo.setPrivateKey(server.getPrivateKey()); return authInfo; }
Example #9
Source File: UploadMojoTest.java From helm-maven-plugin with MIT License | 6 votes |
@Test public void uploadToArtifactoryWithPlainCredentialsFromSettings(UploadMojo mojo) throws IOException, MojoExecutionException { final Server server = new Server(); server.setId("my-artifactory"); server.setUsername("foo"); server.setPassword("bar"); final List<Server> servers = new ArrayList<>(); servers.add(server); mojo.getSettings().setServers(servers); final HelmRepository helmRepo = new HelmRepository(); helmRepo.setType(RepoType.ARTIFACTORY); helmRepo.setName("my-artifactory"); helmRepo.setUrl("https://somwhere.com/repo"); mojo.setUploadRepoStable(helmRepo); final URL resource = this.getClass().getResource("app-0.1.0.tgz"); final File fileToUpload = new File(resource.getFile()); final List<String> tgzs = new ArrayList<>(); tgzs.add(resource.getFile()); doReturn(helmRepo).when(mojo).getHelmUploadRepo(); doReturn(tgzs).when(mojo).getChartTgzs(anyString()); assertNotNull(mojo.getConnectionForUploadToArtifactory(fileToUpload)); }
Example #10
Source File: MavenRegistryAuthSupplier.java From dockerfile-maven with Apache License 2.0 | 6 votes |
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 #11
Source File: AbstractDockerMojo.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
/** * Builds the registryAuth object from server details. * @return {@link RegistryAuth} * @throws MojoExecutionException */ protected RegistryAuth registryAuth() throws MojoExecutionException { if (settings != null && serverId != null) { final Server server = settings.getServer(serverId); if (server != null) { final RegistryAuth.Builder registryAuthBuilder = RegistryAuth.builder(); final String username = server.getUsername(); String password = server.getPassword(); if (secDispatcher != null) { try { password = secDispatcher.decrypt(password); } catch (SecDispatcherException ex) { throw new MojoExecutionException("Cannot decrypt password from settings", ex); } } final String email = getEmail(server); if (!isNullOrEmpty(username)) { registryAuthBuilder.username(username); } if (!isNullOrEmpty(email)) { registryAuthBuilder.email(email); } if (!isNullOrEmpty(password)) { registryAuthBuilder.password(password); } if (!isNullOrEmpty(registryUrl)) { registryAuthBuilder.serverAddress(registryUrl); } return registryAuthBuilder.build(); } else { // settings.xml has no entry for the configured serverId, warn the user getLog().warn("No entry found in settings.xml for serverId=" + serverId + ", cannot configure authentication for that registry"); } } return null; }
Example #12
Source File: AbstractDockerMojo.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
private Optional<Credentials> getCredentialsFromSettings() { if(settings == null) { getLog().debug("No settings.xml"); return empty(); } Server server = settings.getServer(serverId); if(server == null) { getLog().debug("Cannot find server " + serverId + " in Maven settings"); return empty(); } getLog().debug("Using credentials from Maven settings: " + server.getUsername()); return of(new Credentials(server.getUsername(), server.getPassword(), getEmail(server), null)); }
Example #13
Source File: AuthConfigFactory.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
private Server checkForServer(Server server, String id, String registry, String user) { String[] registries = registry != null ? new String[] { registry } : DEFAULT_REGISTRIES; for (String reg : registries) { if (id.equals(user == null ? reg : reg + "/" + user)) { return server; } } return null; }
Example #14
Source File: AuthConfigFactory.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
private AuthConfig createAuthConfigFromServer(Server server) throws MojoExecutionException { return new AuthConfig( server.getUsername(), decrypt(server.getPassword()), extractFromServerConfiguration(server.getConfiguration(), AuthConfig.AUTH_EMAIL), extractFromServerConfiguration(server.getConfiguration(), AuthConfig.AUTH_AUTH) ); }
Example #15
Source File: AuthConfigFactoryTest.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
private void setupServers() { new Expectations() {{ List<Server> servers = new ArrayList<>(); servers.add(create(ECR_NAME, "roland", "secret", "[email protected]")); servers.add(create("test.org", "fabric8io", "secret2", "[email protected]")); servers.add(create("test.org/roland", "roland", "secret", "[email protected]")); servers.add(create("docker.io", "tanja", "doublesecret", "[email protected]")); servers.add(create("another.repo.org/joe", "joe", "3secret", "[email protected]")); settings.getServers(); result = servers; } private Server create(String id, String user, String password, String email) { Server server = new Server(); server.setId(id); server.setUsername(user); server.setPassword(password); Xpp3Dom dom = new Xpp3Dom("configuration"); Xpp3Dom emailD = new Xpp3Dom("email"); emailD.setValue(email); dom.addChild(emailD); server.setConfiguration(dom); return server; } }; }
Example #16
Source File: ConfigurationHelper.java From LicenseScout with Apache License 2.0 | 5 votes |
/** * Converts Maven database configuration to execution database configuration. * * <p>This resolves the server definition given by ID from the settings and takes the DB connection * credentials from there.</p> * * @param databaseConfiguration * @param settings the settings.xml object * @param log the logger * @return a database configuration for the execution engine * @throws MojoExecutionException if the server ID is not found in settings, or username or password are not specified in the server definition */ public static ExecutionDatabaseConfiguration getExecutionDatabaseConfiguration(final DatabaseConfiguration databaseConfiguration, final Settings settings, final ILSLog log) throws MojoExecutionException { if (databaseConfiguration == null) { return null; } final ExecutionDatabaseConfiguration executionDatabaseConfiguration = new ExecutionDatabaseConfiguration(); executionDatabaseConfiguration.setJdbcUrl(databaseConfiguration.getJdbcUrl()); final String serverId = databaseConfiguration.getServerId(); log.info("Resolving database server ID: " + serverId); final Server server = settings.getServer(serverId); if (server == null) { throw new MojoExecutionException( String.format("No definition found for server ID %s in settings.xml", serverId)); } final String username = server.getUsername(); final String password = server.getPassword(); if (username == null) { throw new MojoExecutionException( String.format("No username defined in server specification with ID %s in settings.xml", serverId)); } if (password == null) { throw new MojoExecutionException( String.format("No password defined in server specification with ID %s in settings.xml", serverId)); } executionDatabaseConfiguration.setUsername(username); executionDatabaseConfiguration.setPassword(password); return executionDatabaseConfiguration; }
Example #17
Source File: SettingsStub.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
public SettingsStub() { super(); final Server server = new Server(); server.setId("docker-hub"); server.setUsername("dxia3"); // plaintext value is: SxpxdUQA2mvX7oj server.setPassword("{gc4QPLrlgPwHZjAhPw8JPuGzaPitzuyjeBojwCz88j4=}"); final Xpp3Dom configuration = new Xpp3Dom("configuration"); final Xpp3Dom email = new Xpp3Dom("email"); email.setValue("[email protected]"); configuration.addChild(email); server.setConfiguration(configuration); addServer(server); }
Example #18
Source File: AbstractDockerMojoTest.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
private Server mockServer() { final Server server = new Server(); server.setUsername(USERNAME); server.setPassword(PASSWORD); final Xpp3Dom email = new Xpp3Dom(EMAIL_PROPERTY); email.setValue(EMAIL); final Xpp3Dom configuration = new Xpp3Dom(CONFIGURATION_PROPERTY); configuration.addChild(email); server.setConfiguration(configuration); return server; }
Example #19
Source File: MojoUtils.java From frontend-maven-plugin with Apache License 2.0 | 5 votes |
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 #20
Source File: InstallNodeAndNpmMojo.java From frontend-maven-plugin with Apache License 2.0 | 5 votes |
@Override public void execute(FrontendPluginFactory factory) throws InstallationException { ProxyConfig proxyConfig = MojoUtils.getProxyConfig(session, decrypter); String nodeDownloadRoot = getNodeDownloadRoot(); String npmDownloadRoot = getNpmDownloadRoot(); Server server = MojoUtils.decryptServer(serverId, session, decrypter); if (null != server) { factory.getNodeInstaller(proxyConfig) .setNodeVersion(nodeVersion) .setNodeDownloadRoot(nodeDownloadRoot) .setNpmVersion(npmVersion) .setUserName(server.getUsername()) .setPassword(server.getPassword()) .install(); factory.getNPMInstaller(proxyConfig) .setNodeVersion(nodeVersion) .setNpmVersion(npmVersion) .setNpmDownloadRoot(npmDownloadRoot) .setUserName(server.getUsername()) .setPassword(server.getPassword()) .install(); } else { factory.getNodeInstaller(proxyConfig) .setNodeVersion(nodeVersion) .setNodeDownloadRoot(nodeDownloadRoot) .setNpmVersion(npmVersion) .install(); factory.getNPMInstaller(proxyConfig) .setNodeVersion(this.nodeVersion) .setNpmVersion(this.npmVersion) .setNpmDownloadRoot(npmDownloadRoot) .install(); } }
Example #21
Source File: MavenContainer.java From furnace with Eclipse Public License 1.0 | 5 votes |
private LazyAuthenticationSelector createAuthSelector(final Settings settings, final DefaultMirrorSelector mirrorSelector) { LazyAuthenticationSelector authSelector = new LazyAuthenticationSelector(mirrorSelector); for (Server server : settings.getServers()) { authSelector.add( server.getId(), new AuthenticationBuilder().addUsername(server.getUsername()).addPassword(server.getPassword()) .addPrivateKey(server.getPrivateKey(), server.getPassphrase()).build()); } return authSelector; }
Example #22
Source File: BasicSupport.java From ci.maven with Apache License 2.0 | 5 votes |
protected void installFromArchive() throws Exception { InstallLibertyTask installTask = (InstallLibertyTask) ant.createTask("antlib:io/openliberty/tools/ant:install-liberty"); if (installTask == null) { throw new IllegalStateException(MessageFormat.format(messages.getString("error.dependencies.not.found"), "install-liberty")); } installTask.setBaseDir(assemblyInstallDirectory.getAbsolutePath()); installTask.setLicenseCode(install.getLicenseCode()); installTask.setVersion(install.getVersion()); installTask.setRuntimeUrl(install.getRuntimeUrl()); installTask.setVerbose(install.isVerbose()); installTask.setMaxDownloadTime(install.getMaxDownloadTime()); installTask.setType(install.getType()); installTask.setOffline(settings.isOffline()); installTask.setUseOpenLiberty(useOpenLiberty); String cacheDir = install.getCacheDirectory(); if (cacheDir == null) { File dir = new File(artifactRepository.getBasedir(), "wlp-cache"); installTask.setCacheDir(dir.getAbsolutePath()); } else { installTask.setCacheDir(cacheDir); } String serverId = install.getServerId(); if (serverId != null) { Server server = settings.getServer(serverId); if (server == null) { throw new MojoExecutionException("Server id not found: " + serverId); } installTask.setUsername(server.getUsername()); installTask.setPassword(server.getPassword()); } else { installTask.setUsername(install.getUsername()); installTask.setPassword(install.getPassword()); } installTask.execute(); }
Example #23
Source File: UploadMojoTest.java From helm-maven-plugin with MIT License | 5 votes |
@Test public void uploadToArtifactoryWithEncryptedCredentialsFromSettings(UploadMojo mojo) throws IOException, MojoExecutionException { final Server server = new Server(); server.setId("my-artifactory"); server.setUsername("foo"); server.setPassword("{GGhJc6qP+v0Hg2l+dei1MQFZt/55PzyFXY0MUMxcQdQ=}"); final List<Server> servers = new ArrayList<>(); servers.add(server); mojo.getSettings().setServers(servers); final HelmRepository helmRepo = new HelmRepository(); helmRepo.setType(RepoType.ARTIFACTORY); helmRepo.setName("my-artifactory"); helmRepo.setUrl("https://somwhere.com/repo"); mojo.setUploadRepoStable(helmRepo); final URL resource = this.getClass().getResource("app-0.1.0.tgz"); final File fileToUpload = new File(resource.getFile()); final List<String> tgzs = new ArrayList<>(); tgzs.add(resource.getFile()); doReturn(this.getClass().getResource("settings-security.xml").getFile()).when(mojo).getHelmSecurity(); doReturn(helmRepo).when(mojo).getHelmUploadRepo(); doReturn(tgzs).when(mojo).getChartTgzs(anyString()); assertNotNull(mojo.getConnectionForUploadToArtifactory(fileToUpload)); final PasswordAuthentication pwd = Authenticator.requestPasswordAuthentication(InetAddress.getLocalHost(), 443, "https", "", "basicauth"); assertEquals("foo", pwd.getUserName()); assertEquals("bar", String.valueOf(pwd.getPassword())); }
Example #24
Source File: MavenUtil.java From jkube with Eclipse Public License 2.0 | 5 votes |
public static List<RegistryServerConfiguration> getRegistryServerFromMavenSettings(Settings settings) { List<RegistryServerConfiguration> registryServerConfigurations = new ArrayList<>(); for (Server server : settings.getServers()) { if (server.getUsername() != null) { registryServerConfigurations.add(RegistryServerConfiguration.builder() .id(server.getId()) .username(server.getUsername()) .password(server.getPassword()) .configuration(MavenConfigurationExtractor.extract((Xpp3Dom) server.getConfiguration())) .build()); } } return registryServerConfigurations; }
Example #25
Source File: MavenSettings.java From spring-init with Apache License 2.0 | 5 votes |
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 #26
Source File: AbstractHelmMojo.java From helm-maven-plugin with MIT License | 5 votes |
/** * Get credentials for given helm repo. If username is not provided the repo * name will be used to search for credentials in <code>settings.xml</code>. * * @param repository Helm repo with id and optional credentials. * @return Authentication object or <code>null</code> if no credentials are present. * @throws IllegalArgumentException Unable to get authentication because of misconfiguration. * @throws MojoExecutionException Unable to get password from settings.xml */ PasswordAuthentication getAuthentication(HelmRepository repository) throws IllegalArgumentException, MojoExecutionException { String id = repository.getName(); if (repository.getUsername() != null) { if (repository.getPassword() == null) { throw new IllegalArgumentException("Repo " + id + " has a username but no password defined."); } getLog().debug("Repo " + id + " has credentials definded, skip searching in server list."); return new PasswordAuthentication(repository.getUsername(), repository.getPassword().toCharArray()); } Server server = settings.getServer(id); if (server == null) { getLog().info("No credentials found for " + id + " in configuration or settings.xml server list."); return null; } getLog().debug("Use credentials from server list for " + id + "."); if (server.getUsername() == null || server.getPassword() == null) { throw new IllegalArgumentException("Repo " + id + " was found in server list but has no username/password."); } try { return new PasswordAuthentication(server.getUsername(), getSecDispatcher().decrypt(server.getPassword()).toCharArray()); } catch (SecDispatcherException e) { throw new MojoExecutionException(e.getMessage()); } }
Example #27
Source File: MavenRegistryAuthSupplier.java From dockerfile-maven with Apache License 2.0 | 5 votes |
@Override public RegistryAuth authFor(final String imageName) throws DockerException { final ImageRef ref = new ImageRef(imageName); Server server = settings.getServer(ref.getRegistryName()); if (server != null) { return createRegistryAuth(server); } log.warn("Did not find maven server configuration for docker server " + ref.getRegistryName()); return null; }
Example #28
Source File: MavenRegistryAuthSupplier.java From dockerfile-maven with Apache License 2.0 | 5 votes |
@Override public RegistryConfigs authForBuild() throws DockerException { final Map<String, RegistryAuth> allConfigs = new HashMap<>(); for (Server server : settings.getServers()) { allConfigs.put(server.getId(), createRegistryAuth(server)); } return RegistryConfigs.create(allConfigs); }
Example #29
Source File: MavenSettings.java From spring-cloud-function with Apache License 2.0 | 5 votes |
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 #30
Source File: AbstractBaseConfluenceMojo.java From maven-confluence-plugin with Apache License 2.0 | 5 votes |
/** * Issue 39 * * Load username password from settings if user has not set them in JVM properties * * @throws MojoExecutionException */ private void loadUserInfoFromSettings() throws MojoExecutionException { if ((getUsername() == null || getPassword() == null) && (mavenSettings != null)) { if (this.serverId == null) throw new MojoExecutionException("'serverId' must be set! (username and/or password are not provided)"); Server server = this.mavenSettings.getServer(this.serverId); if (server == null) throw new MojoExecutionException(String.format("server with id [%s] not found in settings!", this.serverId)); if (getUsername() == null && server.getUsername() != null) username = server.getUsername(); if (getPassword() == null && server.getPassword() != null) { try { // // FIX to resolve // org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException: // java.io.FileNotFoundException: ~/.settings-security.xml (No such file or directory) // if (securityDispatcher instanceof DefaultSecDispatcher) { //System.setProperty( DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION, sb.toString() ); ((DefaultSecDispatcher) securityDispatcher).setConfigurationFile("~/.m2/settings-security.xml"); } password = securityDispatcher.decrypt(server.getPassword()); } catch (SecDispatcherException e) { throw new MojoExecutionException(e.getMessage()); } } } }