Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding null checks and logging to filter methods in AccountAdapter #1929

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MSAL Wiki : https://github.com/AzureAD/microsoft-authentication-library-for-android/wiki
vNext
----------
- [PATCH] Adding null checks and logging to filter methods in AccountAdapter (#1929)

Version 4.9.0
----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,27 @@ private interface CacheRecordFilter {
}

private static class GuestAccountFilter implements CacheRecordFilter {
final static String TAG = GuestAccountFilter.class.getSimpleName();

@Override
public List<ICacheRecord> filter(@NonNull List<ICacheRecord> records) {
final String methodTag = TAG + ":filter";

final List<ICacheRecord> result = new ArrayList<>();

for (final ICacheRecord cacheRecord : records) {
final String acctHomeAccountId = cacheRecord.getAccount().getHomeAccountId();
final String acctLocalAccountId = cacheRecord.getAccount().getLocalAccountId();

if (!acctHomeAccountId.contains(acctLocalAccountId)) {
boolean isNullorEmpty = false;
if (StringUtil.isNullOrEmpty(acctHomeAccountId)) {
Logger.warn(methodTag, "Home account id is null or empty.");
melissaahn marked this conversation as resolved.
Show resolved Hide resolved
isNullorEmpty = true;
}
if (StringUtil.isNullOrEmpty(acctLocalAccountId)) {
Logger.warn(methodTag, "Local account id is null or empty.");
isNullorEmpty = true;
}
if (!isNullorEmpty && !acctHomeAccountId.contains(acctLocalAccountId)) {
result.add(cacheRecord);
}
}
Expand All @@ -74,15 +85,26 @@ public List<ICacheRecord> filter(@NonNull List<ICacheRecord> records) {
* constructor initialization.
*/
private static class HomeAccountFilter implements CacheRecordFilter {
final static String TAG = HomeAccountFilter.class.getSimpleName();

@Override
public List<ICacheRecord> filter(@NonNull final List<ICacheRecord> records) {
final String methodTag = TAG + ":filter";
final List<ICacheRecord> result = new ArrayList<>();

for (final ICacheRecord cacheRecord : records) {
final String acctHomeAccountId = cacheRecord.getAccount().getHomeAccountId();
final String acctLocalAccountId = cacheRecord.getAccount().getLocalAccountId();
if (acctLocalAccountId != null && acctHomeAccountId.contains(acctLocalAccountId)) {
boolean isNullorEmpty = false;
if (StringUtil.isNullOrEmpty(acctHomeAccountId)) {
Logger.warn(methodTag, "Home account id is null or empty.");
isNullorEmpty = true;
}
if (StringUtil.isNullOrEmpty(acctLocalAccountId)) {
Logger.warn(methodTag, "Local account id is null or empty.");
isNullorEmpty = true;
}
if (!isNullorEmpty && acctHomeAccountId.contains(acctLocalAccountId)) {
result.add(cacheRecord);
}
}
Expand All @@ -96,10 +118,17 @@ public List<ICacheRecord> filter(@NonNull final List<ICacheRecord> records) {
*/
private static final CacheRecordFilter guestAccountsWithNoHomeTenantAccountFilter = new CacheRecordFilter() {

final String TAG = CacheRecordFilter.class.getSimpleName();

private boolean hasNoCorrespondingHomeAccount(@NonNull final ICacheRecord guestRecord,
@NonNull final List<ICacheRecord> homeRecords) {
final String methodTag = TAG + ":hasNoCorrespondingHomeAccount";
// Init our sought value
final String guestAccountHomeAccountId = guestRecord.getAccount().getHomeAccountId();
if (StringUtil.isNullOrEmpty(guestAccountHomeAccountId)){
Logger.warn(methodTag, "Guest account home account id is null or empty.");
melissaahn marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

// Create a List of home_account_ids from the homeRecords...
final List<String> homeAccountIds = new ArrayList<String>() {{
Expand Down
Loading