Java Code Examples for org.kohsuke.stapler.AncestorInPath

The following examples show how to use org.kohsuke.stapler.AncestorInPath. These examples are extracted from open source projects. 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 Project: gitlab-branch-source-plugin   Source File: GitLabSCMSource.java    License: MIT License 6 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner context,
        @QueryParameter String serverName, @QueryParameter String credentialsId) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (context == null) {
        // must have admin if you want the list without a context
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            result.includeCurrentValue(credentialsId);
            return result;
        }
    } else {
        if (!context.hasPermission(Item.EXTENDED_READ)
                && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
            // must be able to read the configuration or use the item credentials if you
            // want the list
            result.includeCurrentValue(credentialsId);
            return result;
        }
    }
    result.includeEmptyValue();
    result.includeMatchingAs(
            context instanceof Queue.Task ? ((Queue.Task) context).getDefaultAuthentication() : ACL.SYSTEM,
            context, StandardUsernameCredentials.class, fromUri(getServerUrlFromName(serverName)).build(),
            GitClient.CREDENTIALS_MATCHER);
    return result;
}
 
Example 2
Source Project: warnings-ng-plugin   Source File: AxivionSuite.java    License: MIT License 6 votes vote down vote up
/**
 * Shows the user all available credential id items.
 *
 * @param item
 *         jenkins configuration
 * @param credentialsId
 *         current used credentials
 *
 * @return a list view of all credential ids
 */
public ListBoxModel doFillCredentialsIdItems(
        @AncestorInPath final Item item, @QueryParameter final String credentialsId) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (item == null) {
        if (!new JenkinsFacade().hasPermission(Jenkins.ADMINISTER)) {
            return result.includeCurrentValue(credentialsId);
        }
    }
    else {
        if (!item.hasPermission(Item.EXTENDED_READ)
                && !item.hasPermission(CredentialsProvider.USE_ITEM)) {
            return result.includeCurrentValue(credentialsId);
        }
    }
    return result.includeAs(
            ACL.SYSTEM,
            item,
            StandardUsernamePasswordCredentials.class,
            Collections.emptyList())
            .includeCurrentValue(credentialsId);
}
 
Example 3
Source Project: warnings-ng-plugin   Source File: ModelValidation.java    License: MIT License 6 votes vote down vote up
/**
 * Performs on-the-fly validation on the ant pattern for input files.
 *
 * @param project
 *         the project
 * @param pattern
 *         the file pattern
 *
 * @return the validation result
 */
public FormValidation doCheckPattern(@AncestorInPath final AbstractProject<?, ?> project,
        @QueryParameter final String pattern) {
    if (project != null) { // there is no workspace in pipelines
        try {
            FilePath workspace = project.getSomeWorkspace();
            if (workspace != null && workspace.exists()) {
                return validatePatternInWorkspace(pattern, workspace);
            }
        }
        catch (InterruptedException | IOException ignore) {
            // ignore and return ok
        }
    }

    return FormValidation.ok();
}
 
Example 4
Source Project: kubernetes-plugin   Source File: KubernetesCloud.java    License: Apache License 2.0 6 votes vote down vote up
@RequirePOST
@SuppressWarnings("unused") // used by jelly
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter String serverUrl) {
    Jenkins.get().checkPermission(Jenkins.ADMINISTER);
    StandardListBoxModel result = new StandardListBoxModel();
    result.includeEmptyValue();
    result.includeMatchingAs(
        ACL.SYSTEM,
        context,
        StandardCredentials.class,
        serverUrl != null ? URIRequirementBuilder.fromUri(serverUrl).build()
                    : Collections.EMPTY_LIST,
        CredentialsMatchers.anyOf(
            AuthenticationTokens.matcher(KubernetesAuth.class)
        )
    );
    return result;
}
 
Example 5
public FormValidation doCheckRemoteURL(StaplerRequest req, @AncestorInPath Item context, @QueryParameter String value) {
    String url = Util.fixEmptyAndTrim(value);

    if (url == null) {
        return FormValidation.error("Repository URL is required");
    }

    if (url.indexOf('$') != -1) {
        return FormValidation.warning("This repository URL is parameterized, syntax validation skipped");
    }

    try {
        new URIish(value);
    } catch (URISyntaxException e) {
        return FormValidation.error("Repository URL is illegal");
    }
    return FormValidation.ok();
}
 
