[jboss-cvs] JBossAS SVN: r104797 - branches/JBPAPP_5_1/connector/src/main/org/jboss/resource/connectionmanager.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 14 10:22:44 EDT 2010


Author: jesper.pedersen
Date: 2010-05-14 10:22:44 -0400 (Fri, 14 May 2010)
New Revision: 104797

Modified:
   branches/JBPAPP_5_1/connector/src/main/org/jboss/resource/connectionmanager/ManagedConnectionFactoryDeployment.java
Log:
[JBPAPP-3638] XA Resource Recovery (Part 4)

Modified: branches/JBPAPP_5_1/connector/src/main/org/jboss/resource/connectionmanager/ManagedConnectionFactoryDeployment.java
===================================================================
--- branches/JBPAPP_5_1/connector/src/main/org/jboss/resource/connectionmanager/ManagedConnectionFactoryDeployment.java	2010-05-14 14:15:32 UTC (rev 104796)
+++ branches/JBPAPP_5_1/connector/src/main/org/jboss/resource/connectionmanager/ManagedConnectionFactoryDeployment.java	2010-05-14 14:22:44 UTC (rev 104797)
@@ -67,6 +67,9 @@
 import org.jboss.resource.metadata.mcf.SecurityMetaData;
 import org.jboss.resource.metadata.mcf.XAConnectionPropertyMetaData;
 import org.jboss.resource.metadata.mcf.XADataSourceDeploymentMetaData;
+import org.jboss.security.SecurityContext;
+import org.jboss.security.SecurityContextAssociation;
+import org.jboss.security.SecurityContextFactory;
 import org.jboss.security.SimplePrincipal;
 import org.jboss.security.SubjectFactory;
 import org.jboss.system.ServiceDynamicMBeanSupport;
@@ -453,15 +456,6 @@
             {
                for (XAConnectionPropertyMetaData xcpmd : xdsdm.getXADataSourceProperties())
                {
-                  if (xcpmd.getName().equals("RecoverUser"))
-                     recoverUserName = xcpmd.getValue();
-               }
-            }
-
-            if (recoverUserName == null)
-            {
-               for (XAConnectionPropertyMetaData xcpmd : xdsdm.getXADataSourceProperties())
-               {
                   if (xcpmd.getName().equals("User"))
                      recoverUserName = xcpmd.getValue();
                }
@@ -471,15 +465,6 @@
             {
                for (XAConnectionPropertyMetaData xcpmd : xdsdm.getXADataSourceProperties())
                {
-                  if (xcpmd.getName().equals("RecoverPassword"))
-                     recoverPassword = xcpmd.getValue();
-               }
-            }
-
-            if (recoverPassword == null)
-            {
-               for (XAConnectionPropertyMetaData xcpmd : xdsdm.getXADataSourceProperties())
-               {
                   if (xcpmd.getName().equals("Password"))
                      recoverPassword = xcpmd.getValue();
                }
@@ -669,27 +654,50 @@
             else
             {
                // Security-domain use-case
-               Subject subject = subjectFactory.createSubject(recoverSecurityDomain);
-
-               if (recoverUserName != null && recoverPassword != null)
+               try
                {
-                  // Principals
-                  Principal p = new SimplePrincipal(recoverUserName);
-                  subject.getPrincipals().add(p);
+                  // Create a security context on the association
+                  SecurityContext securityContext = SecurityContextFactory.createSecurityContext(recoverSecurityDomain);
+                  SecurityContextAssociation.setSecurityContext(securityContext);
+               
+                  if (recoverUserName != null && recoverPassword != null)
+                  {
+                     Subject userPassword = new Subject();
 
-                  // PrivateCredentials
-                  PasswordCredential pc = new PasswordCredential(recoverUserName, recoverPassword.toCharArray());
-                  pc.setManagedConnectionFactory(mcf);
-                  subject.getPrivateCredentials().add(pc);
+                     // Principals
+                     Principal principal = new SimplePrincipal(recoverUserName);
+                     userPassword.getPrincipals().add(principal);
 
-                  // PublicCredentials
-                  // None
+                     // Credentials
+                     PasswordCredential credential = new PasswordCredential(recoverUserName, recoverPassword.toCharArray());
+                     credential.setManagedConnectionFactory(mcf);
+                     userPassword.getPrivateCredentials().add(credential);
+                  
+                     // Set the authenticated subject
+                     securityContext.getSubjectInfo().setAuthenticatedSubject(userPassword);
+
+                     // Use the userPassword subject to get the real recovery subject instance
+                     Subject subject = subjectFactory.createSubject(recoverSecurityDomain);
+
+                     if (log.isDebugEnabled())
+                        log.debug("Recovery Subject=" + subject);
+                     
+                     return subject;
+                  }
+                  else
+                  {
+                     // Unauthenticated
+                     log.error("NYI");
+                     log.debug("SecurityContext=" + securityContext);
+                     log.debug("SubjectInfo=" + securityContext.getSubjectInfo());
+                  }
                }
+               catch (Throwable t)
+               {
+                  log.debug("Exception during getSubject()" + t.getMessage(), t);
+               }
 
-               if (log.isDebugEnabled())
-                  log.debug("Recovery Subject=" + subject);
-
-               return subject;
+               return null;
             }
          }
       });




More information about the jboss-cvs-commits mailing list