Skip to content

Commit

Permalink
OF-1894: Allow the contents of Cache's to be kept private
Browse files Browse the repository at this point in the history
  • Loading branch information
GregDThomas authored and guusdk committed Nov 1, 2019
1 parent d592fcb commit 5b52694
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Expand Up @@ -48,20 +48,23 @@ protected void doGet(final HttpServletRequest request, final HttpServletResponse
request.setAttribute("warningMessage", LocaleUtils.getLocalizedString("system.cache-details.cache_not_found", Collections.singletonList(cacheName)));
}

final boolean secretKey = optionalCache.map(Cache::isKeySecret).orElse(Boolean.FALSE);
final boolean secretValue = optionalCache.map(Cache::isValueSecret).orElse(Boolean.FALSE);

final List<Map.Entry<String, String>> cacheEntries = optionalCache.map(Cache::entrySet)
.map(Collection::stream)
.orElseGet(Stream::empty)
.map(entry -> new AbstractMap.SimpleEntry<>(entry.getKey().toString(), entry.getValue().toString()))
.map(entry -> new AbstractMap.SimpleEntry<>(secretKey ? "************" : entry.getKey().toString(), secretValue ? "************" : entry.getValue().toString()))
.sorted(Comparator.comparing(Map.Entry::getKey))
.collect(Collectors.toList());

// Find what we're searching for
final Search search = new Search(request);
Predicate<Map.Entry<String, String>> predicate = entry -> true;
if (!search.key.isEmpty()) {
if (!search.key.isEmpty() && !secretKey) {
predicate = predicate.and(entry -> StringUtils.containsIgnoringCase(entry.getKey(), search.key));
}
if (!search.value.isEmpty()) {
if (!search.value.isEmpty() && !secretValue) {
predicate = predicate.and(entry -> StringUtils.containsIgnoringCase(entry.getValue(), search.value));
}

Expand Down
18 changes: 18 additions & 0 deletions xmppserver/src/main/java/org/jivesoftware/util/cache/Cache.java
Expand Up @@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;

/**
Expand Down Expand Up @@ -186,4 +187,21 @@ default Lock getLock(final K key) {
return CacheFactory.getLock(key, this);
}

AtomicBoolean secretKey = new AtomicBoolean(false);
AtomicBoolean secretValue = new AtomicBoolean(false);
default void setSecretKey() {
this.secretKey.set(true);
}

default void setSecretValue() {
this.secretValue.set(true);
}

default boolean isKeySecret() {
return this.secretKey.get();
}

default boolean isValueSecret() {
return this.secretValue.get();
}
}

0 comments on commit 5b52694

Please sign in to comment.