Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
vNext
----------
- [MINOR] Migrate URIbuilder to httpcore5 (#2522)

Version 18.1.0
----------
(common4j 15.1.0)
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ dependencies {

implementation(group: 'com.microsoft.device.display', name: 'display-mask', version: '0.3.0')

implementation 'org.apache.httpcomponents.core5:httpcore5:5.3'
implementation "cz.msebera.android:httpclient:$rootProject.ext.mseberaApacheHttpClientVersion"
implementation "com.nimbusds:nimbus-jose-jwt:$rootProject.ext.nimbusVersion"
implementation "androidx.appcompat:appcompat:$rootProject.ext.appCompatVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.microsoft.identity.common.java.interfaces.INameValueStorage
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import net.jcip.annotations.ThreadSafe
import javax.annotation.concurrent.ThreadSafe

/**
* A cache for storing the active broker as known by the caller.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
package com.microsoft.identity.common.internal.cache

import com.microsoft.identity.common.internal.broker.BrokerData
import net.jcip.annotations.ThreadSafe
import javax.annotation.concurrent.ThreadSafe


/**
Expand Down
1 change: 1 addition & 0 deletions common4j/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ dependencies {
implementation "org.json:json:$rootProject.ext.jsonVersion"
implementation "com.github.stephenc.jcip:jcip-annotations:$rootProject.ext.jcipAnnotationVersion"
implementation "cz.msebera.android:httpclient:$rootProject.ext.mseberaApacheHttpClientVersion"
implementation 'org.apache.httpcomponents.core5:httpcore5:5.3'

testCompileOnly "com.github.spotbugs:spotbugs-annotations:$rootProject.ext.spotBugsAnnotationVersion"
testCompileOnly "org.projectlombok:lombok:$rootProject.ext.lombokVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class NativeAuthOAuth2Configuration(
private fun getEndpointUrlFromRootAndTenantAndSuffix(root: URL, endpointSuffix: String): URL {
return try {
if (BuildValues.getDC().isNotEmpty()) {
UrlUtil.appendPathAndQueryToURL(root, endpointSuffix, "dc=${BuildValues.getDC()}")
UrlUtil.appendPathAndQueryToURL(root, endpointSuffix, mapOf("dc" to BuildValues.getDC()))
} else {
UrlUtil.appendPathToURL(root, endpointSuffix)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@
// THE SOFTWARE.
package com.microsoft.identity.common.java.util;

import org.apache.hc.core5.http.NameValuePair;
import org.apache.hc.core5.net.URIBuilder;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;

import cz.msebera.android.httpclient.NameValuePair;
import edu.umd.cs.findbugs.annotations.Nullable;
import lombok.NonNull;

/**
* Our URIBuilder.
* We want to make sure we never send duplicated parameters to the server.
* This is done by
* 1. disabling {@link cz.msebera.android.httpclient.client.utils.URIBuilder#addParameter(String, String)} and
* {@link cz.msebera.android.httpclient.client.utils.URIBuilder#addParameters(List)}
* 1. disabling {@link org.apache.hc.core5.net.URIBuilder#addParameter(String, String)} and
* {@link org.apache.hc.core5.net.URIBuilder#addParameters(List)}
* 2. adding {@link CommonURIBuilder#addParametersIfAbsent}
*/
public class CommonURIBuilder extends cz.msebera.android.httpclient.client.utils.URIBuilder {
public class CommonURIBuilder extends URIBuilder {

public CommonURIBuilder() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static URL appendPathToURL(@NonNull final URL urlToAppend,
*/
public static URL appendPathAndQueryToURL(@NonNull final URL urlToAppend,
@Nullable final String pathString,
@Nullable final String queryParam)
@Nullable final Map<String, String> queryParam)
throws URISyntaxException, MalformedURLException {

if (StringUtil.isNullOrEmpty(pathString)) {
Expand Down Expand Up @@ -99,9 +99,8 @@ public static URL appendPathAndQueryToURL(@NonNull final URL urlToAppend,
}

builder.setPathSegments(pathSegments);
if (queryParam != null && !queryParam.isEmpty()) {
builder.setQuery(queryParam);
}
builder.addParametersIfAbsent(queryParam);

return builder.build().toURL();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Constants {
public static final String MOCK_STATE = "MOCK_STATE";
public static final String MOCK_STATE_ENCODED = "TU9DS19TVEFURQ";
public static final String MOCK_SCOPE = "MOCK_SCOPE MOCK_SCOPE2";
public static final String MOCK_SCOPE_ENCODED = "MOCK_SCOPE+MOCK_SCOPE2";
public static final String MOCK_SCOPE_ENCODED = "MOCK_SCOPE%20MOCK_SCOPE2";
public static final String MOCK_QUERY_1 = "MOCK_QUERY_1";
public static final String MOCK_QUERY_2 = "MOCK_QUERY_2";
public static final String MOCK_VALUE_1 = "MOCK_VALUE_1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class MicrosoftStsAuthorizationRequestTests {
private static final String DEFAULT_TEST_REDIRECT_URI_ENCODED = "some%3A%2F%2Fredirect.uri";
private static final String DEFAULT_TEST_LOGIN_HINT = "someLoginHint";
private static final String DEFAULT_TEST_SCOPE = "scope1 scope2";
private static final String DEFAULT_TEST_SCOPE_ENCODED = "scope1+scope2";
private static final String DEFAULT_TEST_SCOPE_ENCODED = "scope1%20scope2";
private static final String DEFAULT_TEST_AUTHORIZATION_ENDPOINT = "https://login.microsoftonline.com/common/oAuth2/v2.0/authorize";
private static final UUID DEFAULT_TEST_CORRELATION_ID = UUID.randomUUID();
private static final List<Map.Entry<String, String>> DEFAULT_TEST_EXTRA_QP = new ArrayList<Map.Entry<String, String>>() {{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package com.microsoft.identity.common.java.util;

import org.apache.hc.core5.http.NameValuePair;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -34,8 +35,6 @@
import java.util.List;
import java.util.Map;

import cz.msebera.android.httpclient.NameValuePair;

@RunWith(JUnit4.class)
public class CommonURIBuilderTest {

Expand Down Expand Up @@ -80,6 +79,29 @@ public void testCallingAddParametersIfAbsent_ValueAlreadyExists(){
Assert.assertEquals("Value1", builder.getQueryParams().get(0).getValue());
}

@Test
public void testCallingAddParametersIfAbsent_WithNullMap(){
final CommonURIBuilder builder = new CommonURIBuilder()
.setParameter("Test1", "Value1")
.addParametersIfAbsent((Map<String, ?>) null);

Assert.assertEquals(1, builder.getQueryParams().size());
Assert.assertEquals("Test1", builder.getQueryParams().get(0).getName());
Assert.assertEquals("Value1", builder.getQueryParams().get(0).getValue());
}

@Test
public void testCallingAddParametersIfAbsent_WithEmptyMap(){
final Map<String, String> map = new HashMap<>();
final CommonURIBuilder builder = new CommonURIBuilder()
.setParameter("Test1", "Value1")
.addParametersIfAbsent(map);

Assert.assertEquals(1, builder.getQueryParams().size());
Assert.assertEquals("Test1", builder.getQueryParams().get(0).getName());
Assert.assertEquals("Value1", builder.getQueryParams().get(0).getValue());
}

@Test
public void testCallingAddParametersIfAbsent_WithMap(){
final Map<String, String> map = new HashMap<>();
Expand Down
Loading