Skip to content

Commit

Permalink
Merge pull request #135 from srvrguy/misc-updates
Browse files Browse the repository at this point in the history
Misc updates
  • Loading branch information
srvrguy authored Aug 2, 2022
2 parents 6789da6 + 9768383 commit f110ad7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 32 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<licenses>
<license>
<name>The MIT License (MIT)</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<url>https://opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>
Expand Down Expand Up @@ -100,7 +100,7 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
<version>20220320</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -124,7 +124,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.21.0</version>
<version>3.23.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -136,7 +136,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.12.4</version>
<version>4.6.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -148,7 +148,7 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>4.9.2</version>
<version>4.10.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
29 changes: 8 additions & 21 deletions src/main/java/org/almrangers/auth/aad/AadSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public class AadSettings {
protected static final String DIRECTORY_LOCATION = "sonar.auth.aad.directoryLocation";
protected static final String DIRECTORY_LOC_GLOBAL = "Azure AD (Global)";
protected static final String DIRECTORY_LOC_USGOV = "Azure AD for US Government";
protected static final String DIRECTORY_LOC_DE = "Azure AD for Germany";
protected static final String DIRECTORY_LOC_CN = "Azure AD China";
protected static final String ENABLE_GROUPS_SYNC = "sonar.auth.aad.enableGroupsSync";
protected static final String ENABLE_CLIENT_CRED = "sonar.auth.aad.enableClientCredential";
Expand All @@ -65,15 +64,13 @@ public class AadSettings {

protected static final String LOGIN_URL = "https://login.microsoftonline.com";
protected static final String LOGIN_URL_USGOV = "https://login.microsoftonline.us";
protected static final String LOGIN_URL_DE = "https://login.microsoftonline.de";
protected static final String LOGIN_URL_CN = "https://login.chinacloudapi.cn";
protected static final String AUTHORIZATION_URL = "oauth2/authorize";
protected static final String AUTHORITY_URL = "oauth2/token";
protected static final String COMMON_URL = "common";

protected static final String GRAPH_URL = "https://graph.microsoft.com";
protected static final String GRAPH_URL_USGOV = "https://graph.microsoft.com";
protected static final String GRAPH_URL_DE = "https://graph.microsoft.de";
protected static final String GRAPH_URL_CN = "https://microsoftgraph.chinacloudapi.cn";
protected static final String AUTH_REQUEST_FORMAT = "%s?client_id=%s&response_type=code&redirect_uri=%s&state=%s&scope=openid";
protected static final String GROUPS_REQUEST_FORMAT = "/v1.0/%s/users/%s/transitiveMemberOf";
Expand Down Expand Up @@ -144,7 +141,7 @@ public static List<PropertyDefinition> definitions() {
.subCategory(SUBCATEGORY_ADVANCED)
.type(SINGLE_SELECT_LIST)
.defaultValue(DIRECTORY_LOC_GLOBAL)
.options(DIRECTORY_LOC_GLOBAL, DIRECTORY_LOC_USGOV, DIRECTORY_LOC_DE, DIRECTORY_LOC_CN)
.options(DIRECTORY_LOC_GLOBAL, DIRECTORY_LOC_USGOV, DIRECTORY_LOC_CN)
.index(3)
.build(),
PropertyDefinition.builder(ENABLE_CLIENT_CRED)
Expand Down Expand Up @@ -201,14 +198,9 @@ private String getLoginHost() {
Optional<String> directoryLocation = config.get(DIRECTORY_LOCATION);

if(directoryLocation.isPresent()) {
switch (directoryLocation.get()) {
case DIRECTORY_LOC_USGOV:
return LOGIN_URL_USGOV;

case DIRECTORY_LOC_DE:
return LOGIN_URL_DE;

case DIRECTORY_LOC_CN:
if (directoryLocation.get().equals(DIRECTORY_LOC_USGOV)) {
return LOGIN_URL_USGOV;
} else if (directoryLocation.get().equals(DIRECTORY_LOC_CN)) {
return LOGIN_URL_CN;
}
}
Expand All @@ -229,15 +221,10 @@ public String getGraphURL() {
Optional<String> directoryLocation = config.get(DIRECTORY_LOCATION);

if(directoryLocation.isPresent()) {
switch (directoryLocation.get()) {
case DIRECTORY_LOC_USGOV:
return GRAPH_URL_USGOV;

case DIRECTORY_LOC_DE:
return GRAPH_URL_DE;

case DIRECTORY_LOC_CN:
return GRAPH_URL_CN;
if (directoryLocation.get().equals(DIRECTORY_LOC_USGOV)) {
return GRAPH_URL_USGOV;
} else if (directoryLocation.get().equals(DIRECTORY_LOC_CN)) {
return GRAPH_URL_CN;
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/test/java/org/almrangers/auth/aad/AadSettingsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,12 @@ public void return_correct_urls() {
assertThat(underTest.authorizationUrl()).startsWith("https://login.microsoftonline.us");
assertThat(underTest.getGraphURL()).startsWith("https://graph.microsoft.com");

//Azure Germany
settings.setProperty("sonar.auth.aad.directoryLocation", DIRECTORY_LOC_DE);
assertThat(underTest.authorizationUrl()).startsWith("https://login.microsoftonline.de");
assertThat(underTest.getGraphURL()).startsWith("https://graph.microsoft.de");

//Azure China
settings.setProperty("sonar.auth.aad.directoryLocation", DIRECTORY_LOC_CN);
assertThat(underTest.authorizationUrl()).startsWith("https://login.chinacloudapi.cn");
assertThat(underTest.getGraphURL()).startsWith("https://microsoftgraph.chinacloudapi.cn");
}

@Test
public void return_graph_membership_url() {
settings.setProperty("sonar.auth.aad.directoryLocation", DIRECTORY_LOC_GLOBAL);
Expand Down

0 comments on commit f110ad7

Please sign in to comment.