private static String createCredentials(String serverAPIUrl, StandardCredentials credentials) throws Exception { List<DomainSpecification> specifications = new ArrayList<DomainSpecification>(2); URI serverUri = new URI(serverAPIUrl); if (serverUri.getPort() > 0) { specifications.add(new HostnamePortSpecification(serverUri.getHost() + ":" + serverUri.getPort(), null)); } else { specifications.add(new HostnameSpecification(serverUri.getHost(), null)); } specifications.add(new SchemeSpecification(serverUri.getScheme())); String path = serverUri.getPath(); if (StringUtils.isEmpty(path)) { path = "/"; } specifications.add(new PathSpecification(path, null, false)); Domain domain = new Domain(serverUri.getHost(), "Auto generated credentials domain", specifications); CredentialsStore provider = new SystemCredentialsProvider.StoreImpl(); provider.addDomain(domain, credentials); return credentials.getId(); }
new SchemeSpecification(serverUri.getScheme()), new HostnameSpecification(serverUri.getHost(), null) );
private void addGitHubCredentialFromToken(Map<Domain, List<Credentials>> domainCredentialsMap, GitHubCredential gitHubCredential) { List<Credentials> gitHubCredentialsForDomain = new CopyOnWriteArrayList<Credentials>(); URI serverUri = URI.create(gitHubCredential.getGitHubApiUrl()); List<DomainSpecification> specifications = Arrays.asList( new SchemeSpecification(serverUri.getScheme()), new HostnameSpecification(serverUri.getHost(), null)); Domain domain = new Domain(serverUri.getHost(), "GitHub domain (autogenerated)", specifications); String description = String.format("GitHub (%s) auto generated token credentials for %s", gitHubCredential.getGitHubApiUrl(), gitHubCredential.getUsername()); StringCredentialsImpl creds = new StringCredentialsImpl( CredentialsScope.GLOBAL, id(gitHubCredential.getId()), description, Secret.fromString(gitHubCredential.getOauthToken())); gitHubCredentialsForDomain.add(creds); domainCredentialsMap.put(domain, gitHubCredentialsForDomain); }
new HostnameSpecification(hostnameRequirement.getHostname(), null)); if (schemeRequirement != null) { specs.add(new SchemeSpecification(schemeRequirement.getScheme()));