Example 6
public ListBoxModel doFillValueItems(@AncestorInPath Job<?, ?> context, @QueryParameter String param)
        throws IOException, InterruptedException {
    ListBoxModel items = new ListBoxModel();
    if (context != null && context.hasPermission(Item.BUILD)) {
        ParametersDefinitionProperty prop = context.getProperty(ParametersDefinitionProperty.class);
        if (prop != null) {
            ParameterDefinition def = prop.getParameterDefinition(param);
            if (def instanceof ListGitBranchesParameterDefinition) {
                Map<String, String> paramList = ((ListGitBranchesParameterDefinition) def).generateContents(context);
                for (Map.Entry<String, String> entry : paramList.entrySet()) {
                    items.add(entry.getValue(), entry.getKey());
                }
            }
        }
    }
    return items;
}
 
Example 7
Source Project: remoting-kafka-plugin   Source File: GlobalKafkaConfiguration.java    License: MIT License 6 votes vote down vote up
private FormValidation checkCredentialsId(@AncestorInPath Item item, @QueryParameter String value) {
    if (item == null) {
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            return FormValidation.ok();
        }
    }
    if (value.startsWith("${") && value.endsWith("}")) {
        return FormValidation.warning("Cannot validate expression based credentials");
    }
    if (CredentialsProvider.listCredentials(
            StandardUsernamePasswordCredentials.class,
            Jenkins.get(),
            ACL.SYSTEM,
            Collections.singletonList(KAFKA_SCHEME),
            CredentialsMatchers.withId(value)
    ).isEmpty()) {
        return FormValidation.error("Cannot find currently selected credentials");
    }
    return FormValidation.ok();
}
 
Example 8
Source Project: remoting-kafka-plugin   Source File: GlobalKafkaConfiguration.java    License: MIT License 6 votes vote down vote up
private ListBoxModel fillCredentialsIdItems(@AncestorInPath Item item, @QueryParameter String credentialsId) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (item == null) {
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            return result.includeCurrentValue(credentialsId);
        }
    }
    return result
            .includeMatchingAs(
                    ACL.SYSTEM,
                    Jenkins.get(),
                    StandardUsernamePasswordCredentials.class,
                    Collections.singletonList(KAFKA_SCHEME),
                    CredentialsMatchers.always()
            )
            .includeCurrentValue(credentialsId);
}
 
Example 9
Source Project: github-autostatus-plugin   Source File: BuildStatusConfig.java    License: MIT License 6 votes vote down vote up
/**
 * Validates the credentials id.
 *
 * @param item context for validation
 * @param value to validate
 * @return FormValidation
 */
public FormValidation doCheckCredentialsId(@AncestorInPath Item item, @QueryParameter String value) {
    if (item == null) {
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            return FormValidation.ok();
        }
    } else {
        if (!item.hasPermission(Item.EXTENDED_READ)
                && !item.hasPermission(CredentialsProvider.USE_ITEM)) {
            return FormValidation.ok();
        }
    }
    if (StringUtils.isEmpty(value)) {
        return FormValidation.ok();
    }
    if (null == getCredentials(UsernamePasswordCredentials.class, value)) {
        return FormValidation.error("Cannot find currently selected credentials");
    }
    return FormValidation.ok();
}
 
Example 10
Source Project: acunetix-plugin   Source File: BuildScanner.java    License: MIT License 6 votes vote down vote up
public ListBoxModel doFillGApiKeyIDItems(
        @AncestorInPath Item item) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (item == null) {
        if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
            return result.includeCurrentValue(gApiKeyID);
        }
    } else {
        if (!item.hasPermission(Item.EXTENDED_READ)
                && !item.hasPermission(CredentialsProvider.USE_ITEM)) {
            return result.includeCurrentValue(gApiKeyID);
        }
    }
    if (gApiKeyID != null) {
        result.includeMatchingAs(ACL.SYSTEM, Jenkins.getInstance(), StringCredentials.class,
                Collections.<DomainRequirement> emptyList(), CredentialsMatchers.allOf(CredentialsMatchers.withId(gApiKeyID)));
    }
    return result
            .includeMatchingAs(ACL.SYSTEM, Jenkins.getInstance(), StringCredentials.class,
                    Collections.<DomainRequirement> emptyList(), CredentialsMatchers.allOf(CredentialsMatchers.instanceOf(StringCredentials.class)));
}
 
