Skip to content

Commit 423618a

Browse files
committed
Pass settings directly to postProcessXml and improve tests
1 parent 23c12fb commit 423618a

File tree

8 files changed

+34
-15
lines changed

8 files changed

+34
-15
lines changed

core/src/main/java/com/onelogin/saml2/authn/AuthnRequest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import org.slf4j.Logger;
1212
import org.slf4j.LoggerFactory;
1313

14-
import com.onelogin.saml2.settings.Saml2Settings;
1514
import com.onelogin.saml2.model.Organization;
15+
import com.onelogin.saml2.settings.Saml2Settings;
1616
import com.onelogin.saml2.util.Constants;
1717
import com.onelogin.saml2.util.Util;
1818

@@ -101,7 +101,7 @@ public AuthnRequest(Saml2Settings settings, boolean forceAuthn, boolean isPassiv
101101
this.nameIdValueReq = nameIdValueReq;
102102

103103
StrSubstitutor substitutor = generateSubstitutor(settings);
104-
authnRequestString = postProcessXml(substitutor.replace(getAuthnRequestTemplate()));
104+
authnRequestString = postProcessXml(substitutor.replace(getAuthnRequestTemplate()), settings);
105105
LOGGER.debug("AuthNRequest --> " + authnRequestString);
106106
}
107107

