Issue 8678 Non-coordinator services are repeatedly logging JsonMappingException when using druid-basic-security extension with an authenticator that has no users setup (#8692)

This commit is contained in:
Mohammad J. Khan 2019-10-18 13:09:53 -05:00 committed by Jonathan Wei
parent 8b2afa5c49
commit 1ca859584f
1 changed files with 12 additions and 6 deletions

View File

@ -23,6 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.google.inject.Injector;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.druid.client.coordinator.Coordinator;
import org.apache.druid.concurrent.LifecycleLock;
import org.apache.druid.discovery.DruidLeaderClient;
@ -247,6 +248,7 @@ public class CoordinatorPollingBasicAuthenticatorCacheManager implements BasicAu
private Map<String, BasicAuthenticatorUser> tryFetchUserMapFromCoordinator(String prefix) throws Exception
{
Map<String, BasicAuthenticatorUser> userMap = null;
Request req = druidLeaderClient.makeRequest(
HttpMethod.GET,
StringUtils.format("/druid-ext/basic-security/authentication/db/%s/cachedSerializedUserMap", prefix)
@ -256,12 +258,16 @@ public class CoordinatorPollingBasicAuthenticatorCacheManager implements BasicAu
new BytesFullResponseHandler()
);
byte[] userMapBytes = responseHolder.getContent();
Map<String, BasicAuthenticatorUser> userMap = objectMapper.readValue(
userMapBytes,
BasicAuthUtils.AUTHENTICATOR_USER_MAP_TYPE_REFERENCE
);
if (userMap != null && commonCacheConfig.getCacheDirectory() != null) {
writeUserMapToDisk(prefix, userMapBytes);
if (ArrayUtils.isNotEmpty(userMapBytes)) {
userMap = objectMapper.readValue(
userMapBytes,
BasicAuthUtils.AUTHENTICATOR_USER_MAP_TYPE_REFERENCE
);
if (userMap != null && commonCacheConfig.getCacheDirectory() != null) {
writeUserMapToDisk(prefix, userMapBytes);
}
} else {
LOG.info("Empty cached serialized user map retrieved, authenticator - %s", prefix);
}
return userMap;
}