Example 11
Source Project: jira-steps-plugin   Source File: Site.java    License: Apache License 2.0 6 votes vote down vote up
public FormValidation doCheckCredentialsId(@AncestorInPath Item item,
    final @QueryParameter String credentialsId,
    final @QueryParameter String url) {

  if (item == null) {
    if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
      return FormValidation.ok();
    }
  } else if (!item.hasPermission(Item.EXTENDED_READ) && !item.hasPermission(CredentialsProvider.USE_ITEM)) {
    return FormValidation.ok();
  }
  if (StringUtils.isBlank(credentialsId)) {
    return FormValidation.warning(Messages.Site_emptyCredentialsId());
  }

  List<DomainRequirement> domainRequirements = URIRequirementBuilder.fromUri(url).build();
  if (CredentialsProvider.listCredentials(StandardUsernameCredentials.class, item, getAuthentication(item), domainRequirements, CredentialsMatchers.withId(credentialsId)).isEmpty()) {
    return FormValidation.error(Messages.Site_invalidCredentialsId());
  }
  return FormValidation.ok();
}
 
Example 12
@Restricted(NoExternalUse.class)
public ListBoxModel doFillCheckoutCredentialsIdItems(@AncestorInPath SCMSourceOwner context, @QueryParameter String connectionName, @QueryParameter String checkoutCredentialsId) {
    if (context == null && !Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER) ||
            context != null && !context.hasPermission(Item.EXTENDED_READ)) {
        return new StandardListBoxModel().includeCurrentValue(checkoutCredentialsId);
    }

    StandardListBoxModel result = new StandardListBoxModel();
    result.add("- anonymous -", CHECKOUT_CREDENTIALS_ANONYMOUS);
    return result.includeMatchingAs(
            context instanceof Queue.Task
                    ? Tasks.getDefaultAuthenticationOf((Queue.Task) context)
                    : ACL.SYSTEM,
            context,
            StandardUsernameCredentials.class,
            SettingsUtils.gitLabConnectionRequirements(connectionName),
            GitClient.CREDENTIALS_MATCHER
    );
}
 
Example 13
public FormValidation doCheckCredentialsId(@QueryParameter final String credentialsId,
                                           @AncestorInPath final Job<?,?> owner) {
    String globalCredentialsId = this.getGlobalCredentialsId();

    if (credentialsId == null || credentialsId.isEmpty()) {
        if (globalCredentialsId == null || globalCredentialsId.isEmpty()) {
            return FormValidation.error("Please enter Bitbucket OAuth credentials");
        } else {
            return this.doCheckGlobalCredentialsId(this.getGlobalCredentialsId());
        }
    }

    UsernamePasswordCredentials credentials = BitbucketBuildStatusHelper.getCredentials(credentialsId, owner);

    return this.checkCredentials(credentials);
}
 
Example 14
public static ListBoxModel doFillCredentialsIDItems(@AncestorInPath Jenkins context) {
    if (context == null || !context.hasPermission(Item.CONFIGURE)) {
        return new StandardListBoxModel();
    }

    List<DomainRequirement> domainRequirements = new ArrayList<DomainRequirement>();
    return new StandardListBoxModel()
            .withEmptySelection()
            .withMatching(
                    CredentialsMatchers.anyOf(
                            CredentialsMatchers.instanceOf(ConduitCredentials.class)),
                    CredentialsProvider.lookupCredentials(
                            StandardCredentials.class,
                            context,
                            ACL.SYSTEM,
                            domainRequirements));
}
 
Example 15
Source Project: gitlab-branch-source-plugin   Source File: GitLabSCMNavigator.java    License: MIT License 5 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner context,
    @QueryParameter String serverName,
    @QueryParameter String credentialsId) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (context == null) {
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            // must have admin if you want the list without a context
            result.includeCurrentValue(credentialsId);
            return result;
        }
    } else {
        if (!context.hasPermission(Item.EXTENDED_READ)
            && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
            // must be able to read the configuration or use the item credentials if you want the list
            result.includeCurrentValue(credentialsId);
            return result;
        }
    }
    result.includeEmptyValue();
    result.includeMatchingAs(
        context instanceof Queue.Task
            ? ((Queue.Task) context).getDefaultAuthentication()
            : ACL.SYSTEM,
        context,
        StandardUsernameCredentials.class,
        fromUri(getServerUrlFromName(serverName)).build(),
        GitClient.CREDENTIALS_MATCHER
    );
    return result;
}
 
