currentAlias = peerEntityAlias;
} else {
//try to locate in certstore using user supplied CertSelector
getCertStore(context);
if (certStore != null) {
CertSelector selector = null;
if (this.certSelectorClass != null) {
selector = XWSSUtil.getCertSelector(certSelectorClass, context);
}
if (selector != null) {
Collection certs = null;
try {
certs = certStore.getCertificates(selector);
} catch (CertStoreException ex) {
log.log(Level.SEVERE, LogStringsMessages.WSS_1526_FAILEDTO_GETCERTIFICATE(), ex);
throw new RuntimeException(ex);
}
if (certs.size() > 0) {
req.setX509Certificate((X509Certificate) certs.iterator().next());
return;
}
}
}
if (getTrustStore(context) != null) {
if (this.truststoreCertSelectorClass != null) {
CertSelector selector = XWSSUtil.getCertSelector(this.truststoreCertSelectorClass, context);
if (selector != null) {
Enumeration aliases = null;
try {
aliases = trustStore.aliases();
} catch (KeyStoreException ex) {
log.log(Level.SEVERE, LogStringsMessages.WSS_1526_FAILEDTO_GETCERTIFICATE(), ex);
throw new RuntimeException(ex);
}
while (aliases.hasMoreElements()) {
String currAlias = (String) aliases.nextElement();
Certificate thisCertificate = null;
try {
thisCertificate = trustStore.getCertificate(currAlias);
} catch (KeyStoreException ex) {
log.log(Level.SEVERE, LogStringsMessages.WSS_1526_FAILEDTO_GETCERTIFICATE(), ex);
throw new RuntimeException(ex);
}
if ((thisCertificate instanceof X509Certificate) && selector.match(thisCertificate)) {
req.setX509Certificate((X509Certificate) thisCertificate);
return;
}
}
}