From fe1efd8503f14a26306d9e5d1187a355129bf920 Mon Sep 17 00:00:00 2001 From: Jim Ma Date: Wed, 14 Aug 2024 20:44:19 +0800 Subject: [PATCH] [JBWS-4424]:Add AccessController.doPrivileged to ServiceImpl.class.getClassLoader() to fix the security permission check failed issue --- .../wsf/stack/cxf/client/ProviderImpl.java | 2 +- .../wsf/stack/cxf/client/SecurityActions.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java b/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java index f5adb241c..3ba005c09 100644 --- a/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java +++ b/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java @@ -577,7 +577,7 @@ protected T createPort(QName portName, EndpointReferenceType epr, Class s ClassLoader origClassLoader = getContextClassLoader(); T port = null; try { - setContextClassLoader(createDelegateClassLoader(origClassLoader, ServiceImpl.class.getClassLoader())); + setContextClassLoader(createDelegateClassLoader(origClassLoader, SecurityActions.getClassLoader(ServiceImpl.class)); port = super.createPort(portName, epr, serviceEndpointInterface, features); } finally { setContextClassLoader(origClassLoader); diff --git a/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/SecurityActions.java b/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/SecurityActions.java index cae156178..7b6925035 100644 --- a/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/SecurityActions.java +++ b/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/SecurityActions.java @@ -76,6 +76,26 @@ public Object run() }); } } + + static ClassLoader getClassLoader(Class clazz) + { + SecurityManager sm = System.getSecurityManager(); + if (sm == null) + { + return clazz.getClassLoader(); + } + else + { + return AccessController.doPrivileged(new PrivilegedAction() + { + public ClassLoader run() + { + return clazz.getClassLoader(); + } + }); + } + } + /** * Return the current value of the specified system property