Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTTP-POST binding support for IdP SingleSignOnService #116

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ onelogin.saml2.idp.single_sign_on_service.url =

# SAML protocol binding to be used when returning the <Response>
# message. Onelogin Toolkit supports for this endpoint the
# HTTP-Redirect binding only
# HTTP-Redirect and HTTP-POST bindings
onelogin.saml2.idp.single_sign_on_service.binding = urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect

# SLO endpoint info of the IdP.
Expand Down
6 changes: 5 additions & 1 deletion toolkit/src/main/java/com/onelogin/saml2/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,11 @@ public String login(String returnTo, Boolean forceAuthn, Boolean isPassive, Bool
if (!stay) {
LOGGER.debug("AuthNRequest sent to " + ssoUrl + " --> " + samlRequest);
}
return ServletUtils.sendRedirect(response, ssoUrl, parameters, stay);

if (Constants.BINDING_HTTP_POST.equals(settings.getIdpSingleSignOnServiceBinding()))
return ServletUtils.sendPost(response, ssoUrl, parameters, stay);
else // Anything else is assumed to be a redirect
return ServletUtils.sendRedirect(response, ssoUrl, parameters, stay);
}

/**
Expand Down
19 changes: 19 additions & 0 deletions toolkit/src/main/java/com/onelogin/saml2/servlet/ServletUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;

import com.onelogin.saml2.http.HttpRequest;
Expand Down Expand Up @@ -180,6 +181,24 @@ public static String sendRedirect(HttpServletResponse response, String location,
return target;
}

public static String sendPost(HttpServletResponse response, String location, Map<String, String> parameters, Boolean stay) throws IOException {
StringBuilder html = new StringBuilder();
html.append("<html>\n<head>\n<title>SAML Post</title>\n</head>\n")
.append("<body onload=\"document.getElementById('theform').submit();\">\n")
.append("<form id=\"theform\" action=\"").append(location).append("\" method=\"post\">\n");
for (String name : parameters.keySet()) {
String value = parameters.get(name);
html.append("<input type=\"hidden\" name=\"").append(name).append("\" value=\"").append(StringEscapeUtils.escapeHtml4(value)).append("\"/>\n");
}
html.append("</form>\n</body>\n</html>");
if (!stay) {
response.setContentType("text/html;charset=UTF-8");
response.setContentLength(html.toString().getBytes("UTF-8").length);
response.getWriter().write(html.toString());
}
return html.toString();
}

/**
* Redirect to location url
*
Expand Down