From 62fb7357f822459ea7ce6eeba359cf6f166fcb2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robby=20J=C3=BCrgen=20Pascal=20Gedike?= Date: Wed, 23 Nov 2022 19:40:51 +0100 Subject: [PATCH 1/4] setup multirelease jar build (required updated plugins) --- msal4j-sdk/pom.xml | 67 +++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/msal4j-sdk/pom.xml b/msal4j-sdk/pom.xml index df950e77..887ae128 100644 --- a/msal4j-sdk/pom.xml +++ b/msal4j-sdk/pom.xml @@ -51,7 +51,7 @@ org.projectlombok lombok - 1.18.6 + 1.18.24 provided @@ -161,7 +161,7 @@ org.projectlombok lombok-maven-plugin - 1.18.2.0 + 1.18.20.0 @@ -179,9 +179,12 @@ org.apache.maven.plugins maven-jar-plugin - 2.5 + 3.2.0 + + true + true true @@ -236,11 +239,41 @@ org.apache.maven.plugins maven-compiler-plugin - 3.7.0 - - 8 - 8 - + 3.10.1 + + + default-testCompile + + testCompile + + + 9 + + + default-compile + + compile + + + 8 + 8 + + + + compile-java-9 + compile + + compile + + + 9 + + ${project.basedir}/src/main/java9 + + true + + + org.codehaus.mojo @@ -275,16 +308,14 @@ - biz.aQute.bnd - bnd-maven-plugin - 4.3.1 - - - - bnd-process - - - + org.apache.felix + maven-bundle-plugin + 5.1.8 + + + <_fixupmessages>"Classes found in the wrong directory";is:=warning + + From 05029a3dc9f5184c85855ef50282fc56950190b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robby=20J=C3=BCrgen=20Pascal=20Gedike?= Date: Wed, 23 Nov 2022 19:42:15 +0100 Subject: [PATCH 2/4] use ModuleDescriptor.Version for JDK 9+ --- .../com/microsoft/aad/msal4j/HttpHeaders.java | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 msal4j-sdk/src/main/java9/com/microsoft/aad/msal4j/HttpHeaders.java diff --git a/msal4j-sdk/src/main/java9/com/microsoft/aad/msal4j/HttpHeaders.java b/msal4j-sdk/src/main/java9/com/microsoft/aad/msal4j/HttpHeaders.java new file mode 100644 index 00000000..56d1e1cb --- /dev/null +++ b/msal4j-sdk/src/main/java9/com/microsoft/aad/msal4j/HttpHeaders.java @@ -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 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 extraHttpHeaders = requestContext.apiParameters() == null ? + null : + requestContext.apiParameters().extraHttpHeaders(); + this.initializeHeaders(extraHttpHeaders); + } + + private void initializeHeaders(Map extraHttpHeaders) { + StringBuilder sb = new StringBuilder(); + + BiConsumer 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 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"); + } +} From c4fe49b19843f21480ac3be9d85730194c020194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robby=20J=C3=BCrgen=20Pascal=20Gedike?= Date: Thu, 24 Nov 2022 08:04:07 +0100 Subject: [PATCH 3/4] fixupmessages for multirelease build (not yet supported by bnd, https://github.com/bndtools/bnd/issues/2227) --- msal4j-sdk/bnd.bnd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/msal4j-sdk/bnd.bnd b/msal4j-sdk/bnd.bnd index e5483c84..fd5973f7 100644 --- a/msal4j-sdk/bnd.bnd +++ b/msal4j-sdk/bnd.bnd @@ -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 \ No newline at end of file From 9901b428195091d58e551633c3806fcbf28a1fed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robby=20J=C3=BCrgen=20Pascal=20Gedike?= Date: Thu, 24 Nov 2022 08:04:26 +0100 Subject: [PATCH 4/4] bnd dependency --- msal4j-sdk/pom.xml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/msal4j-sdk/pom.xml b/msal4j-sdk/pom.xml index 887ae128..282d171d 100644 --- a/msal4j-sdk/pom.xml +++ b/msal4j-sdk/pom.xml @@ -308,14 +308,16 @@ - org.apache.felix - maven-bundle-plugin - 5.1.8 - - - <_fixupmessages>"Classes found in the wrong directory";is:=warning - - + biz.aQute.bnd + bnd-maven-plugin + 6.3.1 + + + + bnd-process + + +