Skip to content

Commit e6d5ea5

Browse files
author
sgonzalezMSFT
committed
Pr Feedback
1 parent 974f555 commit e6d5ea5

File tree

7 files changed

+31
-69
lines changed

7 files changed

+31
-69
lines changed

src/main/java/com/microsoft/aad/msal4j/ServiceExceptionClassification.java renamed to src/main/java/com/microsoft/aad/msal4j/InteractionRequiredExceptionReason.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Details about the cause of an {@link MsalInteractionRequiredException}, giving a hint about the
88
* user can expect when they go through interactive authentication
99
*/
10-
public enum ServiceExceptionClassification {
10+
public enum InteractionRequiredExceptionReason {
1111

1212
/**
1313
* No further details are provided. It is possible that the user will be able to resolve the issue
@@ -47,18 +47,19 @@ public enum ServiceExceptionClassification {
4747

4848
private String error;
4949

50-
ServiceExceptionClassification(String error){
50+
InteractionRequiredExceptionReason(String error){
5151
this.error = error;
5252
}
5353

54-
static ServiceExceptionClassification fromSubErrorString(String subError){
54+
static InteractionRequiredExceptionReason fromSubErrorString(String subError){
5555
if(StringHelper.isBlank(subError)){
5656
return NONE;
5757
}
5858

59-
for(ServiceExceptionClassification classification: ServiceExceptionClassification.values()){
60-
if(classification.error.equalsIgnoreCase(subError)){
61-
return classification;
59+
for(InteractionRequiredExceptionReason reason:
60+
InteractionRequiredExceptionReason.values()){
61+
if(reason.error.equalsIgnoreCase(subError)){
62+
return reason;
6263
}
6364
}
6465
return NONE;

src/main/java/com/microsoft/aad/msal4j/MsalClientException.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
1-
// Copyright (c) Microsoft Corporation.
2-
// All rights reserved.
3-
//
4-
// This code is licensed under the MIT License.
5-
//
6-
// Permission is hereby granted, free of charge, to any person obtaining a copy
7-
// of this software and associated documentation files(the "Software"), to deal
8-
// in the Software without restriction, including without limitation the rights
9-
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10-
// copies of the Software, and to permit persons to whom the Software is
11-
// furnished to do so, subject to the following conditions :
12-
//
13-
// The above copyright notice and this permission notice shall be included in
14-
// all copies or substantial portions of the Software.
15-
//
16-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
19-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22-
// THE SOFTWARE.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
233

244
package com.microsoft.aad.msal4j;
255

src/main/java/com/microsoft/aad/msal4j/MsalInteractionRequiredException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
public class MsalInteractionRequiredException extends MsalServiceException{
1717

1818
/**
19-
* Classification of the conditional access error, enabling you to do more actions or inform the
19+
* Reason for the MsalInteractionRequiredException, enabling you to do more actions or inform the
2020
* user depending on your scenario.
2121
*/
2222
@Accessors(fluent = true)
2323
@Getter
24-
private ServiceExceptionClassification classification;
24+
private InteractionRequiredExceptionReason reason;
2525

2626
/**
2727
* Initializes a new instance of the exception class
@@ -33,6 +33,6 @@ public MsalInteractionRequiredException(
3333
Map<String,List<String>> headerMap) {
3434
super(errorResponse, headerMap);
3535

36-
classification = ServiceExceptionClassification.fromSubErrorString(errorResponse.subError);
36+
reason = InteractionRequiredExceptionReason.fromSubErrorString(errorResponse.subError);
3737
}
3838
}

src/main/java/com/microsoft/aad/msal4j/MsalServiceException.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
1-
// Copyright (c) Microsoft Corporation.
2-
// All rights reserved.
3-
//
4-
// This code is licensed under the MIT License.
5-
//
6-
// Permission is hereby granted, free of charge, to any person obtaining a copy
7-
// of this software and associated documentation files(the "Software"), to deal
8-
// in the Software without restriction, including without limitation the rights
9-
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10-
// copies of the Software, and to permit persons to whom the Software is
11-
// furnished to do so, subject to the following conditions :
12-
//
13-
// The above copyright notice and this permission notice shall be included in
14-
// all copies or substantial portions of the Software.
15-
//
16-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
19-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22-
// THE SOFTWARE.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
233

244
package com.microsoft.aad.msal4j;
255

src/main/java/com/microsoft/aad/msal4j/MsalServiceExceptionFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ static MsalServiceException fromHttpResponse(HTTPResponse httpResponse){
3030
errorResponse.statusCode(httpResponse.getStatusCode());
3131
errorResponse.statusMessage(httpResponse.getStatusMessage());
3232

33+
34+
boolean bool = errorResponse.error().equalsIgnoreCase(AuthenticationErrorCode.INVALID_GRANT);
35+
3336
if(errorResponse.error() != null &&
3437
errorResponse.error().equalsIgnoreCase(AuthenticationErrorCode.INVALID_GRANT)) {
3538

src/main/java/com/microsoft/aad/msal4j/TokenRequest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@
66
import java.io.IOException;
77
import java.net.MalformedURLException;
88
import java.net.URISyntaxException;
9-
import java.net.URL;
10-
import java.util.Arrays;
119
import java.util.Date;
12-
import java.util.HashSet;
1310
import java.util.List;
1411
import java.util.Map;
15-
import java.util.Set;
1612

1713
import com.nimbusds.oauth2.sdk.ParseException;
1814
import com.nimbusds.oauth2.sdk.SerializeException;

src/test/java/com/microsoft/aad/msal4j/TokenRequestTest.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@
2828
public class TokenRequestTest extends AbstractMsalTests {
2929

3030
@Test
31-
public void executeOAuthRequest_SCBadRequestErrorInteractionRequired_AuthenticationServiceException()
31+
public void executeOAuthRequest_SCBadRequestErrorInvalidGrant_InteractionRequiredException()
3232
throws SerializeException, ParseException, MsalException,
3333
IOException, URISyntaxException {
3434

3535
TokenRequest request = createMockedTokenRequest();
3636

37-
OAuthHttpRequest msalOAuthHttpRequest = PowerMock
38-
.createMock(OAuthHttpRequest.class);
37+
OAuthHttpRequest msalOAuthHttpRequest = PowerMock.createMock(OAuthHttpRequest.class);
3938

4039
HTTPResponse httpResponse = new HTTPResponse(HTTPResponse.SC_BAD_REQUEST);
4140

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

44-
String content = "{\"error\":\"interaction_required\"," +
45-
"\"error_description\":\"AADSTS50076: description\\r\\nCorrelation ID: 3a...5a\\r\\nTimestamp:2017-07-15 02:35:05Z\"," +
43+
String content = "{\"error\":\"invalid_grant\"," +
44+
"\"error_description\":\"AADSTS65001: description\\r\\nCorrelation ID: 3a...5a\\r\\nTimestamp:2017-07-15 02:35:05Z\"," +
4645
"\"error_codes\":[50076]," +
4746
"\"timestamp\":\"2017-07-15 02:35:05Z\"," +
4847
"\"trace_id\":\"0788...000\"," +
4948
"\"correlation_id\":\"3a...95a\"," +
49+
"\"suberror\":\"basic_action\"," +
5050
"\"claims\":\"" + claims + "\"}";
5151
httpResponse.setContent(content);
5252
httpResponse.setContentType(CommonContentTypes.APPLICATION_JSON);
@@ -59,20 +59,22 @@ public void executeOAuthRequest_SCBadRequestErrorInteractionRequired_Authenticat
5959
try {
6060
request.executeOauthRequestAndProcessResponse();
6161
Assert.fail("Expected MsalServiceException was not thrown");
62-
} catch (MsalServiceException ex) {
62+
} catch (MsalInteractionRequiredException ex) {
6363
Assert.assertEquals(claims.replace("\\", ""), ex.claims());
64+
Assert.assertEquals(ex.reason(), InteractionRequiredExceptionReason.BASIC_ACTION);
6465
}
6566
PowerMock.verifyAll();
6667
}
6768

6869
@Test
69-
public void executeOAuthRequest_SCBadRequestErrorInvalidGrant_InteractionRequiredException()
70+
public void executeOAuthRequest_SCBadRequestErrorInvalidGrant_SubErrorFilteredServiceExceptionThrown()
7071
throws SerializeException, ParseException, MsalException,
7172
IOException, URISyntaxException {
7273

7374
TokenRequest request = createMockedTokenRequest();
7475

75-
OAuthHttpRequest msalOAuthHttpRequest = PowerMock.createMock(OAuthHttpRequest.class);
76+
OAuthHttpRequest msalOAuthHttpRequest = PowerMock
77+
.createMock(OAuthHttpRequest.class);
7678

7779
HTTPResponse httpResponse = new HTTPResponse(HTTPResponse.SC_BAD_REQUEST);
7880

@@ -84,7 +86,7 @@ public void executeOAuthRequest_SCBadRequestErrorInvalidGrant_InteractionRequire
8486
"\"timestamp\":\"2017-07-15 02:35:05Z\"," +
8587
"\"trace_id\":\"0788...000\"," +
8688
"\"correlation_id\":\"3a...95a\"," +
87-
"\"suberror\":\"basic_action\"," +
89+
"\"suberror\":\"client_mismatch\"," +
8890
"\"claims\":\"" + claims + "\"}";
8991
httpResponse.setContent(content);
9092
httpResponse.setContentType(CommonContentTypes.APPLICATION_JSON);
@@ -97,9 +99,9 @@ public void executeOAuthRequest_SCBadRequestErrorInvalidGrant_InteractionRequire
9799
try {
98100
request.executeOauthRequestAndProcessResponse();
99101
Assert.fail("Expected MsalServiceException was not thrown");
100-
} catch (MsalInteractionRequiredException ex) {
102+
} catch (MsalServiceException ex) {
101103
Assert.assertEquals(claims.replace("\\", ""), ex.claims());
102-
Assert.assertEquals(ex.classification(), ServiceExceptionClassification.BASIC_ACTION);
104+
Assert.assertTrue(!(ex instanceof MsalInteractionRequiredException));
103105
}
104106
PowerMock.verifyAll();
105107
}
@@ -127,7 +129,7 @@ private TokenRequest createMockedTokenRequest() throws URISyntaxException, Malfo
127129

128130
return PowerMock.createPartialMock(
129131
TokenRequest.class, new String[]{"toOauthHttpRequest"},
130-
new URL("http://login.windows.net"),
132+
new AADAuthority(new URL(TestConstants.ORGANIZATIONS_AUTHORITY)),
131133
acr,
132134
serviceBundle);
133135
}

0 commit comments

Comments
 (0)