1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.wss4j.dom.action;
21
22 import org.apache.wss4j.dom.WSConstants;
23 import org.apache.wss4j.dom.engine.WSSecurityEngineResult;
24 import org.apache.wss4j.common.SecurityActionToken;
25 import org.apache.wss4j.common.SignatureActionToken;
26 import org.apache.wss4j.common.WSEncryptionPart;
27 import org.apache.wss4j.common.ext.WSSecurityException;
28 import org.apache.wss4j.dom.handler.RequestData;
29 import org.apache.wss4j.dom.handler.WSHandler;
30 import org.apache.wss4j.dom.handler.WSHandlerConstants;
31 import org.apache.wss4j.dom.handler.WSHandlerResult;
32 import org.apache.wss4j.dom.message.WSSecSignatureConfirmation;
33
34 import java.util.List;
35
36 public class SignatureConfirmationAction implements Action {
37 private static final org.slf4j.Logger LOG =
38 org.slf4j.LoggerFactory.getLogger(SignatureConfirmationAction.class);
39
40 @SuppressWarnings("unchecked")
41 public void execute(WSHandler handler, SecurityActionToken actionToken, RequestData reqData)
42 throws WSSecurityException {
43 LOG.debug("Perform Signature confirmation");
44
45 List<WSHandlerResult> results =
46 (List<WSHandlerResult>) handler.getProperty(
47 reqData.getMsgContext(), WSHandlerConstants.RECV_RESULTS
48 );
49 if (results == null || results.isEmpty()) {
50 return;
51 }
52
53
54
55
56 WSSecSignatureConfirmation wsc = new WSSecSignatureConfirmation(reqData.getSecHeader());
57 wsc.setIdAllocator(reqData.getWssConfig().getIdAllocator());
58 wsc.setWsDocInfo(reqData.getWsDocInfo());
59 wsc.setExpandXopInclude(reqData.isExpandXopInclude());
60 SignatureActionToken signatureToken = (SignatureActionToken)actionToken;
61 if (signatureToken == null) {
62 signatureToken = reqData.getSignatureToken();
63 }
64 List<WSEncryptionPart> signatureParts = signatureToken.getParts();
65
66
67
68
69 boolean signatureAdded = false;
70 for (WSHandlerResult wshResult : results) {
71 List<WSSecurityEngineResult> resultList = wshResult.getResults();
72
73 for (WSSecurityEngineResult result : resultList) {
74 Integer resultAction = (Integer) result.get(WSSecurityEngineResult.TAG_ACTION);
75
76
77 if (resultAction != null
78 && (WSConstants.SIGN == resultAction.intValue()
79 || WSConstants.ST_SIGNED == resultAction.intValue()
80 || WSConstants.UT_SIGN == resultAction.intValue())) {
81 byte[] sigVal = (byte[]) result.get(WSSecurityEngineResult.TAG_SIGNATURE_VALUE);
82 wsc.build(sigVal);
83 signatureParts.add(new WSEncryptionPart(wsc.getId()));
84 signatureAdded = true;
85 }
86 }
87 }
88
89 if (!signatureAdded) {
90 wsc.build(null);
91 signatureParts.add(new WSEncryptionPart(wsc.getId()));
92 }
93 handler.setProperty(
94 reqData.getMsgContext(), WSHandlerConstants.SIG_CONF_DONE, ""
95 );
96 }
97
98 }