pzampino commented on code in PR #1016:
URL: https://github.com/apache/knox/pull/1016#discussion_r2031461469


##########
gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/ClientCredentialsResource.java:
##########
@@ -40,6 +54,47 @@ public class ClientCredentialsResource extends TokenResource 
{
     public static final String CLIENT_ID = "client_id";
     public static final String CLIENT_SECRET = "client_secret";
 
+    private GatewayServices services;
+
+    @Override
+    protected ServletContext wrapContextForDefaultParams(ServletContext 
context) throws ServletException {
+        ServletContext wrapperContext = new ServletContextWrapper(context);
+        
wrapperContext.setInitParameter(TokenStateService.CONFIG_SERVER_MANAGED, 
"true");
+        wrapperContext.setInitParameter(TokenResource.TOKEN_TTL_PARAM, "-1");

Review Comment:
   This could never be set otherwise then, right?



##########
gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/TokenResource.java:
##########
@@ -219,8 +220,13 @@ public int toInt() {
     }
   }
 
+  protected ServletContext wrapContextForDefaultParams(ServletContext context) 
throws ServletException {
+    return context;
+  }
+
   @PostConstruct
-  public void init() throws AliasServiceException, ServiceLifecycleException, 
KeyLengthException {
+  public void init() throws AliasServiceException, ServiceLifecycleException, 
KeyLengthException, ServletException {
+    ServletContext context = wrapContextForDefaultParams(this.context);

Review Comment:
   Is there any harm is assigning the wrapped ServletContext to the context 
member? If that were done, the other method signatures need not change, and the 
potential for someone referencing the "wrong" context in the future could be 
prevented.



##########
gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/ServletContextWrapper.java:
##########
@@ -0,0 +1,324 @@
+/*
+ * 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.service.knoxtoken;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterRegistration;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRegistration;
+import javax.servlet.SessionCookieConfig;
+import javax.servlet.SessionTrackingMode;
+import javax.servlet.descriptor.JspConfigDescriptor;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.EventListener;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+class ServletContextWrapper implements ServletContext {
+    private ServletContext delegate;
+    private Map<String, String> defaultParams;
+
+    ServletContextWrapper(ServletContext delegate) {
+        this.delegate = delegate;
+        defaultParams = new HashMap<>();
+    }
+
+    @Override
+    public String getContextPath() {
+        return delegate.getContextPath();
+    }
+
+    @Override
+    public ServletContext getContext(String uripath) {
+        return delegate.getContext(uripath);
+    }
+
+    @Override
+    public int getMajorVersion() {
+        return delegate.getMajorVersion();
+    }
+
+    @Override
+    public int getMinorVersion() {
+        return delegate.getMinorVersion();
+    }
+
+    @Override
+    public int getEffectiveMajorVersion() {
+        return delegate.getEffectiveMajorVersion();
+    }
+
+    @Override
+    public int getEffectiveMinorVersion() {
+        return delegate.getEffectiveMinorVersion();
+    }
+
+    @Override
+    public String getMimeType(String file) {
+        return delegate.getMimeType(file);
+    }
+
+    @Override
+    public Set<String> getResourcePaths(String path) {
+        return delegate.getResourcePaths(path);
+    }
+
+    @Override
+    public URL getResource(String path) throws MalformedURLException {
+        return delegate.getResource(path);
+    }
+
+    @Override
+    public InputStream getResourceAsStream(String path) {
+        return delegate.getResourceAsStream(path);
+    }
+
+    @Override
+    public RequestDispatcher getRequestDispatcher(String path) {
+        return delegate.getRequestDispatcher(path);
+    }
+
+    @Override
+    public RequestDispatcher getNamedDispatcher(String name) {
+        return delegate.getNamedDispatcher(name);
+    }
+
+    @Override
+    public Servlet getServlet(String name) throws ServletException {
+        return delegate.getServlet(name);
+    }
+
+    @Override
+    public Enumeration<Servlet> getServlets() {
+        return delegate.getServlets();
+    }
+
+    @Override
+    public Enumeration<String> getServletNames() {
+        return delegate.getServletNames();
+    }
+
+    @Override
+    public void log(String msg) {
+        delegate.log(msg);
+    }
+
+    @Override
+    public void log(Exception exception, String msg) {
+        delegate.log(exception, msg);
+    }
+
+    @Override
+    public void log(String message, Throwable throwable) {
+        delegate.log(message, throwable);
+    }
+
+    @Override
+    public String getRealPath(String path) {
+        return delegate.getRealPath(path);
+    }
+
+    @Override
+    public String getServerInfo() {
+        return delegate.getServerInfo();
+    }
+
+    @Override
+    public String getInitParameter(String name) {
+        String value = delegate.getInitParameter(name);
+        if (value == null) {
+            value =  defaultParams.get(name);
+        }
+        return value;
+    }
+
+    @Override
+    public Enumeration<String> getInitParameterNames() {
+        // Add all keys from the overriddenParams map
+        Set<String> combinedNames = new HashSet<>(defaultParams.keySet());
+
+        // Add all parameter names from the delegate context
+        Enumeration<String> delegateNames = delegate.getInitParameterNames();
+        while (delegateNames.hasMoreElements()) {
+            combinedNames.add(delegateNames.nextElement());

Review Comment:
   HashSet eliminates the possibility of duplicate entries, right?



##########
gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/ServletContextWrapper.java:
##########
@@ -0,0 +1,324 @@
+/*
+ * 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.service.knoxtoken;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterRegistration;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRegistration;
+import javax.servlet.SessionCookieConfig;
+import javax.servlet.SessionTrackingMode;
+import javax.servlet.descriptor.JspConfigDescriptor;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.EventListener;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+class ServletContextWrapper implements ServletContext {
+    private ServletContext delegate;
+    private Map<String, String> defaultParams;
+
+    ServletContextWrapper(ServletContext delegate) {
+        this.delegate = delegate;
+        defaultParams = new HashMap<>();
+    }
+
+    @Override
+    public String getContextPath() {
+        return delegate.getContextPath();
+    }
+
+    @Override
+    public ServletContext getContext(String uripath) {
+        return delegate.getContext(uripath);
+    }
+
+    @Override
+    public int getMajorVersion() {
+        return delegate.getMajorVersion();
+    }
+
+    @Override
+    public int getMinorVersion() {
+        return delegate.getMinorVersion();
+    }
+
+    @Override
+    public int getEffectiveMajorVersion() {
+        return delegate.getEffectiveMajorVersion();
+    }
+
+    @Override
+    public int getEffectiveMinorVersion() {
+        return delegate.getEffectiveMinorVersion();
+    }
+
+    @Override
+    public String getMimeType(String file) {
+        return delegate.getMimeType(file);
+    }
+
+    @Override
+    public Set<String> getResourcePaths(String path) {
+        return delegate.getResourcePaths(path);
+    }
+
+    @Override
+    public URL getResource(String path) throws MalformedURLException {
+        return delegate.getResource(path);
+    }
+
+    @Override
+    public InputStream getResourceAsStream(String path) {
+        return delegate.getResourceAsStream(path);
+    }
+
+    @Override
+    public RequestDispatcher getRequestDispatcher(String path) {
+        return delegate.getRequestDispatcher(path);
+    }
+
+    @Override
+    public RequestDispatcher getNamedDispatcher(String name) {
+        return delegate.getNamedDispatcher(name);
+    }
+
+    @Override
+    public Servlet getServlet(String name) throws ServletException {
+        return delegate.getServlet(name);
+    }
+
+    @Override
+    public Enumeration<Servlet> getServlets() {
+        return delegate.getServlets();
+    }
+
+    @Override
+    public Enumeration<String> getServletNames() {
+        return delegate.getServletNames();
+    }
+
+    @Override
+    public void log(String msg) {
+        delegate.log(msg);
+    }
+
+    @Override
+    public void log(Exception exception, String msg) {
+        delegate.log(exception, msg);
+    }
+
+    @Override
+    public void log(String message, Throwable throwable) {
+        delegate.log(message, throwable);
+    }
+
+    @Override
+    public String getRealPath(String path) {
+        return delegate.getRealPath(path);
+    }
+
+    @Override
+    public String getServerInfo() {
+        return delegate.getServerInfo();
+    }
+
+    @Override
+    public String getInitParameter(String name) {
+        String value = delegate.getInitParameter(name);

Review Comment:
   So, anything configured in the topology should override the defaults 
explicitly set in the wrapContextForDefaultParams method?



-- 
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: dev-unsubscr...@knox.apache.org

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

Reply via email to