- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用二进制安全 token 来发送 SOAP 消息。在 SoapUI 中一切正常,但在 Java 中我无法得到相同的结果。我正在使用 wss4j-2.2.2。
我想要实现的目标:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:stat="http://example.com/y/ws/x/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1" wsu:Id="X509-8A99177A7EC2D385BA155346257881246">MIIP(...)Rw==</wsse:BinarySecurityToken>
<ds:Signature Id="SIG-8A99177A7EC2D385BA155346257888650" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces PrefixList="soapenv stat" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<ds:Reference URI="#id-8A99177A7EC2D385BA155346257881349">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces PrefixList="stat" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>EJK(...)U=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>hFK(...)w==</ds:SignatureValue>
<ds:KeyInfo Id="KI-8A99177A7EC2D385BA155346257881247">
<wsse:SecurityTokenReference wsse11:TokenType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1" wsu:Id="STR-8A99177A7EC2D385BA155346257881248" xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd">
<wsse:Reference URI="#X509-8A99177A7EC2D385BA155346257881246" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1"/>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature>
</wsse:Security>
</soapenv:Header>
<soapenv:Body wsu:Id="id-8A99177A7EC2D385BA155346257881349" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<stat:zapytajOStatusKomunikatu>
<komunikat>
<identyfikatorKomunikatu>12345</identyfikatorKomunikatu>
</komunikat>
</stat:zapytajOStatusKomunikatu>
</soapenv:Body>
</soapenv:Envelope>
我正在使用 WSS4J 进行签名,但收到错误:没有 ID 为“noXMLSig”的消息。我有有效的 PKCS12 keystore ,但我做错了什么。
这是我的代码:
@Override
public boolean handleMessage(SOAPMessageContext context) {
Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty) {
SOAPMessage message = context.getMessage(); // <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><S:Body><ns2:zapytajOStatusKomunikatu xmlns:ns2="http://example.com/y/ws/x/"><komunikat><identyfikatorKomunikatu>1234</identyfikatorKomunikatu></komunikat></ns2:zapytajOStatusKomunikatu></S:Body></S:Envelope>
try {
org.apache.xml.security.Init.init();
String certPath = "file.p12";
String pass = "pass";
String alias = "alias";
KeyStore store = KeyStore.getInstance("PKCS12");
store.load(new FileInputStream(certPath), pass.toCharArray());
Document doc = message.getSOAPBody().getOwnerDocument();
Properties properties = new Properties();
properties.setProperty("org.apache.ws.security.crypto.provider", "org.apache.wss4j.common.crypto.Merlin");
properties.setProperty("org.apache.wss4j.crypto.merlin.keystore.alias", alias);
properties.setProperty("org.apache.ws.security.crypto.merlin.keystore.type", "PKCS12");
properties.setProperty("org.apache.ws.security.crypto.merlin.keystore.password", pass);
properties.setProperty("org.apache.ws.security.crypto.merlin.keystore.file", certPath);
Merlin crypto = (Merlin)CryptoFactory.getInstance(properties);
// crypto.setKeyStore(store);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.setMustUnderstand(false);
secHeader.insertSecurityHeader();
WSSecSignature sign = new WSSecSignature(doc);
sign.setUserInfo(alias, pass);
sign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); // Binary Security Token - SecurityTokenReference
sign.setSigCanonicalization(CanonicalizationMethod.EXCLUSIVE);
sign.setDigestAlgo(DigestMethod.SHA1);
Document signedDoc = sign.build(crypto);
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
}
行sign.build(crypto)导致异常:
org.apache.wss4j.common.ext.WSSecurityException: No message with ID "noXMLSig" found in resource bundle "org/apache/xml/security/resource/xmlsecurity". Original Exception was a java.lang.NullPointerException and message null
Original Exception was java.lang.NullPointerException
at org.apache.wss4j.dom.message.WSSecSignature.prepare(WSSecSignature.java:185)
at org.apache.wss4j.dom.message.WSSecSignature.build(WSSecSignature.java:382)
at com.example.MySOAPHandler.handleMessage(MySOAPHandler.java:165)
at com.example.MySOAPHandler.handleMessage(MySOAPHandler.java:57)
at com.sun.xml.internal.ws.handler.HandlerProcessor.callHandleMessage(HandlerProcessor.java:282)
at com.sun.xml.internal.ws.handler.HandlerProcessor.callHandlersRequest(HandlerProcessor.java:123)
at com.sun.xml.internal.ws.handler.ClientSOAPHandlerTube.callHandlersOnRequest(ClientSOAPHandlerTube.java:127)
at com.sun.xml.internal.ws.handler.HandlerTube.processRequest(HandlerTube.java:112)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:1121)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:1035)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:1004)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:862)
at com.sun.xml.internal.ws.client.Stub.process(Stub.java:448)
at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:178)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:77)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147)
at com.sun.proxy.$Proxy106.checkStatus(Unknown Source)
at com.example.MenuService.checkStatus(MenuService.java:1819)
at com.example.MenuService.testAction3(MenuService.java:1795)
at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
at com.example.action.ActionDelegate.perform(ActionDelegate.java:157)
at com.example.action.ActionDelegate.perform(ActionDelegate.java:152)
at org.apache.pivot.wtk.Button.press(Button.java:453)
at org.apache.pivot.wtk.Menu$Item.press(Menu.java:195)
at org.apache.pivot.wtk.skin.MenuItemSkin.mouseUp(MenuItemSkin.java:144)
at org.apache.pivot.wtk.Component$ComponentMouseButtonListenerList.mouseUp(Component.java:521)
at org.apache.pivot.wtk.Component.mouseUp(Component.java:2952)
at org.apache.pivot.wtk.Container.mouseUp(Container.java:845)
at org.apache.pivot.wtk.Container.mouseUp(Container.java:845)
at org.apache.pivot.wtk.Container.mouseUp(Container.java:845)
at org.apache.pivot.wtk.Container.mouseUp(Container.java:845)
at org.apache.pivot.wtk.Container.mouseUp(Container.java:845)
at org.apache.pivot.wtk.ApplicationContext$DisplayHost.processMouseEvent(ApplicationContext.java:998)
at java.awt.Component.processEvent(Component.java:6298)
at org.apache.pivot.wtk.ApplicationContext$DisplayHost.processEvent(ApplicationContext.java:792)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.NullPointerException
at org.apache.wss4j.dom.util.SignatureUtils.getInclusivePrefixes(SignatureUtils.java:78)
at org.apache.wss4j.dom.message.WSSecSignatureBase.getInclusivePrefixes(WSSecSignatureBase.java:323)
at org.apache.wss4j.dom.message.WSSecSignature.prepare(WSSecSignature.java:178)
... 61 more
我不知道我做错了什么。
最佳答案
应该是
WSSecSignature sign = new WSSecSignature(secHeader);
而不是
WSSecSignature sign = new WSSecSignature(doc);
No message with ID "noXMLSig" found in resource bundle
实际上意味着:我找不到标题
关于java - 使用 WSS4J 签署 XML。没有 ID 为 "noXMLSig"的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55328931/
在C语言中,当有变量(假设都是int)i小于j时,我们可以用等式 i^=j^=i^=j 交换两个变量的值。例如,令int i = 3,j = 5;在计算 i^=j^=i^=j 之后,我有 i = 5,
我为以下问题编写了以下代码: 给定一个由 N 个正整数组成的序列 A,编写一个程序来查找满足 i > A[j]A[i](A[i] 的 A[j] 次方 > A[j] 的 A[i] 次方)。 我的代码通过
这个表达式是从左到右解析的吗?我试图解释解析的结果,但最后的结果是错误的。 int j=10, k=10; j+=j-=j*=j; //j=j+(j-=j*=j)=j+(j-j*j) k+=k*=
给定一个整数数组 A ,我试图找出在给定位置 j ,A[j] 从每个 i=0 到 i=j 在 A 中出现了多少次。我设计了一个如下所示的解决方案 map CF[400005]; for(int i=0
你能帮我算法吗: 给定 2 个相同大小的数组 a[]和 b[]具有大于或等于 1 的整数。 查找不相等的索引 i和 j ( i != j ) 使得值 -max(a[i]*b[i] + a[i] * b
每次用J的M.副词,性能显着下降。因为我怀疑艾弗森和许比我聪明得多,我一定是做错了什么。 考虑 Collatz conjecture .这里似乎有各种各样的内存机会,但不管我放在哪里M. ,性能太差了
假设一个包含各种类型的盒装矩阵: matrix =: ('abc';'defgh';23),:('foo';'bar';45) matrix +---+-----+--+|abc|defgh|23|+
是否有可能对于两个正整数 i 和 j,(-i)/j 不等于 -(i/j)?我不知道这是否可能......我认为这将是关于位的东西,或者 char 类型的溢出或其他东西,但我找不到它。有什么想法吗? 最
假设两个不同大小的数组: N0 =: i. 50 N1 =: i. 500 应该有一种方法可以获得唯一的对,只需将两者结合起来即可。我发现的“最简单”是: ]$R =: |:,"2 |: (,.N0)
我是 J 的新用户,我只是想知道 J 包中是否实现了三次样条插值方法? 最佳答案 我自己不熟悉,但是我确实安装了所有的包,所以 $ rg -l -i spline /usr/share/j/9.02
在 Q/kdb 中,您可以使用 ': 轻松修改动词,它代表每个优先级。它会将动词应用于一个元素及其之前的邻居。例如 =': 检查值对是否相等。在 J 中,您可以轻松折叠 /\ 但它是累积的,是否有成对
嗨,我有一个 4x4 双矩阵 A 1+2i 2-1i -3-2i -1+4i 3-1i -3+2i 1-3i -1-3i 4+3i 3+5i 1-2i -1-4i
刚刚发现 J 语言,我输入: 1+^o.*0j1 I expected the answer to be 0 ,但我得到了 0j1.22465e_16。虽然这非常接近于 0,但我想知道为什么 J 应该
这个问题在这里已经有了答案: With arrays, why is it the case that a[5] == 5[a]? (20 个答案) 关闭 3 年前。 我正在阅读“C++ 编程语言”
当第一行是 1, 1/2 , 1/3 ....这是支持该问题的图像。 是否存在比朴素的 O(n^2) 方法更有效的方法? 我在研究伯努利数时遇到了这个问题,然后在研究“Akiyama-Tanigawa
我写了一段Java代码,它在无限循环中运行。 下面是代码: public class TestProgram { public static void main(String[] args){
for (int i = n; i > 0; i /= 2) { for (int j = 0; j 0; i /= 2) 的第一个循环结果 O(log N) . 第二个循环for (int
如问题中所述,需要找到数组中 (i,j) 对的总数,使得 (1) **ia[j]** 其中 i 和 j 是数组的索引。没有空间限制。 我的问题是 1) Is there any approach w
for l in range(1,len(S)-1): for i in range(1,len(S)-l): j=i+l for X in N:
第二个for循环的复杂度是多少?会是n-i吗?根据我的理解,第一个 for 循环将执行 n 次,但第二个 for 循环中的索引设置为 i。 //where n is the number elemen
我是一名优秀的程序员,十分优秀!