1 7 8 package ersatz.resourceadapter; 9 10 11 import javax.resource.ResourceException; 12 import javax.resource.spi.ConnectionRequestInfo; 13 import javax.resource.spi.SecurityException; 14 import javax.resource.spi.security.PasswordCredential; 15 import javax.security.auth.Subject; 16 import java.util.Set; 17 import java.util.Iterator; 18 19 import org.objectweb.jonas.common.Log; 20 import org.objectweb.util.monolog.api.Logger; 21 import org.objectweb.util.monolog.api.BasicLevel; 22 23 27 public class Utility 28 { 29 private static Logger logger = null; 30 36 public static synchronized void log(String msg) { 37 if (logger == null) { 38 logger = Log.getLogger("ersatz.resourceadapter"); 39 } 40 logger.log(BasicLevel.DEBUG, msg); 41 } 42 43 44 52 static synchronized PasswordCredential getPasswordCredential 53 (ManagedConnectionFactoryImpl mcf, Subject subject, 54 ConnectionRequestInfo info) 55 throws ResourceException 56 { 57 String mName = "Utility.getPasswordCredential"; 58 if (subject == null) 59 { 60 if (info == null) return null; 61 ConnectionRequestInfoImpl crii = (ConnectionRequestInfoImpl) info; 62 PasswordCredential pc = 63 new PasswordCredential(crii.getUserName(), 64 crii.getPassword().toCharArray()); 65 pc.setManagedConnectionFactory(mcf); 66 return pc; 67 } 68 Set cred = subject.getPrivateCredentials(PasswordCredential.class); 69 PasswordCredential pc = null; 70 for (Iterator iter = cred.iterator(); iter.hasNext();) 71 { 72 PasswordCredential tmpPc = (PasswordCredential) iter.next(); 73 if (mcf.equals(tmpPc.getManagedConnectionFactory())) 74 { 75 log(mName+" PasswordCredential found mcf="+mcf); 76 pc = tmpPc; 77 break; 78 } 79 } 80 if (pc == null) 81 { 82 SecurityException se = new SecurityException("No PasswordCredential found"); 83 log(mName+" No PasswordCredential found."); 84 throw se; 85 } 86 return pc; 87 } 88 89 90 } 91 | Popular Tags |