1 Reply Latest reply on Jun 23, 2015 2:03 AM by Mirko Swillus

    How to add Filters to pluginPostFilterChain

    Mirko Swillus

      Hej,

       

      I'm trying to add a filter to pluginPostFilterChain within my custom plugin in Jive 8.0.0.0 and I'm wondering if there is a chance to declare that new filter in my plugins spring.xml. I know that there's a way to add those filters programmatically by the initialization of the plugin, but that feels not to be the right way to do so.

       

      This is how I tried that, which is more a guess by reading the code of MergableFilterChainProxy, which is the class behind pluginPostFilterChain:

       

      
       <bean id="twoFactorFilter" class="com.tsystems.jive.foo.plugins.auth.TwoFactorAuthenticationFilter"/>
        
       <bean id="twoFactorFilterChain" parent="pluginPostFilterChain">
         <constructor-arg><security:filter-chain pattern="/**" filters="twoFactorFilter"/></constructor-arg>
        </bean>
      
      

       

      Now Spring refuses to instantiate my twoFactorFilterChain with the exception below. So how do I add Filters to that chain, given that I don't want other plugins to overwrite my added filters? I searched the community multiple times but was not able to find any documentation on this topic.

       

      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'twoFactorFilterChain' defined in URL [file:/Users/mrsw/workspaces/foo-site/web/../foo-2fa-plugin/target/foo-2fa-plugin/spring.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:239)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1133)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1036)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:505)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
        at com.jivesoftware.community.lifecycle.JiveApplication.initialize(JiveApplication.java:151)
        at com.jivesoftware.community.Jive.start(Jive.java:142)
        at com.jivesoftware.community.web.JiveApplicationContextLoaderListener.contextInitialized(JiveApplicationContextLoaderListener.java:29)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:983)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1660)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
      
      

       

      Thanks in advance,

      Mirko

        • Re: How to add Filters to pluginPostFilterChain
          Mirko Swillus

          Thanks to Tom Sinicki we now got a working definition:

           

          <bean id="twoFactorFilterChain" class="com.jivesoftware.community.aaa.util.spring.MergeableFilterChainProxy" parent="pluginPostFilterChain">

                       <security:filter-chain-map path-type="ant">

                              <security:filter-chain pattern="/**" filters="twoFactorFilter"/>

                       </security:filter-chain-map>

          </bean>

           

          Cheers,

          Mirko