if (subject == null) subject = Subject.getSubject(acc);
if (subject != null) {
Iterator iterator = subject.getPrivateCredentials(UsernamePasswordCredential.class).iterator();
while (iterator.hasNext()) {
UsernamePasswordCredential key = (UsernamePasswordCredential) iterator.next();
if (username == null || username.equals(key.getUsername())) {
return key;
}
}
}