You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Julien Greffe (Jira)" <ji...@apache.org> on 2021/07/21 17:16:00 UTC

[jira] [Created] (CXF-8566) cxf-ws-rt-security & ehcache

Julien Greffe created CXF-8566:
----------------------------------

             Summary: cxf-ws-rt-security & ehcache
                 Key: CXF-8566
                 URL: https://issues.apache.org/jira/browse/CXF-8566
             Project: CXF
          Issue Type: Bug
          Components: WS-* Components
    Affects Versions: 3.4.3
            Reporter: Julien Greffe


Hello,

during some tests in Karaf container, we faced this exception
{code:java}
Caused by: java.lang.IllegalArgumentException: CacheTemplate 'org.apache.cxf.ws.security.tokenstore.TokenStore' declares value type of org.apache.cxf.ws.security.tokenstore.SecurityToken. Provided: class org.apache.cxf.ws.security.tokenstore.SecurityTokenCaused by: java.lang.IllegalArgumentException: CacheTemplate 'org.apache.cxf.ws.security.tokenstore.TokenStore' declares value type of org.apache.cxf.ws.security.tokenstore.SecurityToken. Provided: class org.apache.cxf.ws.security.tokenstore.SecurityToken at org.ehcache.xml.ConfigurationParser.checkTemplateTypeConsistency(ConfigurationParser.java:279) ~[bundleFile:3.8.1 a19322e8d4b3f7157e878112c2afc0b6e3090fdd] at org.ehcache.xml.ConfigurationParser.access$000(ConfigurationParser.java:108) ~[bundleFile:3.8.1 a19322e8d4b3f7157e878112c2afc0b6e3090fdd] at org.ehcache.xml.ConfigurationParser$1.builderFor(ConfigurationParser.java:255) ~[bundleFile:3.8.1 a19322e8d4b3f7157e878112c2afc0b6e3090fdd] at org.ehcache.xml.XmlConfiguration.newCacheConfigurationBuilderFromTemplate(XmlConfiguration.java:277) ~[bundleFile:3.8.1 a19322e8d4b3f7157e878112c2afc0b6e3090fdd] at org.apache.cxf.ws.security.tokenstore.EHCacheTokenStore.<init>(EHCacheTokenStore.java:66) ~[bundleFile:3.4.3] at org.apache.cxf.ws.security.tokenstore.EHCacheTokenStoreFactory.newTokenStore(EHCacheTokenStoreFactory.java:45) ~[bundleFile:3.4.3] at org.apache.cxf.ws.security.tokenstore.TokenStoreUtils.getTokenStore(TokenStoreUtils.java:58) ~[bundleFile:3.4.3] at org.apache.cxf.ws.security.trust.DefaultSTSTokenCacher.storeToken(DefaultSTSTokenCacher.java:103) ~[bundleFile:3.4.3] at org.apache.cxf.ws.security.trust.STSTokenRetriever.getToken(STSTokenRetriever.java:117) ~[bundleFile:3.4.3] ... 18 more {code}
 

It seems it's due to different class loaders for classes {{XmlConfiguration}} and {{SecurityToken.}}

I tried to force the {{cacheClassLoaders}} from {{ehcache}} in {{EHCacheTokenStore}} (https://github.com/apache/cxf/blob/9387c3f65862bbe9356457ad4c111eda852fcc90/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java#L56-L76)
{code:java}
try {
            // Exclude the endpoint info bit added in TokenStoreUtils when getting the template name
            String template = key;
            if (template.contains("-")) {
                template = key.substring(0, key.lastIndexOf('-'));
            }

            Map<String, ClassLoader> cacheClassLoaders = new HashMap<>();
            cacheClassLoaders.put(template, SecurityToken.class.getClassLoader());
            XmlConfiguration xmlConfig = new XmlConfiguration(configFileURL, ClassLoading.getDefaultClassLoader(),
                    cacheClassLoaders);

            CacheConfigurationBuilder<String, SecurityToken> configurationBuilder =
                    xmlConfig.newCacheConfigurationBuilderFromTemplate(template,
                            String.class, SecurityToken.class);

            cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache(key, configurationBuilder).build();

            cacheManager.init();
            cache = cacheManager.getCache(key, String.class, SecurityToken.class);

        } catch (Exception e) {
            throw new TokenStoreException(e);
        }
{code}
 It seems to resolve the issue, but I'm not sure about the proper implementation, and the unit tests to set (?)

Thanks,



--
This message was sent by Atlassian Jira
(v8.3.4#803005)