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(); }
/** * Constructor for stapler. * * @param schemes A comma separated list of scheme names. */ @DataBoundConstructor @SuppressWarnings("unused")// by stapler public SchemeSpecification(@CheckForNull String schemes) { this.schemes = new LinkedHashSet<String>(); schemes = Util.fixEmptyAndTrim(schemes); if (schemes != null) { for (String scheme : schemes.split("[,\\n ]")) { scheme = Util.fixEmptyAndTrim(scheme); if (scheme != null) { this.schemes.add(toWellFormedScheme(scheme)); } } } }
new SchemeSpecification(serverUri.getScheme()), new HostnameSpecification(serverUri.getHost(), null) );
/** * Constructor for stapler. * * @param schemes A comma separated list of scheme names. */ @DataBoundConstructor @SuppressWarnings("unused")// by stapler public SchemeSpecification(@CheckForNull String schemes) { this.schemes = new LinkedHashSet<String>(); schemes = Util.fixEmptyAndTrim(schemes); if (schemes != null) { for (String scheme : schemes.split("[,\\n ]")) { scheme = Util.fixEmptyAndTrim(scheme); if (scheme != null) { this.schemes.add(toWellFormedScheme(scheme)); } } } }
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); }
/** * {@inheritDoc} */ @NonNull @Override public Result test(@NonNull DomainRequirement requirement) { if (requirement instanceof SchemeRequirement) { String scheme = toWellFormedScheme(((SchemeRequirement) requirement).getScheme()); if (!schemes.isEmpty() && schemes.contains(scheme)) { // we know the scheme is an exact test, no need to check this requirement any more return Result.POSITIVE; } return Result.NEGATIVE; } return Result.UNKNOWN; }
new HostnameSpecification(hostnameRequirement.getHostname(), null)); if (schemeRequirement != null) { specs.add(new SchemeSpecification(schemeRequirement.getScheme()));
/** * {@inheritDoc} */ @NonNull @Override public Result test(@NonNull DomainRequirement requirement) { if (requirement instanceof SchemeRequirement) { String scheme = toWellFormedScheme(((SchemeRequirement) requirement).getScheme()); if (!schemes.isEmpty() && schemes.contains(scheme)) { // we know the scheme is an exact test, no need to check this requirement any more return Result.POSITIVE; } return Result.NEGATIVE; } return Result.UNKNOWN; }