[
https://issues.apache.org/jira/browse/KNOX-2544?focusedWorklogId=591227&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-591227
]
ASF GitHub Bot logged work on KNOX-2544:
----------------------------------------
Author: ASF GitHub Bot
Created on: 29/Apr/21 20:26
Start Date: 29/Apr/21 20:26
Worklog Time Spent: 10m
Work Description: pzampino commented on a change in pull request #440:
URL: https://github.com/apache/knox/pull/440#discussion_r623374691
##########
File path:
gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/SignatureVerificationCache.java
##########
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.knox.gateway.provider.federation.jwt.filter;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import org.apache.knox.gateway.i18n.messages.MessagesFactory;
+import org.apache.knox.gateway.provider.federation.jwt.JWTMessages;
+
+import javax.servlet.FilterConfig;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A shared record of tokens for which the signature has been verified.
+ */
+public class SignatureVerificationCache {
+
+ public static final String JWT_VERIFIED_CACHE_MAX =
"jwt.verified.cache.max";
+ public static final int JWT_VERIFIED_CACHE_MAX_DEFAULT = 250;
+
+ static final String DEFAULT_CACHE_ID = "default-cache";
+
+ static JWTMessages log = MessagesFactory.get( JWTMessages.class );
+
+ private static final Map<String, SignatureVerificationCache> instances =
new HashMap<>();
+
+ /**
+ * Caches are topology-specific because the configuration is defined at
the provider level.
+ *
+ * @param topology The topology for which the cache is being requested, or
null if the default is sufficient.
+ * @param config The FilterConfig associated with the calling provider.
+ *
+ * @return A SignatureVerificationCache for the specified topology, or the
default one if no topology is specified.
+ */
+ @SuppressWarnings("PMD.SingletonClassReturningNewInstance")
+ public static SignatureVerificationCache getInstance(final String
topology, final FilterConfig config) {
+ SignatureVerificationCache instance;
+ String cacheId = topology != null ? topology : DEFAULT_CACHE_ID;
+ synchronized (instances) {
+ instance = instances.get(cacheId);
+ if (instance == null) {
+ instance = new SignatureVerificationCache(config);
+ instances.put(cacheId, instance);
+ log.initializedSignatureVerificationCache(cacheId);
+ }
+ }
+ return instance;
+ }
+
+ private Cache<String, Boolean> verifiedTokens;
Review comment:
I generally try to separate instance methods/members from class
methods/members, but apparently this isn't providing the clarity
intended...I'll change it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 591227)
Time Spent: 1.5h (was: 1h 20m)
> Token-based providers should cache successful token verifications
> -----------------------------------------------------------------
>
> Key: KNOX-2544
> URL: https://issues.apache.org/jira/browse/KNOX-2544
> Project: Apache Knox
> Issue Type: Improvement
> Components: Server
> Affects Versions: 1.5.0
> Reporter: Philip Zampino
> Assignee: Philip Zampino
> Priority: Major
> Fix For: 1.6.0
>
> Time Spent: 1.5h
> Remaining Estimate: 0h
>
> The token-based providers should record the successful verification of tokens
> in a LRU-like cache to minimize the frequency of performing the expensive
> (CPU-intensive) operation.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)