activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbert...@apache.org
Subject [2/2] activemq-artemis git commit: ARTEMIS-1463 - added SSL example + docs
Date Wed, 18 Oct 2017 20:41:48 GMT
ARTEMIS-1463 - added SSL example + docs

also added support for anon login

https://issues.apache.org/jira/browse/ARTEMIS-1463


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/a64d7c2e
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/a64d7c2e
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/a64d7c2e

Branch: refs/heads/master
Commit: a64d7c2e422d7066dd6a82f2e4fb6ec312d9c752
Parents: b7125d5
Author: Andy Taylor <andy.tayls67@gmail.com>
Authored: Wed Oct 18 09:58:39 2017 +0100
Committer: Justin Bertram <jbertram@apache.org>
Committed: Wed Oct 18 15:24:44 2017 -0500

----------------------------------------------------------------------
 .../core/config/JMXConnectorConfiguration.java  |   6 +-
 .../server/management/JaasAuthenticator.java    |  34 ++--
 docs/user-manual/en/management.md               |  36 +++-
 examples/features/standard/jmx-ssl/pom.xml      | 114 ++++++++++++
 examples/features/standard/jmx-ssl/readme.html  | 176 +++++++++++++++++++
 .../artemis/jms/example/JMXExample.java         | 127 +++++++++++++
 .../activemq/server0/activemq.example.keystore  | Bin 0 -> 1273 bytes
 .../server0/activemq.example.truststore         | Bin 0 -> 866 bytes
 .../main/resources/activemq/server0/broker.xml  |  64 +++++++
 .../resources/activemq/server0/management.xml   |  56 ++++++
 .../jmx-ssl/src/main/resources/jndi.properties  |  20 +++
 examples/features/standard/jmx/pom.xml          |   2 +-
 examples/features/standard/jmx/readme.html      |   3 +-
 .../artemis/jms/example/JMXExample.java         |   1 +
 .../resources/activemq/server0/management.xml   |   2 +-
 .../features/standard/message-counters/pom.xml  |   1 +
 .../jms/example/MessageCounterExample.java      |   1 +
 17 files changed, 614 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/JMXConnectorConfiguration.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/JMXConnectorConfiguration.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/JMXConnectorConfiguration.java
index 786f554..b47acf5 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/JMXConnectorConfiguration.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/JMXConnectorConfiguration.java
@@ -16,6 +16,8 @@
  */
 package org.apache.activemq.artemis.core.config;
 
