ilgrosso commented on code in PR #1420:
URL: https://github.com/apache/syncope/pull/1420#discussion_r3387356907


##########
core/idrepo/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/RESTProperties.java:
##########
@@ -28,7 +31,79 @@ public class RESTProperties {
     @NestedConfigurationProperty
     private final ExecutorProperties batchExecutor = new ExecutorProperties();
 
+    @NestedConfigurationProperty
+    private final RateLimit rateLimit = new RateLimit();

Review Comment:
   Please rename this class as `RateLimitProperties`



##########
core/idrepo/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/CXFRateLimitFilter.java:
##########
@@ -0,0 +1,177 @@
+/*
+ * 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.syncope.core.rest.cxf;
+
+import jakarta.annotation.Priority;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.ws.rs.Priorities;
+import jakarta.ws.rs.container.ContainerRequestContext;
+import jakarta.ws.rs.container.ContainerRequestFilter;
+import jakarta.ws.rs.container.PreMatching;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.HttpHeaders;
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.ext.Provider;
+import java.io.Serializable;
+import java.time.Duration;
+import java.util.Arrays;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+import javax.cache.Cache;
+import javax.cache.configuration.MutableConfiguration;
+import javax.cache.expiry.TouchedExpiryPolicy;
+import org.apache.commons.lang3.StringUtils;
+
+@Provider
+@PreMatching
+@Priority(Priorities.AUTHENTICATION - 100)
+public class CXFRateLimitFilter implements ContainerRequestFilter {
+
+    public static final String CACHE_NAME =
+            "org.apache.syncope.core.rest.cxf.CXFRateLimitFilter";
+
+    protected record RateLimitDecision(boolean allowed, long 
retryAfterSeconds) {
+    }
+
+    public record ClientWindow(long windowStartMillis, int count, long 
lockedUntilMillis) implements Serializable {
+
+        private static final long serialVersionUID = -473897805205955157L;
+    }
+
+    public static MutableConfiguration<String, ClientWindow> 
cacheConfiguration(final RESTProperties.RateLimit props) {

Review Comment:
   Please move the cache definition in the Spring context.
   
   I can imagine you did put it here to reuse it in test code: no issue with 
duplicated code for tests.



##########
core/idrepo/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/CXFRateLimitFilter.java:
##########
@@ -0,0 +1,177 @@
+/*
+ * 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.syncope.core.rest.cxf;
+
+import jakarta.annotation.Priority;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.ws.rs.Priorities;
+import jakarta.ws.rs.container.ContainerRequestContext;
+import jakarta.ws.rs.container.ContainerRequestFilter;
+import jakarta.ws.rs.container.PreMatching;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.HttpHeaders;
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.ext.Provider;
+import java.io.Serializable;
+import java.time.Duration;
+import java.util.Arrays;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+import javax.cache.Cache;
+import javax.cache.configuration.MutableConfiguration;
+import javax.cache.expiry.TouchedExpiryPolicy;
+import org.apache.commons.lang3.StringUtils;
+
+@Provider
+@PreMatching
+@Priority(Priorities.AUTHENTICATION - 100)
+public class CXFRateLimitFilter implements ContainerRequestFilter {
+
+    public static final String CACHE_NAME =
+            "org.apache.syncope.core.rest.cxf.CXFRateLimitFilter";
+
+    protected record RateLimitDecision(boolean allowed, long 
retryAfterSeconds) {
+    }
+
+    public record ClientWindow(long windowStartMillis, int count, long 
lockedUntilMillis) implements Serializable {
+
+        private static final long serialVersionUID = -473897805205955157L;
+    }
+
+    public static MutableConfiguration<String, ClientWindow> 
cacheConfiguration(final RESTProperties.RateLimit props) {

Review Comment:
   Moreover, we have already `IdRepoRESTCXFTestContext` there.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to