public InputStream getInputStream() throws CoreException { if (filePath != null) { File file = new File(filePath); if (file.isFile()) { IMaven maven = MavenPlugin.getDefault().getMaven(); Settings settings = maven.buildSettings(null, filePath); List<Server> servers = settings.getServers(); if (servers != null) { for (Server server : servers) { server.setUsername(obfuscate(server.getUsername())); server.setPassword(obfuscate(server.getPassword())); server.setPassphrase(obfuscate(server.getPassphrase())); } } List<Proxy> proxies = settings.getProxies(); if (proxies != null) { for (Proxy proxy : proxies) { proxy.setUsername(obfuscate(proxy.getUsername())); proxy.setPassword(obfuscate(proxy.getPassword())); } } ByteArrayOutputStream baos = new ByteArrayOutputStream(1024 * 4); maven.writeSettings(settings, baos); return new ByteArrayInputStream(baos.toByteArray()); } } return null; }
private AuthenticationSelector getAuthSelector() { DefaultAuthenticationSelector selector = new DefaultAuthenticationSelector(); Collection<String> ids = new HashSet<String>(); for (Authentication auth : authentications) { List<String> servers = auth.getServers(); if (!servers.isEmpty()) { org.sonatype.aether.repository.Authentication a = ConverterUtils.toAuthentication(auth); for (String server : servers) { if (ids.add(server)) { selector.add(server, a); } } } } Settings settings = getSettings(); for (Server server : settings.getServers()) { org.sonatype.aether.repository.Authentication auth = new org.sonatype.aether.repository.Authentication( server.getUsername(), server.getPassword(), server.getPrivateKey(), server.getPassphrase()); selector.add(server.getId(), auth); } return new ConservativeAuthenticationSelector(selector); }
/** * Retrieves the credentials for the given server or null if none could be found * * @param serverID * @return */ public Credentials findCredentials(String serverID) { List<Server> decryptedServers = getDecryptedServers(); for (Server ds : decryptedServers) { if (ds.getId().equals(serverID)) { getLog() .debug( "credentials have been found for server: " + serverID + ", login:"******", password:"******"no credentials found for server: " + serverID); return null; }
private static RemoteRepository makeRemoteRepository( Metadata.Repository info, Server server, boolean snapshot) { return new RemoteRepository(info.getId(), "default", info.getUri()) .setPolicy( true, new RepositoryPolicy( snapshot, RepositoryPolicy.UPDATE_POLICY_ALWAYS, RepositoryPolicy.CHECKSUM_POLICY_FAIL)) .setPolicy( false, new RepositoryPolicy( !snapshot, RepositoryPolicy.UPDATE_POLICY_ALWAYS, RepositoryPolicy.CHECKSUM_POLICY_FAIL)) .setAuthentication(new Authentication(server.getUsername(), server.getPassword())); }
protected Expose exposeSettings(String serverId) throws MojoFailureException { Server server = settings.getServer(serverId); Expose expose = new Expose(); if (null != server) { expose.setServerId(serverId); expose.setAccessKey(server.getUsername()); expose.setSharedKey(getDecryptedAwsKey(server.getPassword().trim())); } else { getLog().warn(format("serverId['%s'] not found. Using runtime defaults", serverId)); expose.setServerId("runtime"); expose.setAccessKey(getAWSCredentials().getCredentials().getAWSAccessKeyId()); expose.setSharedKey(getAWSCredentials().getCredentials().getAWSSecretKey()); } return expose; }
public void configureAuthentication(String githubAPIServerId, Settings settings, Log log) { boolean configured = false; List<Server> servers = settings.getServers(); for (Server server : servers) { if (server.getId().equals(githubAPIServerId)) { String user = server.getUsername(); String password = server.getPassword(); this.client.setCredentials(user, password); configured = true; break; } } if (!configured) { log.warn("Can't find server id [" + githubAPIServerId + "] configured in githubAPIServerId."); } }
@SuppressWarnings("unchecked") protected void uploadAppZip(boolean newUserAdded) throws Exception { File file = getZipFile(); if (!file.exists()) { getLog() .error( "No App Zip file at " + file.getAbsolutePath() + ". Did you execute the fabric8:zip goal?"); return; } if (!file.isFile()) { getLog() .error( "Invalid App Zip file at " + file.getAbsolutePath() + ". This should be a file not a directory!"); return; } String user = fabricServer.getUsername(); String password = fabricServer.getPassword(); if (Strings.isNullOrBlank(user)) { getLog() .warn( "No <username> value defined for the server " + serverId + " in your ~/.m2/settings.xml. Please add a value!"); } if (Strings.isNullOrBlank(password)) { getLog() .warn( "No <password> value defined for the server " + serverId + " in your ~/.m2/settings.xml. Please add a value!"); } Apps.postFileToGit(file, user, password, consoleUrl, branch, deployPath, LOG); }
/** * Configure client with credentials from given server id * * @param client * @param serverId * @param settings * @param session * @return true if configured, false otherwise * @throws MojoExecutionException */ protected boolean configureServerCredentials( final GitHubClient client, final String serverId, final Settings settings, final MavenSession session) throws MojoExecutionException { if (StringUtils.isEmpty(serverId)) return false; String serverUsername = null; String serverPassword = null; // Maven 3.1.0 - It's now impossible to retrieve the username and password from the remote // repository. // if (session != null) { // RepositorySystemSession systemSession = session // .getRepositorySession(); // if (systemSession != null) { // RemoteRepository.Builder builder = new RemoteRepository.Builder(serverId, "", // ""); // Authentication authInfo = // systemSession.getAuthenticationSelector().getAuthentication // (builder.build()); // if (authInfo != null) { // serverUsername = authInfo.getUsername(); // serverPassword = authInfo.getPassword(); // } // } // } // Always true. // if (StringUtils.isEmpty(serverPassword)) { Server server = getServer(settings, serverId); if (server == null) throw new MojoExecutionException( MessageFormat.format("Server ''{0}'' not found in settings", serverId)); if (isDebug()) debug(MessageFormat.format("Using ''{0}'' server credentials", serverId)); serverUsername = server.getUsername(); serverPassword = server.getPassword(); // } if (!StringUtils.isEmpty(serverUsername, serverPassword)) { if (isDebug()) debug("Using basic authentication with username: "******"Using OAuth2 access token authentication"); client.setOAuth2Token(serverPassword); return true; } if (isDebug()) debug( MessageFormat.format( "Server ''{0}'' is missing username/password credentials", serverId)); return false; }
private void addTargetFileContentToTargetPlatform( TargetPlatformConfiguration configuration, TargetPlatformBuilder resolutionContext, MavenSession session) { final TargetDefinitionFile target; try { target = TargetDefinitionFile.read(configuration.getTarget()); } catch (TargetDefinitionSyntaxException e) { throw new RuntimeException( "Invalid syntax in target definition " + configuration.getTarget() + ": " + e.getMessage(), e); } catch (IOException e) { throw new RuntimeException(e); } Set<URI> uris = new HashSet<URI>(); for (Location location : target.getLocations()) { if (!(location instanceof InstallableUnitLocation)) { continue; } for (TargetDefinition.Repository repository : ((InstallableUnitLocation) location).getRepositories()) { try { URI uri = getMirror(repository, session.getRequest().getMirrors()); if (uris.add(uri)) { if (!session.isOffline()) { String id = repository.getId(); if (id != null) { Server server = session.getSettings().getServer(id); if (server != null) { // TODO don't do this via magic side-effects, but when loading repositories resolutionContext.setCredentials(uri, server.getUsername(), server.getPassword()); } else { getLogger() .info( "Unknown server id=" + id + " for repository location=" + repository.getLocation()); } } // TODO mirrors are no longer considered -> lookup mirrors when loading p2 // repositories } } } catch (URISyntaxException e) { throw new RuntimeException(e); } } try { getLogger().debug("Resolving target definition file \"" + configuration.getTarget() + "\""); resolutionContext.addTargetDefinition(target, getEnvironments(configuration)); } catch (TargetDefinitionSyntaxException e) { throw new RuntimeException( "Invalid syntax in target definition " + configuration.getTarget() + ": " + e.getMessage(), e); } catch (TargetDefinitionResolutionException e) { throw new RuntimeException( "Failed to resolve target definition " + configuration.getTarget(), e); } } }