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

Use newly created nullsafe equalsIgnoreCase. #1551

Closed
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ private void verifyBrokerRedirectUri(final AuthenticationRequest request) throws
throw new UsageAuthenticationException(ADALError.DEVELOPER_REDIRECTURI_INVALID, "The redirectUri is null or blank.");
}

if (inputUri.equalsIgnoreCase(AuthenticationConstants.Broker.BROKER_REDIRECT_URI)) {
if (AuthenticationConstants.Broker.BROKER_REDIRECT_URI.equalsIgnoreCase(inputUri)) {
// TODO: Clean this up once we migrate all Logger functions to the common one.
com.microsoft.identity.common.internal.logging.Logger.info(TAG + methodName, "This is a broker redirectUri. Bypass the check.");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* tokenCacheItem is not persisted. Memory cache does not keep static items.
Expand All @@ -42,9 +42,7 @@ public class MemoryTokenCacheStore implements ITokenCacheStore {

private static final String TAG = "MemoryTokenCacheStore";

private final Map<String, TokenCacheItem> mCache = new HashMap<>();

private transient Object mCacheLock = new Object();
private final Map<String, TokenCacheItem> mCache = new ConcurrentHashMap<>(16, 0.75f, 1);

/**
* Creates MemoryTokenCacheStore.
Expand All @@ -59,9 +57,7 @@ public TokenCacheItem getItem(String key) {
}

Logger.i(TAG, "Get Item from cache. ", "Key:" + key);
synchronized (mCacheLock) {
return mCache.get(key);
}
return mCache.get(key);
}

@Override
Expand All @@ -75,9 +71,7 @@ public void setItem(String key, TokenCacheItem item) {
}

Logger.i(TAG, "Set Item to cache. ", "Key: " + key);
synchronized (mCacheLock) {
mCache.put(key, item);
}
mCache.put(key, item);
}

@Override
Expand All @@ -87,17 +81,13 @@ public void removeItem(String key) {
}

Logger.i(TAG, "Remove Item from cache. ", "Key:" + key.hashCode());
synchronized (mCacheLock) {
mCache.remove(key);
}
mCache.remove(key);
}

@Override
public void removeAll() {
Logger.v(TAG, "Remove all items from cache.");
synchronized (mCacheLock) {
mCache.clear();
}
mCache.clear();
}

private synchronized void writeObject(ObjectOutputStream out) throws IOException {
Expand All @@ -108,7 +98,6 @@ private void readObject(ObjectInputStream inputStream) throws IOException,
ClassNotFoundException {
inputStream.defaultReadObject();

mCacheLock = new Object();
}

@Override
Expand All @@ -118,16 +107,12 @@ public boolean contains(String key) {
}

Logger.i(TAG, "contains Item from cache.", "Key: " + key);
synchronized (mCacheLock) {
return mCache.get(key) != null;
}
return mCache.get(key) != null;
}

@Override
public Iterator<TokenCacheItem> getAll() {
Logger.v(TAG, "Retrieving all items from cache. ");
synchronized (mCacheLock) {
return mCache.values().iterator();
}
return mCache.values().iterator();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryOAuth2Configuration;
import com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryOAuth2Strategy;
import com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryTokenResponse;
import com.microsoft.identity.common.internal.util.StringUtil;

import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -443,7 +444,7 @@ boolean isMultipleMRRTsMatchingGivenApp(final String clientId) {
final List<TokenCacheItem> mrrtsMatchingRequest = new ArrayList<>();
while (allItems.hasNext()) {
final TokenCacheItem tokenCacheItem = allItems.next();
if (tokenCacheItem.getAuthority().equalsIgnoreCase(mAuthority) && tokenCacheItem.getClientId().equalsIgnoreCase(clientId)
if (StringUtil.equalsIgnoreCase(tokenCacheItem.getAuthority(), mAuthority) && StringUtil.equalsIgnoreCase(tokenCacheItem.getClientId(), clientId)
&& (tokenCacheItem.getIsMultiResourceRefreshToken() || StringExtensions.isNullOrBlank(tokenCacheItem.getResource()))) {
mrrtsMatchingRequest.add(tokenCacheItem);
}
Expand Down