Skip to content

Commit

Permalink
Pass settings directly to postProcessXml and improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mauromol committed Jul 23, 2021
1 parent 23c12fb commit 423618a
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 15 deletions.
8 changes: 5 additions & 3 deletions core/src/main/java/com/onelogin/saml2/authn/AuthnRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.onelogin.saml2.settings.Saml2Settings;
import com.onelogin.saml2.model.Organization;
import com.onelogin.saml2.settings.Saml2Settings;
import com.onelogin.saml2.util.Constants;
import com.onelogin.saml2.util.Util;

Expand Down Expand Up @@ -101,7 +101,7 @@ public AuthnRequest(Saml2Settings settings, boolean forceAuthn, boolean isPassiv
this.nameIdValueReq = nameIdValueReq;

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

Expand Down Expand Up @@ -132,10 +132,12 @@ public AuthnRequest(Saml2Settings settings, boolean forceAuthn, boolean isPassiv
* @param authnRequestXml
* the XML produced for this AuthnRequest by the standard
* implementation provided by {@link AuthnRequest}
* @param settings
* the settings
* @return the post-processed XML for this AuthnRequest, which will then be
* returned by any call to {@link #getAuthnRequestXml()}
*/
protected String postProcessXml(final String authnRequestXml) {
protected String postProcessXml(final String authnRequestXml, final Saml2Settings settings) {
return authnRequestXml;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public LogoutRequest(Saml2Settings settings, HttpRequest request, String nameId,
this.sessionIndex = sessionIndex;

StrSubstitutor substitutor = generateSubstitutor(settings);
logoutRequestString = postProcessXml(substitutor.replace(getLogoutRequestTemplate()));
logoutRequestString = postProcessXml(substitutor.replace(getLogoutRequestTemplate()), settings);
} else {
logoutRequestString = Util.base64decodedInflated(samlLogoutRequest);
Document doc = Util.loadXML(logoutRequestString);
Expand Down Expand Up @@ -237,10 +237,12 @@ public LogoutRequest(Saml2Settings settings, HttpRequest request) {
* @param logoutRequestXml
* the XML produced for this LogoutRequest by the standard
* implementation provided by {@link LogoutRequest}
* @param settings
* the settings
* @return the post-processed XML for this LogoutRequest, which will then be
* returned by any call to {@link #getLogoutRequestXml()}
*/
protected String postProcessXml(final String logoutRequestXml) {
protected String postProcessXml(final String logoutRequestXml, final Saml2Settings settings) {
return logoutRequestXml;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public void build(String inResponseTo, String statusCode) {
this.inResponseTo = inResponseTo;

StrSubstitutor substitutor = generateSubstitutor(settings, statusCode);
this.logoutResponseString = postProcessXml(substitutor.replace(getLogoutResponseTemplate()));
this.logoutResponseString = postProcessXml(substitutor.replace(getLogoutResponseTemplate()), settings);
}

/**
Expand Down Expand Up @@ -396,10 +396,12 @@ public void build() {
* @param logoutResponseXml
* the XML produced for this LogoutResponse by the standard
* implementation provided by {@link LogoutResponse}
* @param settings
* the settings
* @return the post-processed XML for this LogoutResponse, which will then be
* returned by any call to {@link #getLogoutResponseXml()}
*/
protected String postProcessXml(final String logoutResponseXml) {
protected String postProcessXml(final String logoutResponseXml, final Saml2Settings settings) {
return logoutResponseXml;
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/main/java/com/onelogin/saml2/settings/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Metadata(Saml2Settings settings, Calendar validUntilTime, Integer cacheDu
this.cacheDuration = cacheDuration;

StrSubstitutor substitutor = generateSubstitutor(settings);
String unsignedMetadataString = postProcessXml(substitutor.replace(getMetadataTemplate()));
String unsignedMetadataString = postProcessXml(substitutor.replace(getMetadataTemplate()), settings);

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

StrSubstitutor substitutor = generateSubstitutor(settings);
String unsignedMetadataString = postProcessXml(substitutor.replace(getMetadataTemplate()));
String unsignedMetadataString = postProcessXml(substitutor.replace(getMetadataTemplate()), settings);

LOGGER.debug("metadata --> " + unsignedMetadataString);
metadataString = unsignedMetadataString;
Expand All @@ -126,10 +126,12 @@ public Metadata(Saml2Settings settings) throws CertificateEncodingException {
* @param metadataXml
* the XML produced for this metadata instance by the standard
* implementation provided by {@link Metadata}
* @param settings
* the settings
* @return the post-processed XML for this metadata instance, which will then be
* returned by any call to {@link #getMetadataString()}
*/
protected String postProcessXml(final String metadataXml) {
protected String postProcessXml(final String metadataXml, final Saml2Settings settings) {
return metadataXml;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -395,7 +396,9 @@ public void testPostProcessXml() throws Exception {
Saml2Settings settings = new SettingsBuilder().fromFile("config/config.min.properties").build();
AuthnRequest authnRequest = new AuthnRequest(settings) {
@Override
protected String postProcessXml(String authRequestXml) {
protected String postProcessXml(String authRequestXml, Saml2Settings sett) {
assertEquals(authRequestXml, super.postProcessXml(authRequestXml, sett));
assertSame(settings, sett);
return "changed";
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -945,7 +946,9 @@ public void testPostProcessXml() throws Exception {
Saml2Settings settings = new SettingsBuilder().fromFile("config/config.min.properties").build();
LogoutRequest logoutRequest = new LogoutRequest(settings) {
@Override
protected String postProcessXml(String authRequestXml) {
protected String postProcessXml(String authRequestXml, Saml2Settings sett) {
assertEquals(authRequestXml, super.postProcessXml(authRequestXml, sett));
assertSame(settings, sett);
return "changed";
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -704,7 +705,9 @@ public void testPostProcessXml() throws Exception {
Saml2Settings settings = new SettingsBuilder().fromFile("config/config.min.properties").build();
LogoutResponse logoutResponse = new LogoutResponse(settings, null) {
@Override
protected String postProcessXml(String authRequestXml) {
protected String postProcessXml(String authRequestXml, Saml2Settings sett) {
assertEquals(authRequestXml, super.postProcessXml(authRequestXml, sett));
assertSame(settings, sett);
return "changed";
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;

import static org.junit.Assert.assertSame;

import java.io.IOException;
import java.security.GeneralSecurityException;
Expand Down Expand Up @@ -533,7 +533,9 @@ public void testPostProcessXml() throws Exception {
Saml2Settings settings = new SettingsBuilder().fromFile("config/config.min.properties").build();
Metadata metadata = new Metadata(settings) {
@Override
protected String postProcessXml(String authRequestXml) {
protected String postProcessXml(String authRequestXml, Saml2Settings sett) {
assertEquals(authRequestXml, super.postProcessXml(authRequestXml, sett));
assertSame(settings, sett);
return "changed";
}
};
Expand Down

0 comments on commit 423618a

Please sign in to comment.