org.kohsuke.stapler.interceptor.RequirePOST Java Examples
The following examples show how to use
org.kohsuke.stapler.interceptor.RequirePOST.
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: GitHubPRRepository.java From github-integration-plugin with MIT License | 6 votes |
@RequirePOST public FormValidation doClearRepo() throws IOException { FormValidation result; try { if (job.hasPermission(Item.DELETE)) { pulls.clear(); save(); result = FormValidation.ok("Pulls deleted"); } else { result = FormValidation.error("Forbidden"); } } catch (Exception e) { LOG.error("Can\'t delete repository file '{}'", configFile.getFile().getAbsolutePath(), e); result = FormValidation.error(e, "Can't delete: %s", e.getMessage()); } return result; }
Example #2
Source File: GitHubBranchRepository.java From github-integration-plugin with MIT License | 6 votes |
@Override @RequirePOST public FormValidation doRunTrigger() throws IOException { FormValidation result; try { if (job.hasPermission(Item.BUILD)) { GitHubBranchTrigger trigger = ghBranchTriggerFromJob(job); if (trigger != null) { trigger.run(); result = FormValidation.ok("GitHub Branch trigger run"); LOG.debug("GitHub Branch trigger run for {}", job); } else { LOG.error("GitHub Branch trigger not available for {}", job); result = FormValidation.error("GitHub Branch trigger not available"); } } else { LOG.warn("No permissions to run GitHub Branch trigger"); result = FormValidation.error("Forbidden"); } } catch (Exception e) { LOG.error("Can't run trigger", e.getMessage()); result = FormValidation.error(e, "Can't run trigger: %s", e.getMessage()); } return result; }
Example #3
Source File: GlobalKafkaConfiguration.java From remoting-kafka-plugin with MIT License | 6 votes |
@RequirePOST public FormValidation doTestBrokerConnection(@QueryParameter("brokerURL") final String brokerURL) throws IOException, ServletException { if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { return FormValidation.error("Need admin permission to perform this action"); } try { String[] hostport = brokerURL.split(":"); String host = hostport[0]; int port = Integer.parseInt(hostport[1]); testConnection(host, port); return FormValidation.ok("Success"); } catch (Exception e) { return FormValidation.error("Connection error : " + e.getMessage()); } }
Example #4
Source File: GlobalKafkaConfiguration.java From remoting-kafka-plugin with MIT License | 6 votes |
@RequirePOST public FormValidation doTestZookeeperConnection(@QueryParameter("zookeeperURL") final String zookeeperURL) throws IOException, ServletException { if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { return FormValidation.error("Need admin permission to perform this action"); } try { String[] hostport = zookeeperURL.split(":"); String host = hostport[0]; int port = Integer.parseInt(hostport[1]); testConnection(host, port); return FormValidation.ok("Success"); } catch (Exception e) { return FormValidation.error("Connection error : " + e.getMessage()); } }
Example #5
Source File: GroovyParser.java From warnings-ng-plugin with MIT License | 6 votes |
/** * Parses the example message with the specified regular expression and script. * * @param example * example that should be resolve to a warning * @param regexp * the regular expression * @param script * the script * * @return the validation result */ @RequirePOST public FormValidation doCheckExample(@QueryParameter final String example, @QueryParameter final String regexp, @QueryParameter final String script) { if (isNotAllowedToRunScripts()) { return NO_RUN_SCRIPT_PERMISSION_WARNING; } if (StringUtils.isNotBlank(example) && StringUtils.isNotBlank(regexp) && StringUtils.isNotBlank(script)) { FormValidation response = parseExample(script, example, regexp, containsNewline(regexp)); if (example.length() <= MAX_EXAMPLE_SIZE) { return response; } return FormValidation.aggregate(Arrays.asList( FormValidation.warning(Messages.GroovyParser_long_examples_will_be_truncated()), response)); } else { return FormValidation.ok(); } }
Example #6
Source File: GroovyParser.java From warnings-ng-plugin with MIT License | 6 votes |
/** * Performs on-the-fly validation on the Groovy script. * * @param script * the script * * @return the validation result */ @RequirePOST public FormValidation doCheckScript(@QueryParameter(required = true) final String script) { if (isNotAllowedToRunScripts()) { return NO_RUN_SCRIPT_PERMISSION_WARNING; } try { if (StringUtils.isBlank(script)) { return FormValidation.error(Messages.GroovyParser_Error_Script_isEmpty()); } GroovyExpressionMatcher matcher = new GroovyExpressionMatcher(script); Script compiled = matcher.compile(); Ensure.that(compiled).isNotNull(); return FormValidation.ok(); } catch (CompilationFailedException exception) { return FormValidation.error( Messages.GroovyParser_Error_Script_invalid(exception.getLocalizedMessage())); } }
Example #7
Source File: DockerSwarmCloud.java From docker-swarm-plugin with MIT License | 6 votes |
@RequirePOST public FormValidation doValidateTestDockerApiConnection(@QueryParameter("uri") String uri, @QueryParameter("credentialsId") String credentialsId) throws IOException { if (uri.endsWith("/")) { return FormValidation.error("URI must not have trailing /"); } Object response = new PingRequest(uri).execute(); if (response instanceof ApiException) { return FormValidation.error(((ApiException) response).getCause(), "Couldn't ping docker api: " + uri + "/_ping"); } if (response instanceof ApiError) { return FormValidation.error(((ApiError) response).getMessage()); } return FormValidation.ok("Connection successful"); }
Example #8
Source File: GitLabPersonalAccessTokenCreator.java From gitlab-branch-source-plugin with MIT License | 6 votes |
@SuppressWarnings("unused") @RequirePOST public FormValidation doCreateTokenByPassword( @QueryParameter String serverUrl, @QueryParameter String login, @QueryParameter String password) { Jenkins.get().checkPermission(Jenkins.ADMINISTER); try { String tokenName = UUID.randomUUID().toString(); String token = AccessTokenUtils.createPersonalAccessToken( defaultIfBlank(serverUrl, GitLabServer.GITLAB_SERVER_URL), login, password, tokenName, GL_PLUGIN_REQUIRED_SCOPE ); tokenName = getShortName(tokenName); createCredentials(serverUrl, token, login, tokenName); return FormValidation.ok( "Created credentials with id %s", tokenName ); } catch (GitLabApiException e) { return FormValidation .error(e, "Can't create GL token for %s - %s", login, e.getMessage()); } }
Example #9
Source File: GitHubBranchRepository.java From github-integration-plugin with MIT License | 6 votes |
@Override @RequirePOST public FormValidation doRebuildAllFailed() throws IOException { FormValidation result; try { if (job.hasPermission(Item.BUILD)) { Map<String, List<Run<?, ?>>> builds = getAllBranchBuilds(); for (List<Run<?, ?>> buildList : builds.values()) { if (!buildList.isEmpty() && Result.FAILURE.equals(buildList.get(0).getResult())) { Run<?, ?> lastBuild = buildList.get(0); rebuild(lastBuild); } } result = FormValidation.ok("Rebuild scheduled"); } else { result = FormValidation.error("Forbidden"); } } catch (Exception e) { LOG.error("Can't start rebuild", e.getMessage()); result = FormValidation.error(e, "Can't start rebuild: %s", e.getMessage()); } return result; }
Example #10
Source File: KafkaKubernetesCloud.java From remoting-kafka-plugin with MIT License | 6 votes |
@RequirePOST public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl) { Jenkins.get().checkPermission(Jenkins.ADMINISTER); return new StandardListBoxModel().withEmptySelection() .withMatching( CredentialsMatchers.anyOf( CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class), CredentialsMatchers.instanceOf(FileCredentials.class), CredentialsMatchers.instanceOf(TokenProducer.class), CredentialsMatchers.instanceOf(StandardCertificateCredentials.class), CredentialsMatchers.instanceOf(StringCredentials.class)), CredentialsProvider.lookupCredentials(StandardCredentials.class, Jenkins.get(), ACL.SYSTEM, serverUrl != null ? URIRequirementBuilder.fromUri(serverUrl).build() : Collections.EMPTY_LIST )); }
Example #11
Source File: GitHubPRRepository.java From github-integration-plugin with MIT License | 6 votes |
/** * Run trigger from web. */ @RequirePOST public FormValidation doRunTrigger() { FormValidation result; try { if (job.hasPermission(Item.BUILD)) { GitHubPRTrigger trigger = JobHelper.ghPRTriggerFromJob(job); if (trigger != null) { trigger.run(); result = FormValidation.ok("GitHub PR trigger run"); LOG.debug("GitHub PR trigger run for {}", job); } else { LOG.error("GitHub PR trigger not available for {}", job); result = FormValidation.error("GitHub PR trigger not available"); } } else { LOG.warn("No permissions to run GitHub PR trigger"); result = FormValidation.error("Forbidden"); } } catch (Exception e) { LOG.error("Can't run trigger", e); result = FormValidation.error(e, "Can't run trigger: %s", e.getMessage()); } return result; }
Example #12
Source File: ConfigurationAsCode.java From configuration-as-code-plugin with MIT License | 6 votes |
@RequirePOST @Restricted(NoExternalUse.class) public void doCheck(StaplerRequest req, StaplerResponse res) throws Exception { if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { res.sendError(HttpServletResponse.SC_FORBIDDEN); return; } final Map<Source, String> issues = checkWith(YamlSource.of(req)); res.setContentType("application/json"); final JSONArray warnings = new JSONArray(); issues.entrySet().stream().map(e -> new JSONObject().accumulate("line", e.getKey().line).accumulate("warning", e.getValue())) .forEach(warnings::add); warnings.write(res.getWriter()); }
Example #13
Source File: GitHubBranchRepository.java From github-integration-plugin with MIT License | 6 votes |
@Override @RequirePOST public FormValidation doClearRepo() throws IOException { LOG.debug("Got clear GitHub Branch repo request for {}", getJob().getFullName()); FormValidation result; try { if (job.hasPermission(Item.DELETE)) { branches.clear(); save(); result = FormValidation.ok("Branches deleted"); } else { result = FormValidation.error("Forbidden"); } } catch (Exception e) { LOG.error("Can't delete repository file '{}'.", configFile.getFile().getAbsolutePath(), e); result = FormValidation.error(e, "Can't delete: " + e.getMessage()); } return result; }
Example #14
Source File: DockerConnector.java From yet-another-docker-plugin with MIT License | 6 votes |
@RequirePOST public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context) { AccessControlled ac = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()); if (!ac.hasPermission(Jenkins.ADMINISTER)) { return new ListBoxModel(); } List<StandardCredentials> credentials = CredentialsProvider.lookupCredentials(StandardCredentials.class, context, ACL.SYSTEM, Collections.emptyList()); return new CredentialsListBoxModel() .includeEmptyValue() .withMatching(CredentialsMatchers.always(), credentials); }
Example #15
Source File: EnvDashboardView.java From environment-dashboard-plugin with MIT License | 6 votes |
@RequirePOST public void doPurgeSubmit(final StaplerRequest req, StaplerResponse res) throws IOException, ServletException, FormException { checkPermission(Jenkins.ADMINISTER); Connection conn = null; Statement stat = null; conn = DBConnection.getConnection(); try { assert conn != null; stat = conn.createStatement(); stat.execute("TRUNCATE TABLE env_dashboard"); } catch (SQLException e) { System.out.println("E15: Could not truncate table env_dashboard.\n" + e.getMessage()); } finally { DBConnection.closeConnection(); } res.forwardToPreviousPage(req); }
Example #16
Source File: KubernetesCloud.java From kubernetes-plugin with Apache License 2.0 | 6 votes |
@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 #17
Source File: TokenReloadAction.java From configuration-as-code-plugin with MIT License | 6 votes |
@RequirePOST public void doIndex(StaplerRequest request, StaplerResponse response) throws IOException { String token = getReloadTokenProperty(); if (Strings.isNullOrEmpty(token)) { response.sendError(404); LOGGER.warning("Configuration reload via token is not enabled"); } else { String requestToken = getRequestToken(request); if (token.equals(requestToken)) { LOGGER.info("Configuration reload triggered via token"); try (ACLContext ignored = ACL.as(ACL.SYSTEM)) { ConfigurationAsCode.get().configure(); } } else { response.sendError(401); LOGGER.warning("Invalid token received, not reloading configuration"); } } }
Example #18
Source File: GlobalKafkaConfiguration.java From remoting-kafka-plugin with MIT License | 6 votes |
@RequirePOST public ListBoxModel doFillKubernetesCredentialsIdItems() { Jenkins.get().checkPermission(Jenkins.ADMINISTER); return new StandardListBoxModel().withEmptySelection() .withMatching( CredentialsMatchers.anyOf( CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class), CredentialsMatchers.instanceOf(FileCredentials.class), CredentialsMatchers.instanceOf(TokenProducer.class), CredentialsMatchers.instanceOf(StandardCertificateCredentials.class), CredentialsMatchers.instanceOf(StringCredentials.class)), CredentialsProvider.lookupCredentials(StandardCredentials.class, Jenkins.get(), ACL.SYSTEM, Collections.EMPTY_LIST )); }
Example #19
Source File: GitHubPRRepository.java From github-integration-plugin with MIT License | 6 votes |
@RequirePOST public FormValidation doRebuildAllFailed() throws IOException { FormValidation result; try { if (job.hasPermission(Item.BUILD)) { Map<Integer, List<Run<?, ?>>> builds = getAllPrBuilds(); for (List<Run<?, ?>> buildList : builds.values()) { if (!buildList.isEmpty() && Result.FAILURE.equals(buildList.get(0).getResult())) { Run<?, ?> lastBuild = buildList.get(0); rebuild(lastBuild); } } result = FormValidation.ok("Rebuild scheduled"); } else { result = FormValidation.error("Forbidden"); } } catch (Exception e) { LOG.error("Can't start rebuild", e); result = FormValidation.error(e, "Can't start rebuild: %s", e.getMessage()); } return result; }
Example #20
Source File: TemplateDrivenMultiBranchProject.java From multi-branch-project-plugin with MIT License | 5 votes |
@SuppressWarnings(UNUSED) @CLIMethod(name = "disable-job") @RequirePOST public HttpResponse doDisable() throws IOException, ServletException { // NOSONAR checkPermission(CONFIGURE); makeDisabled(true); return new HttpRedirect("."); }
Example #21
Source File: DynamicBuild.java From DotCi with MIT License | 5 votes |
@Override @RequirePOST public void doDoDelete(final StaplerRequest req, final StaplerResponse rsp) throws IOException, ServletException { checkPermission(DELETE); this.model.deleteBuild(); rsp.sendRedirect2(req.getContextPath() + '/' + getParent().getUrl()); }
Example #22
Source File: TemplateDrivenMultiBranchProject.java From multi-branch-project-plugin with MIT License | 5 votes |
@SuppressWarnings(UNUSED) @CLIMethod(name = "enable-job") @RequirePOST public HttpResponse doEnable() throws IOException, ServletException { // NOSONAR checkPermission(CONFIGURE); makeDisabled(false); return new HttpRedirect("."); }
Example #23
Source File: TestObject.java From junit-plugin with MIT License | 5 votes |
@RequirePOST public synchronized HttpResponse doSubmitDescription( @QueryParameter String description) throws IOException, ServletException { Run<?, ?> run = getRun(); if (run == null) { LOGGER.severe("getRun() is null, can't save description."); } else { run.checkPermission(Run.UPDATE); setDescription(description); run.save(); } return new HttpRedirect("."); }
Example #24
Source File: DockerAPI.java From docker-plugin with MIT License | 5 votes |
@RequirePOST public FormValidation doTestConnection( @AncestorInPath Item context, @QueryParameter String uri, @QueryParameter String credentialsId, @QueryParameter String apiVersion, @QueryParameter int connectTimeout, @QueryParameter int readTimeout ) { throwIfNoPermission(context); final FormValidation credentialsIdCheckResult = doCheckCredentialsId(context, uri, credentialsId); if (credentialsIdCheckResult != FormValidation.ok()) { return FormValidation.error("Invalid credentials"); } try { final DockerServerEndpoint dsep = new DockerServerEndpoint(uri, credentialsId); final DockerAPI dapi = new DockerAPI(dsep, connectTimeout, readTimeout, apiVersion, null); try(final DockerClient dc = dapi.getClient()) { final VersionCmd vc = dc.versionCmd(); final Version v = vc.exec(); final String actualVersion = v.getVersion(); final String actualApiVersion = v.getApiVersion(); return FormValidation.ok("Version = " + actualVersion + ", API Version = " + actualApiVersion); } } catch (Exception e) { return FormValidation.error(e, e.getMessage()); } }
Example #25
Source File: GitHubSCMSource.java From github-branch-source-plugin with MIT License | 5 votes |
@RequirePOST @Restricted(NoExternalUse.class) public FormValidation doCheckCredentialsId(@CheckForNull @AncestorInPath Item context, @QueryParameter String apiUri, @QueryParameter String value) { return Connector.checkScanCredentials(context, apiUri, value); }
Example #26
Source File: DockerManagementServer.java From docker-plugin with MIT License | 5 votes |
@SuppressWarnings("unused") @RequirePOST public void doControlSubmit(@QueryParameter("stopId") String stopId, StaplerRequest req, StaplerResponse rsp) throws IOException { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); final DockerAPI dockerApi = theCloud.getDockerApi(); try(final DockerClient client = dockerApi.getClient()) { client.stopContainerCmd(stopId).exec(); } rsp.sendRedirect("."); }
Example #27
Source File: DockerConnector.java From yet-another-docker-plugin with MIT License | 5 votes |
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "docker-java uses runtime exceptions") @RequirePOST public FormValidation doTestConnection( @QueryParameter String serverUrl, @QueryParameter String apiVersion, @QueryParameter String credentialsId, @QueryParameter ConnectorType connectorType, @QueryParameter Integer connectTimeout, @QueryParameter Integer readTimeout ) throws IOException, ServletException, DockerException { try { DefaultDockerClientConfig.Builder configBuilder = new DefaultDockerClientConfig.Builder() .withApiVersion(apiVersion) .withDockerHost(serverUrl); final DockerClient testClient = newClientBuilderForConnector() .withConfigBuilder(configBuilder) .withConnectorType(connectorType) .withCredentialsId(credentialsId) .withConnectTimeout(connectTimeout) .withReadTimeout(readTimeout) .build(); Version verResult = testClient.versionCmd().exec(); return ok(reflectionToString(verResult, MULTI_LINE_STYLE)); } catch (Exception e) { return FormValidation.error(e, e.getMessage()); } }
Example #28
Source File: Endpoint.java From github-branch-source-plugin with MIT License | 5 votes |
@RequirePOST @Restricted(NoExternalUse.class) public FormValidation doCheckApiUri(@QueryParameter String apiUri) { Jenkins.get().checkPermission(Jenkins.ADMINISTER); if (Util.fixEmptyAndTrim(apiUri) == null) { return FormValidation.warning("You must specify the API URL"); } try { URL api = new URL(apiUri); GitHub github = GitHub.connectToEnterpriseAnonymously(api.toString()); github.checkApiUrlValidity(); LOGGER.log(Level.FINE, "Trying to configure a GitHub Enterprise server"); // For example: https://api.github.com/ or https://github.mycompany.com/api/v3/ (with private mode disabled). return FormValidation.ok("GitHub Enterprise server verified"); } catch (MalformedURLException mue) { // For example: https:/api.github.com LOGGER.log(Level.WARNING, "Trying to configure a GitHub Enterprise server: " + apiUri, mue.getCause()); return FormValidation.error("The endpoint does not look like a GitHub Enterprise (malformed URL)"); } catch (JsonParseException jpe) { LOGGER.log(Level.WARNING, "Trying to configure a GitHub Enterprise server: " + apiUri, jpe.getCause()); return FormValidation.error("The endpoint does not look like a GitHub Enterprise (invalid JSON response)"); } catch (FileNotFoundException fnt) { // For example: https://github.mycompany.com/server/api/v3/ gets a FileNotFoundException LOGGER.log(Level.WARNING, "Getting HTTP Error 404 for " + apiUri); return FormValidation.error("The endpoint does not look like a GitHub Enterprise (page not found"); } catch (IOException e) { // For example: https://github.mycompany.com/api/v3/ or https://github.mycompany.com/api/v3/mypath if (e.getMessage().contains("private mode enabled")) { LOGGER.log(Level.FINE, e.getMessage()); return FormValidation.warning("Private mode enabled, validation disabled"); } LOGGER.log(Level.WARNING, e.getMessage()); return FormValidation.error("The endpoint does not look like a GitHub Enterprise (verify network and/or try again later)"); } }
Example #29
Source File: GitHubSCMSource.java From github-branch-source-plugin with MIT License | 5 votes |
@RequirePOST @Restricted(NoExternalUse.class) public FormValidation doCheckScanCredentialsId(@CheckForNull @AncestorInPath Item context, @QueryParameter String apiUri, @QueryParameter String scanCredentialsId) { return doCheckCredentialsId(context, apiUri, scanCredentialsId); }
Example #30
Source File: GitHubStatusNotificationStep.java From pipeline-githubnotify-step-plugin with MIT License | 5 votes |
@RequirePOST public FormValidation doCheckRepo(@QueryParameter ("credentialsId") final String credentialsId, @QueryParameter ("repo") final String repo, @QueryParameter ("account") final String account, @QueryParameter ("gitApiUrl") final String gitApiUrl, @AncestorInPath Item context) { context.checkPermission(Item.CONFIGURE); try { getRepoIfValid(credentialsId, gitApiUrl, account, repo, context); return FormValidation.ok("Success"); } catch (Exception e) { return FormValidation.error(e.getMessage()); } }