Example 16
Source Project: gitlab-branch-source-plugin   Source File: SSHCheckoutTrait.java    License: MIT License 5 votes vote down vote up
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // stapler form binding
public ListBoxModel doFillCredentialsIdItems(@CheckForNull @AncestorInPath Item context,
    @QueryParameter String serverUrl,
    @QueryParameter String credentialsId) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (context == null) {
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            // must have admin if you want the list without a context
            result.includeCurrentValue(credentialsId);
            return result;
        }
    } else {
        if (!context.hasPermission(Item.EXTENDED_READ)
            && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
            // must be able to read the configuration or use the item credentials if you want the list
            result.includeCurrentValue(credentialsId);
            return result;
        }
    }
    result.includeEmptyValue();
    result.includeMatchingAs(
        context instanceof Queue.Task
            ? ((Queue.Task) context).getDefaultAuthentication()
            : ACL.SYSTEM,
        context,
        StandardUsernameCredentials.class,
        URIRequirementBuilder.fromUri(serverUrl).build(),
        CredentialsMatchers.instanceOf(SSHUserPrivateKey.class)
    );
    return result;
}
 
Example 17
Source Project: docker-swarm-plugin   Source File: DockerSwarmCloud.java    License: MIT License 5 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter String value) {
    AccessControlled ac = (context instanceof AccessControlled ? (AccessControlled) context
            : Jenkins.getInstance());
    if (!ac.hasPermission(Jenkins.ADMINISTER)) {
        return new StandardListBoxModel().includeCurrentValue(value);
    }
    return new StandardListBoxModel().includeAs(ACL.SYSTEM, context, DockerServerCredentials.class,
            Collections.<DomainRequirement>emptyList());
}
 
Example 18
Source Project: docker-swarm-plugin   Source File: DockerSwarmAgentTemplate.java    License: MIT License 5 votes vote down vote up
public ListBoxModel doFillPullCredentialsIdItems(@AncestorInPath Item item,
        @QueryParameter String pullCredentialsId) {
    if (item == null && !Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)
            || item != null && !item.hasPermission(Item.EXTENDED_READ)) {
        return new StandardListBoxModel();
    }

    final DockerRegistryEndpoint.DescriptorImpl descriptor = (DockerRegistryEndpoint.DescriptorImpl) Jenkins
            .getInstance().getDescriptorOrDie(DockerRegistryEndpoint.class);
    return descriptor.doFillCredentialsIdItems(item);
}
 
Example 19
Source Project: yet-another-docker-plugin   Source File: DockerCreateContainer.java    License: MIT License 5 votes vote down vote up
public static ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context) {
    AccessControlled ac = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance());
    if (!ac.hasPermission(Jenkins.ADMINISTER)) {
        return new ListBoxModel();
    }

    return new SSHUserListBoxModel().withMatching(
            SSHAuthenticator.matcher(Connection.class),
            CredentialsProvider.lookupCredentials(
                    StandardUsernameCredentials.class,
                    context,
                    ACL.SYSTEM,
                    SSHLauncher.SSH_SCHEME)
    );
}
 
Example 20
Source Project: yet-another-docker-plugin   Source File: DockerPullImage.java    License: MIT License 5 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context) {
    List<DockerRegistryAuthCredentials> credentials =
            CredentialsProvider.lookupCredentials(DockerRegistryAuthCredentials.class, context, ACL.SYSTEM,
                    Collections.emptyList());

    return new StandardListBoxModel().withEmptySelection()
            .withMatching(CredentialsMatchers.instanceOf(DockerRegistryAuthCredentials.class), credentials);
}
 
Example 21
Source Project: remoting-kafka-plugin   Source File: GlobalKafkaConfiguration.java    License: MIT License 5 votes vote down vote up
public FormValidation doCheckKafkaCredentialsId(@AncestorInPath Item item, @QueryParameter String value) {
    FormValidation checkedResult = checkCredentialsId(item, value);
    boolean isAdminOrNullItem = (item != null || Jenkins.get().hasPermission(Jenkins.ADMINISTER));
    if (isAdminOrNullItem && checkedResult.equals(FormValidation.ok())) {
        this.kafkaCredentialsId = value;
    }
    return checkedResult;
}
 
