[jboss-svn-commits] JBL Code SVN: r28271 - in labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration: classes/com/arjuna/ats/internal/jbossatx/jta and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Jul 21 05:11:41 EDT 2009
Author: jhalliday
Date: 2009-07-21 05:11:41 -0400 (Tue, 21 Jul 2009)
New Revision: 28271
Modified:
labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/build.xml
labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/AppServerJDBCXARecovery.java
Log:
Backported app server recovery jmx auth support to SP branch. JBTM-432
Modified: labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/build.xml
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/build.xml 2009-07-21 09:09:03 UTC (rev 28270)
+++ labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/build.xml 2009-07-21 09:11:41 UTC (rev 28271)
@@ -121,7 +121,7 @@
<!-- libs from JBoss App Server installation. Note: these jars were refactored between
AS 4.x and AS 5.0. The list below is a hybrid to allow building against either version. -->
<property name="jboss.libs" value="jboss-common.jar jboss-system.jar jboss-jmx.jar jboss-logging-spi.jar jboss-common-core.jar jboss-j2se.jar jboss-system-jmx.jar"/>
- <property name="jboss.server.jta.libs" value="jmx-adaptor-plugin.jar jboss-transaction.jar jboss.jar"/>
+ <property name="jboss.server.jta.libs" value="jmx-adaptor-plugin.jar jboss-transaction.jar jboss.jar jbosssx.jar"/>
<property name="jboss.server.jts.libs" value="jboss-iiop.jar jacorb.jar"/>
<condition property="jboss.server.libs" value="${jboss.server.jta.libs} ${jboss.server.jts.libs}">
<isset property="com.hp.mwlabs.ts.build.jts"/>
Modified: labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/AppServerJDBCXARecovery.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/AppServerJDBCXARecovery.java 2009-07-21 09:09:03 UTC (rev 28270)
+++ labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/AppServerJDBCXARecovery.java 2009-07-21 09:11:41 UTC (rev 28271)
@@ -36,16 +36,19 @@
import java.sql.Connection;
import java.util.Properties;
import java.util.Iterator;
+import java.util.StringTokenizer;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.lang.reflect.Method;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
+import org.jboss.security.SecurityAssociation;
+import org.jboss.security.SimplePrincipal;
import org.jboss.logging.Logger;
/**
- * This provides recovery for compliant JDBC drivers accessed via datasources deployed in JBossAS 4.2
+ * This provides recovery for compliant JDBC drivers accessed via datasources deployed in JBossAS 5
* It is not meant to be db driver specific.
*
* This code is based on JDBCXARecovery, which expects JNDI to contain an XADataSource implementation.
@@ -55,8 +58,19 @@
* which it can then create an XAConnection.
*
* To use this class, add an XAResourceRecovery entry in the jta section of jbossjta-properties.xml
- * for each datasource for which you need recovery, ensuring the value ends with ;<datasource-name>
+ * for each database for which you need recovery, ensuring the value ends with ;jndiname=<datasource-name>
* i.e. the same value as is in the -ds.xml jndi-name element.
+ *
+ * Note for users with secured JMX invokers, use the extended format:
+ * ;jndiname=MyExampleDbName,username=foo,password=bar
+ * The username and password refer to the JMX invoker, NOT the datasource.
+ *
+ * It's not possible to override the jdbc username and password given in the -ds.xml file at present.
+ * Since the recovery system sometimes needs greater db user privs than the app code, it may be preferable to
+ * set up a -ds.xml file only for recovery usage. This approach works for databases which allow users to
+ * recover one another's transactions, which is most of them. But consult
+ * your db docs or friendly neighbourhood DBA to be sure, then test it anyhow.
+ *
* You also need the XARecoveryModule enabled and appropriate values for nodeIdentifier and xaRecoveryNode set.
* See the JBossTS recovery guide if you are unclear on how the recovery system works.
*
@@ -64,9 +78,11 @@
* if you configure the recovery manager to run as a separate process. (JMX can be accessed remotely,
* but it would need code changes to the lookup function and some classpath additions).
*
+ *
* <properties depends="arjuna" name="jta">
* ...
- * <property name="com.arjuna.ats.jta.recovery.XAResourceRecovery1" value= "com.arjuna.ats.internal.jbossatx.jta.AppServerJDBCXARecovery;MyExampleDbName"/>
+ * <property name="com.arjuna.ats.jta.recovery.XAResourceRecovery1"
+ * value= "com.arjuna.ats.internal.jbossatx.jta.AppServerJDBCXARecovery;jndiname=MyExampleDbName[,username=foo,password=bar]"/>
* <!-- xaRecoveryNode should match value in nodeIdentifier or be * -->
* <property name="com.arjuna.ats.jta.xaRecoveryNode" value="1"/>
*
@@ -102,10 +118,9 @@
if (parameter == null)
return false;
+
+ retrieveData(parameter, _DELIMITER);
- // don't create the datasource yet, we'll do it lazily. Just keep its id.
- _dataSourceId = parameter;
-
return true;
}
@@ -164,8 +179,16 @@
InitialContext context = new InitialContext();
MBeanServerConnection server = (MBeanServerConnection)context.lookup("jmx/invoker/RMIAdaptor");
ObjectName objectName = new ObjectName("jboss.jca:name="+_dataSourceId+",service=ManagedConnectionFactory");
+
+ if(_username !=null && _password !=null)
+ {
+ SecurityAssociation.setPrincipal(new SimplePrincipal(_username));
+ SecurityAssociation.setCredential(_password);
+ }
+
String className = (String)server.invoke(objectName, "getManagedConnectionFactoryAttribute", new Object[] {"XADataSourceClass"}, new String[] {"java.lang.String"});
log.debug("AppServerJDBCXARecovery datasource classname = "+className);
+
String properties = (String)server.invoke(objectName, "getManagedConnectionFactoryAttribute", new Object[] {"XADataSourceProperties"}, new String[] {"java.lang.String"});
// debug disabled due to security paranoia - it may log datasource password in cleartext.
// log.debug("AppServerJDBCXARecovery.result="+properties);
@@ -343,7 +366,36 @@
}
return xads;
}
-
+
+ public void retrieveData(String parameter,String delimiter)
+ {
+ StringTokenizer st = new StringTokenizer(parameter,delimiter);
+ while (st.hasMoreTokens())
+ {
+ String data = st.nextToken();
+ if(data.length()>9)
+ {
+ if(_USERNAME.equalsIgnoreCase(data.substring(0,8)))
+ {
+ _username =data.substring(9);
+ }
+ if(_PASSWORD.equalsIgnoreCase(data.substring(0,8)))
+ {
+ _password =data.substring(9);
+ }
+ if(_JNDINAME.equalsIgnoreCase(data.substring(0,8)))
+ {
+ _dataSourceId=data.substring(9);
+ }
+ }
+ }
+
+ if(_dataSourceId == null && parameter != null && !parameter.contains("=")) {
+ // try to fallback to old parameter format where only the dataSourceId is given, without jndiname= prefix
+ _dataSourceId = parameter;
+ }
+ }
+
private boolean _supportsIsValidMethod;
private XAConnection _connection;
private XADataSource _dataSource;
@@ -351,5 +403,13 @@
private boolean _hasMoreResources;
private String _dataSourceId;
+ private String _username;
+ private String _password;
+
+ private final String _JNDINAME = "jndiname";
+ private final String _USERNAME = "username";
+ private final String _PASSWORD = "password";
+ private final String _DELIMITER = ",";
+
private Logger log = org.jboss.logging.Logger.getLogger(AppServerJDBCXARecovery.class);
}
More information about the jboss-svn-commits
mailing list