Skip to content

Commit 8ce9c8e

Browse files
authored
Merge pull request #233 from juazugas/master
Allow only multiple certs when checking idp settings.
2 parents fd80067 + 8818ea2 commit 8ce9c8e

3 files changed

Lines changed: 58 additions & 9 deletions

File tree

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
import java.util.ArrayList;
88
import java.util.LinkedList;
99
import java.util.List;
10-
1110
import org.slf4j.Logger;
1211
import org.slf4j.LoggerFactory;
1312
import org.w3c.dom.Document;
1413
import org.w3c.dom.Element;
15-
1614
import com.onelogin.saml2.model.Contact;
1715
import com.onelogin.saml2.model.Organization;
1816
import com.onelogin.saml2.util.Constants;
@@ -846,7 +844,7 @@ public List<String> checkIdPSettings() {
846844
LOGGER.error(errorMsg);
847845
}
848846

849-
if (this.getIdpx509cert() == null && !checkRequired(this.getIdpCertFingerprint())) {
847+
if (!checkIdpx509certRequired() && !checkRequired(this.getIdpCertFingerprint())) {
850848
errorMsg = "idp_cert_or_fingerprint_not_found_and_required";
851849
errors.add(errorMsg);
852850
LOGGER.error(errorMsg);
@@ -861,6 +859,19 @@ public List<String> checkIdPSettings() {
861859
return errors;
862860
}
863861

862+
/**
863+
* Auxiliary method to check Idp certificate is configured.
864+
*
865+
* @return true if the Idp Certificate settings are valid
866+
*/
867+
private boolean checkIdpx509certRequired () {
868+
if (this.getIdpx509cert() != null) {
869+
return true;
870+
}
871+
872+
return this.getIdpx509certMulti() != null && !this.getIdpx509certMulti().isEmpty();
873+
}
874+
864875
/**
865876
* Checks the SP settings .
866877
*

core/src/test/java/com/onelogin/saml2/test/settings/Saml2SettingsTest.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
package com.onelogin.saml2.test.settings;
22

33
import static org.hamcrest.CoreMatchers.containsString;
4-
import static org.hamcrest.CoreMatchers.not;
54
import static org.hamcrest.CoreMatchers.hasItem;
5+
import static org.hamcrest.CoreMatchers.not;
66
import static org.junit.Assert.assertEquals;
77
import static org.junit.Assert.assertFalse;
8-
import static org.junit.Assert.assertTrue;
98
import static org.junit.Assert.assertThat;
10-
9+
import static org.junit.Assert.assertTrue;
1110
import java.io.IOException;
1211
import java.util.Calendar;
1312
import java.util.List;
14-
1513
import org.junit.Test;
1614
import org.w3c.dom.Document;
1715
import org.w3c.dom.Node;
18-
1916
import com.onelogin.saml2.exception.Error;
2017
import com.onelogin.saml2.settings.Metadata;
2118
import com.onelogin.saml2.settings.Saml2Settings;
@@ -184,7 +181,22 @@ public void testCheckSettingsIdPErrors() throws IOException, Error {
184181
settingsErrors = settings.checkSettings();
185182
assertTrue(settingsErrors.isEmpty());
186183
}
187-
184+
185+
/**
186+
* Tests the checkIdpSettings method of the {@link Saml2Settings}
187+
* Case: Multiple certs defined.
188+
*
189+
* @throws Exception
190+
*
191+
* @see com.onelogin.saml2.settings.Saml2Settings#checkIdPSettings
192+
*/
193+
@Test
194+
public void testCheckIdpMultipleCertSettings () throws Exception {
195+
Saml2Settings settings = new SettingsBuilder().fromFile("config/config.min_idp_multicert.properties").build();
196+
List<String> settingsErrors = settings.checkSettings();
197+
assertTrue(settingsErrors.isEmpty());
198+
}
199+
188200
/**
189201
* Tests the checkSettings method of the Saml2Settings
190202
* Case: No SP Errors
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Service Provider Data that we are deploying
2+
# Identifier of the SP entity (must be a URI)
3+
onelogin.saml2.sp.entityid = http://localhost:8080/java-saml-jspsample/metadata.jsp
4+
# Specifies info about where and how the <AuthnResponse> message MUST be
5+
# returned to the requester, in this case our SP.
6+
# URL Location where the <Response> from the IdP will be returned
7+
onelogin.saml2.sp.assertion_consumer_service.url = http://localhost:8080/java-saml-jspsample/acs.jsp
8+
9+
# Specifies info about Logout service
10+
# URL Location where the <LogoutResponse> from the IdP will be returned or where to send the <LogoutRequest>
11+
onelogin.saml2.sp.single_logout_service.url = http://localhost:8080/java-saml-jspsample/sls.jsp
12+
13+
# Identity Provider Data that we want connect with our SP
14+
# Identifier of the IdP entity (must be a URI)
15+
onelogin.saml2.idp.entityid = http://idp.example.com/
16+
17+
# SSO endpoint info of the IdP. (Authentication Request protocol)
18+
# URL Target of the IdP where the SP will send the Authentication Request Message
19+
onelogin.saml2.idp.single_sign_on_service.url = http://idp.example.com/simplesaml/saml2/idp/SSOService.php
20+
21+
# SLO endpoint info of the IdP.
22+
# URL Location of the IdP where the SP will send the SLO Request
23+
onelogin.saml2.idp.single_logout_service.url = http://idp.example.com/simplesaml/saml2/idp/SingleLogoutService.php
24+
25+
# Public Multiple x509 certificate of the IdP
26+
onelogin.saml2.idp.x509certMulti.0 = -----BEGIN CERTIFICATE-----\nMIIBrTCCAaGgAwIBAgIBATADBgEAMGcxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRUwEwYDVQQHDAxTYW50YSBNb25pY2ExETAPBgNVBAoMCE9uZUxvZ2luMRkwFwYDVQQDDBBhcHAub25lbG9naW4uY29tMB4XDTEwMTAxMTIxMTUxMloXDTE1MTAxMTIxMTUxMlowZzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFTATBgNVBAcMDFNhbnRhIE1vbmljYTERMA8GA1UECgwIT25lTG9naW4xGTAXBgNVBAMMEGFwcC5vbmVsb2dpbi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMPmjfjy7L35oDpeBXBoRVCgktPkLno9DOEWB7MgYMMVKs2B6ymWQLEWrDugMK1hkzWFhIb5fqWLGbWy0J0veGR9/gHOQG+rD/I36xAXnkdiXXhzoiAG/zQxM0edMOUf40n314FC8moErcUg6QabttzesO59HFz6shPuxcWaVAgxAgMBAAEwAwYBAAMBAA==\n-----END CERTIFICATE-----

0 commit comments

Comments
 (0)