1818import hudson .util .FormValidation ;
1919import hudson .util .ListBoxModel ;
2020import hudson .util .Secret ;
21+ import jenkins .model .Jenkins ;
2122import org .apache .commons .codec .binary .Hex ;
2223import org .apache .commons .lang .StringUtils ;
2324import org .jenkinsci .plugins .plaincredentials .StringCredentials ;
3233import org .kohsuke .stapler .DataBoundConstructor ;
3334import org .kohsuke .stapler .QueryParameter ;
3435import org .kohsuke .stapler .export .Exported ;
36+ import org .kohsuke .stapler .verb .POST ;
3537
3638import javax .crypto .Mac ;
3739import javax .crypto .spec .SecretKeySpec ;
3840import java .io .IOException ;
39- import java .net .URISyntaxException ;
4041import java .nio .charset .Charset ;
4142import java .util .ArrayList ;
4243import java .util .Arrays ;
@@ -57,7 +58,7 @@ public class GhprbGitHubAuth extends AbstractDescribableImpl<GhprbGitHubAuth> {
5758
5859 private static final int SHA1_PREFIX_LENGTH = 5 ;
5960
60- static final int INITIAL_CAPACITY = 3 ;
61+ private static final int INITIAL_CAPACITY = 3 ;
6162
6263 private final String serverAPIUrl ;
6364
@@ -241,16 +242,15 @@ public String getDisplayName() {
241242 * @param serverAPIUrl the github api server url.
242243 * @param credentialsId the credentialsId from the credentials plugin
243244 * @return list box model.
244- * @throws URISyntaxException If the url is bad
245245 */
246246 public ListBoxModel doFillCredentialsIdItems (
247247 @ AncestorInPath Item context ,
248248 @ QueryParameter String serverAPIUrl ,
249249 @ QueryParameter String credentialsId
250- ) throws URISyntaxException {
250+ ) {
251251 List <DomainRequirement > domainRequirements = URIRequirementBuilder .fromUri (serverAPIUrl ).build ();
252252
253- List <CredentialsMatcher > matchers = new ArrayList <CredentialsMatcher >(INITIAL_CAPACITY );
253+ List <CredentialsMatcher > matchers = new ArrayList <>(INITIAL_CAPACITY );
254254 if (!StringUtils .isEmpty (credentialsId )) {
255255 matchers .add (0 , CredentialsMatchers .withId (credentialsId ));
256256 }
@@ -273,14 +273,16 @@ public ListBoxModel doFillCredentialsIdItems(
273273 );
274274 }
275275
276-
276+ @ POST
277277 public FormValidation doCreateApiToken (
278278 @ QueryParameter ("serverAPIUrl" ) final String serverAPIUrl ,
279279 @ QueryParameter ("credentialsId" ) final String credentialsId ,
280280 @ QueryParameter ("username" ) final String username ,
281281 @ QueryParameter ("password" ) final String password ) {
282282 try {
283283
284+ Jenkins .getInstance ().checkPermission (Jenkins .ADMINISTER );
285+
284286 GitHubBuilder builder = new GitHubBuilder ()
285287 .withEndpoint (serverAPIUrl )
286288 .withConnector (new HttpConnectorWithJenkinsProxy ());
@@ -326,10 +328,14 @@ public FormValidation doCheckServerAPIUrl(@QueryParameter String value) {
326328 return FormValidation .warning ("GitHub API URI is \" https://api.github.com\" . GitHub Enterprise API URL ends with \" /api/v3\" " );
327329 }
328330
331+ @ POST
329332 public FormValidation doCheckRepoAccess (
330333 @ QueryParameter ("serverAPIUrl" ) final String serverAPIUrl ,
331334 @ QueryParameter ("credentialsId" ) final String credentialsId ,
332335 @ QueryParameter ("repo" ) final String repo ) {
336+
337+ Jenkins .getInstance ().checkPermission (Jenkins .ADMINISTER );
338+
333339 try {
334340 GitHubBuilder builder = getBuilder (null , serverAPIUrl , credentialsId );
335341 if (builder == null ) {
@@ -339,7 +345,7 @@ public FormValidation doCheckRepoAccess(
339345 GHRepository repository = gh .getRepository (repo );
340346 StringBuilder sb = new StringBuilder ();
341347 sb .append ("User has access to: " );
342- List <String > permissions = new ArrayList <String >(INITIAL_CAPACITY );
348+ List <String > permissions = new ArrayList <>(INITIAL_CAPACITY );
343349 if (repository .hasAdminAccess ()) {
344350 permissions .add ("Admin" );
345351 }
@@ -357,9 +363,13 @@ public FormValidation doCheckRepoAccess(
357363 }
358364 }
359365
366+ @ POST
360367 public FormValidation doTestGithubAccess (
361368 @ QueryParameter ("serverAPIUrl" ) final String serverAPIUrl ,
362369 @ QueryParameter ("credentialsId" ) final String credentialsId ) {
370+
371+ Jenkins .getInstance ().checkPermission (Jenkins .ADMINISTER );
372+
363373 try {
364374 GitHubBuilder builder = getBuilder (null , serverAPIUrl , credentialsId );
365375 if (builder == null ) {
0 commit comments