Skip to content

Commit 0c8970f

Browse files
committed
#111 Let initialize settings only checking SP data to be used on metadata
1 parent 5d462ea commit 0c8970f

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class Saml2Settings {
7070
private String requestedAuthnContextComparison = "exact";
7171
private Boolean wantXMLValidation = true;
7272
private String signatureAlgorithm = Constants.RSA_SHA1;
73-
private boolean rejectUnsolicitedResponsesWithInResponseTo = false;
73+
private Boolean rejectUnsolicitedResponsesWithInResponseTo = false;
7474

7575
// Compress
7676
private Boolean compressRequest = true;
@@ -80,7 +80,8 @@ public class Saml2Settings {
8080
private List<Contact> contacts = new LinkedList<Contact>();
8181
private Organization organization = null;
8282

83-
83+
private boolean spValidationOnly = false;
84+
8485
/**
8586
* @return the strict setting value
8687
*/
@@ -744,7 +745,9 @@ protected final void setOrganization(Organization organization) {
744745
*/
745746
public List<String> checkSettings() {
746747
List<String> errors = new ArrayList<String>(this.checkSPSettings());
747-
errors.addAll(this.checkIdPSettings());
748+
if (!spValidationOnly) {
749+
errors.addAll(this.checkIdPSettings());
750+
}
748751

749752
return errors;
750753
}
@@ -890,13 +893,32 @@ private boolean checkRequired(Object value) {
890893
return true;
891894
}
892895

896+
/**
897+
* Set the spValidationOnly value, used to check IdP data on checkSettings method
898+
*
899+
* @param spValidationOnly
900+
* the spValidationOnly value to be set
901+
*/
902+
public void setSPValidationOnly(Boolean spValidationOnly)
903+
{
904+
this.spValidationOnly = spValidationOnly;
905+
}
906+
907+
/**
908+
* @return the spValidationOnly value
909+
*/
910+
public boolean getSPValidationOnly()
911+
{
912+
return this.spValidationOnly;
913+
}
914+
893915
/**
894916
* Gets the SP metadata. The XML representation.
895917
*
896918
* @return the SP metadata (xml)
897919
*
898920
* @throws CertificateEncodingException
899-
*/
921+
*/
900922
public String getSPMetadata() throws CertificateEncodingException {
901923
Metadata metadataObj = new Metadata(this);
902924
String metadataString = metadataObj.getMetadataString();

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void testCheckSPSettingsOk() throws IOException, Error {
136136

137137
/**
138138
* Tests the checkSettings method of the Saml2Settings
139-
* Case: Check that all possible IdP errors are found
139+
* Case: Check that all possible errors are found
140140
*
141141
* @throws IOException
142142
* @throws Error
@@ -159,6 +159,30 @@ public void testCheckSettingsAllErrors() throws IOException, Error {
159159
assertThat(settingsErrors, hasItem("idp_cert_not_found_and_required"));
160160
}
161161

162+
/**
163+
* Tests the checkSettings method of the Saml2Settings
164+
* Case: Check IdP errors
165+
*
166+
* @throws IOException
167+
* @throws Error
168+
*
169+
* @see com.onelogin.saml2.settings.Saml2Settings#checkSettings
170+
*/
171+
@Test
172+
public void testCheckSettingsIdPErrors() throws IOException, Error {
173+
Saml2Settings settings = new SettingsBuilder().fromFile("config/config.idperrors.properties").build();
174+
List<String> settingsErrors = settings.checkSettings();
175+
assertFalse(settingsErrors.isEmpty());
176+
assertThat(settingsErrors, hasItem("idp_entityId_not_found"));
177+
assertThat(settingsErrors, hasItem("idp_sso_url_invalid"));
178+
assertThat(settingsErrors, hasItem("idp_cert_or_fingerprint_not_found_and_required"));
179+
assertThat(settingsErrors, hasItem("idp_cert_not_found_and_required"));
180+
181+
settings.setSPValidationOnly(true);
182+
settingsErrors = settings.checkSettings();
183+
assertTrue(settingsErrors.isEmpty());
184+
}
185+
162186
/**
163187
* Tests the checkSettings method of the Saml2Settings
164188
* Case: No SP Errors

samples/java-saml-tookit-jspsample/src/main/webapp/metadata.jsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<%@page import="java.util.*,com.onelogin.saml2.Auth,com.onelogin.saml2.settings.Saml2Settings" language="java" contentType="application/xhtml+xml"%><%
22
Auth auth = new Auth();
33
Saml2Settings settings = auth.getSettings();
4+
settings.setSPValidationOnly(true);
45
String metadata = settings.getSPMetadata();
56
List<String> errors = Saml2Settings.validateMetadata(metadata);
67
if (errors.isEmpty()) {

0 commit comments

Comments
 (0)