test_class.file: agent/osgi/src/test/java/org/jolokia/osgi/security/ServiceAuthenticationHttpContextTest.java
test_class.identifier: ServiceAuthenticationHttpContextTest
test_case.body: @Test
      public void anyAuthenticator() throws Exception {
          Object[] testData = new Object[]{
              "service-any", new boolean[]{true, false}, true,
              "service-all", new boolean[]{true, false}, false,
              "service-any", new boolean[]{true, true}, true,
              "service-all", new boolean[]{true, true}, true,
              "service-any", new boolean[]{false, false}, false,
              "service-all", new boolean[]{false, false}, false,
              "service-any", new boolean[]{false, true}, true,
              "service-all", new boolean[]{false, true}, false,
              "service-all", new boolean[]{true, true, true, true, false, true}, false,
              "service-any", new boolean[]{false, false, false, false, false, true}, true
          };
  
          for (int i = 0; i < testData.length; i += 3) {
              BundleContext bundleContext = createBundleContext();
              ServiceReference[] serviceRefs = createServiceReferences(bundleContext, (boolean[]) testData[i + 1]);
  
              expect(bundleContext.getServiceReferences(eq(Authenticator.class.getName()), (String) isNull())).andReturn(serviceRefs);
              replay(bundleContext);
  
              ServiceAuthenticationHttpContext ctx = createContext(bundleContext, (String) testData[i]);
              HttpServletResponse resp = prepareResponse();
              assertEquals(ctx.handleSecurity(null, resp), testData[i + 2],
                           String.format("%s: %s --> %s", testData[i], printBooleanList((boolean[]) testData[i + 1]), testData[i + 2]));
          }
      }
test_case.class_method_signature: ServiceAuthenticationHttpContextTest.anyAuthenticator()
test_case.full_signature: @Test public void anyAuthenticator()
test_case.identifier: anyAuthenticator
test_case.invocations: createBundleContext createServiceReferences andReturn expect getServiceReferences eq getName isNull replay createContext prepareResponse assertEquals handleSecurity format printBooleanList
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void anyAuthenticator()
focal_class.declarator: AUTHMODE_SERVICE_ALL = "service-all"
focal_class.modifier: static final
focal_class.original_string: static final String AUTHMODE_SERVICE_ALL = "service-all";
focal_class.type: String
focal_class.var_name: AUTHMODE_SERVICE_ALL
focal_class.declarator: AUTHMODE_SERVICE_ANY = "service-any"
focal_class.modifier: static final
focal_class.original_string: static final String AUTHMODE_SERVICE_ANY = "service-any";
focal_class.type: String
focal_class.var_name: AUTHMODE_SERVICE_ANY
focal_class.declarator: authenticators = new HashSet<Authenticator>()
focal_class.modifier: private final
focal_class.original_string: private final Set<Authenticator> authenticators = new HashSet<Authenticator>();
focal_class.type: Set<Authenticator>
focal_class.var_name: authenticators
focal_class.declarator: authenticatorServiceTracker
focal_class.modifier: private
focal_class.original_string: private ServiceTracker authenticatorServiceTracker;
focal_class.type: ServiceTracker
focal_class.var_name: authenticatorServiceTracker
focal_class.declarator: checkModeAny
focal_class.modifier: private final
focal_class.original_string: private final boolean checkModeAny;
focal_class.type: boolean
focal_class.var_name: checkModeAny
focal_class.file: agent/osgi/src/main/java/org/jolokia/osgi/security/ServiceAuthenticationHttpContext.java
focal_class.identifier: ServiceAuthenticationHttpContext
focal_class.class_method_signature: ServiceAuthenticationHttpContext.ServiceAuthenticationHttpContext(final BundleContext bundleContext, final String authMode)
focal_class.full_signature: public  ServiceAuthenticationHttpContext(final BundleContext bundleContext, final String authMode)
focal_class.identifier: ServiceAuthenticationHttpContext
focal_class.modifiers: public
focal_class.parameters: (final BundleContext bundleContext, final String authMode)
focal_class.signature:  ServiceAuthenticationHttpContext(final BundleContext bundleContext, final String authMode)
focal_class.class_method_signature: ServiceAuthenticationHttpContext.handleSecurity(final HttpServletRequest request, final HttpServletResponse response)
focal_class.full_signature: @Override public boolean handleSecurity(final HttpServletRequest request, final HttpServletResponse response)
focal_class.identifier: handleSecurity
focal_class.modifiers: @Override public
focal_class.parameters: (final HttpServletRequest request, final HttpServletResponse response)
focal_class.return: boolean
focal_class.signature: boolean handleSecurity(final HttpServletRequest request, final HttpServletResponse response)
focal_class.class_method_signature: ServiceAuthenticationHttpContext.close()
focal_class.full_signature: public void close()
focal_class.identifier: close
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void close()
focal_class.class_method_signature: ServiceAuthenticationHttpContext.shouldBeUsed(String authMode)
focal_class.full_signature: public static boolean shouldBeUsed(String authMode)
focal_class.identifier: shouldBeUsed
focal_class.modifiers: public static
focal_class.parameters: (String authMode)
focal_class.return: boolean
focal_class.signature: boolean shouldBeUsed(String authMode)
focal_class.superclass: extends DefaultHttpContext
focal_method.body: @Override
      public boolean handleSecurity(final HttpServletRequest request, final HttpServletResponse response)
              throws IOException {
  
          synchronized(authenticators) {
              // deny access if authMode is set to service but a service is not provided
              if (authenticators.isEmpty()) {
                  response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                  return false;
              }
              for (final Authenticator authenticator : authenticators) {
                  boolean authenticated = authenticator.authenticate(request);
                  if (checkModeAny && authenticated) {
                      // One successful authenticator is good enough
                      return true;
                  }
                  else if (!checkModeAny && !authenticated) {
                      // All must succeed, so any negative respond will kill the authentication
                      response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                      return false;
                  }
              }
              // if checkModeAny: Not a single succeeded, if checkModeAll: All have succeeded
              return !checkModeAny;
          }
      }
focal_method.class_method_signature: ServiceAuthenticationHttpContext.handleSecurity(final HttpServletRequest request, final HttpServletResponse response)
focal_method.full_signature: @Override public boolean handleSecurity(final HttpServletRequest request, final HttpServletResponse response)
focal_method.identifier: handleSecurity
focal_method.invocations: isEmpty sendError authenticate sendError
focal_method.modifiers: @Override public
focal_method.parameters: (final HttpServletRequest request, final HttpServletResponse response)
focal_method.return: boolean
focal_method.signature: boolean handleSecurity(final HttpServletRequest request, final HttpServletResponse response)