Skip to content

Commit

Permalink
Merge c295f18 into b8e348d
Browse files Browse the repository at this point in the history
  • Loading branch information
niekraaijmakers committed Apr 28, 2019
2 parents b8e348d + c295f18 commit 8784d40
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@
import java.util.Map;

public abstract class AbstractKeyValueExtension implements HttpCacheConfigExtension, CacheKeyFactory {

abstract public Map<String, String[]> getAllowedKeyValues();

abstract public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheConfig, Map<String, String[]> allowedKeyValues);

abstract public String getCacheKeyId();


@Override
public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheConfig) {
return accepts(request, cacheConfig, getAllowedKeyValues());
Expand All @@ -61,4 +55,9 @@ public boolean doesKeyMatchConfig(CacheKey key, HttpCacheConfig cacheConfig) {
return new KeyValueCacheKey(key.getUri(), cacheConfig, getCacheKeyId(), getAllowedKeyValues()).equals(key);
}

abstract public Map<String, String[]> getAllowedKeyValues();

abstract public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheConfig, Map<String, String[]> allowedKeyValues);

abstract public String getCacheKeyId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
import java.util.Map;
import java.util.UUID;

import static org.apache.commons.lang3.ArrayUtils.contains;
import static org.apache.commons.lang3.ArrayUtils.isEmpty;

/**
* RequestHeaderHttpCacheConfigExtension
* <p>
Expand Down Expand Up @@ -95,12 +98,9 @@ public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheCon
final String header = request.getHeader(entry.getKey());

if (header != null) {
if (ArrayUtils.isEmpty(entry.getValue())) {
if (isEmpty(entry.getValue()) || contains(entry.getValue(), header)) {
// If no values were specified, then assume ANY and ALL values are acceptable, and were are merely looking for the existence of the request header
return true;
} else if (ArrayUtils.contains(entry.getValue(), header)) {
// The request header value matched one of the allowed values
return true;
}
// No matches found for this row; continue looking through the allowed list
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
import java.util.Map;
import java.util.UUID;

import static org.apache.commons.collections.CollectionUtils.containsAny;
import static org.apache.commons.lang3.ArrayUtils.isEmpty;

/**
* RequestParameterHttpCacheConfigExtension
* <p>
Expand Down Expand Up @@ -98,12 +101,9 @@ public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheCon
if (request.getParameterMap().keySet().contains(entry.getKey())) {
final String[] parameterValues = request.getParameterMap().get(entry.getKey());

if (ArrayUtils.isEmpty(entry.getValue())) {
if (isEmpty(entry.getValue()) || containsAny(Arrays.asList(entry.getValue()), Arrays.asList(parameterValues))) {
// If no values were specified, then assume ANY and ALL values are acceptable, and were are merely looking for the existence of the request parameter
return true;
} else if (CollectionUtils.containsAny(Arrays.asList(entry.getValue()), Arrays.asList(parameterValues))) {
// The request parameter value matched one of the allowed values
return true;
}
// No matches found for this row; continue looking through the allowed list
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@
import org.osgi.service.metatype.annotations.Designate;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;

import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import static org.apache.commons.collections.CollectionUtils.containsAny;
import static org.apache.commons.lang3.ArrayUtils.isEmpty;


/**
* ResourcePropertiesHttpCacheConfigExtension
Expand Down Expand Up @@ -97,12 +104,9 @@ public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheCon
if (properties.containsKey(entry.getKey())) {
final String[] propertyValues = properties.get(entry.getKey(), String[].class);

if (ArrayUtils.isEmpty(propertyValues)) {
if (isEmpty(propertyValues) || containsAny(Arrays.asList(entry.getValue()), Arrays.asList(propertyValues))) {
// If no values were specified, then assume ANY and ALL values are acceptable, and were are merely looking for the existence of the property
return true;
} else if (CollectionUtils.containsAny(Arrays.asList(entry.getValue()), Arrays.asList(propertyValues))) {
// The resource property value matched one of the allowed values
return true;
}
// No matches found for this row; continue looking through the allowed list
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,19 @@
import com.adobe.granite.jmx.annotation.AnnotatedStandardMBean;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.*;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.References;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.ReferencePolicyOption;
import org.apache.felix.scr.annotations.ReferenceCardinality;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.commons.osgi.PropertiesUtil;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2013 Adobe
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.adobe.acs.commons.httpcache.store.caffeine.impl;

import com.adobe.acs.commons.util.impl.CacheMBean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@
import com.github.benmanes.caffeine.cache.*;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.felix.scr.annotations.*;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.ConfigurationPolicy;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void setUp() throws Exception {

final Map<String, Object> config = new HashMap<>();

config.put("httpcache.cachestore.caffeine.ttl", 60l);
config.put("httpcache.cachestore.caffeine.maxsize", 10l);
config.put("httpcache.cachestore.caffeine.ttl", 60L);
config.put("httpcache.cachestore.caffeine.maxsize", 10L);

caffeine.activate(config);
}
Expand Down

0 comments on commit 8784d40

Please sign in to comment.