4 Replies Latest reply on Jul 26, 2013 3:17 AM by Marek Posolda

    How to add filter in a portal extension

    Timothy Drisdelle Newbie

      I have successfully created a custom portal extension "my-portal-extension", and I want to add a filter that will process on <url-mapping>/*</url-mapping>

       

      The MyFilter.jar is places in my-portal-extension/WEB-INF/lib/

       

      While I can see the filter is initialized (via log messages), it doesn't get called when I visit the portal:

      http://myserver.com:8080/portal/

       

      It does get into the doFilter method if I visit:

      http://myserver.com:8080/my-portal-extension/

       

      But obviously this isn't intended. Clearly, the Tomcat context for the portal extension (which is deployed as a "separate" webapp my-portal-extension.war), uses its own context (ie. /my-portal-extension) and will not filter for a different context (ie. /portal), which is what I actually want.

       

       

      How do I add a filter to my portal extension?

        • 1. Re: How to add filter in a portal extension
          Nick Scavelli Novice

          /google "gatein filter" -> results[0] = https://community.jboss.org/thread/172870

          1 of 1 people found this helpful
          • 2. Re: How to add filter in a portal extension
            Timothy Drisdelle Newbie

            Wow - I guess my Google chops are in need of tuning (too verbose!)

             

            Thanks for the thread, I'll go check it out!

            • 3. Re: How to add filter in a portal extension
              Timothy Drisdelle Newbie

              Alright...

               

              I've followed the direction on the referenced thread and I think I've got everything working.

               

              However, I'm not able to read in my init-params from the configuration in web-inf-extension-configuration.xml

               

              These params used to be in my web.xml file, and now I've got them like this:

              <init-params>

                      <properties-param>

                        <name>authfilter.properties</name>

                        <property name="APP_ID" value="1234"/>

                        <property name="APP_ID_KEY" value="aaabbbcccddd111222333444"/>

                        <property name="APP_ADMIN_PASSWORD" value="abcde12345"/>

                      </properties-param>

               

                      <object-param>

                        <name>Auth Filter Definition</name>

                        <object type="org.exoplatform.web.filter.FilterDefinition">

                          <!-- The filter instance -->

                          <field name="filter">

                            <object type="com.mycompany.authfilter.AuthFilter"/>

                          </field>

                          <!-- The mapping to use -->

                          <!-- WARNING: the mapping is expressed with regular expressions -->

                          <field name="patterns">

                            <collection type="java.util.ArrayList" item-type="java.lang.String">

                              <value>

                                <string>/.*</string>

                              </value>

                            </collection>

                          </field>

                        </object>

                      </object-param>

                    </init-params>

               

              I'm not sure I've done this correctly, and when my filter tries filterConfig.getInitParameter("APP_ID") it throws NPE.

               

              Am I supposed to use a different <name> in the <properties-param> ?

               

               

              I just noticed that the interface org.exoplatform.web.filter.Filter does not include methods for init and destroy, which I was using to populate my FilterConfig (and contained the properties).

              • 4. Re: How to add filter in a portal extension
                Marek Posolda Apprentice

                Hi,

                 

                I think that you need to create constructor of your filter, which will just accept InitParams as the argument and read parameters here. Something like

                 

                {code}

                public MyFilter implements Filter

                {

                 

                  public MyFilter(InitParams params)

                  {

                     params.getPropertiesParam('APP_ID');

                     // Read other parameters here

                  }

                 

                  ...

                }

                {code}