|
22 | 22 | // THE SOFTWARE. |
23 | 23 | package com.microsoft.identity.client; |
24 | 24 |
|
| 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 | + |
25 | 45 | import android.app.Activity; |
26 | 46 | import android.content.Context; |
27 | 47 |
|
|
31 | 51 |
|
32 | 52 | import com.microsoft.identity.client.exception.MsalClientException; |
33 | 53 | import com.microsoft.identity.client.exception.MsalException; |
34 | | -import com.microsoft.identity.client.exception.MsalServiceException; |
35 | 54 | import com.microsoft.identity.client.internal.AsyncResult; |
36 | 55 | import com.microsoft.identity.client.internal.CommandParametersAdapter; |
37 | 56 | import com.microsoft.identity.client.internal.controllers.MSALControllerFactory; |
38 | 57 | import com.microsoft.identity.client.internal.controllers.MsalExceptionAdapter; |
39 | 58 | import com.microsoft.identity.common.adal.internal.util.JsonExtensions; |
40 | 59 | import com.microsoft.identity.common.adal.internal.util.StringExtensions; |
41 | 60 | 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; |
44 | 61 | 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; |
46 | 63 | import com.microsoft.identity.common.internal.commands.GetCurrentAccountCommand; |
47 | 64 | 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; |
48 | 68 | import com.microsoft.identity.common.java.commands.parameters.CommandParameters; |
49 | 69 | import com.microsoft.identity.common.java.commands.parameters.RemoveAccountCommandParameters; |
50 | 70 | import com.microsoft.identity.common.java.controllers.BaseController; |
51 | 71 | import com.microsoft.identity.common.java.controllers.CommandDispatcher; |
52 | 72 | 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; |
56 | 73 | import com.microsoft.identity.common.java.exception.BaseException; |
| 74 | +import com.microsoft.identity.common.java.result.ILocalAuthenticationResult; |
57 | 75 | import com.microsoft.identity.common.java.result.LocalAuthenticationResult; |
58 | 76 | import com.microsoft.identity.common.java.util.ResultFuture; |
59 | 77 | import com.microsoft.identity.common.logging.Logger; |
|
63 | 81 | import java.util.List; |
64 | 82 | import java.util.concurrent.ExecutionException; |
65 | 83 |
|
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 | | - |
86 | 84 | public class SingleAccountPublicClientApplication |
87 | 85 | extends PublicClientApplication |
88 | 86 | implements ISingleAccountPublicClientApplication { |
@@ -146,8 +144,9 @@ public void onTaskCompleted(final List<ICacheRecord> result) { |
146 | 144 | // To simplify the logic, if more than one account is returned, the first account will be picked. |
147 | 145 | // We do not support switching from MULTIPLE to SINGLE. |
148 | 146 | // See getAccountFromICacheRecordList() for more details. |
149 | | - checkCurrentAccountNotifyCallback(callback, result); |
| 147 | + final MultiTenantAccount oldAccount = getPersistedCurrentAccount(); |
150 | 148 | persistCurrentAccount(result); |
| 149 | + checkCurrentAccountNotifyCallback(callback, result, oldAccount); |
151 | 150 | } |
152 | 151 |
|
153 | 152 | @Override |
@@ -228,14 +227,14 @@ public void onError(@NonNull final MsalException exception) { |
228 | 227 | } |
229 | 228 |
|
230 | 229 | 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) { |
233 | 232 | final MultiTenantAccount newAccount = newAccountRecords == null |
234 | 233 | ? null |
235 | 234 | : getAccountFromICacheRecordList(newAccountRecords); |
236 | 235 |
|
237 | | - if (!isHomeAccountIdMatching(localAccount, newAccount)) { |
238 | | - callback.onAccountChanged(localAccount, newAccount); |
| 236 | + if (!isHomeAccountIdMatching(oldAccount, newAccount)) { |
| 237 | + callback.onAccountChanged(oldAccount, newAccount); |
239 | 238 | } |
240 | 239 |
|
241 | 240 | callback.onAccountLoaded(newAccount); |
|
0 commit comments