-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid exposing identityClientOptions (#37546)
* Avoid exposing identityClientOptions Instead of making this field protected we'll access it with reflection from the new broker builder. * Use a helper type instead * Cleanup loggers * unused import
- Loading branch information
Showing
4 changed files
with
53 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...identity/src/main/java/com/azure/identity/implementation/CredentialBuilderBaseHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.identity.implementation; | ||
|
||
import com.azure.core.util.logging.ClientLogger; | ||
import com.azure.identity.CredentialBuilderBase; | ||
|
||
/** | ||
* Helper type for accessing private fields of {@link CredentialBuilderBase}. | ||
*/ | ||
public final class CredentialBuilderBaseHelper { | ||
private static final ClientLogger LOGGER = new ClientLogger(CredentialBuilderBaseHelper.class); | ||
private static CredentialBuilderBaseAccessor accessor; | ||
|
||
private CredentialBuilderBaseHelper() { } | ||
|
||
public interface CredentialBuilderBaseAccessor { | ||
IdentityClientOptions getClientOptions(CredentialBuilderBase<?> builder); | ||
} | ||
|
||
public static void setAccessor(final CredentialBuilderBaseAccessor newAccessor) { | ||
if (accessor != null) { | ||
throw LOGGER.logExceptionAsError(new NullPointerException("Accessor must be non-null")); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
accessor = newAccessor; | ||
} | ||
|
||
public static CredentialBuilderBaseAccessor getAccessor() { | ||
if (accessor == null) { | ||
throw LOGGER.logExceptionAsError(new IllegalStateException("CredentialBuilderBaseHelper must be initialized")); | ||
} | ||
return accessor; | ||
} | ||
|
||
public static IdentityClientOptions getClientOptions(CredentialBuilderBase<?> builder) { | ||
return getAccessor().getClientOptions(builder); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hey, accessor is already a non-null in your if condition. I feel "Accessor must be non-null" being thrown in Logger is not correct.
Instead I wonder if you actually wanted to write Acessor must be null.
Please recheck this code block. Its contradicting itself is what I feel. Thank you