Skip to content

Commit bed44f3

Browse files
committed
Support NameID Encryptation with MultiCert
1 parent 8ce9c8e commit bed44f3

3 files changed

Lines changed: 24 additions & 13 deletions

File tree

core/src/main/java/com/onelogin/saml2/logout/LogoutRequest.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,15 @@ private StrSubstitutor generateSubstitutor(Saml2Settings settings) {
321321
if (nameIdFormat != null && nameIdFormat.equals(Constants.NAMEID_UNSPECIFIED)) {
322322
nameIdFormat = null;
323323
}
324-
324+
325325
X509Certificate cert = null;
326326
if (settings.getNameIdEncrypted()) {
327327
cert = settings.getIdpx509cert();
328+
if (cert == null) {
329+
List<X509Certificate> multipleCertList = settings.getIdpx509certMulti();
330+
if (multipleCertList != null && !multipleCertList.isEmpty())
331+
cert = multipleCertList.get(0);
332+
}
328333
}
329334

330335
String nameIdStr = Util.generateNameId(nameId, spNameQualifier, nameIdFormat, nameQualifier, cert);
@@ -429,19 +434,22 @@ public Boolean isValid() throws Exception {
429434

430435
if (signature != null && !signature.isEmpty()) {
431436
X509Certificate cert = settings.getIdpx509cert();
432-
if (cert == null) {
433-
throw new SettingsException("In order to validate the sign on the Logout Request, the x509cert of the IdP is required", SettingsException.CERT_NOT_FOUND);
434-
}
435-
437+
436438
List<X509Certificate> certList = new ArrayList<X509Certificate>();
437439
List<X509Certificate> multipleCertList = settings.getIdpx509certMulti();
438440

439441
if (multipleCertList != null && multipleCertList.size() != 0) {
440442
certList.addAll(multipleCertList);
441443
}
442444

443-
if (certList.isEmpty() || !certList.contains(cert)) {
444-
certList.add(0, cert);
445+
if (cert != null) {
446+
if (certList.isEmpty() || !certList.contains(cert)) {
447+
certList.add(0, cert);
448+
}
449+
}
450+
451+
if (certList.isEmpty()) {
452+
throw new SettingsException("In order to validate the sign on the Logout Request, the x509cert of the IdP is required", SettingsException.CERT_NOT_FOUND);
445453
}
446454

447455
String signAlg = request.getParameter("SigAlg");

core/src/main/java/com/onelogin/saml2/logout/LogoutResponse.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,6 @@ public Boolean isValid(String requestId) {
230230

231231
if (signature != null && !signature.isEmpty()) {
232232
X509Certificate cert = settings.getIdpx509cert();
233-
if (cert == null) {
234-
throw new SettingsException("In order to validate the sign on the Logout Response, the x509cert of the IdP is required", SettingsException.CERT_NOT_FOUND);
235-
}
236233

237234
List<X509Certificate> certList = new ArrayList<X509Certificate>();
238235
List<X509Certificate> multipleCertList = settings.getIdpx509certMulti();
@@ -241,8 +238,14 @@ public Boolean isValid(String requestId) {
241238
certList.addAll(multipleCertList);
242239
}
243240

244-
if (certList.isEmpty() || !certList.contains(cert)) {
245-
certList.add(0, cert);
241+
if (cert != null) {
242+
if (certList.isEmpty() || !certList.contains(cert)) {
243+
certList.add(0, cert);
244+
}
245+
}
246+
247+
if (certList.isEmpty()) {
248+
throw new SettingsException("In order to validate the sign on the Logout Response, the x509cert of the IdP is required", SettingsException.CERT_NOT_FOUND);
246249
}
247250

248251
String signAlg = request.getParameter("SigAlg");

core/src/main/java/com/onelogin/saml2/settings/Saml2Settings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ public List<String> checkIdPSettings() {
850850
LOGGER.error(errorMsg);
851851
}
852852

853-
if (this.getNameIdEncrypted() == true && this.getIdpx509cert() == null) {
853+
if (!checkIdpx509certRequired() && this.getNameIdEncrypted()) {
854854
errorMsg = "idp_cert_not_found_and_required";
855855
errors.add(errorMsg);
856856
LOGGER.error(errorMsg);

0 commit comments

Comments
 (0)