View Javadoc

1   package com.atlassian.plugins.rest.common.security.jersey;
2   
3   import com.google.common.base.Preconditions;
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   import com.atlassian.plugins.rest.common.security.AuthenticationContext;
8   
9   import javax.ws.rs.ext.Provider;
10  import java.util.Collections;
11  import java.util.List;
12  
13  /**
14   * <p>A {@link ResourceFilterFactory} that checks wether the client is authenticated or not.<p>
15   * @see AuthenticatedResourceFilter
16   */
17  @Provider
18  public class AuthenticatedResourceFilterFactory implements ResourceFilterFactory
19  {
20      private final AuthenticationContext authenticationContext;
21  
22      public AuthenticatedResourceFilterFactory(final AuthenticationContext authenticationContext)
23      {
24          this.authenticationContext = Preconditions.checkNotNull(authenticationContext);
25      }
26  
27      public List<ResourceFilter> create(AbstractMethod abstractMethod)
28      {
29          return Collections.<ResourceFilter>singletonList(new AuthenticatedResourceFilter(abstractMethod, authenticationContext));
30      }
31  }