List of usage examples for javax.management.remote JMXConnector CREDENTIALS
String CREDENTIALS
To view the source code for javax.management.remote JMXConnector CREDENTIALS.
Click Source Link
Name of the attribute that specifies the credentials to send to the connector server during connection.
From source file:jmxbf.java
public static void main(String[] args) throws IOException, MalformedObjectNameException { String HOST = ""; String PORT = ""; String usersFile = ""; String pwdFile = ""; CommandLine cmd = getParsedCommandLine(args); if (cmd != null) { HOST = cmd.getOptionValue("host"); PORT = cmd.getOptionValue("port"); usersFile = cmd.getOptionValue("usernames-file"); pwdFile = cmd.getOptionValue("passwords-file"); } else {// w w w . j a v a2 s .c o m System.exit(1); } String finalResults = ""; BufferedReader users = new BufferedReader(new FileReader(usersFile)); BufferedReader pwds = new BufferedReader(new FileReader(pwdFile)); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + HOST + ":" + PORT + "/jmxrmi"); //new JMXServiceURL("service:jmx:remoting-jmx://" + HOST + ":" + PORT); String user = null; boolean found = false; while ((user = users.readLine()) != null) { String pwd = null; while ((pwd = pwds.readLine()) != null) { //System.out.println(user+":"+pwd); Map<String, String[]> env = new HashMap<>(); String[] credentials = { user, pwd }; env.put(JMXConnector.CREDENTIALS, credentials); try { JMXConnector jmxConnector = JMXConnectorFactory.connect(url, env); System.out.println(); System.out.println(); System.out.println(); System.out.println( "[+] ###SUCCESS### - We got a valid connection for: " + user + ":" + pwd + "\r\n\r\n"); finalResults = finalResults + "\n" + user + ":" + pwd; jmxConnector.close(); found = true; break; } catch (java.lang.SecurityException e) { System.out.println("Auth failed!!!\r\n"); } } if (found) { System.out.println("Found some valid credentials - continuing brute force"); found = false; } //closing and reopening pwds pwds.close(); pwds = new BufferedReader(new FileReader(pwdFile)); } users.close(); //print final results if (finalResults.length() != 0) { System.out.println("The following valid credentials were found:\n"); System.out.println(finalResults); } }
From source file:org.wso2.carbon.integration.test.client.JMXAnalyzerClient.java
public static int getThreadCount(String host, String port) throws IOException { String username = "admin"; String password = "admin"; int threadCount = 0; String threadName = "JMSThreads"; JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi"); Map<String, String[]> env = new HashMap<String, String[]>(); ThreadInfo threadIDInfo;/* w ww. j a v a 2 s .c o m*/ String[] credentials = { username, password }; env.put(JMXConnector.CREDENTIALS, credentials); JMXConnector jmxConnector = JMXConnectorFactory.connect(url, env); MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection(); final ThreadMXBean remoteThread = ManagementFactory.newPlatformMXBeanProxy(mbeanServerConnection, ManagementFactory.THREAD_MXBEAN_NAME, ThreadMXBean.class); long[] allThreadIDsArray = remoteThread.getAllThreadIds(); //get jms thread count for (long threadID : allThreadIDsArray) { threadIDInfo = remoteThread.getThreadInfo(threadID); if (threadIDInfo != null && threadIDInfo.getThreadName() != null && threadIDInfo.getThreadName().startsWith(threadName)) { threadCount++; } } //close the connection jmxConnector.close(); return threadCount; }
From source file:com.appdynamics.monitors.muleesb.JMXUtil.java
private static JMXConnector connect(String host, int port, String username, String password) throws IOException { String jmxUrl = buildUrl(host, port); JMXServiceURL url = new JMXServiceURL(jmxUrl); final Map<String, Object> env = new HashMap<String, Object>(); JMXConnector connector = null; if (!Strings.isNullOrEmpty(username)) { env.put(JMXConnector.CREDENTIALS, new String[] { username, password }); connector = JMXConnectorFactory.connect(url, env); } else {/*from w ww .j av a 2 s . c om*/ connector = JMXConnectorFactory.connect(url); } return connector; }
From source file:com.adaptris.core.services.jmx.JmxOperationInvoker.java
public Object invoke(String serviceUrl, String objectName, String username, String password, String methodName, Object[] params, String[] signatures) throws Exception { Map<String, String[]> env = new HashMap<>(); if ((!StringUtils.isEmpty(username)) && (!StringUtils.isEmpty(password))) { String[] credentials = { username, Password.decode(password) }; env.put(JMXConnector.CREDENTIALS, credentials); }//from www . j a v a2 s . c o m JMXServiceURL jmxServiceUrl = new JMXServiceURL(serviceUrl); JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceUrl, env); ObjectName objectNameInst = ObjectName.getInstance(objectName); MBeanServerConnection mbeanConn = jmxConnector.getMBeanServerConnection(); try { return mbeanConn.invoke(objectNameInst, methodName, params, signatures); } finally { jmxConnector.close(); } }
From source file:com.fusesource.forge.jmstest.probe.jmx.JMXConnectionFactory.java
public JMXConnector getConnector() { JMXConnector connector = null; try {/* w w w. j a v a 2 s.c om*/ if (connector == null) { if (username != null && password != null) { Map<String, String[]> m = new HashMap<String, String[]>(); m.put(JMXConnector.CREDENTIALS, new String[] { username, password }); connector = JMXConnectorFactory.connect(new JMXServiceURL(url), m); } else { connector = JMXConnectorFactory.connect(new JMXServiceURL(url)); } } } catch (IOException ioe) { // TODO: do this right log().error("Error connecting to JMX server ", ioe); } return connector; }
From source file:com.riotgames.mondev.JMXDiscovery.java
protected String discoverMBeans(String key) throws Exception { try {//ww w . ja va 2 s . c om HashMap<String, String[]> env = null; if (null != username && null != password) { env = new HashMap<String, String[]>(); env.put(JMXConnector.CREDENTIALS, new String[] { username, password }); } jmxc = JMXConnectorFactory.connect(jmxServerUrl, env); mbsc = jmxc.getMBeanServerConnection(); ObjectName filter = new ObjectName(key); JSONArray beanList = new JSONArray(); JSONObject mapping = new JSONObject(); Set beans = mbsc.queryMBeans(filter, null); for (Object obj : beans) { JSONObject bean = new JSONObject(); ObjectName beanName; // Return the ObjectName instance correctly for both Objects and Instances if (obj instanceof ObjectName) beanName = (ObjectName) obj; else if (obj instanceof ObjectInstance) beanName = ((ObjectInstance) obj).getObjectName(); else throw new RuntimeException("Unexpected object type: " + obj); // Build the standing info, description and object path MBeanInfo mbi = mbsc.getMBeanInfo(beanName); bean.put("{#JMXDESC}", mbi.getDescription()); bean.put("{#JMXOBJ}", beanName.getCanonicalName()); // Build a list of all the MBean properties as {#PROP<NAME>} Hashtable<String, String> pt = beanName.getKeyPropertyList(); for (Map.Entry<String, String> prop : pt.entrySet()) bean.put(String.format("{#PROP%s}", prop.getKey().toUpperCase()), prop.getValue()); beanList.put(bean); } mapping.put("data", beanList); return mapping.toString(); } catch (Exception e) { JSONArray data = new JSONArray(); JSONObject out = new JSONObject(); out.put("data", data); return out.toString(); } finally { try { if (null != jmxc) jmxc.close(); } catch (java.io.IOException exception) { } jmxc = null; mbsc = null; } }
From source file:org.springside.modules.utils.jmx.JmxClientTemplate.java
/** * JMX Server./*from w ww. jav a2s .c o m*/ */ private void initConnector(final String serviceUrl, final String userName, final String passwd) throws IOException { JMXServiceURL url = new JMXServiceURL(serviceUrl); boolean hasCredentlals = StringUtils.isNotBlank(userName); if (hasCredentlals) { Map environment = Collections.singletonMap(JMXConnector.CREDENTIALS, new String[] { userName, passwd }); connector = JMXConnectorFactory.connect(url, environment); } else { connector = JMXConnectorFactory.connect(url); } connection = connector.getMBeanServerConnection(); connected.set(true); }
From source file:com.rosy.bill.utils.jmx.JmxClientTemplate.java
/** * JMX Server./*from www . j av a 2 s.c o m*/ */ @SuppressWarnings("unchecked") private void initConnector(final String serviceUrl, final String userName, final String passwd) throws IOException { JMXServiceURL url = new JMXServiceURL(serviceUrl); boolean hasCredentlals = StringUtils.isNotBlank(userName); if (hasCredentlals) { Map environment = Collections.singletonMap(JMXConnector.CREDENTIALS, new String[] { userName, passwd }); connector = JMXConnectorFactory.connect(url, environment); } else { connector = JMXConnectorFactory.connect(url); } connection = connector.getMBeanServerConnection(); connected.set(true); }
From source file:com.clustercontrol.HinemosManagerCli.java
private void invoke() { System.setProperty("sun.rmi.transport.connectionTimeout", String.valueOf(connectTimeout)); System.setProperty("sun.rmi.transport.tcp.responseTimeout", String.valueOf(responseTimeout)); try {/*from w ww . ja v a 2 s . com*/ JMXServiceURL url = new JMXServiceURL( String.format("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", ip, port)); Map<String, Object> env = new HashMap<String, Object>(); if (user != null && password != null) { env.put(JMXConnector.CREDENTIALS, new String[] { user, password }); } MBeanServerConnection mbsc = JMXConnectorFactory.connect(url, env).getMBeanServerConnection(); ObjectName mbeanName = new ObjectName("com.clustercontrol.mbean:type=" + name); if (doesOutputInfo) { printMBeanInfo(mbsc.getMBeanInfo(mbeanName)); return; } Object ret; if (attribute != null) { ret = mbsc.getAttribute(mbeanName, attribute); } else { String[] signature = new String[operationArgs.length]; for (int i = 0; i < signature.length; i++) { signature[i] = String.class.getName(); } ret = mbsc.invoke(mbeanName, operation, operationArgs, signature); } System.out.println(ret); } catch (Exception e) { e.printStackTrace(); System.exit(2); } }
From source file:com.tribloom.module.JmxClient.java
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { Map<String, Object> model = new HashMap<String, Object>(); model.put("connectionSuccess", true); model.put("time", System.currentTimeMillis()); try {/*from w w w . j a va2s . c o m*/ // Create an RMI connector client and // connect it to the RMI connector server // echo("\nCreate an RMI connector client and " + "connect it to the RMI connector server"); JMXServiceURL url = new JMXServiceURL( "service:jmx:rmi://ignored/jndi/rmi://localhost:50500/alfresco/jmxrmi"); Map<String, Object> env = new HashMap<String, Object>(); String[] creds = { "controlRole", "change_asap" }; env.put(JMXConnector.CREDENTIALS, creds); JMXConnector jmxc = JMXConnectorFactory.connect(url, env); // Get an MBeanServerConnection // echo("\nGet an MBeanServerConnection"); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName memory = new ObjectName("java.lang:type=Memory"); CompositeData heapMemUsage = (CompositeData) mbsc.getAttribute(memory, "HeapMemoryUsage"); addCompositeData(model, heapMemUsage, "heapMemoryUsage"); CompositeData nonHeapMemUsage = (CompositeData) mbsc.getAttribute(memory, "NonHeapMemoryUsage"); addCompositeData(model, nonHeapMemUsage, "nonHeapMemoryUsage"); ObjectName operatingSystem = new ObjectName("java.lang:type=OperatingSystem"); model.put("openFileDescriptorCount", mbsc.getAttribute(operatingSystem, "OpenFileDescriptorCount")); model.put("maxFileDescriptorCount", mbsc.getAttribute(operatingSystem, "MaxFileDescriptorCount")); model.put("committedVirtualMemorySize", mbsc.getAttribute(operatingSystem, "CommittedVirtualMemorySize")); model.put("totalSwapSpaceSize", mbsc.getAttribute(operatingSystem, "TotalSwapSpaceSize")); model.put("freeSwapSpaceSize", mbsc.getAttribute(operatingSystem, "FreeSwapSpaceSize")); model.put("processCpuTime", mbsc.getAttribute(operatingSystem, "ProcessCpuTime")); model.put("freePhysicalMemorySize", mbsc.getAttribute(operatingSystem, "FreePhysicalMemorySize")); model.put("totalPhysicalMemorySize", mbsc.getAttribute(operatingSystem, "TotalPhysicalMemorySize")); model.put("operatingSystemName", mbsc.getAttribute(operatingSystem, "Name")); model.put("operatingSystemVersion", mbsc.getAttribute(operatingSystem, "Version")); model.put("operatingSystemArch", mbsc.getAttribute(operatingSystem, "Arch")); model.put("availableProcessors", mbsc.getAttribute(operatingSystem, "AvailableProcessors")); model.put("systemLoadAverage", mbsc.getAttribute(operatingSystem, "SystemLoadAverage")); try { ObjectName parNewGarbageCollector = new ObjectName("java.lang:type=GarbageCollector,name=ParNew"); echo("\nparNewGarbageCollector = " + parNewGarbageCollector); CompositeData parNewLastGcInfo = (CompositeData) mbsc.getAttribute(parNewGarbageCollector, "LastGcInfo"); addCompositeData(model, parNewLastGcInfo, "parNewLastGcInfo"); } catch (InstanceNotFoundException ex) { // No Garbage Collection has occurred yet echo("No Garbage Collection found: " + ex.getMessage()); } try { ObjectName concurrentGarbageCollector = new ObjectName( "java.lang:type=GarbageCollector,name=ConcurrentMarkSweep"); echo("\nconcurrentGarbageCollector = " + concurrentGarbageCollector); CompositeData concurrentGarbageCollectorLastGcInfo = (CompositeData) mbsc .getAttribute(concurrentGarbageCollector, "LastGcInfo"); addCompositeData(model, concurrentGarbageCollectorLastGcInfo, "concurrentMarkSweepLastGcInfo"); } catch (InstanceNotFoundException ex) { // No Garbage Collection has occurred yet echo("No Garbage Collection found: " + ex.getMessage()); } ObjectName classLoading = new ObjectName("java.lang:type=ClassLoading"); model.put("classLoadingLoadedClassCount", mbsc.getAttribute(classLoading, "LoadedClassCount")); model.put("classLoadingUnloadedClassCount", mbsc.getAttribute(classLoading, "UnloadedClassCount")); model.put("classLoadingTotalLoadedClassCount", mbsc.getAttribute(classLoading, "TotalLoadedClassCount")); ObjectName runtime = new ObjectName("java.lang:type=Runtime"); model.put("runtimeName", mbsc.getAttribute(runtime, "Name")); model.put("runtimeClassPath", mbsc.getAttribute(runtime, "ClassPath")); // TODO: Tabular type... Object sysProps = mbsc.getAttribute(runtime, "SystemProperties"); echo("\nsysProps = " + sysProps); model.put("runtimeStartTime", mbsc.getAttribute(runtime, "StartTime")); model.put("runtimeVmName", mbsc.getAttribute(runtime, "VmName")); model.put("runtimeVmVendor", mbsc.getAttribute(runtime, "VmVendor")); model.put("runtimeVmVersion", mbsc.getAttribute(runtime, "VmVersion")); model.put("runtimeLibraryPath", mbsc.getAttribute(runtime, "LibraryPath")); model.put("runtimeBootClassPath", mbsc.getAttribute(runtime, "BootClassPath")); model.put("runtimeManagementSpecVersion", mbsc.getAttribute(runtime, "ManagementSpecVersion")); model.put("runtimeSpecName", mbsc.getAttribute(runtime, "SpecName")); model.put("runtimeSpecVendor", mbsc.getAttribute(runtime, "SpecVendor")); model.put("runtimeSpecVersion", mbsc.getAttribute(runtime, "SpecVersion")); model.put("runtimeInputArguments", mbsc.getAttribute(runtime, "InputArguments")); // TODO: Array... model.put("runtimeUptime", mbsc.getAttribute(runtime, "Uptime")); try { ObjectName memoryPool = new ObjectName("java.lang:type=MemoryPool"); model.put("memoryPoolName", mbsc.getAttribute(memoryPool, "Name")); model.put("memoryPoolType", mbsc.getAttribute(memoryPool, "Type")); CompositeData memoryPoolUsage = (CompositeData) mbsc.getAttribute(memoryPool, "Usage"); addCompositeData(model, memoryPoolUsage, "memoryPoolUsage"); CompositeData memoryPoolPeakUsage = (CompositeData) mbsc.getAttribute(memoryPool, "PeakUsage"); addCompositeData(model, memoryPoolPeakUsage, "memoryPoolPeakUsage"); model.put("memoryPoolMemoryManagerNames", mbsc.getAttribute(memoryPool, "MemoryManagerNames")); // Array of strings model.put("memoryPoolUsageThreshold", mbsc.getAttribute(memoryPool, "UsageThreshold")); model.put("memoryPoolUsageThresholdExceeded", mbsc.getAttribute(memoryPool, "UsageThresholdExceeded")); model.put("memoryPoolUsageThresholdCount", mbsc.getAttribute(memoryPool, "UsageThresholdCount")); model.put("memoryPoolUsageThresholdSupported", mbsc.getAttribute(memoryPool, "UsageThresholdSupported")); model.put("memoryPoolCollectionUsageThreshold", mbsc.getAttribute(memoryPool, "CollectionUsageThreshold")); model.put("memoryPoolCollectionUsageThresholdExceeded", mbsc.getAttribute(memoryPool, "CollectionUsageThresholdExceeded")); model.put("memoryPoolCollectionUsageThresholdCount", mbsc.getAttribute(memoryPool, "CollectionUsageThresholdCount")); CompositeData collectionUsage = (CompositeData) mbsc.getAttribute(memoryPool, "CollectionUsage"); addCompositeData(model, collectionUsage, "memoryPoolCollectionUsage"); model.put("memoryPoolCollectionUsageThresholdSupported", mbsc.getAttribute(memoryPool, "CollectionUsageThresholdSupported")); } catch (InstanceNotFoundException ex) { // Memory pool not initialized yet } echo("\nClose the connection to the server"); jmxc.close(); echo("\nBye! Bye!"); } catch (Exception ex) { ex.printStackTrace(); model.put("connectionSuccess", false); model.put("exception", ex.getMessage()); } return model; }