@@ -132,10 +132,12 @@ public AuthnRequest(Saml2Settings settings, boolean forceAuthn, boolean isPassiv
132132
* @param authnRequestXml
133133
* the XML produced for this AuthnRequest by the standard
134134
* implementation provided by {@link AuthnRequest}
135+
* @param settings
136+
* the settings
135137
* @return the post-processed XML for this AuthnRequest, which will then be
136138
* returned by any call to {@link #getAuthnRequestXml()}
137139
*/
138-
protected String postProcessXml(final String authnRequestXml) {
140+
protected String postProcessXml(final String authnRequestXml, final Saml2Settings settings) {
139141
return authnRequestXml;
140142
}
141143

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public LogoutRequest(Saml2Settings settings, HttpRequest request, String nameId,
139139
this.sessionIndex = sessionIndex;
140140

141141
StrSubstitutor substitutor = generateSubstitutor(settings);
142-
logoutRequestString = postProcessXml(substitutor.replace(getLogoutRequestTemplate()));
142+
logoutRequestString = postProcessXml(substitutor.replace(getLogoutRequestTemplate()), settings);
143143
} else {
144144
logoutRequestString = Util.base64decodedInflated(samlLogoutRequest);
145145
Document doc = Util.loadXML(logoutRequestString);
@@ -237,10 +237,12 @@ public LogoutRequest(Saml2Settings settings, HttpRequest request) {
237237
* @param logoutRequestXml
238238
* the XML produced for this LogoutRequest by the standard
239239
* implementation provided by {@link LogoutRequest}
240+
* @param settings
241+
* the settings
240242
* @return the post-processed XML for this LogoutRequest, which will then be
241243
* returned by any call to {@link #getLogoutRequestXml()}
242244
*/
243-
protected String postProcessXml(final String logoutRequestXml) {
245+
protected String postProcessXml(final String logoutRequestXml, final Saml2Settings settings) {
244246
return logoutRequestXml;
245247
}
246248

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ public void build(String inResponseTo, String statusCode) {
364364
this.inResponseTo = inResponseTo;
365365

366366
StrSubstitutor substitutor = generateSubstitutor(settings, statusCode);
367-
this.logoutResponseString = postProcessXml(substitutor.replace(getLogoutResponseTemplate()));
367+
this.logoutResponseString = postProcessXml(substitutor.replace(getLogoutResponseTemplate()), settings);
368368
}
369369

370370
/**
@@ -396,10 +396,12 @@ public void build() {
396396
* @param logoutResponseXml
397397
* the XML produced for this LogoutResponse by the standard
398398
* implementation provided by {@link LogoutResponse}
399+
* @param settings
400+
* the settings
399401
* @return the post-processed XML for this LogoutResponse, which will then be
400402
* returned by any call to {@link #getLogoutResponseXml()}
401403
*/
402-
protected String postProcessXml(final String logoutResponseXml) {
404+
protected String postProcessXml(final String logoutResponseXml, final Saml2Settings settings) {
403405
return logoutResponseXml;
404406
}
405407

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public Metadata(Saml2Settings settings, Calendar validUntilTime, Integer cacheDu
7777
this.cacheDuration = cacheDuration;
7878

7979
StrSubstitutor substitutor = generateSubstitutor(settings);
80-
String unsignedMetadataString = postProcessXml(substitutor.replace(getMetadataTemplate()));
80+
String unsignedMetadataString = postProcessXml(substitutor.replace(getMetadataTemplate()), settings);
8181

8282
LOGGER.debug("metadata --> " + unsignedMetadataString);
8383
metadataString = unsignedMetadataString;
@@ -109,7 +109,7 @@ public Metadata(Saml2Settings settings) throws CertificateEncodingException {
109109
this.cacheDuration = SECONDS_CACHED;
110110

111111
StrSubstitutor substitutor = generateSubstitutor(settings);
112-
String unsignedMetadataString = postProcessXml(substitutor.replace(getMetadataTemplate()));
112+
String unsignedMetadataString = postProcessXml(substitutor.replace(getMetadataTemplate()), settings);
113113

114114
LOGGER.debug("metadata --> " + unsignedMetadataString);
115115
metadataString = unsignedMetadataString;
@@ -126,10 +126,12 @@ public Metadata(Saml2Settings settings) throws CertificateEncodingException {
126126
* @param metadataXml
127127
* the XML produced for this metadata instance by the standard
128128
* implementation provided by {@link Metadata}
129+
* @param settings
130+
* the settings
129131
* @return the post-processed XML for this metadata instance, which will then be
130132
* returned by any call to {@link #getMetadataString()}
131133
*/
132-
protected String postProcessXml(final String metadataXml) {
134+
protected String postProcessXml(final String metadataXml, final Saml2Settings settings) {
133135
return metadataXml;
134136
}
135137

core/src/test/java/com/onelogin/saml2/test/authn/AuthnRequestTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.junit.Assert.assertEquals;
66
import static org.junit.Assert.assertNotEquals;
77
import static org.junit.Assert.assertNotNull;
8+
import static org.junit.Assert.assertSame;
89
import static org.junit.Assert.assertThat;
910
import static org.junit.Assert.assertTrue;
1011

@@ -395,7 +396,9 @@ public void testPostProcessXml() throws Exception {
395396
Saml2Settings settings = new SettingsBuilder().fromFile("config/config.min.properties").build();
396397
AuthnRequest authnRequest = new AuthnRequest(settings) {
397398
@Override
398-
protected String postProcessXml(String authRequestXml) {
399+
protected String postProcessXml(String authRequestXml, Saml2Settings sett) {
400+
assertEquals(authRequestXml, super.postProcessXml(authRequestXml, sett));
401+
assertSame(settings, sett);
399402
return "changed";
400403
}
401404
};

core/src/test/java/com/onelogin/saml2/test/logout/LogoutRequestTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.junit.Assert.assertEquals;
66
import static org.junit.Assert.assertThat;
77
import static org.junit.Assert.assertNull;
8+
import static org.junit.Assert.assertSame;
89
import static org.junit.Assert.assertFalse;
910
import static org.junit.Assert.assertNotEquals;
1011
import static org.junit.Assert.assertNotNull;
@@ -945,7 +946,9 @@ public void testPostProcessXml() throws Exception {
945946
Saml2Settings settings = new SettingsBuilder().fromFile("config/config.min.properties").build();
946947
LogoutRequest logoutRequest = new LogoutRequest(settings) {
947948
@Override
948-
protected String postProcessXml(String authRequestXml) {
949+
protected String postProcessXml(String authRequestXml, Saml2Settings sett) {
950+
assertEquals(authRequestXml, super.postProcessXml(authRequestXml, sett));
951+
assertSame(settings, sett);
949952
return "changed";
950953
}
951954
};

core/src/test/java/com/onelogin/saml2/test/logout/LogoutResponseTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.junit.Assert.assertEquals;
66
import static org.junit.Assert.assertThat;
77
import static org.junit.Assert.assertNull;
8+
import static org.junit.Assert.assertSame;
89
import static org.junit.Assert.assertFalse;
910
import static org.junit.Assert.assertNotEquals;
1011
import static org.junit.Assert.assertNotNull;
@@ -704,7 +705,9 @@ public void testPostProcessXml() throws Exception {
704705
Saml2Settings settings = new SettingsBuilder().fromFile("config/config.min.properties").build();
705706
LogoutResponse logoutResponse = new LogoutResponse(settings, null) {
706707
@Override
707-
protected String postProcessXml(String authRequestXml) {
708+
protected String postProcessXml(String authRequestXml, Saml2Settings sett) {
709+
assertEquals(authRequestXml, super.postProcessXml(authRequestXml, sett));
710+
assertSame(settings, sett);
708711
return "changed";
709712
}
710713
};

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import static org.junit.Assert.assertThat;
88
import static org.junit.Assert.assertTrue;
99
import static org.junit.Assert.assertNull;
10-
10+
import static org.junit.Assert.assertSame;
1111

1212
import java.io.IOException;
1313
import java.security.GeneralSecurityException;
@@ -533,7 +533,9 @@ public void testPostProcessXml() throws Exception {
533533
Saml2Settings settings = new SettingsBuilder().fromFile("config/config.min.properties").build();
534534
Metadata metadata = new Metadata(settings) {
535535
@Override
536-
protected String postProcessXml(String authRequestXml) {
536+
protected String postProcessXml(String authRequestXml, Saml2Settings sett) {
537+
assertEquals(authRequestXml, super.postProcessXml(authRequestXml, sett));
538+
assertSame(settings, sett);
537539
return "changed";
538540
}
539541
};

0 commit comments

Comments
 (0)