Skip to content

Commit 76ec1d2

Browse files
committed
Fix previous merge
1 parent 5d5fbb3 commit 76ec1d2

4 files changed

Lines changed: 13 additions & 100 deletions

File tree

core/src/main/java/com/onelogin/saml2/util/Util.java

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,13 @@
99
import java.io.OutputStream;
1010
import java.io.StringReader;
1111
import java.io.UnsupportedEncodingException;
12-
import java.math.BigInteger;
13-
import java.net.URISyntaxException;
1412
import java.net.URL;
1513
import java.net.URLDecoder;
1614
import java.net.URLEncoder;
1715
import java.nio.charset.Charset;
18-
import java.nio.file.Files;
19-
import java.nio.file.Path;
20-
import java.nio.file.Paths;
2116
import java.security.GeneralSecurityException;
2217
import java.security.InvalidKeyException;
2318
import java.security.KeyFactory;
24-
import java.security.MessageDigest;
2519
import java.security.NoSuchAlgorithmException;
2620
import java.security.NoSuchProviderException;
2721
import java.security.Key;
@@ -33,11 +27,8 @@
3327
import java.security.cert.X509Certificate;
3428
import java.security.spec.PKCS8EncodedKeySpec;
3529
import java.util.Calendar;
36-
import java.util.HashMap;
3730
import java.util.Iterator;
3831
import java.util.Locale;
39-
import java.util.Map;
40-
import java.util.Random;
4132
import java.util.TimeZone;
4233
import java.util.UUID;
4334
import java.util.zip.Deflater;
@@ -553,80 +544,6 @@ public static String convertToPem(X509Certificate certificate) {
553544
return pemCert;
554545
}
555546

556-
/**
557-
* Redirect to location url
558-
*
559-
* @param response
560-
* HttpServletResponse object to be used
561-
* @param location
562-
* target location url
563-
* @param parameters
564-
* GET parameters to be added
565-
*
566-
* @throws IOException
567-
*
568-
* @see javax.servlet.http.HttpServletResponse#sendRedirect(String)
569-
*/
570-
public static void sendRedirect(HttpServletResponse response, String location, Map<String, String> parameters) throws IOException {
571-
String target = location;
572-
573-
if (!parameters.isEmpty()) {
574-
boolean first = !location.contains("?");
575-
for (Map.Entry<String, String> parameter : parameters.entrySet())
576-
{
577-
if (first) {
578-
target += "?";
579-
first = false;
580-
} else {
581-
target += "&";
582-
}
583-
target += parameter.getKey();
584-
if (!parameter.getValue().isEmpty()) {
585-
target += "=" + Util.urlEncoder(parameter.getValue());
586-
}
587-
}
588-
}
589-
response.sendRedirect(target);
590-
}
591-
592-
/**
593-
* Redirect to location url
594-
*
595-
* @param response
596-
* HttpServletResponse object to be used
597-
* @param location
598-
* target location url
599-
*
600-
* @throws IOException
601-
*
602-
* @see javax.servlet.http.HttpServletResponse#sendRedirect(String)
603-
*/
604-
public static void sendRedirect(HttpServletResponse response, String location) throws IOException {
605-
Map<String, String> parameters =new HashMap<String, String>();
606-
sendRedirect(response, location, parameters);
607-
}
608-
609-
610-
/**
611-
* Returns the protocol + the current host + the port (if different than
612-
* common ports).
613-
*
614-
* @param request
615-
* HttpServletRequest object to be processed
616-
*
617-
* @return the HOST URL
618-
*/
619-
public static String getSelfURLhost(HttpServletRequest request) {
620-
String hostUrl = StringUtils.EMPTY;
621-
final int serverPort = request.getServerPort();
622-
if ((serverPort == 80) || (serverPort == 443) || serverPort == 0) {
623-
hostUrl = String.format("%s://%s", request.getScheme(), request.getServerName());
624-
} else {
625-
hostUrl = String.format("%s://%s:%s", request.getScheme(), request.getServerName(), serverPort);
626-
}
627-
return hostUrl;
628-
}
629-
630547
/**
631548
* Loads a resource located at a relative path
632549
*

core/src/test/java/com/onelogin/saml2/test/util/UtilsTest.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
import static org.junit.Assert.assertTrue;
1515

1616
import static org.mockito.Mockito.mock;
17-
import static org.mockito.Mockito.verify;
1817
import static org.mockito.Mockito.when;
1918

2019
import java.io.FileNotFoundException;
2120
import java.io.IOException;
2221
import java.io.UnsupportedEncodingException;
2322
import java.net.URISyntaxException;
24-
import java.nio.file.Path;
2523
import java.security.cert.Certificate;
2624
import java.security.cert.CertificateException;
2725
import java.security.cert.X509Certificate;
@@ -32,10 +30,7 @@
3230
import java.security.PrivateKey;
3331
import java.security.SignatureException;
3432
import java.security.spec.InvalidKeySpecException;
35-
import java.util.Collections;
3633
import java.util.Date;
37-
import java.util.HashMap;
38-
import java.util.Map;
3934

4035
import javax.xml.parsers.ParserConfigurationException;
4136
import javax.xml.xpath.XPathExpressionException;
@@ -1889,15 +1884,4 @@ public void testQuery() throws XPathExpressionException, URISyntaxException, IOE
18891884
assertEquals("saml2:Assertion", assertion_2.getNodeName());
18901885
}
18911886

1892-
@Test
1893-
public void sendRedirectToShouldHandleUrlsWithQueryParams() throws Exception {
1894-
// having
1895-
final HttpServletResponse response = mock(HttpServletResponse.class);
1896-
1897-
// when
1898-
Util.sendRedirect(response, "https://sso.connect.pingidentity.com/sso/idp/SSO.saml2?idpid=ffee-aabbb", Collections.singletonMap("SAMLRequest", "data"));
1899-
1900-
// then
1901-
verify(response).sendRedirect("https://sso.connect.pingidentity.com/sso/idp/SSO.saml2?idpid=ffee-aabbb&SAMLRequest=data");
1902-
}
19031887
}

toolkit/src/main/java/com/onelogin/saml2/servlet/ServletUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public static void sendRedirect(HttpServletResponse response, String location, M
145145
String target = location;
146146

147147
if (!parameters.isEmpty()) {
148-
Boolean first = true;
148+
boolean first = !location.contains("?");
149149
for (Map.Entry<String, String> parameter : parameters.entrySet())
150150
{
151151
if (first) {

toolkit/src/test/java/com/onelogin/saml2/test/servlet/ServletUtilsTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,16 @@ public void testMakeHttpRequest() throws Exception {
250250
assertThat(httpRequest.getRequestURL(), equalTo(url));
251251
assertThat(httpRequest.getParameters(), equalTo(singletonMap("name", singletonList("a"))));
252252
}
253+
254+
@Test
255+
public void sendRedirectToShouldHandleUrlsWithQueryParams() throws Exception {
256+
// having
257+
final HttpServletResponse response = mock(HttpServletResponse.class);
258+
259+
// when
260+
ServletUtils.sendRedirect(response, "https://sso.connect.pingidentity.com/sso/idp/SSO.saml2?idpid=ffee-aabbb", singletonMap("SAMLRequest", "data"));
261+
262+
// then
263+
verify(response).sendRedirect("https://sso.connect.pingidentity.com/sso/idp/SSO.saml2?idpid=ffee-aabbb&SAMLRequest=data");
264+
}
253265
}

0 commit comments

Comments
 (0)