throws javax.resource.ResourceException
{
String username2use = null;
String password2use = null;
PasswordCredential pc = null;
//System.out.println("MQRA:U:getPC()-subject="+subject+":CRInfo="+myinfo);
if (subject != null) {
//System.out.println("MQRA:U:getPC:non-null subject");
pc = (PasswordCredential)
AccessController.doPrivileged(
new PrivilegedAction<Object>()
{
public Object
run()
{
Set creds = subject.getPrivateCredentials
(PasswordCredential.class);
if (creds == null) {
//System.out.println("MQRA:U:getPC:null creds-return null pc");
return null;
}
Iterator iter = creds.iterator();
while (iter.hasNext()) {
PasswordCredential temp =
(PasswordCredential) iter.next();
if (temp != null) {
//System.out.println("MQRA:U:getPC:pwc from subject="+temp.toString());
//Sufficient if username is non-null; do not retrieve the pw
if (temp.getUserName() != null) {
//System.out.println("MQRA:U:getPC:un+pw exist;return pwc="+temp.toString());
return temp;
}
}
}
//System.out.println("MQRA:U:getPC:null or empty subject-return null pc");
return null;
}
}
);
}
// Return only if a valid PasswordCredential is obtained
if (pc != null) {
//System.out.println("MQRA:U:getPC:-returning real pc from Subject");
return pc;
} else {
// else need to construct a pc from CRI or MCF
if (myinfo != null) {
if (myinfo.getUserName() != null) {
//System.out.println("MQRA:U:getPC():non-null CRI:creating pwc from CRI");
username2use = myinfo.getUserName();
password2use = myinfo.getPassword();
} else {
//System.out.println("MQRA:U:getPC():non-null CRI BUT un==null:creating pwc from MCF");
username2use = mcf.getUserName();
password2use = mcf.getPassword();
}
} else {
// need to construct a pc from MCF
//System.out.println("MQRA:U:getPC():null CRI:creating pwc from MCF");
username2use = mcf.getUserName();
password2use = mcf.getPassword();
}
char [] password = password2use.toCharArray();
pc = new PasswordCredential(username2use, password);
//System.out.println("MQRA:U:getPC:-returning pc from CRI/MCF");
return pc;
}
}