JBOSS5.1
JMS
セキュリティ
JMSのセキュリティ
問題
セキュリティ設定されているトピックで、
durableSubscriberを認証されていないユーザで作成使用とするとExceptionが出る。
対処1
動的トピック作成をする。
JBOSSのMBeanを使用して、動的にトピック作成をする。
そうすると、セキュリティ設定の無いトピックができる。
InitialContext context = new InitialContext();
MBeanServerConnection mBeanServer
= (MBeanServerConnection)context.lookup("jmx/invoker/RMIAdaptor");
ObjectName serverObjectName = new ObjectName("jboss.messaging:service=ServerPeer");
String topicName = "newTopic";
mBeanServer.invoke(serverObjectName, "deployTopic",
new Object[] {topicName, "topic/" + topicName},
new String[] {"java.lang.String", "java.lang.String"});
対処2
セキュリティ設定をしないで、トピックを作成する。
JBOSSに配置するトピック設定ファイルから、セキュリティ設定を削除する。
%JBOSS_HOME%\server\XXX\deploy\messaging\トピック設定ファイル.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Messaging Example Destinations
-->
<server>
<mbean code="org.jboss.jms.server.destination.TopicService"
name="jboss.messaging.destination:service=Topic,name=testTopic"
xmbean-dd="xmdesc/Topic-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends>jboss.messaging:service=PostOffice</depends>
<attribute name="SecurityConfig"> ←このSecurityConfigを削除する。
<security>
<role name="publisher" read="true" write="true" create="false"/>
<role name="noacc" read="false" write="false" create="false"/>
</security>
</attribute>
</mbean>
</server>
対処3
JMSセキュリティの認証ユーザを作成する。
JBOSSに配置するトピック設定ファイルに、セキュリティ認証できるロールを設定する。
%JBOSS_HOME%\server\XXX\deploy\messaging\トピック設定ファイル.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Messaging Example Destinations
-->
<server>
<mbean code="org.jboss.jms.server.destination.TopicService"
name="jboss.messaging.destination:service=Topic,name=testTopic"
xmbean-dd="xmdesc/Topic-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends>jboss.messaging:service=PostOffice</depends>
<attribute name="SecurityConfig"> ←このSecurityConfigを削除する。
<security>
<role name="test-role" read="true" write="true" create="false"/>←test-roleを追加(読み書き作成できるロール)
<role name="publisher" read="true" write="true" create="false"/>
<role name="noacc" read="false" write="false" create="false"/>
</security>
</attribute>
</mbean>
</server>
%JBOSS_HOME%\server\XXX\deploy\messaging\hsqldb-persistence-service.xml
~~ ↓のところを編集する。
<attribute name="SqlProperties"><![CDATA[
POPULATE.TABLES.1 = INSERT INTO JBM_USER (USER_ID, PASSWD) VALUES ('guest', 'guest')
POPULATE.TABLES.2 = INSERT INTO JBM_USER (USER_ID, PASSWD) VALUES ('j2ee', 'j2ee')
POPULATE.TABLES.3 = INSERT INTO JBM_USER (USER_ID, PASSWD, CLIENTID) VALUES ('john', 'needle', 'DurableSubscriberExample')
POPULATE.TABLES.4 = INSERT INTO JBM_USER (USER_ID, PASSWD) VALUES ('nobody', 'nobody')
POPULATE.TABLES.5 = INSERT INTO JBM_USER (USER_ID, PASSWD) VALUES ('dynsub', 'dynsub')
POPULATE.TABLES.6 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('guest','guest')
POPULATE.TABLES.7 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('j2ee','guest')
POPULATE.TABLES.8 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('john','john')
POPULATE.TABLES.9 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('subscriber','john')
POPULATE.TABLES.10 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('publisher','john')
POPULATE.TABLES.11 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('publisher','dynsub')
POPULATE.TABLES.12 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('durpublisher','john')
POPULATE.TABLES.13 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('durpublisher','dynsub')
POPULATE.TABLES.14 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('noacc','nobody')
POPULATE.TABLES.15 = INSERT INTO JBM_USER (USER_ID, PASSWD, CLIENTID) VALUES ('prm-user','password', 'prm-user')
POPULATE.TABLES.16 = INSERT INTO JBM_USER (USER_ID, PASSWD) VALUES ('ecm-user','password')
POPULATE.TABLES.17 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('prm-role','prm-user')
POPULATE.TABLES.18 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('ecm-role','ecm-user')
POPULATE.TABLES.19 = INSERT INTO JBM_USER (USER_ID, PASSWD) VALUES ('reffi', 'reffiPass')←ユーザの追加
POPULATE.TABLES.20 = INSERT INTO JBM_ROLE (ROLE_ID, USER_ID) VALUES ('reffi-role','reffi')←ロールの追加
]]></attribute>
※※※以下のように設定すると、クライアントIDも設定することができる。
POPULATE.TABLES.19 = INSERT INTO JBM_USER (USER_ID, PASSWD, CLIENTID) VALUES ('reffi', 'reffiPass', 'clientID')
ソース(DurableSubscriberの作成)
String topicName = "testTopic";
ObjectName serverObjectName = new ObjectName("jboss.messaging:service=ServerPeer");
TopicConnectionFactory tcf =
(TopicConnectionFactory)context.lookup("ConnectionFactory");
TopicConnection con = tcf.createTopicConnection("reffi", "reffiPass"); ←認証されているユーザで作成
con.setClientID("testConnection"); ←ClientIDが設定ファイルで指定されている場合はエラーになる。
Topic sampleTopic = (Topic)context.lookup("topic/" + topicName);
TopicSession session = con.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
con.start();
TopicSubscriber subscriber = session.createDurableSubscriber(sampleTopic, "subscriberName");
session.unsubscribe("subscriberName");
con.stop();
session.close();
con.close();
[0回]