Example 22
Source Project: remoting-kafka-plugin   Source File: GlobalKafkaConfiguration.java    License: MIT License 5 votes vote down vote up
public FormValidation doCheckSslTruststoreCredentialsId(@AncestorInPath Item item, @QueryParameter String value) {
    FormValidation checkedResult = checkCredentialsId(item, value);
    boolean isAdminOrNullItem = (item != null || Jenkins.get().hasPermission(Jenkins.ADMINISTER));
    if (isAdminOrNullItem && checkedResult.equals(FormValidation.ok())) {
        this.sslTruststoreCredentialsId = value;
    }
    return checkedResult;
}
 
Example 23
Source Project: remoting-kafka-plugin   Source File: GlobalKafkaConfiguration.java    License: MIT License 5 votes vote down vote up
public FormValidation doCheckSslKeystoreCredentialsId(@AncestorInPath Item item, @QueryParameter String value) {
    FormValidation checkedResult = checkCredentialsId(item, value);
    boolean isAdminOrNullItem = (item != null || Jenkins.get().hasPermission(Jenkins.ADMINISTER));
    if (isAdminOrNullItem && checkedResult.equals(FormValidation.ok())) {
        this.sslKeystoreCredentialsId = value;
    }
    return checkedResult;
}
 
Example 24
Source Project: remoting-kafka-plugin   Source File: GlobalKafkaConfiguration.java    License: MIT License 5 votes vote down vote up
public FormValidation doCheckSslKeyCredentialsId(@AncestorInPath Item item, @QueryParameter String value) {
    FormValidation checkedResult = checkCredentialsId(item, value);
    boolean isAdminOrNullItem = (item != null || Jenkins.get().hasPermission(Jenkins.ADMINISTER));
    if (isAdminOrNullItem && checkedResult.equals(FormValidation.ok())) {
        this.sslKeyCredentialsId = value;
    }
    return checkedResult;
}
 
Example 25
Source Project: gitea-plugin   Source File: GiteaSCMNavigator.java    License: MIT License 5 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner context,
                                             @QueryParameter String serverUrl,
                                             @QueryParameter String credentialsId) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (context == null) {
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            // must have admin if you want the list without a context
            result.includeCurrentValue(credentialsId);
            return result;
        }
    } else {
        if (!context.hasPermission(Item.EXTENDED_READ)
                && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
            // must be able to read the configuration or use the item credentials if you want the list
            result.includeCurrentValue(credentialsId);
            return result;
        }
    }
    result.includeEmptyValue();
    result.includeMatchingAs(
            context instanceof Queue.Task ?
                    ((Queue.Task) context).getDefaultAuthentication()
                    : ACL.SYSTEM,
            context,
            StandardCredentials.class,
            URIRequirementBuilder.fromUri(serverUrl).build(),
            AuthenticationTokens.matcher(GiteaAuth.class)
    );
    return result;
}
 
Example 26
Source Project: gitea-plugin   Source File: GiteaSCMNavigator.java    License: MIT License 5 votes vote down vote up
public FormValidation doCheckCredentialsId(@AncestorInPath SCMSourceOwner context,
                                           @QueryParameter String serverUrl,
                                           @QueryParameter String value)
        throws IOException, InterruptedException {
    if (context == null) {
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            return FormValidation.ok();
        }
    } else {
        if (!context.hasPermission(Item.EXTENDED_READ)
                && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
            return FormValidation.ok();
        }
    }
    GiteaServer server = GiteaServers.get().findServer(serverUrl);
    if (server == null) {
        return FormValidation.ok();
    }
    if (StringUtils.isBlank(value)) {
        return FormValidation.ok();
    }
    if (CredentialsProvider.listCredentials(
            StandardCredentials.class,
            context,
            context instanceof Queue.Task ?
                    ((Queue.Task) context).getDefaultAuthentication()
                    : ACL.SYSTEM,
            URIRequirementBuilder.fromUri(serverUrl).build(),
            CredentialsMatchers.allOf(
                    CredentialsMatchers.withId(value),
                    AuthenticationTokens.matcher(GiteaAuth.class)

            )).isEmpty()) {
        return FormValidation.error(Messages.GiteaSCMNavigator_selectedCredentialsMissing());
    }
    return FormValidation.ok();
}
 
