exceptionfactory commented on a change in pull request #5262:
URL: https://github.com/apache/nifi/pull/5262#discussion_r680404259



##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/main/java/org/apache/nifi/web/security/jwt/revocation/StandardJwtRevocationService.java
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.nifi.web.security.jwt.revocation;
+
+import org.apache.nifi.components.state.Scope;
+import org.apache.nifi.components.state.StateManager;
+import org.apache.nifi.components.state.StateMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.time.Instant;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * Standard JSON Web Token Revocation Service using State Manager
+ */
+public class StandardJwtRevocationService implements JwtRevocationService {
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(StandardJwtRevocationService.class);
+
+    private static final Scope SCOPE = Scope.LOCAL;
+
+    private final StateManager stateManager;
+
+    public StandardJwtRevocationService(final StateManager stateManager) {
+        this.stateManager = stateManager;
+    }
+
+    /**
+     * Delete Expired Revocations is synchronized is avoid losing updates from 
setRevoked()
+     */
+    @Override
+    public synchronized void deleteExpired() {
+        final Map<String, String> state = getStateMap().toMap();
+
+        final Instant now = Instant.now();
+        final Map<String, String> updatedState = state
+                .entrySet()
+                .stream()
+                .filter(entry -> Instant.parse(entry.getValue()).isAfter(now))
+                .collect(Collectors.toMap(Map.Entry::getKey, 
Map.Entry::getValue));
+
+        if (updatedState.equals(state)) {
+            LOGGER.debug("Expired Revocations not found");
+        } else {
+            try {
+                stateManager.setState(updatedState, SCOPE);
+            } catch (final IOException e) {
+                throw new UncheckedIOException("Delete Expired Revocations 
Failed", e);
+            }
+            LOGGER.debug("Delete Expired Revocations: Before [{}] After [{}]", 
state.size(), updatedState.size());

Review comment:
       That's a good question, but it seems better as a debug message than an 
information message. Key generation and expiration should be transparent to the 
user under normal circumstances, so leaving as a debug message seems sufficient 
as an option for troubleshooting.




-- 
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.

To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to