Skip to content

Commit 7faee8f

Browse files
authored
Merge branch 'dev' into shahzaibj/dev-msal-prod-broker-pipeline
2 parents 4b45b1f + 4290fc3 commit 7faee8f

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MSAL Wiki : https://github.com/AzureAD/microsoft-authentication-library-for-android/wiki
22
V.Next
33
----------
4+
- [PATCH] Updating the single account cache before notifying the caller of account change/load via callback. (#1688)
45
- [MINOR] Added keyboard flag to configChanges in Manifest for YubiKey compatibility. (#1685)
56

67
Version 4.0.1

msal/src/main/java/com/microsoft/identity/client/SingleAccountPublicClientApplication.java

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@
2222
// THE SOFTWARE.
2323
package com.microsoft.identity.client;
2424

25+
import static com.microsoft.identity.client.exception.MsalClientException.UNKNOWN_ERROR;
26+
import static com.microsoft.identity.client.internal.MsalUtils.throwOnMainThread;
27+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_ACQUIRE_TOKEN_SILENT_ASYNC_WITH_PARAMETERS;
28+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_ACQUIRE_TOKEN_SILENT_ASYNC_WITH_SCOPES_AUTHORITY_CALLBACK;
29+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_ACQUIRE_TOKEN_SILENT_WITH_PARAMETERS;
30+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_ACQUIRE_TOKEN_SILENT_WITH_SCOPES_AUTHORITY;
31+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_ACQUIRE_TOKEN_WITH_ACTIVITY_SCOPES_CALLBACK;
32+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_ACQUIRE_TOKEN_WITH_PARAMETERS;
33+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_EXISTING_SIGN_IN_WITH_PARAMETERS;
34+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_EXISTING_SIGN_IN_WITH_PARAMETERS_PROMPT;
35+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_EXISTING_SIGN_IN_WITH_PROMPT;
36+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_GET_CURRENT_ACCOUNT;
37+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_GET_CURRENT_ACCOUNT_ASYNC;
38+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_SIGN_IN;
39+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_SIGN_IN_WITH_PARAMETERS;
40+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_SIGN_IN_WITH_PARAMETERS_PROMPT;
41+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_SIGN_IN_WITH_PROMPT;
42+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_SIGN_OUT;
43+
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_SIGN_OUT_WITH_CALLBACK;
44+
2545
import android.app.Activity;
2646
import android.content.Context;
2747

@@ -31,29 +51,27 @@
3151

3252
import com.microsoft.identity.client.exception.MsalClientException;
3353
import com.microsoft.identity.client.exception.MsalException;
34-
import com.microsoft.identity.client.exception.MsalServiceException;
3554
import com.microsoft.identity.client.internal.AsyncResult;
3655
import com.microsoft.identity.client.internal.CommandParametersAdapter;
3756
import com.microsoft.identity.client.internal.controllers.MSALControllerFactory;
3857
import com.microsoft.identity.client.internal.controllers.MsalExceptionAdapter;
3958
import com.microsoft.identity.common.adal.internal.util.JsonExtensions;
4059
import com.microsoft.identity.common.adal.internal.util.StringExtensions;
4160
import com.microsoft.identity.common.crypto.AndroidAuthSdkStorageEncryptionManager;
42-
import com.microsoft.identity.common.internal.commands.DeviceCodeFlowCommandCallback;
43-
import com.microsoft.identity.common.java.cache.ICacheRecord;
4461
import com.microsoft.identity.common.internal.cache.SharedPreferencesFileManager;
45-
import com.microsoft.identity.common.java.commands.CommandCallback;
62+
import com.microsoft.identity.common.internal.commands.DeviceCodeFlowCommandCallback;
4663
import com.microsoft.identity.common.internal.commands.GetCurrentAccountCommand;
4764
import com.microsoft.identity.common.internal.commands.RemoveCurrentAccountCommand;
65+
import com.microsoft.identity.common.internal.migration.TokenMigrationCallback;
66+
import com.microsoft.identity.common.java.cache.ICacheRecord;
67+
import com.microsoft.identity.common.java.commands.CommandCallback;
4868
import com.microsoft.identity.common.java.commands.parameters.CommandParameters;
4969
import com.microsoft.identity.common.java.commands.parameters.RemoveAccountCommandParameters;
5070
import com.microsoft.identity.common.java.controllers.BaseController;
5171
import com.microsoft.identity.common.java.controllers.CommandDispatcher;
5272
import com.microsoft.identity.common.java.dto.AccountRecord;
53-
import com.microsoft.identity.common.internal.migration.TokenMigrationCallback;
54-
import com.microsoft.identity.common.java.exception.ServiceException;
55-
import com.microsoft.identity.common.java.result.ILocalAuthenticationResult;
5673
import com.microsoft.identity.common.java.exception.BaseException;
74+
import com.microsoft.identity.common.java.result.ILocalAuthenticationResult;
5775
import com.microsoft.identity.common.java.result.LocalAuthenticationResult;
5876
import com.microsoft.identity.common.java.util.ResultFuture;
5977
import com.microsoft.identity.common.logging.Logger;
@@ -63,26 +81,6 @@
6381
import java.util.List;
6482
import java.util.concurrent.ExecutionException;
6583

66-
import static com.microsoft.identity.client.exception.MsalClientException.UNKNOWN_ERROR;
67-
import static com.microsoft.identity.client.internal.MsalUtils.throwOnMainThread;
68-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_ACQUIRE_TOKEN_SILENT_ASYNC_WITH_PARAMETERS;
69-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_ACQUIRE_TOKEN_SILENT_ASYNC_WITH_SCOPES_AUTHORITY_CALLBACK;
70-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_ACQUIRE_TOKEN_SILENT_WITH_PARAMETERS;
71-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_ACQUIRE_TOKEN_SILENT_WITH_SCOPES_AUTHORITY;
72-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_ACQUIRE_TOKEN_WITH_ACTIVITY_SCOPES_CALLBACK;
73-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_ACQUIRE_TOKEN_WITH_PARAMETERS;
74-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_EXISTING_SIGN_IN_WITH_PROMPT;
75-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_EXISTING_SIGN_IN_WITH_PARAMETERS;
76-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_EXISTING_SIGN_IN_WITH_PARAMETERS_PROMPT;
77-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_GET_CURRENT_ACCOUNT;
78-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_GET_CURRENT_ACCOUNT_ASYNC;
79-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_SIGN_IN;
80-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_SIGN_IN_WITH_PROMPT;
81-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_SIGN_IN_WITH_PARAMETERS;
82-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_SIGN_IN_WITH_PARAMETERS_PROMPT;
83-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_SIGN_OUT;
84-
import static com.microsoft.identity.common.java.eststelemetry.PublicApiId.SINGLE_ACCOUNT_PCA_SIGN_OUT_WITH_CALLBACK;
85-
8684
public class SingleAccountPublicClientApplication
8785
extends PublicClientApplication
8886
implements ISingleAccountPublicClientApplication {
@@ -146,8 +144,9 @@ public void onTaskCompleted(final List<ICacheRecord> result) {
146144
// To simplify the logic, if more than one account is returned, the first account will be picked.
147145
// We do not support switching from MULTIPLE to SINGLE.
148146
// See getAccountFromICacheRecordList() for more details.
149-
checkCurrentAccountNotifyCallback(callback, result);
147+
final MultiTenantAccount oldAccount = getPersistedCurrentAccount();
150148
persistCurrentAccount(result);
149+
checkCurrentAccountNotifyCallback(callback, result, oldAccount);
151150
}
152151

153152
@Override
@@ -228,14 +227,14 @@ public void onError(@NonNull final MsalException exception) {
228227
}
229228

230229
private void checkCurrentAccountNotifyCallback(@NonNull final CurrentAccountCallback callback,
231-
@Nullable final List<ICacheRecord> newAccountRecords) {
232-
final MultiTenantAccount localAccount = getPersistedCurrentAccount();
230+
@Nullable final List<ICacheRecord> newAccountRecords,
231+
@Nullable final MultiTenantAccount oldAccount) {
233232
final MultiTenantAccount newAccount = newAccountRecords == null
234233
? null
235234
: getAccountFromICacheRecordList(newAccountRecords);
236235

237-
if (!isHomeAccountIdMatching(localAccount, newAccount)) {
238-
callback.onAccountChanged(localAccount, newAccount);
236+
if (!isHomeAccountIdMatching(oldAccount, newAccount)) {
237+
callback.onAccountChanged(oldAccount, newAccount);
239238
}
240239

241240
callback.onAccountLoaded(newAccount);

0 commit comments

Comments
 (0)