Example 27
Source Project: gitea-plugin   Source File: SSHCheckoutTrait.java    License: MIT License 5 votes vote down vote up
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // stapler form binding
public ListBoxModel doFillCredentialsIdItems(@CheckForNull @AncestorInPath Item context,
                                             @QueryParameter String serverUrl,
                                             @QueryParameter String credentialsId) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (context == null) {
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            // must have admin if you want the list without a context
            result.includeCurrentValue(credentialsId);
            return result;
        }
    } else {
        if (!context.hasPermission(Item.EXTENDED_READ)
                && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
            // must be able to read the configuration or use the item credentials if you want the list
            result.includeCurrentValue(credentialsId);
            return result;
        }
    }
    result.add(Messages.SSHCheckoutTrait_useAgentKey(), "");
    result.includeMatchingAs(
            context instanceof Queue.Task ?
                    ((Queue.Task) context).getDefaultAuthentication()
                    : ACL.SYSTEM,
            context,
            StandardUsernameCredentials.class,
            URIRequirementBuilder.fromUri(serverUrl).build(),
            CredentialsMatchers.instanceOf(SSHUserPrivateKey.class)
    );
    return result;
}
 
Example 28
Source Project: github-branch-source-plugin   Source File: GitHubSCMSource.java    License: MIT License 5 votes vote down vote up
@RequirePOST
@Restricted(NoExternalUse.class)
public FormValidation doCheckCredentialsId(@CheckForNull @AncestorInPath Item context,
                                               @QueryParameter String apiUri,
                                               @QueryParameter String value) {
    return Connector.checkScanCredentials(context, apiUri, value);
}
 
Example 29
Source Project: gitea-plugin   Source File: GiteaSCMSource.java    License: MIT License 5 votes vote down vote up
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner context,
                                             @QueryParameter String serverUrl,
                                             @QueryParameter String credentialsId) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (context == null) {
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            // must have admin if you want the list without a context
            result.includeCurrentValue(credentialsId);
            return result;
        }
    } else {
        if (!context.hasPermission(Item.EXTENDED_READ)
                && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
            // must be able to read the configuration or use the item credentials if you want the list
            result.includeCurrentValue(credentialsId);
            return result;
        }
    }
    result.includeEmptyValue();
    result.includeMatchingAs(
            context instanceof Queue.Task ?
                    ((Queue.Task) context).getDefaultAuthentication()
                    : ACL.SYSTEM,
            context,
            StandardCredentials.class,
            URIRequirementBuilder.fromUri(serverUrl).build(),
            AuthenticationTokens.matcher(GiteaAuth.class)
    );
    return result;
}
 
Example 30
Source Project: gitea-plugin   Source File: GiteaSCMSource.java    License: MIT License 5 votes vote down vote up
public FormValidation doCheckCredentialsId(@AncestorInPath SCMSourceOwner context,
                                           @QueryParameter String serverUrl,
                                           @QueryParameter String value)
        throws IOException, InterruptedException {
    if (context == null) {
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            return FormValidation.ok();
        }
    } else {
        if (!context.hasPermission(Item.EXTENDED_READ)
                && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
            return FormValidation.ok();
        }
    }
    GiteaServer server = GiteaServers.get().findServer(serverUrl);
    if (server == null) {
        return FormValidation.ok();
    }
    if (StringUtils.isBlank(value)) {
        return FormValidation.ok();
    }
    if (CredentialsProvider.listCredentials(
            StandardCredentials.class,
            context,
            context instanceof Queue.Task
                    ? ((Queue.Task) context).getDefaultAuthentication()
                    : ACL.SYSTEM,
            URIRequirementBuilder.fromUri(serverUrl).build(),
            CredentialsMatchers.allOf(
                    CredentialsMatchers.withId(value),
                    AuthenticationTokens.matcher(GiteaAuth.class)

            )).isEmpty()) {
        return FormValidation.error(Messages.GiteaSCMSource_selectedCredentialsMissing());
    }
    return FormValidation.ok();
}