[jboss-cvs] JBoss Messaging SVN: r6748 - in trunk: examples/jms and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 12 15:43:17 EDT 2009
Author: jmesnil
Date: 2009-05-12 15:43:17 -0400 (Tue, 12 May 2009)
New Revision: 6748
Added:
trunk/examples/jms/jaas/
trunk/examples/jms/jaas/build.xml
trunk/examples/jms/jaas/server0/
trunk/examples/jms/jaas/server0/client-jndi.properties
trunk/examples/jms/jaas/server0/jbm-configuration.xml
trunk/examples/jms/jaas/server0/jbm-jboss-beans.xml
trunk/examples/jms/jaas/server0/jbm-jms.xml
trunk/examples/jms/jaas/server0/jbm-queues.xml
trunk/examples/jms/jaas/src/
trunk/examples/jms/jaas/src/org/
trunk/examples/jms/jaas/src/org/jboss/
trunk/examples/jms/jaas/src/org/jboss/jms/
trunk/examples/jms/jaas/src/org/jboss/jms/example/
trunk/examples/jms/jaas/src/org/jboss/jms/example/ExampleCallbackHandler.java
trunk/examples/jms/jaas/src/org/jboss/jms/example/ExampleConfiguration.java
trunk/examples/jms/jaas/src/org/jboss/jms/example/ExampleLoginModule.java
trunk/examples/jms/jaas/src/org/jboss/jms/example/JAASExample.java
Modified:
trunk/.classpath
Log:
JAAS example
Modified: trunk/.classpath
===================================================================
--- trunk/.classpath 2009-05-12 17:49:33 UTC (rev 6747)
+++ trunk/.classpath 2009-05-12 19:43:17 UTC (rev 6748)
@@ -34,6 +34,7 @@
<classpathentry kind="src" path="examples/jms/http-transport/src"/>
<classpathentry kind="src" path="examples/jms/instantiate-connection-factory/src"/>
<classpathentry kind="src" path="examples/jms/interceptor/src"/>
+ <classpathentry kind="src" path="examples/jms/jaas/src"/>
<classpathentry kind="src" path="examples/jms/jmx/src"/>
<classpathentry kind="src" path="examples/jms/large-message/src"/>
<classpathentry kind="src" path="examples/jms/last-value-queue/src"/>
Property changes on: trunk/examples/jms/jaas
___________________________________________________________________
Name: svn:ignore
+ build
logs
Added: trunk/examples/jms/jaas/build.xml
===================================================================
--- trunk/examples/jms/jaas/build.xml (rev 0)
+++ trunk/examples/jms/jaas/build.xml 2009-05-12 19:43:17 UTC (rev 6748)
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+ <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+ ]>
+
+<!-- =========================================================================================== -->
+<!-- -->
+<!-- JBoss, Home of Professional Open Source -->
+<!-- Copyright 2005, JBoss Inc., and individual contributors as indicated -->
+<!-- by the @authors tag. See the copyright.txt in the distribution for a -->
+<!-- full listing of individual contributors. -->
+<!-- -->
+<!-- This is free software; you can redistribute it and/or modify it -->
+<!-- under the terms of the GNU Lesser General Public License as -->
+<!-- published by the Free Software Foundation; either version 2.1 of -->
+<!-- the License, or (at your option) any later version. -->
+<!-- -->
+<!-- This software is distributed in the hope that it will be useful, -->
+<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
+<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -->
+<!-- Lesser General Public License for more details. -->
+<!-- -->
+<!-- You should have received a copy of the GNU Lesser General Public -->
+<!-- License along with this software; if not, write to the Free -->
+<!-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA -->
+<!-- 02110-1301 USA, or see the FSF site: http://www.fsf.org. -->
+<!-- -->
+<!-- =========================================================================================== -->
+
+
+<project default="run" name="JBoss Messaging JAAS Queue Example">
+
+ <import file="../common/build.xml"/>
+
+ <target name="run">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.jboss.jms.example.JAASExample"/>
+ </antcall>
+ </target>
+
+ <target name="runRemote">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.jboss.jms.example.QueueExample"/>
+ <param name="jbm.example.runServer" value="false"/>
+ </antcall>
+ </target>
+
+</project>
Property changes on: trunk/examples/jms/jaas/server0
___________________________________________________________________
Name: svn:ignore
+ data
logs
Added: trunk/examples/jms/jaas/server0/client-jndi.properties
===================================================================
--- trunk/examples/jms/jaas/server0/client-jndi.properties (rev 0)
+++ trunk/examples/jms/jaas/server0/client-jndi.properties 2009-05-12 19:43:17 UTC (rev 6748)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Added: trunk/examples/jms/jaas/server0/jbm-configuration.xml
===================================================================
--- trunk/examples/jms/jaas/server0/jbm-configuration.xml (rev 0)
+++ trunk/examples/jms/jaas/server0/jbm-configuration.xml 2009-05-12 19:43:17 UTC (rev 6748)
@@ -0,0 +1,26 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-configuration.xsd">
+
+ <!-- Connectors -->
+
+ <connectors>
+ <connector name="netty-connector">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+ <param key="jbm.remoting.netty.port" value="5446" type="Integer"/>
+ </connector>
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <acceptor name="netty-acceptor">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+ <param key="jbm.remoting.netty.port" value="5446" type="Integer"/>
+ </acceptor>
+ </acceptors>
+
+ <!-- Other config -->
+
+ <journal-min-files>2</journal-min-files>
+
+</configuration>
Added: trunk/examples/jms/jaas/server0/jbm-jboss-beans.xml
===================================================================
--- trunk/examples/jms/jaas/server0/jbm-jboss-beans.xml (rev 0)
+++ trunk/examples/jms/jaas/server0/jbm-jboss-beans.xml 2009-05-12 19:43:17 UTC (rev 6748)
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="Naming" class="org.jnp.server.NamingBeanImpl"/>
+
+ <!-- JNDI server. Disable this if you don't want JNDI -->
+ <bean name="JNDIServer" class="org.jnp.server.Main">
+ <property name="namingInfo">
+ <inject bean="Naming"/>
+ </property>
+ <property name="port">1099</property>
+ <property name="bindAddress">localhost</property>
+ <property name="rmiPort">1098</property>
+ <property name="rmiBindAddress">localhost</property>
+ </bean>
+
+ <!-- MBean server -->
+ <bean name="MBeanServer" class="javax.management.MBeanServer">
+ <constructor factoryClass="java.lang.management.ManagementFactory"
+ factoryMethod="getPlatformMBeanServer"/>
+ </bean>
+
+ <!-- The core configuration -->
+ <bean name="Configuration" class="org.jboss.messaging.core.config.impl.FileConfiguration"/>
+
+ <!-- The security manager using JAAS -->
+ <bean name="JBMSecurityManager" class="org.jboss.messaging.integration.security.JAASSecurityManager">
+ <property name="configurationName">org.jboss.jms.example.ExampleLoginModule</property>
+ <property name="configuration">
+ <inject bean="ExampleConfiguration"/>
+ </property>
+ <property name="callbackHandler">
+ <inject bean="ExampleCallbackHandler" />
+ </property>
+ </bean>
+
+ <bean name="ExampleConfiguration" class="org.jboss.jms.example.ExampleConfiguration">
+ <constructor>
+ <parameter>org.jboss.jms.example.ExampleLoginModule</parameter>
+ <parameter>
+ <map class="java.util.HashMap" keyClass="java.lang.String"
+ valueClass="java.lang.String">
+ <entry>
+ <key>user</key>
+ <value>jboss</value>
+ </entry>
+ <entry>
+ <key>pass</key>
+ <value>redhat</value>
+ </entry>
+ <entry>
+ <key>role</key>
+ <value>guest</value>
+ </entry>
+ </map>
+ </parameter>
+ </constructor>
+ </bean>
+
+ <bean name="ExampleCallbackHandler" class="org.jboss.jms.example.ExampleCallbackHandler" />
+
+ <!-- The core server -->
+ <bean name="MessagingServer" class="org.jboss.messaging.core.server.impl.MessagingServerImpl">
+ <start ignored="true"/>
+ <stop ignored="true"/>
+ <constructor>
+ <parameter>
+ <inject bean="Configuration"/>
+ </parameter>
+ <parameter>
+ <inject bean="MBeanServer"/>
+ </parameter>
+ <parameter>
+ <inject bean="JBMSecurityManager"/>
+ </parameter>
+ </constructor>
+ </bean>
+
+ <!-- The JMS server -->
+ <bean name="JMSServerManager" class="org.jboss.messaging.jms.server.impl.JMSServerManagerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="MessagingServer"/>
+ </parameter>
+ </constructor>
+ </bean>
+
+</deployment>
Added: trunk/examples/jms/jaas/server0/jbm-jms.xml
===================================================================
--- trunk/examples/jms/jaas/server0/jbm-jms.xml (rev 0)
+++ trunk/examples/jms/jaas/server0/jbm-jms.xml 2009-05-12 19:43:17 UTC (rev 6748)
@@ -0,0 +1,17 @@
+<deployment xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-jms.xsd ">
+ <!--the connection factory used by the example-->
+ <connection-factory name="ConnectionFactory">
+ <connector-ref connector-name="netty-connector"/>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+ </connection-factory>
+
+ <!--the queue used by the example-->
+ <queue name="exampleQueue">
+ <entry name="/queue/exampleQueue"/>
+ </queue>
+
+</deployment>
Added: trunk/examples/jms/jaas/server0/jbm-queues.xml
===================================================================
--- trunk/examples/jms/jaas/server0/jbm-queues.xml (rev 0)
+++ trunk/examples/jms/jaas/server0/jbm-queues.xml 2009-05-12 19:43:17 UTC (rev 6748)
@@ -0,0 +1,17 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-configuration.xsd ">
+
+ <security-settings>
+ <!--security for example queue-->
+ <security-setting match="jms.queue.exampleQueue">
+ <permission type="createDurableQueue" roles="guest"/>
+ <permission type="deleteDurableQueue" roles="guest"/>
+ <permission type="createTempQueue" roles="guest"/>
+ <permission type="deleteTempQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+</configuration>
Added: trunk/examples/jms/jaas/src/org/jboss/jms/example/ExampleCallbackHandler.java
===================================================================
--- trunk/examples/jms/jaas/src/org/jboss/jms/example/ExampleCallbackHandler.java (rev 0)
+++ trunk/examples/jms/jaas/src/org/jboss/jms/example/ExampleCallbackHandler.java 2009-05-12 19:43:17 UTC (rev 6748)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.jms.example;
+
+import java.io.IOException;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+/**
+ * A ExampleCallbackHandler
+ *
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ */
+public class ExampleCallbackHandler implements CallbackHandler
+{
+
+ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
+ {
+ // do nothing, authentication is done
+ // by passing credentials directly to the ExampleLoginModule
+ }
+}
Added: trunk/examples/jms/jaas/src/org/jboss/jms/example/ExampleConfiguration.java
===================================================================
--- trunk/examples/jms/jaas/src/org/jboss/jms/example/ExampleConfiguration.java (rev 0)
+++ trunk/examples/jms/jaas/src/org/jboss/jms/example/ExampleConfiguration.java 2009-05-12 19:43:17 UTC (rev 6748)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.jms.example;
+
+import java.util.Map;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.security.auth.login.Configuration;
+
+/**
+ * A ExampleConfiguration
+ *
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ */
+public class ExampleConfiguration extends Configuration
+{
+ private final Map<String, ?> options;
+
+ private final String loginModuleName;
+
+ public ExampleConfiguration(String loginModuleName, Map<String, ?> options)
+ {
+ this.loginModuleName = loginModuleName;
+ this.options = options;
+ }
+
+ @Override
+ public AppConfigurationEntry[] getAppConfigurationEntry(final String name)
+ {
+ AppConfigurationEntry entry = new AppConfigurationEntry(loginModuleName,
+ AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
+ options);
+ return new AppConfigurationEntry[]{entry};
+ }
+
+ @Override
+ public void refresh()
+ {
+ }
+}
Added: trunk/examples/jms/jaas/src/org/jboss/jms/example/ExampleLoginModule.java
===================================================================
--- trunk/examples/jms/jaas/src/org/jboss/jms/example/ExampleLoginModule.java (rev 0)
+++ trunk/examples/jms/jaas/src/org/jboss/jms/example/ExampleLoginModule.java 2009-05-12 19:43:17 UTC (rev 6748)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.jms.example;
+
+import java.security.Principal;
+import java.security.acl.Group;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+
+import org.jboss.messaging.integration.security.JAASSecurityManager;
+import org.jboss.security.SimpleGroup;
+
+/**
+ * A ExampleLoginModule
+ *
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ */
+public class ExampleLoginModule implements LoginModule
+{
+ private Map<String, ?> options;
+
+ private Subject subject;
+
+ public ExampleLoginModule()
+ {
+ }
+
+ public boolean abort() throws LoginException
+ {
+ return true;
+ }
+
+ public boolean commit() throws LoginException
+ {
+ return true;
+ }
+
+ public void initialize(Subject subject,
+ CallbackHandler callbackHandler,
+ Map<String, ?> sharedState,
+ Map<String, ?> options)
+ {
+ this.subject = subject;
+ // the credentials are passed directly to the
+ // login module through the options user, pass, role
+ this.options = options;
+ }
+
+ public boolean login() throws LoginException
+ {
+ Iterator<char[]> iterator = subject.getPrivateCredentials(char[].class).iterator();
+ char[] passwordChars = iterator.next();
+ String password = new String(passwordChars);
+ Iterator<Principal> iterator2 = subject.getPrincipals().iterator();
+ String user = iterator2.next().getName();
+
+ boolean authenticated = user.equals(options.get("user")) && password.equals(options.get("pass"));
+
+ if (authenticated)
+ {
+ Group roles = new SimpleGroup("Roles");
+ roles.addMember(new JAASSecurityManager.SimplePrincipal((String)options.get("role")));
+ subject.getPrincipals().add(roles);
+ }
+ System.out.format("JAAS authentication >>> user=%s, password=%s\n", user, password);
+ return authenticated;
+
+ }
+
+ public Subject getSubject()
+ {
+ return subject;
+ }
+
+ public boolean logout() throws LoginException
+ {
+ return true;
+ }
+
+}
Added: trunk/examples/jms/jaas/src/org/jboss/jms/example/JAASExample.java
===================================================================
--- trunk/examples/jms/jaas/src/org/jboss/jms/example/JAASExample.java (rev 0)
+++ trunk/examples/jms/jaas/src/org/jboss/jms/example/JAASExample.java 2009-05-12 19:43:17 UTC (rev 6748)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jms.example;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+
+/**
+ * A simple JMS Queue example that creates a producer and consumer on a queue and sends then receives a message.
+ * The messaging server is configured to use JAAS.
+ *
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ */
+public class JAASExample extends JMSExample
+{
+ public static void main(String[] args)
+ {
+ new JAASExample().run(args);
+ }
+
+ public boolean runExample() throws Exception
+ {
+ Connection connection = null;
+ InitialContext initialContext = null;
+ try
+ {
+ //Step 1. Create an initial context to perform the JNDI lookup.
+ initialContext = getContext(0);
+
+ //Step 2. Perfom a lookup on the queue
+ Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
+
+ //Step 3. Perform a lookup on the Connection Factory
+ ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
+
+ //Step 4.Create a JMS Connection with user "jboss" and password "redhat"
+ connection = cf.createConnection("jboss", "redhat");
+
+ //Step 5. Create a JMS Session
+ Session session = connection.createSession(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. Create a JMS Message Consumer
+ MessageConsumer messageConsumer = session.createConsumer(queue);
+
+ //Step 10. Start the Connection
+ connection.start();
+
+ //Step 11. Receive the message
+ TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
+
+ System.out.println("Received message: " + messageReceived.getText());
+
+ return true;
+ }
+ finally
+ {
+ //Step 12. Be sure to close our JMS resources!
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ if(connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+
+}
More information about the jboss-cvs-commits
mailing list