Skip to content

Commit dfae289

Browse files
committed
Resolve merge conflicts
1 parent 956bcb1 commit dfae289

File tree

9 files changed

+38
-38
lines changed

9 files changed

+38
-38
lines changed

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void addTokenRevocationParametersToQuery(ManagedIdentityParameters parameters) {
9898
// Add client capabilities as a comma separated string for all the values in client capabilities
9999
String clientCapabilities = String.join(",", managedIdentityApplication.getClientCapabilities());
100100

101-
queryParameters.put(Constants.CLIENT_CAPABILITY_REQUEST_PARAM, Collections.singletonList(clientCapabilities.toString()));
101+
queryParameters.put(Constants.CLIENT_CAPABILITY_REQUEST_PARAM, clientCapabilities.toString());
102102
}
103103

104104
// Pass the token revocation parameter if the claims are present and there is a token to revoke
@@ -107,7 +107,7 @@ void addTokenRevocationParametersToQuery(ManagedIdentityParameters parameters) {
107107
if (queryParameters == null) {
108108
queryParameters = new HashMap<>();
109109
}
110-
queryParameters.put(Constants.TOKEN_HASH_CLAIM, Collections.singletonList(parameters.revokedTokenHash()));
110+
queryParameters.put(Constants.TOKEN_HASH_CLAIM, parameters.revokedTokenHash());
111111
}
112112
}
113113
}

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/StringHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static String createSha256HashHexString(String stringToHash) {
7979

8080
static boolean isNullOrBlank(final String str) {
8181
return str == null || str.trim().isEmpty();
82+
}
8283

8384
//Converts a map of parameters into a URL query string
8485
static String serializeQueryParameters(Map<String, String> params) {

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/TokenRequestExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private void addJWTBearerAssertionParams(Map<String, String> queryParameters, St
113113
private AuthenticationResult createAuthenticationResultFromOauthHttpResponse(HttpResponse oauthHttpResponse) {
114114
AuthenticationResult result;
115115

116-
if (oauthHttpResponse.statusCode() == HttpHelper.HTTP_STATUS_200) {
116+
if (oauthHttpResponse.statusCode() == HttpStatus.HTTP_OK) {
117117
final TokenResponse response = TokenResponse.parseHttpResponse(oauthHttpResponse);
118118

119119
AccountCacheEntity accountCacheEntity = null;
@@ -160,7 +160,7 @@ private AuthenticationResult createAuthenticationResultFromOauthHttpResponse(Htt
160160

161161
} else {
162162
// http codes indicating that STS did not log request
163-
if (oauthHttpResponse.getStatusCode() == HttpStatus.HTTP_TOO_MANY_REQUESTS || oauthHttpResponse.getStatusCode() >= HttpStatus.HTTP_INTERNAL_ERROR) {
163+
if (oauthHttpResponse.statusCode() == HttpStatus.HTTP_TOO_MANY_REQUESTS || oauthHttpResponse.statusCode() >= HttpStatus.HTTP_INTERNAL_ERROR) {
164164
serviceBundle.getServerSideTelemetry().previousRequests.putAll(
165165
serviceBundle.getServerSideTelemetry().previousRequestInProgress);
166166
}

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/TokenResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class TokenResponse {
3131

3232
static TokenResponse parseHttpResponse(final HttpResponse httpResponse) {
3333

34-
if (httpResponse.statusCode() != HttpHelper.HTTP_STATUS_200) {
34+
if (httpResponse.statusCode() != HttpStatus.HTTP_OK) {
3535
throw MsalServiceExceptionFactory.fromHttpResponse(httpResponse);
3636
}
3737

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientCertificateTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44
package com.microsoft.aad.msal4j;
55

66
import com.nimbusds.oauth2.sdk.auth.PrivateKeyJWT;
7+
import com.nimbusds.jwt.SignedJWT;
78
import org.junit.jupiter.api.Test;
89
import org.junit.jupiter.api.TestInstance;
910

1011
import static org.junit.jupiter.api.Assertions.assertEquals;
1112
import static org.junit.jupiter.api.Assertions.assertNotNull;
1213
import static org.junit.jupiter.api.Assertions.assertNull;
1314
import static org.junit.jupiter.api.Assertions.assertThrows;
15+
import static org.junit.jupiter.api.Assertions.assertTrue;
1416
import static org.mockito.ArgumentMatchers.any;
1517
import static org.mockito.Mockito.*;
1618

1719
import java.math.BigInteger;
1820
import java.security.*;
1921
import java.security.cert.CertificateException;
2022
import java.security.interfaces.RSAPrivateKey;
23+
import java.text.ParseException;
2124
import java.util.*;
2225

2326
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@@ -70,12 +73,14 @@ void testIClientCertificateInterface_CredentialFactoryUsesSha256() throws Except
7073
HashMap<String, String> tokenResponseValues = new HashMap<>();
7174
tokenResponseValues.put("access_token", "accessTokenSha256");
7275

73-
when(httpClientMock.send(any(HttpRequest.class))).thenAnswer( parameters -> {
76+
when(httpClientMock.send(any(HttpRequest.class))).thenAnswer(parameters -> {
7477
HttpRequest request = parameters.getArgument(0);
75-
Set<String> headerParams = ((PrivateKeyJWT) cca.clientAuthentication()).getClientAssertion().getHeader().getIncludedParams();
76-
//TODO
77-
if (request.body().contains(cca.assertion)
78-
&& headerParams.contains("x5t#S256")) {
78+
String requestBody = request.body();
79+
80+
SignedJWT signedJWT = SignedJWT.parse(cca.assertion);
81+
82+
if (requestBody.contains(cca.assertion)
83+
&& signedJWT.getHeader().toJSONObject().containsKey("x5t#S256")) {
7984
return TestHelper.expectedResponse(200, TestHelper.getSuccessfulTokenResponse(tokenResponseValues));
8085
}
8186
return null;

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ManagedIdentityTests.java

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
package com.microsoft.aad.msal4j;
55

6-
import com.nimbusds.oauth2.sdk.util.URLUtils;
76
import org.junit.jupiter.api.AfterAll;
87
import org.junit.jupiter.api.BeforeAll;
98
import org.junit.jupiter.api.Nested;
@@ -89,15 +88,15 @@ private HttpRequest expectedRequest(ManagedIdentitySourceType source, String res
8988
Map<String, String> queryParameters = new HashMap<>();
9089

9190
// Add resource to query parameters (common for all sources)
92-
queryParameters.put("resource", singletonList(resource));
91+
queryParameters.put("resource", resource);
9392

9493
// Handle claims and capabilities if supported
9594
if (Constants.TOKEN_REVOCATION_SUPPORTED_ENVIRONMENTS.contains(source)) {
9695
if (hasCapabilities) {
97-
queryParameters.put(Constants.CLIENT_CAPABILITY_REQUEST_PARAM, singletonList("cp1"));
96+
queryParameters.put(Constants.CLIENT_CAPABILITY_REQUEST_PARAM, "cp1");
9897
}
9998
if (hasClaims) {
100-
queryParameters.put(Constants.TOKEN_HASH_CLAIM, singletonList(expectedTokenHash));
99+
queryParameters.put(Constants.TOKEN_HASH_CLAIM, expectedTokenHash);
101100
}
102101
}
103102

@@ -110,18 +109,18 @@ private HttpRequest expectedRequest(ManagedIdentitySourceType source, String res
110109
}
111110

112111
if (!queryParameters.isEmpty()) {
113-
endpoint = endpoint + "?" + URLUtils.serializeParameters(queryParameters);
112+
endpoint = endpoint + "?" + StringHelper.serializeQueryParameters(queryParameters);
114113
}
115114

116115
return new HttpRequest(HttpMethod.GET, endpoint, headers);
117116
}
118117

119118
private String configureSourceSpecificParameters(ManagedIdentitySourceType source,
120119
Map<String, String> headers,
121-
Map<String, List<String>> queryParameters) {
120+
Map<String, String> queryParameters) {
122121
switch (source) {
123122
case APP_SERVICE:
124-
queryParameters.put("api-version", singletonList("2019-08-01"));
123+
queryParameters.put("api-version", "2019-08-01");
125124
headers.put("X-IDENTITY-HEADER", "secret");
126125
return ManagedIdentityTestConstants.APP_SERVICE_ENDPOINT;
127126

@@ -131,37 +130,37 @@ private String configureSourceSpecificParameters(ManagedIdentitySourceType sourc
131130
return ManagedIdentityTestConstants.CLOUDSHELL_ENDPOINT;
132131

133132
case AZURE_ARC:
134-
queryParameters.put("api-version", singletonList("2019-11-01"));
133+
queryParameters.put("api-version", "2019-11-01");
135134
headers.put("Metadata", "true");
136135
return ManagedIdentityTestConstants.AZURE_ARC_ENDPOINT;
137136

138137
case SERVICE_FABRIC:
139-
queryParameters.put("api-version", singletonList("2019-07-01-preview"));
138+
queryParameters.put("api-version", "2019-07-01-preview");
140139
headers.put("secret", "secret");
141140
return ManagedIdentityTestConstants.SERVICE_FABRIC_ENDPOINT;
142141

143142
case IMDS:
144143
case NONE:
145144
case DEFAULT_TO_IMDS:
146145
default:
147-
queryParameters.put("api-version", singletonList("2018-02-01"));
146+
queryParameters.put("api-version", "2018-02-01");
148147
headers.put("Metadata", "true");
149148
return ManagedIdentityTestConstants.IMDS_ENDPOINT;
150149
}
151150
}
152151

153-
private void configureIdentitySpecificParameters(ManagedIdentityId id, Map<String, List<String>> queryParameters) {
152+
private void configureIdentitySpecificParameters(ManagedIdentityId id, Map<String, String> queryParameters) {
154153
switch (id.getIdType()) {
155154
case SYSTEM_ASSIGNED:
156155
break;
157156
case CLIENT_ID:
158-
queryParameters.put("client_id", singletonList(id.getUserAssignedId()));
157+
queryParameters.put("client_id", id.getUserAssignedId());
159158
break;
160159
case RESOURCE_ID:
161160
if (ManagedIdentityClient.getManagedIdentitySource() == ManagedIdentitySourceType.IMDS) {
162-
queryParameters.put(Constants.MANAGED_IDENTITY_RESOURCE_ID_IMDS, Collections.singletonList(id.getUserAssignedId()));
161+
queryParameters.put(Constants.MANAGED_IDENTITY_RESOURCE_ID_IMDS, id.getUserAssignedId());
163162
} else {
164-
queryParameters.put(Constants.MANAGED_IDENTITY_RESOURCE_ID, Collections.singletonList(id.getUserAssignedId()));
163+
queryParameters.put(Constants.MANAGED_IDENTITY_RESOURCE_ID, id.getUserAssignedId());
165164
}
166165
break;
167166
case OBJECT_ID:
@@ -359,8 +358,6 @@ void managedIdentityTest_WithClaims(ManagedIdentitySourceType source, String end
359358

360359
when(httpClientMock.send(any())).thenReturn(expectedResponse(HttpStatus.HTTP_OK, getSuccessfulResponse(ManagedIdentityTestConstants.RESOURCE)));
361360

362-
String claimsJson = "{\"default\":\"claim\"}";
363-
364361
// First call, get the token from the identity provider.
365362
IAuthenticationResult result = acquireTokenCommon(ManagedIdentityTestConstants.RESOURCE).get();
366363

@@ -378,7 +375,7 @@ void managedIdentityTest_WithClaims(ManagedIdentitySourceType source, String end
378375
// Third call, when claims are passed bypass the cache.
379376
result = miApp.acquireTokenForManagedIdentity(
380377
ManagedIdentityParameters.builder(ManagedIdentityTestConstants.RESOURCE)
381-
.claims(claimsJson)
378+
.claims(TestConfiguration.CLAIMS_REQUEST)
382379
.build()).get();
383380

384381
assertTokenFromIdentityProvider(result);
@@ -430,7 +427,6 @@ void managedIdentity_ClaimsAndCapabilities(ManagedIdentitySourceType source, Str
430427
.httpClient(httpClientMock)
431428
.build();
432429

433-
String claimsJson = "{\"default\":\"claim\"}";
434430
// First call, get the token from the identity provider.
435431
IAuthenticationResult result = acquireTokenCommon(ManagedIdentityTestConstants.RESOURCE).get();
436432

@@ -448,7 +444,7 @@ void managedIdentity_ClaimsAndCapabilities(ManagedIdentitySourceType source, Str
448444
// Third call, when claims are passed bypass the cache.
449445
result = miApp.acquireTokenForManagedIdentity(
450446
ManagedIdentityParameters.builder(ManagedIdentityTestConstants.RESOURCE)
451-
.claims(claimsJson)
447+
.claims(TestConfiguration.CLAIMS_REQUEST)
452448
.build()).get();
453449

454450
assertTokenFromIdentityProvider(result);
@@ -770,7 +766,7 @@ void managedIdentity_RequestFailed_NoPayload(ManagedIdentitySourceType source, S
770766

771767
when(httpClientMock.send(expectedRequest(source, ManagedIdentityTestConstants.RESOURCE))).thenReturn(expectedResponse(500, ""));
772768

773-
assertMsalServiceException(acquireTokenCommon(ManagedIdentityTestConstants.RESOURCE), source, MsalError.MANAGED_IDENTITY_RESPONSE_PARSE_FAILURE);
769+
assertMsalServiceException(acquireTokenCommon(ManagedIdentityTestConstants.RESOURCE), source, MsalError.MANAGED_IDENTITY_REQUEST_FAILED);
774770
}
775771

776772
@ParameterizedTest

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/RequestThrottlingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private PublicClientApplication getClientApplicationMockedWithOneTokenEndpointRe
9292

9393
switch (responseType) {
9494
case RETRY_AFTER_HEADER:
95-
httpResponse.statusCode(HttpHelper.HTTP_STATUS_200);
95+
httpResponse.statusCode(HttpStatus.HTTP_OK);
9696
httpResponse.body(TestConfiguration.TOKEN_ENDPOINT_OK_RESPONSE_ID_AND_ACCESS);
9797

9898
headers.put("Retry-After", Arrays.asList(THROTTLE_IN_SEC.toString()));

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/TokenRequestExecutorTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void executeOAuthRequest_SCBadRequestErrorInvalidGrant_InteractionRequiredExcept
4242
OAuthHttpRequest msalOAuthHttpRequest = mock(OAuthHttpRequest.class);
4343

4444
HttpResponse httpResponse = new HttpResponse();
45-
httpResponse.statusCode(HttpHelper.HTTP_STATUS_400);
45+
httpResponse.statusCode(HttpStatus.HTTP_BAD_REQUEST);
4646

4747
String claims = "{\\\"access_token\\\":{\\\"polids\\\":{\\\"essential\\\":true,\\\"values\\\":[\\\"5ce770ea-8690-4747-aa73-c5b3cd509cd4\\\"]}}}";
4848

@@ -79,7 +79,7 @@ void executeOAuthRequest_SCBadRequestErrorInvalidGrant_SubErrorFilteredServiceEx
7979
OAuthHttpRequest msalOAuthHttpRequest = mock(OAuthHttpRequest.class);
8080

8181
HttpResponse httpResponse = new HttpResponse();
82-
httpResponse.statusCode(HttpHelper.HTTP_STATUS_400);
82+
httpResponse.statusCode(HttpStatus.HTTP_BAD_REQUEST);
8383

8484
String claims = "{\\\"access_token\\\":{\\\"polids\\\":{\\\"essential\\\":true,\\\"values\\\":[\\\"5ce770ea-8690-4747-aa73-c5b3cd509cd4\\\"]}}}";
8585

@@ -233,9 +233,7 @@ void testExecuteOAuth_Success() throws MsalException, IOException, URISyntaxExce
233233
doReturn(httpResponse).when(msalOAuthHttpRequest).send();
234234
doReturn(JsonHelper.convertJsonToMap(TestConfiguration.TOKEN_ENDPOINT_OK_RESPONSE_ID_AND_ACCESS)).when(httpResponse).getBodyAsMap();
235235

236-
httpResponse.ensureStatusCode(HttpStatus.HTTP_OK);
237-
238-
doReturn(HttpStatus.HTTP_OK).when(httpResponse).getStatusCode();
236+
doReturn(HttpStatus.HTTP_OK).when(httpResponse).statusCode();
239237

240238
final AuthenticationResult result = request.executeTokenRequest();
241239

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/UIRequiredCacheTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ private PublicClientApplication getApp_MockedWith_OKTokenEndpointResponse_Invali
8383
throws Exception {
8484
IHttpClient httpClientMock = mock(IHttpClient.class);
8585

86-
HttpResponse httpResponse = getHttpResponse(HttpHelper.HTTP_STATUS_200, TestConfiguration.TOKEN_ENDPOINT_OK_RESPONSE_ID_AND_ACCESS);
86+
HttpResponse httpResponse = getHttpResponse(HttpStatus.HTTP_OK, TestConfiguration.TOKEN_ENDPOINT_OK_RESPONSE_ID_AND_ACCESS);
8787
lenient().doReturn(httpResponse).when(httpClientMock).send(any());
8888

89-
httpResponse = getHttpResponse(HttpHelper.HTTP_STATUS_401, TestConfiguration.TOKEN_ENDPOINT_INVALID_GRANT_ERROR_RESPONSE);
89+
httpResponse = getHttpResponse(HttpStatus.HTTP_UNAUTHORIZED, TestConfiguration.TOKEN_ENDPOINT_INVALID_GRANT_ERROR_RESPONSE);
9090
lenient().doReturn(httpResponse).when(httpClientMock).send(any());
9191

9292
PublicClientApplication app = getPublicClientApp(httpClientMock);

0 commit comments

Comments
 (0)