Skip to content

Commit

Permalink
Include scope in /oauth/authorize URL (#26)
Browse files Browse the repository at this point in the history
* Include scope in `/oauth/authorize` URL

As described in Gitlab's guide[1], the parameter should be included,
 otherwise a default set of scopes will be granted, which seems to be
 just `read_user` and is not enough for Jenkins.

According to the README, the plugin needs the `api` scope, so that's
what we're explicitly requesting from Gitlab.

[1] https://docs.gitlab.com/ee/api/oauth2.html#web-application-flow

[JENKINS-63536]

* Remove unneeded JavaDoc tags & document some return types
  • Loading branch information
dskrvk authored Aug 28, 2020
1 parent 3dcc8d4 commit 4583875
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public GitlabUser getMyself() {
*
* @param candidateName
* @param organization
* @return
* @return whether given candidate belongs to a given organization
*/
public boolean hasOrganizationPermission(String candidateName, String organization) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,71 +117,65 @@ private Object readResolve() {
}

/**
* @return
* @return comma- and space-separated organization names
* @see org.jenkinsci.plugins.GitLabRequireOrganizationMembershipACL#getOrganizationNameList()
*/
public String getOrganizationNames() {
return StringUtils.join(rootACL.getOrganizationNameList().iterator(), ", ");
}

/**
* @return
* @return comma- and space-separated admin organization names
* @see org.jenkinsci.plugins.GitLabRequireOrganizationMembershipACL#getAdminOrganizationNameList()
*/
public String getAdminOrganizationNames() {
return StringUtils.join(rootACL.getAdminOrganizationNameList().iterator(), ", ");
}

/**
* @return
* @return comma- and space-separated admin usernames
* @see org.jenkinsci.plugins.GitLabRequireOrganizationMembershipACL#getAdminUserNameList()
*/
public String getAdminUserNames() {
return StringUtils.join(rootACL.getAdminUserNameList().iterator(), ", ");
}

/**
* @return
* @see org.jenkinsci.plugins.GitLabRequireOrganizationMembershipACL#isUseRepositoryPermissions()
*/
public boolean isUseRepositoryPermissions() {
return rootACL.isUseRepositoryPermissions();
}

/**
* @return
* @see org.jenkinsci.plugins.GitLabRequireOrganizationMembershipACL#isAuthenticatedUserCreateJobPermission()
*/
public boolean isAuthenticatedUserCreateJobPermission() {
return rootACL.isAuthenticatedUserCreateJobPermission();
}

/**
* @return
* @see org.jenkinsci.plugins.GitLabRequireOrganizationMembershipACL#isAuthenticatedUserStopBuildPermission()
*/
public boolean isAuthenticatedUserStopBuildPermission() {
return rootACL.isAuthenticatedUserStopBuildPermission();
}

/**
* @return
* @see org.jenkinsci.plugins.GitLabRequireOrganizationMembershipACL#isAuthenticatedUserReadPermission()
*/
public boolean isAuthenticatedUserReadPermission() {
return rootACL.isAuthenticatedUserReadPermission();
}

/**
* @return
* @see org.jenkinsci.plugins.GitLabRequireOrganizationMembershipACL#isAllowGitlabWebHookPermission()
*/
public boolean isAllowGitlabWebHookPermission() {
return rootACL.isAllowGitlabWebHookPermission();
}

/**
* @return
* @see org.jenkinsci.plugins.GitLabRequireOrganizationMembershipACL#isAllowCcTrayPermission()
*/
public boolean isAllowCcTrayPermission() {
Expand All @@ -190,7 +184,6 @@ public boolean isAllowCcTrayPermission() {


/**
* @return
* @see org.jenkinsci.plugins.GitLabRequireOrganizationMembershipACL#isAllowAnonymousReadPermission()
*/
public boolean isAllowAnonymousReadPermission() {
Expand All @@ -199,7 +192,6 @@ public boolean isAllowAnonymousReadPermission() {

/**
* @see org.jenkinsci.plugins.GitLabRequireOrganizationMembershipACL#isAllowAnonymousJobStatusPermission()
* @return
*/
public boolean isAllowAnonymousJobStatusPermission() {
return rootACL.isAllowAnonymousJobStatusPermission();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jenkinsci/plugins/GitLabSecurityRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ public HttpResponse doCommenceLogin(StaplerRequest request, @QueryParameter Stri
parameters.add(new BasicNameValuePair("redirect_uri", buildRedirectUrl(request, redirectOnFinish)));
parameters.add(new BasicNameValuePair("response_type", "code"));
parameters.add(new BasicNameValuePair("client_id", clientID));
parameters.add(new BasicNameValuePair("scope", "api"));

return new HttpRedirect(gitlabWebUri + "/oauth/authorize?" + URLEncodedUtils.format(parameters, StandardCharsets.UTF_8));
}
Expand Down Expand Up @@ -504,7 +505,6 @@ public DescriptorImpl getDescriptor() {
/**
*
* @param username
* @return
* @throws UsernameNotFoundException
* @throws DataAccessException
*/
Expand Down Expand Up @@ -561,7 +561,6 @@ public int hashCode() {
/**
*
* @param groupName
* @return
* @throws UsernameNotFoundException
* @throws DataAccessException
*/
Expand Down

0 comments on commit 4583875

Please sign in to comment.