JolokiaActivator implements BundleActivator, JolokiaContext { public synchronized HttpContext getHttpContext() { if (jolokiaHttpContext == null) { final String user = getConfiguration(USER); final String authMode = getConfiguration(AUTH_MODE); if (user == null) { if (ServiceAuthenticationHttpContext.shouldBeUsed(authMode)) { jolokiaHttpContext = new ServiceAuthenticationHttpContext(bundleContext, authMode); } else { jolokiaHttpContext = new DefaultHttpContext(); } } else { jolokiaHttpContext = new BasicAuthenticationHttpContext(getConfiguration(REALM), createAuthenticator(authMode)); } } return jolokiaHttpContext; }  void start(BundleContext pBundleContext); void stop(BundleContext pBundleContext); synchronized HttpContext getHttpContext(); String getServletAlias(); static final String HTTP_SERVICE_FILTER_BASE; }
@Test public void testNoServiceAvailable() throws Exception { final HttpServletRequest request = createMock(HttpServletRequest.class); final HttpServletResponse response = createNiceMock(HttpServletResponse.class); final Dictionary<String, String> dict = new Hashtable<String, String>(); dict.put("org.jolokia.authMode", "service-all"); startActivator(true, AUTHENTICATOR_SERVICE_FILTER, dict); startupHttpServiceWithConfigAdminProps(true); expect(request.getHeader("Authorization")).andReturn("Basic cm9sYW5kOnMhY3IhdA=="); request.setAttribute(HttpContext.AUTHENTICATION_TYPE, HttpServletRequest.BASIC_AUTH); request.setAttribute(HttpContext.REMOTE_USER, "roland"); replay(request, response); final HttpContext httpContext = activator.getHttpContext(); assertFalse(httpContext.handleSecurity(request, response)); unregisterJolokiaServlet(); stopActivator(true); }