private void addCtx(String path, HttpHandler h) {
   HttpContext ctx = server.createContext(path, h);
   if (configuration.isWebAuthenticate()) {
     ctx.setAuthenticator(
         new BasicAuthenticator("") {
           @Override
           public boolean checkCredentials(String user, String pwd) {
             LOGGER.debug("authenticate " + user);
             return pwd.equals(users.get(user));
             // return true;
           }
         });
   }
 }
Exemple #2
0
  /**
   * Initialize this JolokiaServer with the given HttpServer. The calle is responsible for managing
   * (starting/stopping) the HttpServer.
   *
   * @param pServer server to use
   * @param pConfig configuration
   * @param pLazy whether the initialization should be done lazy or not
   */
  protected final void init(HttpServer pServer, JolokiaServerConfig pConfig, boolean pLazy) {
    config = pConfig;
    lazy = pLazy;

    // Create proper context along with handler
    final String contextPath = pConfig.getContextPath();
    jolokiaHttpHandler = new JolokiaHttpHandler(pConfig.getJolokiaConfig());
    HttpContext context = pServer.createContext(contextPath, jolokiaHttpHandler);

    // Add authentication if configured
    final Authenticator authenticator = pConfig.getAuthenticator();
    if (authenticator != null) {
      context.setAuthenticator(authenticator);
    }

    url = detectAgentUrl(pServer, pConfig, contextPath);
  }