You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bu...@apache.org on 2019/12/25 16:11:03 UTC

[cxf-fediz] branch master updated (1e79f2d -> a8b3f88)

This is an automated email from the ASF dual-hosted git repository.

buhhunyx pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/cxf-fediz.git.


    from 1e79f2d  Remove commons-lang3
     new 4249bd1  systests: close stream
     new accd5a5  fediz-spring: fix possible NPE
     new a8b3f88  fediz-core: cleanup ClassLoaderUtils

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../cxf/fediz/example/FederationServlet.java       |   2 +-
 .../cxf/fediz/core/util/ClassLoaderUtils.java      | 204 ---------------------
 ...FederationPreAuthenticatedProcessingFilter.java |   2 +-
 .../protocols/TrustedIdpOIDCProtocolHandler.java   |  20 +-
 .../apache/cxf/fediz/samlsso/example/SamlSso.java  |  19 +-
 5 files changed, 22 insertions(+), 225 deletions(-)


[cxf-fediz] 02/03: fediz-spring: fix possible NPE

Posted by bu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf-fediz.git

commit accd5a5f60833aa75687b6f1865917d794c0d535
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Wed Dec 25 16:49:10 2019 +0300

    fediz-spring: fix possible NPE
---
 .../spring/preauth/FederationPreAuthenticatedProcessingFilter.java      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/plugins/spring/src/main/java/org/apache/cxf/fediz/spring/preauth/FederationPreAuthenticatedProcessingFilter.java b/plugins/spring/src/main/java/org/apache/cxf/fediz/spring/preauth/FederationPreAuthenticatedProcessingFilter.java
index 7322a62..7c6ac44 100644
--- a/plugins/spring/src/main/java/org/apache/cxf/fediz/spring/preauth/FederationPreAuthenticatedProcessingFilter.java
+++ b/plugins/spring/src/main/java/org/apache/cxf/fediz/spring/preauth/FederationPreAuthenticatedProcessingFilter.java
@@ -43,7 +43,7 @@ public class FederationPreAuthenticatedProcessingFilter extends AbstractPreAuthe
         Principal principal = httpRequest.getUserPrincipal();
         if (logger.isDebugEnabled()) {
             logger.debug("PreAuthenticated J2EE principal: "
-                         + principal == null ? null : principal.getName());
+                         + (principal == null ? null : principal.getName()));
         }
         return principal;
     }


[cxf-fediz] 01/03: systests: close stream

Posted by bu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf-fediz.git

commit 4249bd187c034060e9a0eebc481743891d24e652
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Wed Dec 25 16:42:45 2019 +0300

    systests: close stream
---
 .../org/apache/cxf/fediz/samlsso/example/SamlSso.java | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/systests/federation/samlIdpWebapp/src/main/java/org/apache/cxf/fediz/samlsso/example/SamlSso.java b/systests/federation/samlIdpWebapp/src/main/java/org/apache/cxf/fediz/samlsso/example/SamlSso.java
index ff7f4d5..ba85f40 100644
--- a/systests/federation/samlIdpWebapp/src/main/java/org/apache/cxf/fediz/samlsso/example/SamlSso.java
+++ b/systests/federation/samlIdpWebapp/src/main/java/org/apache/cxf/fediz/samlsso/example/SamlSso.java
@@ -23,7 +23,6 @@ package org.apache.cxf.fediz.samlsso.example;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
 import java.nio.charset.StandardCharsets;
 import java.util.Collections;
 import java.util.zip.DataFormatException;
@@ -182,12 +181,13 @@ public class SamlSso {
     }
 
     protected AuthnRequest extractRequest(String samlRequest) throws Base64Exception,
