/** * Get an configuration value as boolean value. The value must * be configured as 'true' for this method to return true * * @param pKey the configuration key for which a boolean config value is requested * @return true if the configuration (or the default value, if the configuration is not set) * is "true" for this key, false otherwise. */ public boolean getAsBoolean(ConfigKey pKey) { return Boolean.valueOf(get(pKey)); }
/** * Create a new HttpHandler for processing HTTP request * * @param pConfig jolokia specific config tuning the processing behaviour * @param pLogHandler log-handler the log handler to use for jolokia */ public JolokiaHttpHandler(Configuration pConfig, LogHandler pLogHandler) { configuration = pConfig; context = pConfig.get(ConfigKey.AGENT_CONTEXT); if (!context.endsWith("/")) { context += "/"; } logHandler = pLogHandler != null ? pLogHandler : createLogHandler(pConfig.get(ConfigKey.LOGHANDLER_CLASS), pConfig.get(ConfigKey.DEBUG)); }
private Map getPluginOptions(Configuration pConfig, LogHandler pLogHandler) { String options = pConfig.get(ConfigKey.MBEAN_PLUGIN_OPTIONS); try { return options != null ? (JSONObject) new JSONParser().parse(options) : new JSONObject(); } catch (ParseException e) { throw new IllegalStateException("Could not parse plugin options '" + options + "' as JSON Objects" + e,e); } }
private Set<String> extractWhiteList(Configuration pConfig) { return extractFrom(pConfig != null ? pConfig.get(ConfigKey.JSR160_PROXY_ALLOWED_TARGETS) : null, System.getProperty(ALLOWED_TARGETS_SYSPROP), System.getenv(ALLOWED_TARGETS_ENV)); }
private void initContext() { context = jolokiaConfig.get(ConfigKey.AGENT_CONTEXT); if (context == null) { context = ConfigKey.AGENT_CONTEXT.getDefaultValue(); } if (!context.endsWith("/")) { context += "/"; } }
private List<RequestDispatcher> createRequestDispatchers(Configuration pConfig, Converters pConverters, ServerHandle pServerHandle, Restrictor pRestrictor) { List<RequestDispatcher> ret = new ArrayList<RequestDispatcher>(); String classes = pConfig != null ? pConfig.get(DISPATCHER_CLASSES) : null; if (classes != null && classes.length() > 0) { String[] names = classes.split("\\s*,\\s*"); for (String name : names) { ret.add(createDispatcher(name, pConverters, pServerHandle, pRestrictor, pConfig)); } } return ret; }
/** * Get an configuration value as int value * @param pKey the configuration key * @return the value set or, if not, the default value */ public int getAsInt(ConfigKey pKey) { int ret; try { ret = Integer.parseInt(get(pKey)); } catch (NumberFormatException exp) { ret = Integer.parseInt(pKey.getDefaultValue()); } return ret; }
private void initCustomAuthenticator() { String authenticatorClass = jolokiaConfig.get(ConfigKey.AUTH_CLASS); if (authenticatorClass != null) { try { Class authClass = Class.forName(authenticatorClass); if (!Authenticator.class.isAssignableFrom(authClass)) { throw new IllegalArgumentException("Provided authenticator class [" + authenticatorClass + "] is not a subclass of Authenticator"); } lookupAuthenticator(authClass); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Cannot find authenticator class", e); } } }
private String findAgentUrl(Configuration pConfig) { // System property has precedence String url = System.getProperty("jolokia." + ConfigKey.DISCOVERY_AGENT_URL.getKeyValue()); if (url == null) { url = System.getenv("JOLOKIA_DISCOVERY_AGENT_URL"); if (url == null) { url = pConfig.get(ConfigKey.DISCOVERY_AGENT_URL); } } return NetworkUtil.replaceExpression(url); }
private void initLimits(Configuration pConfig) { // Max traversal depth if (pConfig != null) { convertOptionsBuilder = new JsonConvertOptions.Builder( getNullSaveIntLimit(pConfig.get(MAX_DEPTH)), getNullSaveIntLimit(pConfig.get(MAX_COLLECTION_SIZE)), getNullSaveIntLimit(pConfig.get(MAX_OBJECTS)) ); } else { convertOptionsBuilder = new JsonConvertOptions.Builder(); } }
private static Restrictor createCustomRestrictor(Configuration pConfig) { String restrictorClassName = pConfig.get(ConfigKey.RESTRICTOR_CLASS); if (restrictorClassName == null) { return null; } Class restrictorClass = ClassUtil.classForName(restrictorClassName); if (restrictorClass == null) { throw new IllegalArgumentException("No custom restrictor class " + restrictorClassName + " found"); } return lookupRestrictor(pConfig, restrictorClass); }
private JSONObject configToJSONObject() { JSONObject info = new JSONObject(); if (config != null) { for (ConfigKey key : ConfigKey.values()) { if (key.isGlobalConfig()) { String value = config.get(key); if (value != null) { info.put(key.getKeyValue(), value); } } } } return info; }
/** * Get the optional options used for detectors. This should be a JSON string specifying all options * for all detectors. Keys are the name of the detector's product, the values are JSON object containing * specific parameters for this agent. E.g. * * <pre> * { * "glassfish" : { "bootAmx": true } * } * </pre> * * * @param pConfig the agent configuration * @param pLogHandler a log handler for putting out error messages * @return the detector specific configuration */ protected JSONObject getDetectorOptions(Configuration pConfig, LogHandler pLogHandler) { String options = pConfig.get(ConfigKey.DETECTOR_OPTIONS); try { if (options != null) { JSONObject opts = (JSONObject) new JSONParser().parse(options); return (JSONObject) opts.get(getProduct()); } return null; } catch (ParseException e) { pLogHandler.error("Could not parse detector options '" + options + "' as JSON object: " + e,e); } return null; } }
/** * Create a new local dispatcher which accesses local MBeans. * * @param pConverters object/string converters * @param pRestrictor restrictor which checks the access for various operations * @param pConfig agent configuration * @param pLogHandler local handler used for logging out errors and warnings */ public LocalRequestDispatcher(Converters pConverters, Restrictor pRestrictor, Configuration pConfig, LogHandler pLogHandler) { // Get all MBean servers we can find. This is done by a dedicated // handler object mBeanServerHandler = new MBeanServerHandler(pConfig,pLogHandler); qualifier = pConfig.get(ConfigKey.MBEAN_QUALIFIER); log = pLogHandler; agentId = NetworkUtil.replaceExpression(pConfig.get(ConfigKey.AGENT_ID)); // Request handling manager requestHandlerManager = new RequestHandlerManager(pConfig,pConverters,mBeanServerHandler.getServerHandle(),pRestrictor); }
/** * Start this server. If we manage an own HttpServer, then the HttpServer will * be started as well. */ public void start() { // URL as configured takes precedence String configUrl = NetworkUtil.replaceExpression(config.getJolokiaConfig().get(ConfigKey.DISCOVERY_AGENT_URL)); jolokiaHttpHandler.start(lazy,configUrl != null ? configUrl : url, config.getAuthenticator() != null); if (httpServer != null) { // Starting our own server in an own thread group with a fixed name // so that the cleanup thread can recognize it. ThreadGroup threadGroup = new ThreadGroup("jolokia"); threadGroup.setDaemon(false); Thread starterThread = new Thread(threadGroup,new Runnable() { @Override public void run() { httpServer.start(); } }); starterThread.start(); cleaner = new CleanupThread(httpServer,threadGroup); cleaner.start(); } }
private String getMimeType(ParsedUri pParsedUri) { return MimeTypeUtil.getResponseMimeType( pParsedUri.getParameter(ConfigKey.MIME_TYPE.getKeyValue()), configuration.get(ConfigKey.MIME_TYPE), pParsedUri.getParameter(ConfigKey.CALLBACK.getKeyValue())); }
/** * Create a new MBeanServer handler who is responsible for managing multiple intra VM {@link MBeanServer} at once * An optional qualifier used for registering this object as an MBean is taken from the given configuration as well * * @param pConfig configuration for this agent which is also given to the {@see ServerHandle#postDetect()} method for * special initialization. * * @param pLogHandler log handler used for logging purposes */ public MBeanServerHandler(Configuration pConfig, LogHandler pLogHandler) { // A qualifier, if given, is used to add the MBean Name of this MBean qualifier = pConfig.get(ConfigKey.MBEAN_QUALIFIER); List<ServerDetector> detectors = lookupDetectors(); mBeanServerManager = new MBeanServerExecutorLocal(detectors); initServerHandle(pConfig, pLogHandler, detectors); initMBean(); initPlugins(pConfig, pLogHandler); }
public static Restrictor createRestrictor(Configuration pConfig, LogHandler logHandler) { Restrictor customRestrictor = createCustomRestrictor(pConfig); if (customRestrictor != null) { logHandler.info("Using restrictor " + customRestrictor.getClass().getCanonicalName()); return customRestrictor; } String location = NetworkUtil.replaceExpression(pConfig.get(ConfigKey.POLICY_LOCATION)); try { Restrictor ret = RestrictorFactory.lookupPolicyRestrictor(location); if (ret != null) { logHandler.info("Using policy access restrictor " + location); return ret; } else { logHandler.info("No access restrictor found, access to any MBean is allowed"); return new AllowAllRestrictor(); } } catch (IOException e) { logHandler.error("Error while accessing access restrictor at " + location + ". Denying all access to MBeans for security reasons. Exception: " + e, e); return new DenyAllRestrictor(); } }