knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmc...@apache.org
Subject knox git commit: KNOX-1120 - Pac4J Stop Using ConfigSingleton
Date Fri, 01 Dec 2017 13:13:28 GMT
Repository: knox
Updated Branches:
  refs/heads/master 27217ead9 -> 55be15928


KNOX-1120 - Pac4J Stop Using ConfigSingleton

Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/55be1592
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/55be1592
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/55be1592

Branch: refs/heads/master
Commit: 55be159283d77b382fa3325df5987410548640c9
Parents: 27217ea
Author: Larry McCay <lmccay@hortonworks.com>
Authored: Fri Dec 1 08:12:45 2017 -0500
Committer: Larry McCay <lmccay@hortonworks.com>
Committed: Fri Dec 1 08:13:12 2017 -0500

----------------------------------------------------------------------
 .../gateway/pac4j/filter/Pac4jDispatcherFilter.java      | 11 ++++++-----
 .../gateway/pac4j/filter/Pac4jIdentityAdapter.java       |  6 ++++--
 .../hadoop/gateway/pac4j/MockHttpServletRequest.java     |  8 +++++++-
 3 files changed, 17 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/55be1592/gateway-provider-security-pac4j/src/main/java/org/apache/hadoop/gateway/pac4j/filter/Pac4jDispatcherFilter.java
----------------------------------------------------------------------
diff --git a/gateway-provider-security-pac4j/src/main/java/org/apache/hadoop/gateway/pac4j/filter/Pac4jDispatcherFilter.java
b/gateway-provider-security-pac4j/src/main/java/org/apache/hadoop/gateway/pac4j/filter/Pac4jDispatcherFilter.java
index fb5fa4a..ca3b26d 100644
--- a/gateway-provider-security-pac4j/src/main/java/org/apache/hadoop/gateway/pac4j/filter/Pac4jDispatcherFilter.java
+++ b/gateway-provider-security-pac4j/src/main/java/org/apache/hadoop/gateway/pac4j/filter/Pac4jDispatcherFilter.java
@@ -29,8 +29,6 @@ import org.apache.hadoop.gateway.services.security.CryptoService;
 import org.pac4j.config.client.PropertiesConfigFactory;
 import org.pac4j.core.client.Client;
 import org.pac4j.core.config.Config;
-import org.pac4j.core.config.ConfigSingleton;
-import org.pac4j.core.context.J2EContext;
 import org.pac4j.core.util.CommonHelper;
 import org.pac4j.http.client.indirect.IndirectBasicAuthClient;
 import org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator;
