Skip to content
This repository was archived by the owner on Jul 1, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.sonarqube.auth.google</groupId>
<artifactId>sonar-auth-googleoauth-plugin</artifactId>
<version>1.6.3-SNAPSHOT</version>
<version>1.7.0</version>
<packaging>sonar-plugin</packaging>
<name>Google Authentication for SonarQube</name>
<inceptionYear>2016</inceptionYear>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public void callback(CallbackContext context) {

GsonUser gsonUser = requestUser(scribe, accessToken);
String redirectTo;
if (settings.oauthDomain()==null || (settings.oauthDomain()!=null && gsonUser.getEmail().endsWith("@"+settings.oauthDomain()))) {

if (domainIsAllowed(gsonUser.getEmail()) ) {
redirectTo = settings.getSonarBaseURL();
String referer_url = request.getHeader("referer");
try {
Expand Down Expand Up @@ -156,6 +157,26 @@ public void callback(CallbackContext context) {
}
}

private Boolean domainIsAllowed(String email) {

if (settings.oauthDomain()==null) {
return true;
}

Boolean domainWhitelisted = true;

if (settings.oauthDomain()!=null) {
domainWhitelisted = false;

for ( String allowedDomain : settings.oauthDomain().split(",")) {
if (email.endsWith("@"+allowedDomain.replaceAll(" ", ""))) {
domainWhitelisted = true;
}
}
}
return domainWhitelisted;
}

private GsonUser requestUser(OAuthService scribe, Token accessToken) {
OAuthRequest userRequest = new OAuthRequest(Verb.GET, settings.apiURL() + "oauth2/v1/userinfo", scribe);
scribe.signRequest(accessToken, userRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public static List<PropertyDefinition> definitions() {
.index(index++)
.build(),
PropertyDefinition.builder(LIMIT_DOMAIN)
.name("Allowed Domain")
.description("When set, this will only allow users from the specified GApps domain to authenticate")
.name("Allowed Domain(s)")
.description("When set, this will only allow users from the specified GApps domain(s) to authenticate (comma-separated)")
.category(CATEGORY)
.subCategory(SUBCATEGORY)
.index(index++)
Expand Down