-
Notifications
You must be signed in to change notification settings - Fork 36
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 check for unset correlation ID when configuring request headers #2435
Changes from all commits
a28a3f7
046593a
9fe242c
428f2ab
f221e24
73f34ff
2e760ac
c1d5a3f
b653ea6
e631037
fed453c
c731847
3391582
5976371
2685650
d0a2618
abc1279
4cf05aa
a9f32fe
77d3dd3
acc8421
b4a923f
c30e22e
8181c6f
3c74bb2
f0c1be5
af209cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
// THE SOFTWARE. | ||
package com.microsoft.identity.common.java.logging; | ||
|
||
import java.util.UUID; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
||
public enum DiagnosticContext { | ||
|
@@ -76,8 +78,8 @@ public IRequestContext getRequestContext() { | |
public String getThreadCorrelationId() { | ||
IRequestContext context = getRequestContext(); | ||
String correlationId = context.get(DiagnosticContext.CORRELATION_ID); | ||
if (correlationId == null) { | ||
correlationId = UNSET; | ||
if (correlationId == null || correlationId.equals("UNSET")) { | ||
correlationId = UUID.randomUUID().toString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am I right in saying:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's correct. |
||
} | ||
return correlationId; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ package com.microsoft.identity.common.java.nativeauth.providers | |
|
||
import com.microsoft.identity.common.java.AuthenticationConstants | ||
import com.microsoft.identity.common.java.eststelemetry.EstsTelemetry | ||
import com.microsoft.identity.common.java.logging.LibraryInfoHelper | ||
import com.microsoft.identity.common.java.nativeauth.commands.parameters.ResetPasswordStartCommandParameters | ||
import com.microsoft.identity.common.java.nativeauth.commands.parameters.ResetPasswordSubmitCodeCommandParameters | ||
import com.microsoft.identity.common.java.nativeauth.commands.parameters.ResetPasswordSubmitNewPasswordCommandParameters | ||
|
@@ -34,7 +35,6 @@ import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignUpS | |
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignUpSubmitCodeCommandParameters | ||
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignUpSubmitPasswordCommandParameters | ||
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignUpSubmitUserAttributesCommandParameters | ||
import com.microsoft.identity.common.java.logging.LibraryInfoHelper | ||
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignInStartCommandParameters | ||
import com.microsoft.identity.common.java.net.HttpConstants | ||
import com.microsoft.identity.common.java.nativeauth.providers.requests.resetpassword.ResetPasswordChallengeRequest | ||
|
@@ -49,6 +49,7 @@ import com.microsoft.identity.common.java.nativeauth.providers.requests.signup.S | |
import com.microsoft.identity.common.java.nativeauth.providers.requests.signup.SignUpContinueRequest | ||
import com.microsoft.identity.common.java.nativeauth.providers.requests.signup.SignUpStartRequest | ||
import com.microsoft.identity.common.java.platform.Device | ||
import com.microsoft.identity.common.java.util.StringUtil | ||
import java.util.TreeMap | ||
|
||
/** | ||
|
@@ -309,7 +310,9 @@ class NativeAuthRequestProvider(private val config: NativeAuthOAuth2Configuratio | |
//region helpers | ||
private fun getRequestHeaders(correlationId: String): Map<String, String?> { | ||
val headers: MutableMap<String, String?> = TreeMap() | ||
headers[AuthenticationConstants.AAD.CLIENT_REQUEST_ID] = correlationId | ||
if (correlationId != "UNSET") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The string 'UNSET' should be used from a constant file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a look at the rest of the codebase and "UNSET" seems to be used in place instead of being used as a constant value. I'd rather stick with the convention here, given that it's a straightforward name and something that doesn't have a specific meaning or is used outside of the context of the SDK. |
||
headers[AuthenticationConstants.AAD.CLIENT_REQUEST_ID] = correlationId | ||
} | ||
headers[AuthenticationConstants.SdkPlatformFields.PRODUCT] = LibraryInfoHelper.getLibraryName() | ||
headers[AuthenticationConstants.SdkPlatformFields.VERSION] = LibraryInfoHelper.getLibraryVersion() | ||
headers.putAll(Device.getPlatformIdParameters()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also use
correlationId = "";
and let CommandDispatcher.initializeDiagnosticContextfinal String correlationId = StringUtil.isNullOrEmpty(requestCorrelationId) ? UUID.randomUUID().toString() : requestCorrelationId;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yuki-YuXin if what you mention is also a solution, then why did you add this code change here? to rephrase: I agree that what
CommandDispatcher.initializeDiagnosticContext
does should be sufficient. So why is your code change needed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the current code snippet will set the correlationId to UNSET. If the correlationId passed into CommandDispatcher.initializeDiagnosticContext is UNSET, then after correlationId = StringUtil.isNullOrEmpty(requestCorrelationId) ? UUID.randomUUID().toString() : requestCorrelationId, the correlationId would keep as "UNSET"