@@ -71,6 +69,8 @@ public class Pac4jDispatcherFilter implements Filter {
 
   private static final String PAC4J_COOKIE_DOMAIN_SUFFIX_PARAM = "pac4j.cookie.domain.suffix";
 
+  private static final String PAC4J_CONFIG = "pac4j.config";
+
   private CallbackFilter callbackFilter;
 
   private SecurityFilter securityFilter;
@@ -153,13 +153,13 @@ public class Pac4jDispatcherFilter implements Filter {
     }
 
     callbackFilter = new CallbackFilter();
+    callbackFilter.setConfigOnly(config);
     securityFilter = new SecurityFilter();
     securityFilter.setClients(clientName);
-    securityFilter.setConfig(config);
+    securityFilter.setConfigOnly(config);
 
     final String domainSuffix = filterConfig.getInitParameter(PAC4J_COOKIE_DOMAIN_SUFFIX_PARAM);
     config.setSessionStore(new KnoxSessionStore(cryptoService, clusterName, domainSuffix));
-    ConfigSingleton.setConfig(config);
   }
 
   private void addDefaultConfig(String clientNameParameter, Map<String, String> properties)
{
@@ -196,7 +196,8 @@ public class Pac4jDispatcherFilter implements Filter {
 
     final HttpServletRequest request = (HttpServletRequest) servletRequest;
     final HttpServletResponse response = (HttpServletResponse) servletResponse;
-    final J2EContext context = new J2EContext(request, response, ConfigSingleton.getConfig().getSessionStore());
+    request.setAttribute(PAC4J_CONFIG, securityFilter.getConfig());
+//    final J2EContext context = new J2EContext(request, response, securityFilter.getConfig().getSessionStore());
 
     // it's a callback from an identity provider
     if (request.getParameter(PAC4J_CALLBACK_PARAMETER) != null) {

http://git-wip-us.apache.org/repos/asf/knox/blob/55be1592/gateway-provider-security-pac4j/src/main/java/org/apache/hadoop/gateway/pac4j/filter/Pac4jIdentityAdapter.java
----------------------------------------------------------------------
diff --git a/gateway-provider-security-pac4j/src/main/java/org/apache/hadoop/gateway/pac4j/filter/Pac4jIdentityAdapter.java
b/gateway-provider-security-pac4j/src/main/java/org/apache/hadoop/gateway/pac4j/filter/Pac4jIdentityAdapter.java
index 20084b1..d8b3489 100644
--- a/gateway-provider-security-pac4j/src/main/java/org/apache/hadoop/gateway/pac4j/filter/Pac4jIdentityAdapter.java
+++ b/gateway-provider-security-pac4j/src/main/java/org/apache/hadoop/gateway/pac4j/filter/Pac4jIdentityAdapter.java
@@ -21,7 +21,7 @@ import org.apache.hadoop.gateway.audit.api.*;
 import org.apache.hadoop.gateway.audit.log4j.audit.AuditConstants;
 import org.apache.hadoop.gateway.filter.AbstractGatewayFilter;
 import org.apache.hadoop.gateway.security.PrimaryPrincipal;
-import org.pac4j.core.config.ConfigSingleton;
+import org.pac4j.core.config.Config;
 import org.pac4j.core.context.J2EContext;
 import org.pac4j.core.profile.CommonProfile;
 import org.pac4j.core.profile.ProfileManager;
@@ -47,6 +47,7 @@ public class Pac4jIdentityAdapter implements Filter {
   private static final Logger logger = LoggerFactory.getLogger(Pac4jIdentityAdapter.class);
 
   public static final String PAC4J_ID_ATTRIBUTE = "pac4j.id_attribute";
+  private static final String PAC4J_CONFIG = "pac4j.config";
 
   private static AuditService auditService = AuditServiceFactory.getAuditService();
   private static Auditor auditor = auditService.getAuditor(
@@ -70,7 +71,8 @@ public class Pac4jIdentityAdapter implements Filter {
 
     final HttpServletRequest request = (HttpServletRequest) servletRequest;
     final HttpServletResponse response = (HttpServletResponse) servletResponse;
-    final J2EContext context = new J2EContext(request, response, ConfigSingleton.getConfig().getSessionStore());
+    final J2EContext context = new J2EContext(request, response,
+        ((Config)request.getAttribute(PAC4J_CONFIG)).getSessionStore());
     final ProfileManager<CommonProfile> manager = new ProfileManager<CommonProfile>(context);
     final Optional<CommonProfile> optional = manager.get(true);
     if (optional.isPresent()) {

http://git-wip-us.apache.org/repos/asf/knox/blob/55be1592/gateway-provider-security-pac4j/src/test/java/org/apache/hadoop/gateway/pac4j/MockHttpServletRequest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-security-pac4j/src/test/java/org/apache/hadoop/gateway/pac4j/MockHttpServletRequest.java
b/gateway-provider-security-pac4j/src/test/java/org/apache/hadoop/gateway/pac4j/MockHttpServletRequest.java
index b09adc9..5d2c5b6 100644
--- a/gateway-provider-security-pac4j/src/test/java/org/apache/hadoop/gateway/pac4j/MockHttpServletRequest.java
+++ b/gateway-provider-security-pac4j/src/test/java/org/apache/hadoop/gateway/pac4j/MockHttpServletRequest.java
@@ -31,6 +31,7 @@ public class MockHttpServletRequest extends HttpServletRequestWrapper {
     private String serverName;
     private Map<String, String> parameters = new HashMap<>();
     private Map<String, String> headers = new HashMap<>();
+    private Map<String, Object> attributes = new HashMap<>();
 
     public MockHttpServletRequest() {
         super(mock(HttpServletRequest.class));
@@ -82,7 +83,12 @@ public class MockHttpServletRequest extends HttpServletRequestWrapper {
     }
 
     @Override
+    public void setAttribute(String name, Object value) {
+        attributes.put(name, value);
+    }
+
+    @Override
     public Object getAttribute(String name) {
-        return null;
+        return attributes.get(name);
     }
 }


Mime
View raw message