-
Notifications
You must be signed in to change notification settings - Fork 137
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
compatability for jpackaged modular applications #571
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
Export-Package: com.microsoft.aad.com.microsoft.aad.msal4j | ||
Automatic-Module-Name: com.microsoft.aad.msal4j | ||
|
||
-fixupmessages: \ "Classes found in the wrong directory...";is:=warning |
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
126 changes: 126 additions & 0 deletions
126
msal4j-sdk/src/main/java9/com/microsoft/aad/msal4j/HttpHeaders.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,126 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.aad.msal4j; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.BiConsumer; | ||
import java.util.Optional; | ||
import java.lang.module.ModuleDescriptor; | ||
|
||
final class HttpHeaders { | ||
|
||
static final String PRODUCT_HEADER_NAME = "x-client-SKU"; | ||
static final String PRODUCT_HEADER_VALUE = "MSAL.Java"; | ||
|
||
static final String PRODUCT_VERSION_HEADER_NAME = "x-client-VER"; | ||
static final String PRODUCT_VERSION_HEADER_VALUE = getProductVersion(); | ||
|
||
static final String CPU_HEADER_NAME = "x-client-CPU"; | ||
static final String CPU_HEADER_VALUE = System.getProperty("os.arch"); | ||
|
||
static final String OS_HEADER_NAME = "x-client-OS"; | ||
static final String OS_HEADER_VALUE = System.getProperty("os.name"); | ||
|
||
static final String APPLICATION_NAME_HEADER_NAME = "x-app-name"; | ||
private final String applicationNameHeaderValue; | ||
|
||
static final String APPLICATION_VERSION_HEADER_NAME = "x-app-ver"; | ||
private final String applicationVersionHeaderValue; | ||
|
||
static final String CORRELATION_ID_HEADER_NAME = "client-request-id"; | ||
private final String correlationIdHeaderValue; | ||
|
||
private static final String REQUEST_CORRELATION_ID_IN_RESPONSE_HEADER_NAME = "return-client-request-id"; | ||
private static final String REQUEST_CORRELATION_ID_IN_RESPONSE_HEADER_VALUE = "true"; | ||
|
||
private static final String X_MS_LIB_CAPABILITY_NAME = "x-ms-lib-capability"; | ||
private static final String X_MS_LIB_CAPABILITY_VALUE = "retry-after, h429"; | ||
|
||
// Used for CCS routing | ||
static final String X_ANCHOR_MAILBOX = "X-AnchorMailbox"; | ||
static final String X_ANCHOR_MAILBOX_OID_FORMAT = "oid:%s"; | ||
static final String X_ANCHOR_MAILBOX_UPN_FORMAT = "upn:%s"; | ||
private String anchorMailboxHeaderValue = null; | ||
|
||
private String headerValues; | ||
private Map<String, String> headerMap = new HashMap<>(); | ||
|
||
HttpHeaders(final RequestContext requestContext) { | ||
correlationIdHeaderValue = requestContext.correlationId(); | ||
applicationNameHeaderValue = requestContext.applicationName(); | ||
applicationVersionHeaderValue = requestContext.applicationVersion(); | ||
|
||
if (requestContext.userIdentifier() != null) { | ||
String upn = requestContext.userIdentifier().upn(); | ||
String oid = requestContext.userIdentifier().oid(); | ||
if (!StringHelper.isBlank(upn)) { | ||
anchorMailboxHeaderValue = String.format(X_ANCHOR_MAILBOX_UPN_FORMAT, upn); | ||
} else if (!StringHelper.isBlank(oid)) { | ||
anchorMailboxHeaderValue = String.format(X_ANCHOR_MAILBOX_OID_FORMAT, oid); | ||
} | ||
} | ||
|
||
Map<String, String> extraHttpHeaders = requestContext.apiParameters() == null ? | ||
null : | ||
requestContext.apiParameters().extraHttpHeaders(); | ||
this.initializeHeaders(extraHttpHeaders); | ||
} | ||
|
||
private void initializeHeaders(Map<String, String> extraHttpHeaders) { | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
BiConsumer<String, String> init = (String key, String val) -> { | ||
headerMap.put(key, val); | ||
sb.append(key).append("=").append(val).append(";"); | ||
}; | ||
|
||
init.accept(PRODUCT_HEADER_NAME, PRODUCT_HEADER_VALUE); | ||
init.accept(PRODUCT_VERSION_HEADER_NAME, PRODUCT_VERSION_HEADER_VALUE); | ||
init.accept(OS_HEADER_NAME, OS_HEADER_VALUE); | ||
init.accept(CPU_HEADER_NAME, CPU_HEADER_VALUE); | ||
init.accept(REQUEST_CORRELATION_ID_IN_RESPONSE_HEADER_NAME, REQUEST_CORRELATION_ID_IN_RESPONSE_HEADER_VALUE); | ||
init.accept(CORRELATION_ID_HEADER_NAME, this.correlationIdHeaderValue); | ||
|
||
if (!StringHelper.isBlank(this.applicationNameHeaderValue)) { | ||
init.accept(APPLICATION_NAME_HEADER_NAME, this.applicationNameHeaderValue); | ||
} | ||
if (!StringHelper.isBlank(this.applicationVersionHeaderValue)) { | ||
init.accept(APPLICATION_VERSION_HEADER_NAME, this.applicationVersionHeaderValue); | ||
} | ||
if (!StringHelper.isBlank(this.anchorMailboxHeaderValue)) { | ||
init.accept(X_ANCHOR_MAILBOX, this.anchorMailboxHeaderValue); | ||
} | ||
|
||
init.accept(X_MS_LIB_CAPABILITY_NAME, X_MS_LIB_CAPABILITY_VALUE); | ||
|
||
if (extraHttpHeaders != null) { | ||
extraHttpHeaders.forEach(init); | ||
} | ||
|
||
this.headerValues = sb.toString(); | ||
} | ||
|
||
Map<String, String> getReadonlyHeaderMap() { | ||
return Collections.unmodifiableMap(this.headerMap); | ||
} | ||
|
||
String getHeaderCorrelationIdValue() { | ||
return this.correlationIdHeaderValue; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.headerValues; | ||
} | ||
|
||
private static String getProductVersion() { | ||
return Optional | ||
.ofNullable(HttpHeaders.class.getModule().getDescriptor()) | ||
.flatMap(ModuleDescriptor::version) | ||
.map(ModuleDescriptor.Version::toString) | ||
.orElse("1.0"); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@siddhijain @Avery-Dunn - please try to respond to community contributions. This looks ok to me, although it's missing tests. What is the context here? I don't see any feedback on this PR.
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.
Sorry, Avery and I talked about this PR, but we never responded.
Context - We use a method getProductVersion() to get the msal4j version, and it returns 1 by default (i.e., when it cannot find the implementation version, for eg when running tests or in a jpackaged modular application). According to the person who raised PR, it is throwing exceptions while using IWA flow.
The PR adds another version of the HttpHeaders class that uses Java 9 features to handle this error. However, we avoid maintaining different versions of a class for different Java versions due to reasons like increased code complexity, code duplication, incompatibility issues, upgrade difficulties, and many more.
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.
As it seems this PR won't be merged, is there any fix you'd propose?
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.
@RJPG-TK For the time being, please continue using the workaround you provided in your message above, as we find a solution to the issue.