SAML 2.0请求编码 [英] Saml 2.0 request encoding
本文介绍了SAML 2.0请求编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想带code Java中的SAML 2.0请求,但是当它使用工具,我去code网上我得到奇怪的字符。
这是输入字符串:
< samlp:AuthnRequest
的xmlns:samlp =瓮:绿洲:名称:TC:SAML:2.0:协议
ID =_ 8d7bd828-6f91-477a-b158-22d693f56972
版本=2.0
IssueInstant =2013-04-19T14:07:53Z
AssertionConsumerServiceURL =HTTP://测试>
< SAML:发行人的xmlns:SAML =瓮:绿洲:名称:TC:SAML:2.0:断言>
测试
< / SAML:发行人>
< samlp:NameIDPolicy
格式=瓮:绿洲:名称:TC:SAML:2.0:NameID的格式:未指定
AllowCreate =真/>
< / samlp:AuthnRequest>
这里的code我使用的是:
字节[] = xmlBytes baos.toByteArray();//放气
ByteArrayOutputStream byteOutputStream =新ByteArrayOutputStream();
DeflaterOutputStream deflaterOutputStream =新DeflaterOutputStream(
byteOutputStream);
尝试{
deflaterOutputStream.write(xmlBytes,0,xmlBytes.length);
deflaterOutputStream.close();
}赶上(IOException异常五){
// TODO自动生成catch块
e.printStackTrace();
}// EN BASE64 code
Base64编码base64En codeR =新的Base64();
字节[] base64En codedByteArray = base64En coder.en code(xmlBytes);
字符串base64En codedMessage =新的String(base64En codedByteArray);// URL连接code
字符串urlEn codedMessage = NULL;
尝试{
urlEn codedMessage = URLEn coder.en code(base64En codedMessage,UTF-8);
}赶上(UnsupportedEncodingException五){
e.printStackTrace();
}
返回urlEn codedMessage;
当我通过网上的解码工具我得到以下结果运行生成的字符串:
X?}?马可福音?@ ?? ????ĴILL @ ??`?0 ?? ^14 B ???通用汽车?} W?`/ ^?03????????,,
?= Z} ?? ??的pT [的iA?-8?q
?一世
21 N
3 H ???妇科\\ PZY:??????? ?? Pt9mS LT&; -D $ ZCC V
啊?? +?ZQ 8 ?? |???D 41 $ ZZ?J + 4
?/)U ???? Kf个D>?????? 9 -X 2.cf LT&;&放大器;??? ZQķ??一O 6-8 IMZ ??`76W?ň ????〜6
W¯¯?m ?????
^ $ ??? ????即; ?? 3-I进口K ?? ???? 7 Srtion>
测试
< / SAML:发行人>
< samlp:NameIDPolicy
格式=瓮:绿洲:名称:TC:SAML:2.0:NameID的格式:未指定
AllowCreate =真/>
< / samlp:AuthnRequest>
解决方案
您需要,然后再使用URL德codeR Base64编码德codeR,是你在做什么?
I'm trying to encode a Saml 2.0 request in Java but when i decode it using tools online i get weird characters.
This is the input string:
<samlp:AuthnRequest
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
ID="_8d7bd828-6f91-477a-b158-22d693f56972"
Version="2.0"
IssueInstant="2013-04-19T14:07:53Z"
AssertionConsumerServiceURL="http://test">
<saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
test
</saml:Issuer>
<samlp:NameIDPolicy
Format="urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified"
AllowCreate="true" />
</samlp:AuthnRequest>
Here's the code I'm using:
byte[] xmlBytes = baos.toByteArray();
//Deflate
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(
byteOutputStream);
try {
deflaterOutputStream.write(xmlBytes, 0, xmlBytes.length);
deflaterOutputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//BASE64 encode
Base64 base64Encoder = new Base64();
byte[] base64EncodedByteArray = base64Encoder.encode(xmlBytes);
String base64EncodedMessage = new String(base64EncodedByteArray);
// URL encode
String urlEncodedMessage = null;
try {
urlEncodedMessage = URLEncoder.encode(base64EncodedMessage,"utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return urlEncodedMessage;
When i run the resulting string through the online decoding tools i get the following result:
x?}?Mk?@??J????ILL@??`?0??^"??B???Gm?}W?`/^?03????,,????
?=Z}??pT??[iA?-8??q
?I
??N
?h???GYN?\pZ?"?Y:??Pt9mS??<-D?$zCc?V
Ah?A??+Zq??8??|?d??$ZZ???J+?4
?/)?u????Kf?d>9??2.cf?-X?<?&??zq?K??A?O???ImZ??`76W???n?~???6
w?m?????
^???$????ie?;??3-I??k??7????Srtion">
test
</saml:Issuer>
<samlp:NameIDPolicy
Format="urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified"
AllowCreate="true" />
</samlp:AuthnRequest>
解决方案
You need to use URL decoder first and then Base64 decoder, is that what you are doing?
这篇关于SAML 2.0请求编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文