Skip to content

Commit 40508fd

Browse files
author
sgonzalezMSFT
committed
Rename exceptions. Add MsalInteractionRequiredException.
1 parent 9405bdc commit 40508fd

25 files changed

+269
-131
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private static String getInstanceDiscoveryEndpoint(String host) {
8787

8888
private static void validate(InstanceDiscoveryResponse instanceDiscoveryResponse) {
8989
if (StringHelper.isBlank(instanceDiscoveryResponse.tenantDiscoveryEndpoint())) {
90-
throw new AuthenticationServiceException(instanceDiscoveryResponse);
90+
throw new MsalServiceException(instanceDiscoveryResponse);
9191
}
9292
}
9393

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,14 @@ private AuthorizationGrant getAuthorizationGrantIntegrated(String userName) thro
153153
updatedGrant = getSAMLAuthorizationGrant(wsTrustResponse);
154154
}
155155
else if (userRealmResponse.isAccountManaged()) {
156-
throw new AuthenticationException("Password is required for managed user");
156+
throw new MsalClientException(
157+
"Password is required for managed user",
158+
AuthenticationErrorCode.PASSWORD_REQUIRED_FOR_MANAGED_USER);
157159
}
158160
else{
159-
throw new AuthenticationException("Unknown User Type");
161+
throw new MsalClientException(
162+
"User Realm request failed",
163+
AuthenticationErrorCode.USER_REALM_DISCOVERY_FAILED);
160164
}
161165

162166
return updatedGrant;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ private AuthenticationResult acquireTokenWithDeviceCode(DeviceCode deviceCode,
7777
}
7878
try {
7979
return acquireTokenByAuthorisationGrantSupplier.execute();
80-
} catch (AuthenticationServiceException ex) {
80+
} catch (MsalServiceException ex) {
8181
if (ex.errorCode().equals(AUTHORIZATION_PENDING)) {
8282
TimeUnit.SECONDS.sleep(deviceCode.interval());
8383
} else {
8484
throw ex;
8585
}
8686
}
8787
}
88-
throw new AuthenticationClientException("Expired Device code");
88+
throw new MsalClientException("Expired Device code", AuthenticationErrorCode.CODE_EXPIRED);
8989
}
9090

9191
private Long getCurrentSystemTimeInSeconds(){

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,42 @@
2525

2626
public class AuthenticationErrorCode {
2727

28+
/**
29+
* In the context of device code user has not yet authenticated via browser
30+
*/
2831
public final static String AUTHORIZATION_PENDING = "authorization_pending";
29-
public final static String INTERACTION_REQUIRED = "interaction_required";
32+
33+
/**
34+
* In the context of device code, this error happens when the device code has expired before
35+
* the user signed-in on another device (this is usually after 15 min)
36+
*/
37+
public final static String CODE_EXPIRED = "code_expired";
38+
39+
/**
40+
* Standard Oauth2 protocol error code. It indicates that the application needs to expose
41+
* the UI to the user so that user does an interactive action in order to get a new token
42+
*/
3043
public final static String INVALID_GRANT = "invalid_grant";
44+
45+
/**
46+
* WS-Trust Endpoint not found in Metadata document
47+
*/
48+
public final static String WSTRUST_ENDPOINT_NOT_FOUND_IN_METADATA_DOCUMENT = "wstrust_endpoint_not_found";
49+
50+
/**
51+
* Password is required for managed user. Will typically happen when trying to do integrated windows authentication
52+
* for managed users
53+
*/
54+
public final static String PASSWORD_REQUIRED_FOR_MANAGED_USER = "password_required_for_managed_user";
55+
56+
/**
57+
* User realm discovery failed
58+
*/
59+
public final static String USER_REALM_DISCOVERY_FAILED = "user_realm_discovery_failed";
60+
61+
/**
62+
* Unknown error occurred
63+
*/
3164
public final static String UNKNOWN = "unknown";
3265
}
66+

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.net.URL;
3232
import java.security.MessageDigest;
3333
import java.security.NoSuchAlgorithmException;
34-
import java.util.Set;
3534
import java.util.concurrent.CompletionException;
3635
import java.util.function.Supplier;
3736

@@ -84,8 +83,8 @@ public IAuthenticationResult get() {
8483
}
8584
} catch(Exception ex) {
8685

87-
if (ex instanceof AuthenticationServiceException) {
88-
apiEvent.setApiErrorCode(((AuthenticationServiceException) ex).errorCode());
86+
if (ex instanceof MsalServiceException) {
87+
apiEvent.setApiErrorCode(((MsalServiceException) ex).errorCode());
8988
}
9089

9190
clientApplication.log.error(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ private static Authority createDefaultAADAuthority() {
409409
try {
410410
authority = new AADAuthority(new URL(DEFAULT_AUTHORITY));
411411
} catch(Exception e){
412-
throw new AuthenticationClientException(e);
412+
throw new MsalClientException(e);
413413
}
414414
return authority;
415415
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private ClientAuthentication createClientAuthFromClientAssertion(
103103
map.put("client_assertion", Collections.singletonList(clientAssertion.assertion()));
104104
return PrivateKeyJWT.parse(map);
105105
} catch (final ParseException e) {
106-
throw new AuthenticationClientException(e);
106+
throw new MsalClientException(e);
107107
}
108108
}
109109

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static void verifyReturnedCorrelationId(Logger log,
168168
}
169169

170170
static String readResponseFromConnection(final HttpsURLConnection conn, HttpEvent httpEvent)
171-
throws AuthenticationException, IOException {
171+
throws MsalServiceException, IOException {
172172
InputStream is = null;
173173
try {
174174
int responseCode = conn.getResponseCode();
@@ -181,7 +181,7 @@ static String readResponseFromConnection(final HttpsURLConnection conn, HttpEven
181181
msg = msg + ", Error details : " + inputStreamToString(is);
182182
}
183183
httpEvent.setOauthErrorCode(AuthenticationErrorCode.UNKNOWN);
184-
throw new AuthenticationServiceException(msg);
184+
throw new MsalServiceException(msg, AuthenticationErrorCode.UNKNOWN);
185185
}
186186

187187
is = conn.getInputStream();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public interface IConfidentialClientApplication extends IClientApplicationBase {
4848
* {@link IAuthenticationResult} of the call. It contains Access
4949
* Token and the Access Token's expiration time. Refresh Token
5050
* property will be null for this overload.
51-
* @throws AuthenticationException {@link AuthenticationException}
51+
* @throws MsalException {@link MsalException}
5252
*/
5353
CompletableFuture<IAuthenticationResult> acquireToken(OnBehalfOfParameters parameters);
5454
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public interface IPublicClientApplication extends IClientApplicationBase {
6666
* @param parameters#deviceCodeConsumer
6767
* @return A {@link CompletableFuture} object representing the {@link IAuthenticationResult} of the call.
6868
* It contains AccessTokenCacheEntity, Refresh Token and the Access Token's expiration time.
69-
* @throws AuthenticationException thrown if authorization is pending or another error occurred.
69+
* @throws MsalException thrown if authorization is pending or another error occurred.
7070
* If the errorCode of the exception is AuthenticationErrorCode.AUTHORIZATION_PENDING,
7171
* the call needs to be retried until the AccessToken is returned.
7272
* DeviceCode.interval - The minimum amount of time in seconds that the client

0 commit comments

Comments
 (0)