【问题标题】:OpenSAML3 resource not found 'default-config.xml' in OSGi container在 OSGi 容器中找不到 OpenSAML3 资源“default-config.xml”
【发布时间】:2016-10-23 05:32:33
【问题描述】:

我正在尝试使用 opensaml servicemix 包 (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 时收到 "resource not found" 错误。

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正在加载资源如下(resourcedefault-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 包应该可以正常工作......

【问题讨论】:

    标签: java osgi osgi-bundle opensaml maven-bundle-plugin


    【解决方案1】:

    我也有同样的问题,但使用的是 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 开发人员,向他们说明这个问题,但没有成功。

    【讨论】:

      【解决方案2】:

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

      在偶然发现 SO 帖子 Better handling of Thread Context ClassLoader in 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);
          }
      

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

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

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

      • org.opensaml.core.xml.config.XMLObjectProviderInitializer
      • org.opensaml.core.xml.config.GlobalParserPoolInitializer

      【讨论】:

        猜你喜欢
        • 2018-08-12
        • 2014-02-15
        • 2020-12-12
        • 1970-01-01
        • 2015-07-02
        • 2012-05-16
        • 2017-05-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多