[jboss-svn-commits] JBL Code SVN: r30911 - labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jan 4 12:18:14 EST 2010


Author: jhalliday
Date: 2010-01-04 12:18:14 -0500 (Mon, 04 Jan 2010)
New Revision: 30911

Modified:
   labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/AppServerJDBCXARecovery.java
Log:
Add JaasSecurityDomainIdentityLoginModule support to AppServerJDBCXARecovery. JBTM-666


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	2010-01-04 17:16:03 UTC (rev 30910)
+++ labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/AppServerJDBCXARecovery.java	2010-01-04 17:18:14 UTC (rev 30911)
@@ -209,12 +209,23 @@
 
                 if(securityDomainName != null && !securityDomainName.equals(""))
                 {
-                	ObjectName _objectName = new ObjectName("jboss.security:service=XMLLoginConfig");
-                	String config = (String)server.invoke(_objectName, "displayAppConfig", new Object[] {securityDomainName}, new String[] {"java.lang.String"});
-            		_dbUsername = getValueForKey(config, _USERNAME);
-            		String _encryptedPassword = getValueForKey(config, _PASSWORD);
-            		_dbPassword = new String (decode(_encryptedPassword));
-            		_encrypted = true;
+                    ObjectName _objectName = new ObjectName("jboss.security:service=XMLLoginConfig");
+                    String config = (String)server.invoke(_objectName, "displayAppConfig", new Object[] {securityDomainName}, new String[] {"java.lang.String"});
+                    String loginModuleClass = getValueForLoginModuleClass(config);
+                    _dbUsername = getValueForKey(config, _USERNAME);
+                    String _encryptedPassword = getValueForKey(config, _PASSWORD);
+
+                    if("org.jboss.resource.security.JaasSecurityDomainIdentityLoginModule".equals(loginModuleClass))
+                    {
+                        String jaasSecurityDomain = getValueForKey(config, "jaasSecurityDomain");
+                        _dbPassword = decodePBE(server, _encryptedPassword, jaasSecurityDomain);
+                    }
+                    else
+                    {
+                        _dbPassword = decode(_encryptedPassword);
+                    }
+
+                    _encrypted = true;
                 }
 
                 try {
@@ -279,7 +290,7 @@
                 if (_connection != null && _supportsIsValidMethod) {
                     Connection connection = _connection.getConnection();
                     Method method = connection.getClass().getMethod("isValid",  new Class[] {Integer.class});
-                    isConnectionValid = (Boolean) method.invoke(connection, new Integer(5));
+                    isConnectionValid = (Boolean) method.invoke(connection, new Object[] {new Integer(5)});
                 } else {
                     isConnectionValid = Boolean.FALSE;
                 }
@@ -422,7 +433,7 @@
             }
         }
         
-        if(_dataSourceId == null && parameter != null && !parameter.contains("=")) {
+        if(_dataSourceId == null && parameter != null && parameter.indexOf('=') == -1) {
             // try to fallback to old parameter format where only the dataSourceId is given, without jndiname= prefix
             _dataSourceId = parameter;
         }
@@ -438,6 +449,17 @@
 		}
 		return "";
 	}
+
+    private String getValueForLoginModuleClass(String config)
+    {
+        Pattern usernamePattern = Pattern.compile("(" + _MODULE + ":)(.*)");
+        Matcher m = usernamePattern.matcher(config);
+        if(m.find())
+        {
+            return m.group(2).trim();
+        }
+        return "";
+    }
     
     private static String decode(String secret) throws NoSuchPaddingException, NoSuchAlgorithmException,
             InvalidKeyException, BadPaddingException, IllegalBlockSizeException
@@ -454,6 +476,13 @@
 	    return new String(decode);
 	 }
 
+    private static String decodePBE(MBeanServerConnection server, String password, String jaasSecurityDomain) throws Exception
+    {
+        byte[] secret = (byte[]) server.invoke(new ObjectName(jaasSecurityDomain), "decode64", new Object[] {password}, new String[] {"java.lang.String"});
+        return new String(secret, "UTF-8");
+    }
+
+
     private boolean _supportsIsValidMethod;
     private XAConnection _connection;
     private XADataSource                 _dataSource;
@@ -470,6 +499,7 @@
     private final String _JNDINAME = "jndiname";
     private final String _USERNAME = "username";
     private final String _PASSWORD = "password";
+    private final String _MODULE = "LoginModule Class";
     private final String _DELIMITER = ",";
     
     private Logger log = org.jboss.logging.Logger.getLogger(AppServerJDBCXARecovery.class);



More information about the jboss-svn-commits mailing list