View Javadoc

1   package com.atlassian.plugins.rest.common.security.jersey;
2   
3   import com.atlassian.plugins.rest.common.security.RequiresXsrfCheck;
4   import com.sun.jersey.api.model.AbstractMethod;
5   import com.sun.jersey.spi.container.ResourceFilter;
6   import com.sun.jersey.spi.container.ResourceFilterFactory;
7   
8   import java.util.Collections;
9   import java.util.List;
10  import javax.ws.rs.ext.Provider;
11  
12  /**
13   * Factory for the XSRF resource filter
14   *
15   * @since 2.4
16   */
17  @Provider
18  public class XsrfResourceFilterFactory implements ResourceFilterFactory
19  {
20      public List<ResourceFilter> create(final AbstractMethod method)
21      {
22          if (method.isAnnotationPresent(RequiresXsrfCheck.class)
23                  || method.getResource().isAnnotationPresent(RequiresXsrfCheck.class))
24          {
25              return Collections.<ResourceFilter>singletonList(new XsrfResourceFilter());
26          }
27          return Collections.emptyList();
28      }
29  }