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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jan 5 05:38:16 EST 2010


Author: jhalliday
Date: 2010-01-05 05:38:16 -0500 (Tue, 05 Jan 2010)
New Revision: 30921

Modified:
   labs/jbosstm/branches/JBOSSTS_4_2_3_GA_CP/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_CP/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/AppServerJDBCXARecovery.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_2_3_GA_CP/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/AppServerJDBCXARecovery.java	2010-01-05 10:20:35 UTC (rev 30920)
+++ labs/jbosstm/branches/JBOSSTS_4_2_3_GA_CP/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/AppServerJDBCXARecovery.java	2010-01-05 10:38:16 UTC (rev 30921)
@@ -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 {
@@ -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