Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for OneBox Environment, Fixes AB#3113751 #2559

Merged
merged 6 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ vNext
- [MINOR] Add Child Spans for Interactive Span (#2516)
- [MINOR] For MSAL CPP flows, match exact claims when deleting AT with intersecting scopes (#2548)
- [MINOR] Replace Deprecated Keystore API for Android 28+ (#2558)
- [MINOR] Add support for OneBox Environment (#2559)

Version 18.2.2
----------
Expand Down
6 changes: 6 additions & 0 deletions common4j/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def dcParameter = "" // will be blank unless specified by developer
def useMockApiForNativeAuthParameter = false // will be false unless specified by developer
def mockApiUrlParameter = "" // will be blank unless specified by developer
def disableAcquireTokenSilentTimeoutParameter = false // will be false unless specified by developer
def allowOneboxAuthorities = false // will be false unless specified by developer

if (project.hasProperty("slice")) {
sliceParameter = slice
Expand All @@ -175,6 +176,10 @@ if (project.hasProperty("disableAcquireTokenSilentTimeout")) {
disableAcquireTokenSilentTimeoutParameter = true
}

if (project.hasProperty("allowOneboxAuthorities")) {
allowOneboxAuthorities = true
}

sourceSets {
main {
java.srcDirs = ['src/main', "$project.buildDir/generated/source/buildConfig/main"]
Expand All @@ -183,6 +188,7 @@ sourceSets {
buildConfigField("boolean", "USE_MOCK_API_FOR_NATIVE_AUTH_AUTHORITY", "${useMockApiForNativeAuthParameter}")
buildConfigField("String", "MOCK_API_URL", "\"$mockApiUrlParameter\"")
buildConfigField("boolean", "DISABLE_ACQUIRE_TOKEN_SILENT_TIMEOUT", "${disableAcquireTokenSilentTimeoutParameter}")
buildConfigField("boolean", "ALLOW_ONEBOX_AUTHORITIES", "${allowOneboxAuthorities}")
}
test {
java.srcDirs = ['src/test']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,17 @@ private static boolean authorityIsKnownFromConfiguration(@NonNull final String a
return null != getEquivalentConfiguredAuthority(authorityStr);
}

private static Authority createAadAuthority(@NonNull final CommonURIBuilder authorityCommonUriBuilder,
private static Authority createAadAuthority(@NonNull final CommonURIBuilder uriBuilder,
@NonNull final List<String> pathSegments) {
final String cloudUrl;
if (uriBuilder.getPort() != -1) {
cloudUrl = uriBuilder.getScheme() + "://" + uriBuilder.getHost() + ":" + uriBuilder.getPort();
} else {
cloudUrl = uriBuilder.getScheme() + "://" + uriBuilder.getHost();
}

AzureActiveDirectoryAudience audience = AzureActiveDirectoryAudience.getAzureActiveDirectoryAudience(
authorityCommonUriBuilder.getScheme() + "://" + authorityCommonUriBuilder.getHost(),
cloudUrl,
pathSegments.get(0)
);

Expand Down Expand Up @@ -344,6 +351,10 @@ public static boolean isKnownAuthority(Authority authority) {
return false;
}

if (BuildConfig.ALLOW_ONEBOX_AUTHORITIES) {
return true; // onebox authorities are always considered to be known.
shahzaibj marked this conversation as resolved.
Show resolved Hide resolved
}

//Check if authority was added to configuration
for (final Authority currentAuthority : knownAuthorities) {
if (currentAuthority.mAuthorityUrlString != null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ public Authority deserialize(JsonElement json, Type typeOfT, JsonDeserialization
if (aadAuthority != null && aadAuthority.mAuthorityUrlString != null) {
try {
final CommonURIBuilder uri = new CommonURIBuilder(URI.create(aadAuthority.mAuthorityUrlString));
final String cloudUrl = uri.getScheme() + "://" + uri.getHost();
final String cloudUrl;
if (uri.getPort() != -1) {
cloudUrl = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort();
} else {
cloudUrl = uri.getScheme() + "://" + uri.getHost();
}

final String tenant = uri.getLastPathSegment();
if (!StringUtil.isNullOrEmpty(tenant)) {
aadAuthority.mAudience = AzureActiveDirectoryAudience.getAzureActiveDirectoryAudience(cloudUrl, tenant);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@

public enum Environment {
PreProduction,
Production
Production,
OneBox // local ests setup
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ public static synchronized void initializeCloudMetadata(@NonNull final String au
public static synchronized String getDefaultCloudUrl() {
if (sEnvironment == Environment.PreProduction) {
return AzureActiveDirectoryEnvironment.PREPRODUCTION_CLOUD_URL;
} else if (sEnvironment == Environment.OneBox) {
return AzureActiveDirectoryEnvironment.ONEBOX_CLOUD_URL;
} else {
return AzureActiveDirectoryEnvironment.PRODUCTION_CLOUD_URL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public class AzureActiveDirectoryEnvironment {
public static final String PRODUCTION_CLOUD_URL = "https://login.microsoftonline.com"; //Prod
public static final String PREPRODUCTION_CLOUD_URL = "https://login.windows-ppe.net"; //PPE
public static final String ONEBOX_CLOUD_URL = "https://zurich.test.dnsdemo1.test:8478"; // Local ESTS Deployment
}
Loading