【发布时间】:2020-07-03 05:29:50
【问题描述】:
我正在使用 HTTP 重定向绑定处理 SAML 请求。 我在另一篇文章中读到,需要执行以下步骤才能检索 SAML 请求的原始内容(URL 中的 SAMLRequest 参数):
- 网址解码
- Base64 解码
- 夸大内容
虽然这些步骤对我来说很清楚,但我无法获得 XML 格式的 SAML 请求。我相信错误在第三步,也许有不止一种方法来膨胀字节?这是执行上述三个的 Java 函数,给定的参数是 URL 中 SAML 参数的值。
private String decodeMessage(String SAMLContent) {
try {
//URLDecode, Base64 and inflate data
//URLDecode
SAMLContent = URLDecoder.decode(SAMLContent, "UTF-8");
//Base64 decoding
SAMLContent = new String(Base64.getDecoder().decode(SAMLContent), "UTF-8");
//Inflating data
try {
byte[] compressed = new byte[10 * SAMLContent.getBytes().length];
Inflater i = new Inflater(true);
i.setInput(SAMLContent.getBytes(), 0, SAMLContent.getBytes().length);
int finalSize = i.inflate(compressed);
//Exception is thrown here
SAMLContent = new String(SAMLContent.getBytes(), 0, finalSize, "UTF-8");
i.end();
} catch (DataFormatException ex) {
JOptionPane.showMessageDialog(null, "DFE: " + ex.getMessage());
}
} catch (UnsupportedEncodingException ex) {
JOptionPane.showMessageDialog(null, "UEE: " + ex.getMessage());
}
return SAMLContent;
}
如果我复制并粘贴第一步的输出here,我可以在页面底部看到格式良好的 XML,因此至少 URL 解码可以按预期工作。 如果您有任何解决方案,请告诉我,谢谢。
【问题讨论】:
标签: java saml http-redirect inflate