+import java.security.KeyStore;
+
 public class JMXConnectorConfiguration {
    private int rmiRegistryPort;
    private String connectorHost = "localhost";
@@ -27,10 +29,10 @@ public class JMXConnectorConfiguration {
    private String objectName = "connector:name=rmi";
    private String authenticatorType = "password";
    private boolean secured =  false;
-   private String keyStoreProvider;
+   private String keyStoreProvider = KeyStore.getDefaultType();
    private String keyStorePath;
    private String keyStorePassword;
-   private String trustStoreProvider;
+   private String trustStoreProvider = KeyStore.getDefaultType();
    private String trustStorePath;
    private String trustStorePassword;
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/JaasAuthenticator.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/JaasAuthenticator.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/JaasAuthenticator.java
index 23167e9..739392a 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/JaasAuthenticator.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/JaasAuthenticator.java
@@ -40,27 +40,29 @@ public class JaasAuthenticator implements JMXAuthenticator {
    }
 
    @Override
-   public Subject authenticate(Object credentials) throws SecurityException {
-      if (!(credentials instanceof String[])) {
-         throw new IllegalArgumentException("Expected String[2], got "
-               + (credentials != null ? credentials.getClass().getName() : null));
-      }
-
-      final String[] params = (String[]) credentials;
-      if (params.length != 2) {
-         throw new IllegalArgumentException("Expected String[2] but length was " + params.length);
-      }
+   public Subject authenticate(final Object credentials) throws SecurityException {
       try {
          Subject subject = new Subject();
-         LoginContext loginContext = new LoginContext(realm, subject, new CallbackHandler()
{
 
+         LoginContext loginContext = new LoginContext(realm, subject, new CallbackHandler()
{
             @Override
             public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
{
+               /*
+               * pull out the jmx credentials if they exist if not, guest login module will
handle it
+               * */
+               String[] params = null;
+               if (credentials instanceof String[] && ((String[]) credentials).length
== 2) {
+                  params = (String[]) credentials;
+               }
                for (int i = 0; i < callbacks.length; i++) {
                   if (callbacks[i] instanceof NameCallback) {
-                     ((NameCallback) callbacks[i]).setName(params[0]);
+                     if (params != null) {
+                        ((NameCallback) callbacks[i]).setName(params[0]);
+                     }
                   } else if (callbacks[i] instanceof PasswordCallback) {
-                     ((PasswordCallback) callbacks[i]).setPassword((params[1].toCharArray()));
+                     if (params != null) {
+                        ((PasswordCallback) callbacks[i]).setPassword((params[1].toCharArray()));
+                     }
                   } else {
                      throw new UnsupportedCallbackException(callbacks[i]);
                   }
@@ -68,12 +70,6 @@ public class JaasAuthenticator implements JMXAuthenticator {
             }
          });
          loginContext.login();
-
-          /*  if (subject.getPrincipals().size() == 0) {
-                // there must be some Principals, but which ones required are tested later
-                throw new FailedLoginException("User does not have the required role");
-            }*/
-
          return subject;
       } catch (LoginException e) {
          throw new SecurityException("Authentication failed", e);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/docs/user-manual/en/management.md
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/management.md b/docs/user-manual/en/management.md
index 9587d05..34a2f45 100644
--- a/docs/user-manual/en/management.md
+++ b/docs/user-manual/en/management.md
@@ -404,10 +404,38 @@ using the service url `service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi`
and
 
 You can also configure the connector using the following:
 
--  connector-host The host to expose the agent on
--  connector-port The port to expose the agent on 
--  jmx-realm The jmx realm to use for authentication, defaults to `activemq` to match the
JAAS configuration.
--  object-name The object name to expose the remote connector on, default is `connector:name=rmi`
+-  connector-host 
+   
+   The host to expose the agent on
+-  connector-port 
+   
+   The port to expose the agent on 
+-  jmx-realm 
+   
+   The jmx realm to use for authentication, defaults to `activemq` to match the JAAS configuration.
+-  object-name 
+   
+   The object name to expose the remote connector on, default is `connector:name=rmi`
+-  secured 
+   
+   Whether the connector is secured using SSL
+-  key-store-path 
+   
+   The location of the keystore
+-  key-store-password 
+   
+   The keystore password
+-  key-store-provider 
+   The provider, JKS by default
+-  trust-store-path 
+   
+   The location of the truststore 
+-  trust-store-password 
+   
+   The trustore password
+-  trust-store-provider 
+   
+   The provider, JKS by default
 
 > **Note**
 >

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/examples/features/standard/jmx-ssl/pom.xml
----------------------------------------------------------------------
diff --git a/examples/features/standard/jmx-ssl/pom.xml b/examples/features/standard/jmx-ssl/pom.xml
new file mode 100644
index 0000000..04e7be9
--- /dev/null
+++ b/examples/features/standard/jmx-ssl/pom.xml
@@ -0,0 +1,114 @@
+<?xml version='1.0'?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+   <modelVersion>4.0.0</modelVersion>
+
+   <parent>
+      <groupId>org.apache.activemq.examples.broker</groupId>
+      <artifactId>jms-examples</artifactId>
+      <version>2.4.0-SNAPSHOT</version>
+   </parent>
+
+   <artifactId>jmx-ssl</artifactId>
+   <packaging>jar</packaging>
+   <name>ActiveMQ Artemis JMS "JMX over SSL" Example</name>
+
+   <properties>
+      <activemq.basedir>${project.basedir}/../../../..</activemq.basedir>
+   </properties>
+
+   <dependencies>
+      <dependency>
+         <groupId>org.apache.activemq</groupId>
+         <artifactId>artemis-core-client</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+      <dependency>
+         <groupId>org.apache.activemq</groupId>
+         <artifactId>artemis-jms-client</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+   </dependencies>
+
+   <build>
+      <plugins>
+         <plugin>
+            <groupId>org.apache.activemq</groupId>
+            <artifactId>artemis-maven-plugin</artifactId>
+            <executions>
+               <execution>
+                  <id>create</id>
+                  <goals>
+                     <goal>create</goal>
+                  </goals>
+                  <configuration>
+                     <ignore>${noServer}</ignore>
+                     <javaOptions>-Djava.rmi.server.hostname=localhost</javaOptions>
+                  </configuration>
+               </execution>
+               <execution>
+                  <id>start</id>
+                  <goals>
+                     <goal>cli</goal>
+                  </goals>
+                  <configuration>
+                     <ignore>${noServer}</ignore>
+                     <spawn>true</spawn>
+                     <testURI>tcp://localhost:61616</testURI>
+                     <args>
+                        <param>run</param>
+                     </args>
+                  </configuration>
+               </execution>
+               <execution>
+                  <id>runClient</id>
+                  <goals>
+                     <goal>runClient</goal>
+                  </goals>
+                  <configuration> 
+                     <clientClass>org.apache.activemq.artemis.jms.example.JMXExample</clientClass>
+                  </configuration>
+               </execution>
+               <execution>
+                  <id>stop</id>
+                  <goals>
+                     <goal>cli</goal>
+                  </goals>
+                  <configuration>
+                     <ignore>${noServer}</ignore>
+                     <args>
+                        <param>stop</param>
+                     </args>
+                  </configuration>
+               </execution>
+            </executions>
+            <dependencies>
+               <dependency>
+                  <groupId>org.apache.activemq.examples.broker</groupId>
+                  <artifactId>jmx</artifactId>
+                  <version>${project.version}</version>
+               </dependency>
+            </dependencies>
+         </plugin>
+      </plugins>
+   </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/examples/features/standard/jmx-ssl/readme.html
----------------------------------------------------------------------
diff --git a/examples/features/standard/jmx-ssl/readme.html b/examples/features/standard/jmx-ssl/readme.html
new file mode 100644
index 0000000..ca4e6da
--- /dev/null
+++ b/examples/features/standard/jmx-ssl/readme.html
@@ -0,0 +1,176 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<html>
+  <head>
+    <title>ActiveMQ Artemis JMX SSL Management Example</title>
+    <link rel="stylesheet" type="text/css" href="../../../common/common.css" />
+    <link rel="stylesheet" type="text/css" href="../../../common/prettify.css" />
+    <script type="text/javascript" src="../../../common/prettify.js"></script>
+  </head>
+  <body onload="prettyPrint()">
+     <h1>JMX Management Example</h1>
+
+     <pre>To run the example, simply type <b>mvn verify -Djavax.net.ssl.keyStore=target/server0/etc/activemq.example.keystore
-Djavax.net.ssl.keyStorePassword=activemqexample -Djavax.net.ssl.trustStore=target/server0/etc/activemq.example.truststore
-Djavax.net.ssl.trustStorePassword=activemqexample</b> from this directory, <br>or
add <b>-PnoServer</b> if you want to start and create the server manually.</pre>
+
+     <p>This example shows how to manage ActiveMQ Artemis using <a href="http://java.sun.com/javase/technologies/core/mntr-mgmt/javamanagement/">JMX
using SSL</a></p>
+
+     <h2>Example configuration</h2>
+
+     <p>ActiveMQ Artemis exposes its managed resources by default on the platform MBeanServer.</p>
+     <p>To access this MBeanServer remotely, add the following to the management.xml
configuration:
+         <pre class="prettyprint">
+             <code><connector connector-port="1099" connector-host="localhost"/></code>
+        </pre>
+        <p>With these properties, ActiveMQ Artemis server will be manageable remotely
using standard JMX URL on port <code>1099</code>.</p>
+     </p>
+
+     <h2>Example step-by-step</h2>
+     <ol>
+        <li>First we need to get an initial context so we can look-up the JMS connection
factory and destination objects from JNDI. This initial context will get its properties from
<a href="server0/client-jndi.properties">client-jndi.properties</a></li>
+        <pre class="prettyprint">
+            <code>InitialContext initialContext = getContext(0);</code>
+        </pre>
+
+        <li>We look up the JMS queue object from JNDI</li>
+        <pre class="prettyprint">
+            <code>Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");</code>
+        </pre>
+
+        <li>We look up the JMS connection factory object from JNDI</li>
+        <pre class="prettyprint">
+            <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code>
+        </pre>
+
+        <li>We create a JMS connection</li>
+        <pre class="prettyprint">
+            <code>connection = cf.createConnection();</code>
+        </pre>
+
+        <li>We create a JMS session. The session is created as non transacted and will
auto acknowledge messages.</li>
+        <pre class="prettyprint">
+            <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
+        </pre>
+
+        <li>We create a JMS message producer on the session. This will be used to send
the messages.</li>
+        <pre class="prettyprint">
+            <code>MessageProducer messageProducer = session.createProducer(topic);</code>
+       </pre>
+
+        <li>We create a JMS text message that we are going to send.</li>
+        <pre class="prettyprint">
+            <code>TextMessage message = session.createTextMessage("This is a text message");</code>
+        </pre>
+
+        <li>We send message to the queue</li>
+        <pre class="prettyprint">
+            <code>messageProducer.send(message);</code>
+        </pre>
+
+        <p><em>Now that we have a message in the queue, we will manage the queue
by retrieving the number of messages in the queue
+            (i.e. 1) and by removing the message which has been sent in step 8.</em></p>
+
+        <li>We retrieve the <code>ObjectName</code> corresponding to the
queue using a helper class <code>ObjectNameBuilder</code></li>
+        <pre class="prettyprint">
+              <code>ObjectName on = ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queue.getQueueName());</code>
+        </pre>
+
+        <li>We create a JMX Connector to connect to the server's MBeanServer using
the <a href="http://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html#gdevg">standard
JMX service URL</a></li>
+        <pre class="prettyprint">
+            <code>JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL),
new HashMap());</code>
+        </pre>
+
+        <li>We retrieve a <code>MBeanServerConnection</code> from the JMX
connector</li>
+        <pre class="prettyprint">
+           <code>TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);</code>
+        </pre>
+
+        <li>We create a <code>JMSQueueControl</code> proxy to manage the
queue on the server</li>
+        <pre class="prettyprint">
+            <code>JMSQueueControl queueControl = (JMSQueueControl)MBeanServerInvocationHandler.newProxyInstance(mbsc,
+                                                                                        
     on,
+                                                                                        
     JMSQueueControl.class,
+                                                                                        
     false);
+             </code>
+        </pre>
+
+        <li>We use this mbean proxy to retrieve the number of messages in the queue
using the <code>getMessageCount</code> method</li>
+        <pre class="prettyprint">
+            <code>System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount()
+ " messages");</code>
+        </pre>
+
+        <li>We will now remove the message sent at step 8 using the <code>removeMessage</code>
method with the JMS Message ID of the message</li>
+        <pre class="prettyprint">
+            <code>System.out.println("message has been removed: " + queueControl.removeMessage(message.getJMSMessageID()));</code>
+        </pre>
+
+        <li>We use again the mbean proxy to retrieve the number of messages. This time,
it will display <code>0</code> messages</li>
+        <pre class="prettyprint">
+            <code>System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount()
+ " messages");</code>
+        </pre>
+
+        <li>Now we have finish the management operations, we close the JMX connector</li>
+        <pre class="prettyprint">
+            <code>connector.close()</code>
+        </pre>
+
+        <p><em>We will now try to consume the message sent to the queue but it
won't be there: it has been removed by the management operation</em></p>
+
+        <li>We create a JMS message consumer on the queue</li>
+        <pre class="prettyprint">
+            <code>MessageConsumer messageConsumer = session.createConsumer(queue);</code>
+        </pre>
+
+        <li>We start the connection. In order for delivery to occur on any consumers
or subscribers on a connection, the connection must be started</li>
+        <pre class="prettyprint">
+            <code>connection.start();</code>
+        </pre>
+
+        <li>We try to receive a message from the queue. Since there is none, the call
will timeout after 5000ms and messageReceived will be null
+        </li>
+        <pre class="prettyprint">
+            <code>TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
+            System.out.println("Received message: " + messageReceived);</code>
+        </pre>
+
+        <li>And finally, <b>always</b> remember to close your JMS connections
and resources after use, in a <code>finally</code> block. Closing a JMS connection
will automatically close all of its sessions, consumers, producer and browser objects</li>
+
+        <pre class="prettyprint">
+           <code>finally
+           {
+              if (initialContext != null)
+              {
+                initialContext.close();
+              }
+              if (connection != null)
+              {
+                 connection.close();
+              }
+           }</code>
+        </pre>
+     </ol>
+
+     <h2>More information</h2>
+
+     <ul>
+        <li>User Manual's <a href="../../../docs/user-manual/en/html_single/index.html#management.jmx">Using
Management Via JMX chapter</a></li>
+        <li><a href="http://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html">Java
management guide</a></li>
+     </ul>
+  </body>
+</html>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/examples/features/standard/jmx-ssl/src/main/java/org/apache/activemq/artemis/jms/example/JMXExample.java
----------------------------------------------------------------------
diff --git a/examples/features/standard/jmx-ssl/src/main/java/org/apache/activemq/artemis/jms/example/JMXExample.java
b/examples/features/standard/jmx-ssl/src/main/java/org/apache/activemq/artemis/jms/example/JMXExample.java
new file mode 100644
index 0000000..9223a5e
--- /dev/null
+++ b/examples/features/standard/jmx-ssl/src/main/java/org/apache/activemq/artemis/jms/example/JMXExample.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.jms.example;
+
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+import javax.naming.InitialContext;
+import java.util.HashMap;
+
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
+import org.apache.activemq.artemis.api.core.management.QueueControl;
+import org.apache.activemq.artemis.jms.client.ActiveMQTextMessage;
+
+/**
+ * An example that shows how to manage ActiveMQ Artemis using JMX.
+ */
+public class JMXExample {
+
+   private static final String JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
+
+   public static void main(final String[] args) throws Exception {
+      QueueConnection connection = null;
+      InitialContext initialContext = null;
+      try {
+         // Step 1. Create an initial context to perform the JNDI lookup.
+         initialContext = new InitialContext();
+
+         // Step 2. Perfom a lookup on the queue
+         Queue queue = (Queue) initialContext.lookup("queue/exampleQueue");
+
+         // Step 3. Perform a lookup on the Connection Factory
+         QueueConnectionFactory cf = (QueueConnectionFactory) initialContext.lookup("ConnectionFactory");
+
+         // Step 4.Create a JMS Connection
+         connection = cf.createQueueConnection();
+
+         // Step 5. Create a JMS Session
+         QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         // Step 6. Create a JMS Message Producer
+         MessageProducer producer = session.createProducer(queue);
+
+         // Step 7. Create a Text Message
+         TextMessage message = session.createTextMessage("This is a text message");
+         System.out.println("Sent message: " + message.getText());
+
+         // Step 8. Send the Message
+         producer.send(message);
+
+         // Step 9. Retrieve the ObjectName of the queue. This is used to identify the server
resources to manage
+         ObjectName on = ObjectNameBuilder.DEFAULT.getQueueObjectName(SimpleString.toSimpleString(queue.getQueueName()),
SimpleString.toSimpleString(queue.getQueueName()), RoutingType.ANYCAST);
+
+         // Step 10. Create JMX Connector to connect to the server's MBeanServer
+         //we dont actually need credentials as the guest login i sused but this is how its
done
+         HashMap env = new HashMap();
+         String[] creds = {"guest", "guest"};
+         env.put(JMXConnector.CREDENTIALS, creds);
+
+         JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMXExample.JMX_URL),
env);
+
+         // Step 11. Retrieve the MBeanServerConnection
+         MBeanServerConnection mbsc = connector.getMBeanServerConnection();
+
+         // Step 12. Create a QueueControl proxy to manage the queue on the server
+         QueueControl queueControl = MBeanServerInvocationHandler.newProxyInstance(mbsc,
on, QueueControl.class, false);
+         // Step 13. Display the number of messages in the queue
+         System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount()
+ " messages");
+
+         // Step 14. Remove the message sent at step #8
+         System.out.println("message has been removed: " + queueControl.removeMessage(((ActiveMQTextMessage)
message).getCoreMessage().getMessageID()));
+
+         // Step 15. Display the number of messages in the queue
+         System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount()
+ " messages");
+
+         // Step 16. We close the JMX connector
+         connector.close();
+
+         // Step 17. Create a JMS Message Consumer on the queue
+         MessageConsumer messageConsumer = session.createConsumer(queue);
+
+         // Step 18. Start the Connection
+         connection.start();
+
+         // Step 19. Trying to receive a message. Since the only message in the queue was
removed by a management
+         // operation, there is none to consume.
+         // The call will timeout after 5000ms and messageReceived will be null
+         TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
+         System.out.println("Received message: " + messageReceived);
+      } finally {
+         // Step 20. Be sure to close the resources!
+         if (initialContext != null) {
+            initialContext.close();
+         }
+         if (connection != null) {
+            connection.close();
+         }
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/activemq.example.keystore
----------------------------------------------------------------------
diff --git a/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/activemq.example.keystore
b/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/activemq.example.keystore
new file mode 100644
index 0000000..50de681
Binary files /dev/null and b/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/activemq.example.keystore
differ

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/activemq.example.truststore
----------------------------------------------------------------------
diff --git a/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/activemq.example.truststore
b/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/activemq.example.truststore
new file mode 100644
index 0000000..129391a
Binary files /dev/null and b/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/activemq.example.truststore
differ

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/broker.xml
----------------------------------------------------------------------
diff --git a/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/broker.xml
b/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/broker.xml
new file mode 100644
index 0000000..7576376
--- /dev/null
+++ b/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/broker.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+--><configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd">
+
+   
+
+   <core xmlns="urn:activemq:core">
+
+      <bindings-directory>./data/messaging/bindings</bindings-directory>
+
+      <journal-directory>./data/messaging/journal</journal-directory>
+
+      <large-messages-directory>./data/messaging/largemessages</large-messages-directory>
+
+      <paging-directory>./data/messaging/paging</paging-directory>
+
+
+      <!-- true to expose ActiveMQ Artemis resources through JMX -->
+      <jmx-management-enabled>true</jmx-management-enabled>
+
+      <!-- Acceptors -->
+      <acceptors>
+         <acceptor name="netty">tcp://localhost:61616</acceptor>
+      </acceptors>
+
+      <!-- Other config -->
+
+      <security-settings>
+         <!--security for example queue-->
+         <security-setting match="exampleQueue">
+            <permission roles="guest" type="createDurableQueue"/>
+            <permission roles="guest" type="deleteDurableQueue"/>
+            <permission roles="guest" type="createNonDurableQueue"/>
+            <permission roles="guest" type="deleteNonDurableQueue"/>
+            <permission roles="guest" type="consume"/>
+            <permission roles="guest" type="send"/>
+         </security-setting>
+      </security-settings>
+
+   <addresses>
+         <address name="exampleQueue">
+            <anycast>
+               <queue name="exampleQueue"/>
+            </anycast>
+         </address>
+      </addresses>
+   </core>
+</configuration>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/management.xml
----------------------------------------------------------------------
diff --git a/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/management.xml
b/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/management.xml
new file mode 100644
index 0000000..9d31f6a
--- /dev/null
+++ b/examples/features/standard/jmx-ssl/src/main/resources/activemq/server0/management.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements. See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License. You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<management-context xmlns="http://activemq.org/schema">
+   <connector
+         connector-port="1099"
+         connector-host="localhost"
+         secured="true"
+         key-store-path="${data.dir}/../etc/activemq.example.keystore"
+         key-store-password="activemqexample"
+         trust-store-path="${data.dir}/../etc/activemq.example.truststore"
+         trust-store-password="activemqexample"/>
+   <authorisation>
+      <whitelist>
+         <entry domain="hawtio"/>
+      </whitelist>
+      <default-access>
+         <access method="list*" roles="view,update,amq,guest"/>
+         <access method="get*" roles="view,update,amq,guest"/>
+         <access method="is*" roles="view,update,amq,guest"/>
+         <access method="set*" roles="update,amq,guest"/>
+         <access method="*" roles="amq,guest"/>
+      </default-access>
+      <role-access>
+         <match domain="org.apache.activemq.apache">
+            <access method="list*" roles="view,update,amq,guest"/>
+            <access method="get*" roles="view,update,amq,guest"/>
+            <access method="is*" roles="view,update,amq,guest"/>
+            <access method="set*" roles="update,amq,guest"/>
+            <access method="*" roles="amq,guest"/>
+         </match>
+         <!--example of how to configure a specific object-->
+         <!--<match domain="org.apache.activemq.apache" key="subcomponent=queues">
+            <access method="list*" roles="view,update,amq"/>
+            <access method="get*" roles="view,update,amq"/>
+            <access method="is*" roles="view,update,amq"/>
+            <access method="set*" roles="update,amq"/>
+            <access method="*" roles="amq"/>
+         </match>-->
+      </role-access>
+   </authorisation>
+</management-context>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/examples/features/standard/jmx-ssl/src/main/resources/jndi.properties
----------------------------------------------------------------------
diff --git a/examples/features/standard/jmx-ssl/src/main/resources/jndi.properties b/examples/features/standard/jmx-ssl/src/main/resources/jndi.properties
new file mode 100644
index 0000000..93537c4
--- /dev/null
+++ b/examples/features/standard/jmx-ssl/src/main/resources/jndi.properties
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
+connectionFactory.ConnectionFactory=tcp://localhost:61616
+queue.queue/exampleQueue=exampleQueue

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/examples/features/standard/jmx/pom.xml
----------------------------------------------------------------------
diff --git a/examples/features/standard/jmx/pom.xml b/examples/features/standard/jmx/pom.xml
index f78c1f3..bca7105 100644
--- a/examples/features/standard/jmx/pom.xml
+++ b/examples/features/standard/jmx/pom.xml
@@ -61,6 +61,7 @@ under the License.
                   </goals>
                   <configuration>
                      <ignore>${noServer}</ignore>
+                     <javaOptions>-Djava.rmi.server.hostname=localhost</javaOptions>
                   </configuration>
                </execution>
                <execution>
@@ -69,7 +70,6 @@ under the License.
                      <goal>cli</goal>
                   </goals>
                   <configuration>
-                     <debug>true</debug>
                      <ignore>${noServer}</ignore>
                      <spawn>true</spawn>
                      <testURI>tcp://localhost:61616</testURI>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/examples/features/standard/jmx/readme.html
----------------------------------------------------------------------
diff --git a/examples/features/standard/jmx/readme.html b/examples/features/standard/jmx/readme.html
index fe981c6..7106e34 100644
--- a/examples/features/standard/jmx/readme.html
+++ b/examples/features/standard/jmx/readme.html
@@ -36,9 +36,8 @@ under the License.
      <p>ActiveMQ Artemis exposes its managed resources by default on the platform MBeanServer.</p>
      <p>To access this MBeanServer remotely, add the following to the management.xml
configuration:
          <pre class="prettyprint">
-             <code><connector connector-port="1099" connector-host="127.0.0.1"/></code>
+             <code><connector connector-port="1099" connector-host="localhost"/></code>
         </pre>
-        <p>If the example does not work then try changing the host to the ip address
of the machine running this example on</p>
         <p>With these properties, ActiveMQ Artemis server will be manageable remotely
using standard JMX URL on port <code>1099</code>.</p>
      </p>
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/examples/features/standard/jmx/src/main/java/org/apache/activemq/artemis/jms/example/JMXExample.java
----------------------------------------------------------------------
diff --git a/examples/features/standard/jmx/src/main/java/org/apache/activemq/artemis/jms/example/JMXExample.java
b/examples/features/standard/jmx/src/main/java/org/apache/activemq/artemis/jms/example/JMXExample.java
index b59f419..9223a5e 100644
--- a/examples/features/standard/jmx/src/main/java/org/apache/activemq/artemis/jms/example/JMXExample.java
+++ b/examples/features/standard/jmx/src/main/java/org/apache/activemq/artemis/jms/example/JMXExample.java
@@ -79,6 +79,7 @@ public class JMXExample {
          ObjectName on = ObjectNameBuilder.DEFAULT.getQueueObjectName(SimpleString.toSimpleString(queue.getQueueName()),
SimpleString.toSimpleString(queue.getQueueName()), RoutingType.ANYCAST);
 
          // Step 10. Create JMX Connector to connect to the server's MBeanServer
+         //we dont actually need credentials as the guest login i sused but this is how its
done
          HashMap env = new HashMap();
          String[] creds = {"guest", "guest"};
          env.put(JMXConnector.CREDENTIALS, creds);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/examples/features/standard/jmx/src/main/resources/activemq/server0/management.xml
----------------------------------------------------------------------
diff --git a/examples/features/standard/jmx/src/main/resources/activemq/server0/management.xml
b/examples/features/standard/jmx/src/main/resources/activemq/server0/management.xml
index 182bb1f..86d29a1 100644
--- a/examples/features/standard/jmx/src/main/resources/activemq/server0/management.xml
+++ b/examples/features/standard/jmx/src/main/resources/activemq/server0/management.xml
@@ -16,7 +16,7 @@
   ~ limitations under the License.
   -->
 <management-context xmlns="http://activemq.org/schema">
-   <connector connector-port="1099" connector-host="127.0.0.1"/>
+   <connector connector-port="1099" connector-host="localhost"/>
    <authorisation>
       <whitelist>
          <entry domain="hawtio"/>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/examples/features/standard/message-counters/pom.xml
----------------------------------------------------------------------
diff --git a/examples/features/standard/message-counters/pom.xml b/examples/features/standard/message-counters/pom.xml
index 8f745a3..d30d90b 100644
--- a/examples/features/standard/message-counters/pom.xml
+++ b/examples/features/standard/message-counters/pom.xml
@@ -61,6 +61,7 @@ under the License.
                   </goals>
                   <configuration>
                      <ignore>${noServer}</ignore>
+                     <javaOptions>-Djava.rmi.server.hostname=localhost</javaOptions>
                   </configuration>
                </execution>
                <execution>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a64d7c2e/examples/features/standard/message-counters/src/main/java/org/apache/activemq/artemis/jms/example/MessageCounterExample.java
----------------------------------------------------------------------
diff --git a/examples/features/standard/message-counters/src/main/java/org/apache/activemq/artemis/jms/example/MessageCounterExample.java
b/examples/features/standard/message-counters/src/main/java/org/apache/activemq/artemis/jms/example/MessageCounterExample.java
index 16947d1..0a8dadc 100644
--- a/examples/features/standard/message-counters/src/main/java/org/apache/activemq/artemis/jms/example/MessageCounterExample.java
+++ b/examples/features/standard/message-counters/src/main/java/org/apache/activemq/artemis/jms/example/MessageCounterExample.java
@@ -75,6 +75,7 @@ public class MessageCounterExample {
 
          // Step 7. Use JMX to retrieve the message counters using the JMSQueueControl
          ObjectName on = ObjectNameBuilder.DEFAULT.getQueueObjectName(SimpleString.toSimpleString(queue.getQueueName()),
SimpleString.toSimpleString(queue.getQueueName()), RoutingType.ANYCAST);
+         //we dont actually need credentials as the guest login i sused but this is how its
done
          HashMap env = new HashMap();
          String[] creds = {"guest", "guest"};
          env.put(JMXConnector.CREDENTIALS, creds);


Mime
View raw message