-        DataFormatException, XMLStreamException, UnsupportedEncodingException, WSSecurityException {
+        DataFormatException, XMLStreamException, IOException, WSSecurityException {
         byte[] deflatedToken = Base64Utility.decode(samlRequest);
 
-        InputStream tokenStream = new DeflateEncoderDecoder().inflateToken(deflatedToken);
-
-        Document responseDoc = StaxUtils.read(new InputStreamReader(tokenStream, StandardCharsets.UTF_8));
+        final Document responseDoc;
+        try (InputStream tokenStream = new DeflateEncoderDecoder().inflateToken(deflatedToken)) {
+            responseDoc = StaxUtils.read(new InputStreamReader(tokenStream, StandardCharsets.UTF_8));
+        }
         AuthnRequest request =
             (AuthnRequest)OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
         System.out.println(DOM2Writer.nodeToString(responseDoc));
@@ -196,9 +196,10 @@ public class SamlSso {
 
     protected javax.ws.rs.core.Response postBindingResponse(String relayState, String racs, String responseStr)
         throws IOException {
-        InputStream inputStream = this.getClass().getResourceAsStream("/TemplateSAMLResponse.xml");
-        String responseTemplate = IOUtils.toString(inputStream, StandardCharsets.UTF_8.name());
-        inputStream.close();
+        String responseTemplate;
+        try (InputStream inputStream = this.getClass().getResourceAsStream("/TemplateSAMLResponse.xml")) {
+            responseTemplate = IOUtils.toString(inputStream, StandardCharsets.UTF_8.name());
+        }
 
         // Perform Redirect to RACS
         responseTemplate = responseTemplate.replace("%RESPONSE_URL%", racs);
@@ -218,5 +219,3 @@ public class SamlSso {
     }
 
 }
-
-


[cxf-fediz] 03/03: fediz-core: cleanup ClassLoaderUtils

Posted by bu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf-fediz.git

commit a8b3f88a370b2fc3880abb02ea2c5daf3e707993
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Wed Dec 25 19:10:18 2019 +0300

    fediz-core: cleanup ClassLoaderUtils
---
 .../cxf/fediz/example/FederationServlet.java       |   2 +-
 .../cxf/fediz/core/util/ClassLoaderUtils.java      | 204 ---------------------
 .../protocols/TrustedIdpOIDCProtocolHandler.java   |  20 +-
 3 files changed, 12 insertions(+), 214 deletions(-)

diff --git a/examples/simpleWebapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java b/examples/simpleWebapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java
index 16cc7ca..f181b00 100644
--- a/examples/simpleWebapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java
+++ b/examples/simpleWebapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java
@@ -63,7 +63,7 @@ public class FederationServlet extends HttpServlet {
         out.println("<body>");
         out.println("<h1>Hello World</h1>");
         out.println("Hello world<br>");
-        out.println("Request url: "); out.println(request.getRequestURL().toString()); out.println("<p>");
+        out.println("Request url: "); out.println(request.getRequestURL()); out.println("<p>");
 
 
         out.println("<br><b>User</b><p>");
diff --git a/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/ClassLoaderUtils.java b/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/ClassLoaderUtils.java
index 9a42faa..572da12 100644
--- a/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/ClassLoaderUtils.java
+++ b/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/ClassLoaderUtils.java
@@ -19,16 +19,6 @@
 
 package org.apache.cxf.fediz.core.util;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-
 /**
  * This class is extremely useful for loading resources and classes in a fault
  * tolerant manner that works across different applications servers. Do not
@@ -42,200 +32,6 @@ public final class ClassLoaderUtils {
     private ClassLoaderUtils() {
     }
 
-    public static class ClassLoaderHolder {
-        ClassLoader loader;
-        ClassLoaderHolder(ClassLoader c) {
-            loader = c;
-        }
-
-        public void reset() {
-            ClassLoaderUtils.setThreadContextClassloader(loader);
-        }
-    }
-    public static ClassLoaderHolder setThreadContextClassloader(final ClassLoader newLoader) {
-        return AccessController.doPrivileged(new PrivilegedAction<ClassLoaderHolder>() {
-            public ClassLoaderHolder run() {
-                ClassLoader l = Thread.currentThread().getContextClassLoader();
-                Thread.currentThread().setContextClassLoader(newLoader);
-                return new ClassLoaderHolder(l);
-            }
-        });
-    }
-
-    public static ClassLoader getURLClassLoader(
-        final URL[] urls, final ClassLoader parent
-    ) {
-        return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
-            public ClassLoader run() {
-                return new URLClassLoader(urls, parent);
-            }
-        });
-    }
-
-    public static ClassLoader getURLClassLoader(
-        final List<URL> urlList, final ClassLoader parent
-    ) {
-        return getURLClassLoader(urlList.toArray(new URL[0]), parent);
-    }
-
-    /**
-     * Load a given resource. This method will try to load the resource
-     * using the following methods (in order):
-     * <ul>
-     * <li>From Thread.currentThread().getContextClassLoader()
-     * <li>From ClassLoaderUtil.class.getClassLoader()
-     * <li>callingClass.getClassLoader()
-     * </ul>
-     *
-     * @param resourceName The name of the resource to load
-     * @param callingClass The Class object of the calling object
-     */
-    public static URL getResource(String resourceName, Class<?> callingClass) {
-        URL url = Thread.currentThread().getContextClassLoader().getResource(resourceName);
-        if (url == null && resourceName.startsWith("/")) {
-            //certain classloaders need it without the leading /
-            url = Thread.currentThread().getContextClassLoader()
-                .getResource(resourceName.substring(1));
-        }
-
-        ClassLoader cluClassloader = ClassLoaderUtils.class.getClassLoader();
-        if (cluClassloader == null) {
-            cluClassloader = ClassLoader.getSystemClassLoader();
-        }
-        if (url == null) {
-            url = cluClassloader.getResource(resourceName);
-        }
-        if (url == null && resourceName.startsWith("/")) {
-            //certain classloaders need it without the leading /
-            url = cluClassloader.getResource(resourceName.substring(1));
-        }
-
-        if (url == null) {
-            ClassLoader cl = callingClass.getClassLoader();
-
-            if (cl != null) {
-                url = cl.getResource(resourceName);
-            }
-        }
-
-        if (url == null) {
-            url = callingClass.getResource(resourceName);
-        }
-
-        if ((url == null) && (resourceName != null) && (resourceName.charAt(0) != '/')) {
-            return getResource('/' + resourceName, callingClass);
-        }
-
-        return url;
-    }
-
-    /**
-     * Load a given resources. <p> This method will try to load the resources
-     * using the following methods (in order):
-     * </p>
-     * <ul>
-     * <li>From Thread.currentThread().getContextClassLoader()
-     * <li>From ClassLoaderUtil.class.getClassLoader()
-     * <li>callingClass.getClassLoader()
-     * </ul>
-     *
-     * @param resourceName The name of the resource to load
-     * @param callingClass The Class object of the calling object
-     */
-    public static List<URL> getResources(String resourceName, Class<?> callingClass) {
-        List<URL> ret = new ArrayList<>();
-        Enumeration<URL> urls = new Enumeration<URL>() {
-            public boolean hasMoreElements() {
-                return false;
-            }
-            public URL nextElement() {
-                return null;
-            }
-
-        };
-        try {
-            urls = Thread.currentThread().getContextClassLoader()
-                .getResources(resourceName);
-        } catch (IOException e) {
-            //ignore
-        }
-        if (!urls.hasMoreElements() && resourceName.startsWith("/")) {
-            //certain classloaders need it without the leading /
-            try {
-                urls = Thread.currentThread().getContextClassLoader()
-                    .getResources(resourceName.substring(1));
-            } catch (IOException e) {
-                // ignore
-            }
-        }
-
-        ClassLoader cluClassloader = ClassLoaderUtils.class.getClassLoader();
-        if (cluClassloader == null) {
-            cluClassloader = ClassLoader.getSystemClassLoader();
-        }
-        if (!urls.hasMoreElements()) {
-            try {
-                urls = cluClassloader.getResources(resourceName);
-            } catch (IOException e) {
-                // ignore
-            }
-        }
-        if (!urls.hasMoreElements() && resourceName.startsWith("/")) {
-            //certain classloaders need it without the leading /
-            try {
-                urls = cluClassloader.getResources(resourceName.substring(1));
-            } catch (IOException e) {
-                // ignore
-            }
-        }
-
-        if (!urls.hasMoreElements()) {
-            ClassLoader cl = callingClass.getClassLoader();
-
-            if (cl != null) {
-                try {
-                    urls = cl.getResources(resourceName);
-                } catch (IOException e) {
-                    // ignore
-                }
-            }
-        }
-
-        if (!urls.hasMoreElements()) {
-            URL url = callingClass.getResource(resourceName);
-            if (url != null) {
-                ret.add(url);
-            }
-        }
-        while (urls.hasMoreElements()) {
-            ret.add(urls.nextElement());
-        }
-
-
-        if (ret.isEmpty() && (resourceName != null) && (resourceName.charAt(0) != '/')) {
-            return getResources('/' + resourceName, callingClass);
-        }
-        return ret;
-    }
-
-
-    /**
-     * This is a convenience method to load a resource as a stream. <p> The
-     * algorithm used to find the resource is given in getResource()
-     * </p>
-     * @param resourceName The name of the resource to load
-     * @param callingClass The Class object of the calling object
-     */
-    public static InputStream getResourceAsStream(String resourceName, Class<?> callingClass) {
-        URL url = getResource(resourceName, callingClass);
-
-        try {
-            return (url != null) ? url.openStream() : null;
-        } catch (IOException e) {
-            return null;
-        }
-    }
-
     /**
      * Load a class with a given name. <p> It will try to load the class in the
      * following order:
diff --git a/services/idp-core/src/main/java/org/apache/cxf/fediz/service/idp/protocols/TrustedIdpOIDCProtocolHandler.java b/services/idp-core/src/main/java/org/apache/cxf/fediz/service/idp/protocols/TrustedIdpOIDCProtocolHandler.java
index badc9da..e991094 100644
--- a/services/idp-core/src/main/java/org/apache/cxf/fediz/service/idp/protocols/TrustedIdpOIDCProtocolHandler.java
+++ b/services/idp-core/src/main/java/org/apache/cxf/fediz/service/idp/protocols/TrustedIdpOIDCProtocolHandler.java
@@ -165,17 +165,19 @@ public class TrustedIdpOIDCProtocolHandler extends AbstractTrustedIdpOAuth2Proto
                 JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(idToken);
                 JwtToken jwt = jwtConsumer.getJwtToken();
 
-                if (jwt != null && jwt.getClaims() != null && LOG.isDebugEnabled()) {
-                    LOG.debug("Received Claims:");
-                    for (Map.Entry<String, Object> claim : jwt.getClaims().asMap().entrySet()) {
-                        LOG.debug(claim.getKey() + ": " + claim.getValue());
+                if (LOG.isDebugEnabled()) {
+                    if (jwt.getClaims() != null) {
+                        LOG.debug("Received Claims:");
+                        for (Map.Entry<String, Object> claim : jwt.getClaims().asMap().entrySet()) {
+                            LOG.debug(claim.getKey() + ": " + claim.getValue());
+                        }
                     }
-                }
 
-                if (jwt != null && jwt.getJwsHeaders() != null && LOG.isDebugEnabled()) {
-                    LOG.debug("Received JWS Headers:");
-                    for (Map.Entry<String, Object> header : jwt.getJwsHeaders().asMap().entrySet()) {
-                        LOG.debug(header.getKey() + ": " + header.getValue());
+                    if (jwt.getJwsHeaders() != null) {
+                        LOG.debug("Received JWS Headers:");
+                        for (Map.Entry<String, Object> header : jwt.getJwsHeaders().asMap().entrySet()) {
+                            LOG.debug(header.getKey() + ": " + header.getValue());
+                        }
                     }
                 }