test_class.declarator: context = new SlingContext()
test_class.modifier: @Rule
      public
test_class.original_string: @Rule
      public SlingContext context = new SlingContext();
test_class.type: SlingContext
test_class.var_name: context
test_class.declarator: securityFilter
test_class.modifier: private
test_class.original_string: private CMSSecurityFilter securityFilter;
test_class.type: CMSSecurityFilter
test_class.var_name: securityFilter
test_class.file: core/src/test/java/org/apache/sling/cms/core/internal/filters/CMSSecurityFilterTest.java
test_class.identifier: CMSSecurityFilterTest
test_case.body: @Test
      public void testPublished() throws IOException, ServletException {
  
          PublicationManagerFactory factory = Mockito.mock(PublicationManagerFactory.class);
          Mockito.when(factory.getPublicationMode()).thenReturn(PUBLICATION_MODE.STANDALONE);
          context.registerService(PublicationManagerFactory.class, factory);
  
          CMSSecurityConfigInstance config = new CMSSecurityConfigInstance();
          config.activate(new CMSSecurityFilterConfig() {
  
              @Override
              public Class<? extends Annotation> annotationType() {
                  return null;
              }
  
              @Override
              public String[] hostDomains() {
                  return new String[] { "cms.apache.org" };
              }
  
              @Override
              public String[] allowedPatterns() {
                  return new String[] { "\\/static\\/.*" };
              }
  
              @Override
              public String group() {
                  return null;
              }
  
          });
          context.registerService(CMSSecurityConfigInstance.class, config);
  
          securityFilter = context.registerInjectActivateService(new CMSSecurityFilter());
  
          context.request().setServerName("cms.apache.org");
          context.request().setServletPath("/content/test1.txt");
  
          PublishableResource published = Mockito.mock(PublishableResource.class);
          Mockito.when(published.isPublished()).thenReturn(true);
          context.registerAdapter(Resource.class, PublishableResource.class, published);
  
          securityFilter.doFilter(context.request(), context.response(), Mockito.mock(FilterChain.class));
          assertEquals(200, context.response().getStatus());
      }
test_case.class_method_signature: CMSSecurityFilterTest.testPublished()
test_case.full_signature: @Test public void testPublished()
test_case.identifier: testPublished
test_case.invocations: mock thenReturn when getPublicationMode registerService activate registerService registerInjectActivateService setServerName request setServletPath request mock thenReturn when isPublished registerAdapter doFilter request response mock assertEquals getStatus response
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testPublished()
focal_class.declarator: log = LoggerFactory.getLogger(CMSSecurityFilter.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = LoggerFactory.getLogger(CMSSecurityFilter.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: securityConfigInstances
focal_class.modifier: @Reference(cardinality = ReferenceCardinality.MULTIPLE, policyOption = ReferencePolicyOption.GREEDY)
      private
focal_class.original_string: @Reference(cardinality = ReferenceCardinality.MULTIPLE, policyOption = ReferencePolicyOption.GREEDY)
      private List<CMSSecurityConfigInstance> securityConfigInstances;
focal_class.type: List<CMSSecurityConfigInstance>
focal_class.var_name: securityConfigInstances
focal_class.declarator: pubMgrFactory
focal_class.modifier: @Reference
      private
focal_class.original_string: @Reference
      private PublicationManagerFactory pubMgrFactory;
focal_class.type: PublicationManagerFactory
focal_class.var_name: pubMgrFactory
focal_class.file: core/src/main/java/org/apache/sling/cms/core/internal/filters/CMSSecurityFilter.java
focal_class.identifier: CMSSecurityFilter
focal_class.interfaces: implements Filter
focal_class.class_method_signature: CMSSecurityFilter.init(FilterConfig filterConfig)
focal_class.full_signature: @Override public void init(FilterConfig filterConfig)
focal_class.identifier: init
focal_class.modifiers: @Override public
focal_class.parameters: (FilterConfig filterConfig)
focal_class.return: void
focal_class.signature: void init(FilterConfig filterConfig)
focal_class.class_method_signature: CMSSecurityFilter.doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
focal_class.full_signature: @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
focal_class.identifier: doFilter
focal_class.modifiers: @Override public
focal_class.parameters: (ServletRequest request, ServletResponse response, FilterChain chain)
focal_class.return: void
focal_class.signature: void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
focal_class.class_method_signature: CMSSecurityFilter.checkAllowed(CMSSecurityConfigInstance securityConfig, SlingHttpServletRequest slingRequest)
focal_class.full_signature: private boolean checkAllowed(CMSSecurityConfigInstance securityConfig, SlingHttpServletRequest slingRequest)
focal_class.identifier: checkAllowed
focal_class.modifiers: private
focal_class.parameters: (CMSSecurityConfigInstance securityConfig, SlingHttpServletRequest slingRequest)
focal_class.return: boolean
focal_class.signature: boolean checkAllowed(CMSSecurityConfigInstance securityConfig, SlingHttpServletRequest slingRequest)
focal_class.class_method_signature: CMSSecurityFilter.checkGroupMembership(CMSSecurityConfigInstance securityConfig,
              SlingHttpServletRequest slingRequest)
focal_class.full_signature: private boolean checkGroupMembership(CMSSecurityConfigInstance securityConfig,
              SlingHttpServletRequest slingRequest)
focal_class.identifier: checkGroupMembership
focal_class.modifiers: private
focal_class.parameters: (CMSSecurityConfigInstance securityConfig,
              SlingHttpServletRequest slingRequest)
focal_class.return: boolean
focal_class.signature: boolean checkGroupMembership(CMSSecurityConfigInstance securityConfig,
              SlingHttpServletRequest slingRequest)
focal_class.class_method_signature: CMSSecurityFilter.destroy()
focal_class.full_signature: @Override public void destroy()
focal_class.identifier: destroy
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void destroy()
focal_method.body: @Override
      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
              throws IOException, ServletException {
  
          if (pubMgrFactory.getPublicationMode() == PUBLICATION_MODE.STANDALONE) {
              SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
              for (CMSSecurityConfigInstance securityConfig : securityConfigInstances) {
                  log.trace("Checking to see if security config {} applies to request", securityConfig);
                  if (securityConfig.applies(slingRequest)) {
                      boolean allowed = checkAllowed(securityConfig, slingRequest);
                      // permission checked failed, so return an unauthorized error
                      if (!allowed) {
                          log.trace("Request to {} not allowed for user {}", slingRequest.getRequestURI(),
                                  slingRequest.getResourceResolver().getUserID());
                          ((HttpServletResponse) response).sendError(401);
                          return;
                      }
                  }
              }
          } else {
              log.trace("Publication mode {} is not standalone", pubMgrFactory.getPublicationMode());
          }
  
          chain.doFilter(request, response);
      }
focal_method.class_method_signature: CMSSecurityFilter.doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
focal_method.full_signature: @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
focal_method.identifier: doFilter
focal_method.invocations: getPublicationMode trace applies checkAllowed trace getRequestURI getUserID getResourceResolver sendError trace getPublicationMode doFilter
focal_method.modifiers: @Override public
focal_method.parameters: (ServletRequest request, ServletResponse response, FilterChain chain)
focal_method.return: void
focal_method.signature: void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)