[jboss-cvs] JBossAS SVN: r110885 - in projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core: security and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Mar 10 11:28:53 EST 2011
Author: jesper.pedersen
Date: 2011-03-10 11:28:52 -0500 (Thu, 10 Mar 2011)
New Revision: 110885
Modified:
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/AbstractConnectionManager.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/security/DefaultSubjectFactory.java
Log:
[JBJCA-520] ManagedConnectionFactory isn't applied to PasswordCredential
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/AbstractConnectionManager.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/AbstractConnectionManager.java 2011-03-10 16:06:06 UTC (rev 110884)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/AbstractConnectionManager.java 2011-03-10 16:28:52 UTC (rev 110885)
@@ -44,6 +44,7 @@
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.spi.security.PasswordCredential;
import javax.security.auth.Subject;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
@@ -651,8 +652,20 @@
Subject subject = null;
if (subjectFactory != null && securityDomain != null)
+ {
subject = subjectFactory.createSubject(securityDomain);
+ Set<PasswordCredential> credentials = subject.getPrivateCredentials(PasswordCredential.class);
+ if (credentials != null && credentials.size() > 0)
+ {
+ ManagedConnectionFactory pcMcf = getManagedConnectionFactory();
+ for (PasswordCredential pc : credentials)
+ {
+ pc.setManagedConnectionFactory(pcMcf);
+ }
+ }
+ }
+
log.tracef("Subject: %s", subject);
return subject;
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/security/DefaultSubjectFactory.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/security/DefaultSubjectFactory.java 2011-03-10 16:06:06 UTC (rev 110884)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/security/DefaultSubjectFactory.java 2011-03-10 16:28:52 UTC (rev 110885)
@@ -21,9 +21,12 @@
*/
package org.jboss.jca.core.security;
+import java.security.Principal;
+
import javax.resource.spi.security.PasswordCredential;
import javax.security.auth.Subject;
+import org.jboss.security.SimplePrincipal;
import org.jboss.security.SubjectFactory;
/**
@@ -99,8 +102,13 @@
throw new IllegalStateException("Password is null");
Subject subject = new Subject();
+
+ Principal p = new SimplePrincipal(userName);
+ subject.getPrincipals().add(p);
+
PasswordCredential credential = new PasswordCredential(userName, password.toCharArray());
subject.getPrivateCredentials().add(credential);
+
return subject;
}
@@ -115,10 +123,13 @@
public int hashCode()
{
final int prime = 31;
+
int result = 1;
+
result = prime * result + ((password == null) ? 0 : password.hashCode());
result = prime * result + ((securityDomain == null) ? 0 : securityDomain.hashCode());
result = prime * result + ((userName == null) ? 0 : userName.hashCode());
+
return result;
}
@@ -127,11 +138,15 @@
{
if (this == obj)
return true;
+
if (obj == null)
return false;
+
if (!(obj instanceof DefaultSubjectFactory))
return false;
+
DefaultSubjectFactory other = (DefaultSubjectFactory) obj;
+
if (password == null)
{
if (other.password != null)
@@ -139,6 +154,7 @@
}
else if (!password.equals(other.password))
return false;
+
if (securityDomain == null)
{
if (other.securityDomain != null)
@@ -146,6 +162,7 @@
}
else if (!securityDomain.equals(other.securityDomain))
return false;
+
if (userName == null)
{
if (other.userName != null)
@@ -153,14 +170,13 @@
}
else if (!userName.equals(other.userName))
return false;
+
return true;
}
@Override
public String toString()
{
- return "DefaultSubjectFactory [securityDomain=" + securityDomain + ", userName=" + userName + ", password=" +
- password + "]";
+ return "DefaultSubjectFactory [securityDomain=" + securityDomain + ", userName=" + userName + "]";
}
}
-
More information about the jboss-cvs-commits
mailing list