Skip to content

Commit ca8d59b

Browse files
authored
Merge pull request #285 from slipset/fix_283
[Fix #283] Expose a new constructor for SamlResponse
2 parents 5bba700 + a680fa0 commit ca8d59b

File tree

2 files changed

+57
-8
lines changed

2 files changed

+57
-8
lines changed

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,32 @@ public class SamlResponse {
8181
*/
8282
private Exception validationException;
8383

84+
/**
85+
* Constructor to have a Response object fully built and ready to validate the saml response.
86+
*
87+
* @param settings
88+
* Saml2Settings object. Setting data
89+
* @param currentUrl
90+
* URL of the current host + current view
91+
*
92+
* @param samlResponse
93+
* A string containting the base64 encoded response from the IdP
94+
*
95+
*
96+
* @throws ValidationError
97+
* @throws SettingsException
98+
* @throws IOException
99+
* @throws SAXException
100+
* @throws ParserConfigurationException
101+
* @throws XPathExpressionException
102+
*
103+
*/
104+
public SamlResponse(Saml2Settings settings, String currentUrl, String samlResponse) throws XPathExpressionException, ParserConfigurationException, SAXException, IOException, SettingsException, ValidationError {
105+
this.settings = settings;
106+
this.currentUrl = currentUrl;
107+
loadXmlFromBase64(samlResponse);
108+
}
109+
84110
/**
85111
* Constructor to have a Response object fully built and ready to validate the saml response.
86112
*
@@ -98,12 +124,7 @@ public class SamlResponse {
98124
*
99125
*/
100126
public SamlResponse(Saml2Settings settings, HttpRequest request) throws XPathExpressionException, ParserConfigurationException, SAXException, IOException, SettingsException, ValidationError {
101-
this.settings = settings;
102-
103-
if (request != null) {
104-
currentUrl = request.getRequestURL();
105-
loadXmlFromBase64(request.getParameter("SAMLResponse"));
106-
}
127+
this(settings, request.getRequestURL(), request.getParameter("SAMLResponse"));
107128
}
108129

109130
/**

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,37 @@ public void goBackToNormal() {
6969
DateTimeUtils.setCurrentMillisSystem();
7070
}
7171

72-
7372
/**
74-
* Tests the constructor of SamlResponse
73+
* Tests the deconstructed constructor of SamlResponse
74+
*
75+
* @throws Error
76+
* @throws IOException
77+
* @throws ValidationError
78+
* @throws SettingsException
79+
* @throws SAXException
80+
* @throws ParserConfigurationException
81+
* @throws XPathExpressionException
82+
*
83+
* @see com.onelogin.saml2.authn.SamlResponse
84+
*/
85+
@Test
86+
public void testDeconstructedConstructor() throws IOException, Error, XPathExpressionException, ParserConfigurationException, SAXException, SettingsException, ValidationError {
87+
Saml2Settings settings = new SettingsBuilder().fromFile("config/config.my.properties").build();
88+
89+
final String requestURL = "/";
90+
String samlResponseEncoded = Util.getFileAsString("data/responses/response1.xml.base64");
91+
92+
SamlResponse samlResponse = new SamlResponse(settings, newHttpRequest(requestURL, samlResponseEncoded));
93+
assertTrue(samlResponse instanceof SamlResponse);
94+
95+
samlResponseEncoded = Util.getFileAsString("data/responses/valid_encrypted_assertion.xml.base64");
96+
samlResponse = new SamlResponse(settings, requestURL, samlResponseEncoded);
97+
assertTrue(samlResponse instanceof SamlResponse);
98+
}
99+
100+
101+
/**
102+
* Tests the httpRequest constructor of SamlResponse
75103
*
76104
* @throws Error
77105
* @throws IOException

0 commit comments

Comments
 (0)