1

我正在尝试使用 opensaml servicemix bundle ( org.apache.servicemix.bundles:org.apache.servicemix.bundles.opensaml:jar:3.2.0_1) 在 Apache Karaf (4.0.5) 上运行的 OSGi 包中升级到 OpenSAML 3。

解析 SAML 的测试正在运行,所以我认为我在正确的轨道上。但是,如果我在 Karaf 上安装捆绑包,我会在尝试加载时收到“找不到资源”default-config.xml错误。

2016-06-21 16:29:10,477 | INFO  | ool-120-thread-1 | InitializationService            | 388 - org.apache.servicemix.bundles.opensaml - 3.2.0.1 | Initializing OpenSAML using the Java Services API
2016-06-21 16:29:10,478 | DEBUG | ool-120-thread-1 | InitializationService            | 388 - org.apache.servicemix.bundles.opensaml - 3.2.0.1 | Initializing module initializer implementation: org.opensaml.core.xml.config.XMLObjectProviderInitializer
2016-06-21 16:29:10,487 | DEBUG | ool-120-thread-1 | XMLConfigurator                  | 388 - org.apache.servicemix.bundles.opensaml - 3.2.0.1 | XMLObjectProviderRegistry did not exist in ConfigurationService, will be created
2016-06-21 16:29:10,488 | DEBUG | ool-120-thread-1 | ractXMLObjectProviderInitializer | 388 - org.apache.servicemix.bundles.opensaml - 3.2.0.1 | Loading XMLObject provider configuration from resource 'default-config.xml'
2016-06-21 16:29:10,489 | ERROR | ool-120-thread-1 | ractXMLObjectProviderInitializer | 388 - org.apache.servicemix.bundles.opensaml - 3.2.0.1 | Problem loading configuration resource
org.opensaml.core.xml.config.XMLConfigurationException: Resource not found
    at org.opensaml.core.xml.config.AbstractXMLObjectProviderInitializer.init(AbstractXMLObjectProviderInitializer.java:54)[388:org.apache.servicemix.bundles.opensaml:3.2.0.1]
    at org.opensaml.core.xml.config.XMLObjectProviderInitializer.init(XMLObjectProviderInitializer.java:45)[388:org.apache.servicemix.bundles.opensaml:3.2.0.1]
    at org.opensaml.core.config.InitializationService.initialize(InitializationService.java:56)[388:org.apache.servicemix.bundles.opensaml:3.2.0.1]

AbstractXMLObjectProviderInitializer正在按如下方式加载资源(resourceis default-config.xml):

Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)

default-config.xml位于 (opensaml) jar 的根目录中,这让我想知道这是否是找不到它的原因。

maven-bundle-plugin在我的项目中使用了,除了依赖项和 opensaml 类的各种用途之外,我还Import-Package为以下包提供了显式导入():

org.opensaml.core.xml.config,
org.opensaml.saml.config,
org.opensaml.xmlsec.config,

我的捆绑清单或其他地方是否缺少任何东西来完成这项工作?我认为 servicemix 本身发布的 opensaml 包应该可以正常工作......

4

2 回答 2

5

我找到了“找不到资源”问题的解决方案,但它比什么都重要......

在偶然发现SO帖子更好地处理OSGi中的线程上下文类加载器后,我调整了我的代码以InitializationService在调用它之前设置类加载器,现在在初始化期间找到了有问题的XML。

    // adapt TCCL
    Thread thread = Thread.currentThread();
    ClassLoader loader = thread.getContextClassLoader();
    thread.setContextClassLoader(InitializationService.class.getClassLoader());
    try {
        InitializationService.initialize();
    } finally {
        // reset TCCL
        thread.setContextClassLoader(loader);
    }

但是,我注意到org.opensaml.core.config.Initializer我的包中的 SPI 配置没有被加载,我还没有找到合适的解决方法。我当前的解决方法是显式调用我需要的初始化程序的 init 方法:

  • org.opensaml.saml.config.XMLObjectProviderInitializer
  • org.opensaml.saml.config.SAMLConfigurationInitializer
  • org.opensaml.xmlsec.config.XMLObjectProviderInitializer

请注意,以下内容也是必需的,但默认情况下会被初始化(因为org.opensaml.core.config.Initializeropensaml 包中的 SPI 配置 - 它确实被加载):

  • org.opensaml.core.xml.config.XMLObjectProviderInitializer
  • org.opensaml.core.xml.config.GlobalParserPoolInitializer
于 2016-08-17T18:57:07.403 回答
3

我有同样的问题,但使用 Apache Felix OSGI。使用“找不到资源”你是对的,因为我在 OSGI 环境中发现使用许多 ClassLoader 进行捆绑,但 SAML v3 框架会像这样加载资源:

ClassLoader classLoader =Thread.currentThread().getContextClassLoader();
Class<?> clazz = classLoader.loadClass(className);
//And same in InitializationService
ServiceLoader<Initializer> serviceLoader = getServiceLoader();
Iterator iter = serviceLoader.iterator();

您的解决方案适用于初始化,但对我来说,当我尝试签署消息或验证时,仍然存在此问题,因此我将资源加载替换为 bundle ClassLoader 无处不在:

BundleWiring bundleWiring = bundleContext.getBundle().adapt(BundleWiring.class);
ClassLoader loader = bundleWiring.getClassLoader();

第二个问题是 opensaml servicemix bundle 的问题,它包含仅针对 CORE 模块的服务初始化程序引用,您可以在 META-INF/services 中找到它,我通过在我的自定义初始化程序中初始化此服务来解决这个问题。

我试图与 servicemix 开发人员联系,向他们说明这个问题,但没有成功。

于 2017-05-29T11:58:31.963 回答