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 EnableSupportLogging feature #36115

Merged
merged 4 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 sdk/identity/azure-identity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Features Added
- Added CAE Authentication support for Service principal authentication.
- Added the ability to log PII from MSAL using new `enableSupportLogging` API.

### Other Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,15 @@ public T disableInstanceDiscovery() {
this.identityClientOptions.disableInstanceDiscovery();
return (T) this;
}

/**
* Enables additional support logging for public and confidential client applications. This enables
* PII logging in MSAL4J as described <a href="https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-logging-java#personal-and-organization-information">here.</a>
billwert marked this conversation as resolved.
Show resolved Hide resolved
* @return An updated instance of this builder with additional support logging enabled.
*/
@SuppressWarnings("unchecked")
public T enableSupportLogging() {
this.identityClientOptions.enableSupportLogging();
return (T) this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ ConfidentialClientApplication getConfidentialClient(boolean enableCae) {
ConfidentialClientApplication.Builder applicationBuilder =
ConfidentialClientApplication.builder(clientId, credential);
try {
applicationBuilder = applicationBuilder.authority(authorityUrl).instanceDiscovery(options.isInstanceDiscoveryEnabled());
applicationBuilder = applicationBuilder.
logPii(options.isSupportLoggingEnabled()).
authority(authorityUrl).
instanceDiscovery(options.isInstanceDiscoveryEnabled());

if (!options.isInstanceDiscoveryEnabled()) {
LOGGER.log(LogLevel.VERBOSE, () -> "Instance discovery and authority validation is disabled. In this"
Expand Down Expand Up @@ -281,7 +284,9 @@ PublicClientApplication getPublicClient(boolean sharedTokenCacheCredential, bool
+ tenantId;
PublicClientApplication.Builder builder = PublicClientApplication.builder(clientId);
try {
builder = builder.authority(authorityUrl).instanceDiscovery(options.isInstanceDiscoveryEnabled());
builder = builder.
logPii(options.isSupportLoggingEnabled()).
billwert marked this conversation as resolved.
Show resolved Hide resolved
authority(authorityUrl).instanceDiscovery(options.isInstanceDiscoveryEnabled());

if (!options.isInstanceDiscoveryEnabled()) {
LOGGER.log(LogLevel.VERBOSE, () -> "Instance discovery and authority validation is disabled. In this"
Expand Down Expand Up @@ -340,7 +345,11 @@ ConfidentialClientApplication getManagedIdentityConfidentialClient() {
ConfidentialClientApplication.Builder applicationBuilder =
ConfidentialClientApplication.builder(clientId == null ? "SYSTEM-ASSIGNED-MANAGED-IDENTITY"
: clientId, credential);
applicationBuilder.validateAuthority(false);

applicationBuilder.
validateAuthority(false).
logPii(options.isSupportLoggingEnabled());

try {
applicationBuilder = applicationBuilder.authority(authorityUrl);
} catch (MalformedURLException e) {
Expand Down Expand Up @@ -395,7 +404,9 @@ ConfidentialClientApplication getWorkloadIdentityConfidentialClient() {
: clientId, credential);

try {
applicationBuilder = applicationBuilder.authority(authorityUrl).instanceDiscovery(options.isInstanceDiscoveryEnabled());
applicationBuilder = applicationBuilder.authority(authorityUrl).
logPii(options.isSupportLoggingEnabled()).
billwert marked this conversation as resolved.
Show resolved Hide resolved
instanceDiscovery(options.isInstanceDiscoveryEnabled());

if (!options.isInstanceDiscoveryEnabled()) {
LOGGER.log(LogLevel.VERBOSE, () -> "Instance discovery and authority validation is disabled. In this"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public final class IdentityClientOptions implements Cloneable {
private Duration credentialProcessTimeout = Duration.ofSeconds(10);

private boolean isChained;
private boolean enableSupportLogging;

/**
* Creates an instance of IdentityClientOptions with default settings.
Expand Down Expand Up @@ -713,6 +714,23 @@ public IdentityClientOptions setChained(boolean isChained) {
return this;
}

/**
* Gets the status whether support logging is enabled or not.
* @return the flag indicating if support logging is enabled or not.
*/
public boolean isSupportLoggingEnabled() {
return enableSupportLogging;
}

/**
* Enables additional support logging (including PII) for MSAL based credentials.
* @return the updated client options
*/
public IdentityClientOptions enableSupportLogging() {
this.enableSupportLogging = true;
return this;
}

public IdentityClientOptions clone() {
IdentityClientOptions clone = new IdentityClientOptions()
.setAdditionallyAllowedTenants(this.additionallyAllowedTenants)
Expand Down Expand Up @@ -745,6 +763,9 @@ public IdentityClientOptions clone() {
if (!isInstanceDiscoveryEnabled()) {
clone.disableInstanceDiscovery();
}
if (isSupportLoggingEnabled()) {
clone.enableSupportLogging();
}
return clone;
}
}