"<sp:IncludeTimestamp/>\n" +
"<sp:EncryptSignature/>\n" +
"<sp:OnlySignEntireHeadersAndBody/>\n" +
"</wsp:Policy>\n" +
"</sp:SymmetricBinding>";
PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString);
TimestampSecurityEvent timestampSecurityEvent = new TimestampSecurityEvent();
policyEnforcer.registerSecurityEvent(timestampSecurityEvent);
RequiredElementSecurityEvent requiredElementSecurityEvent = new RequiredElementSecurityEvent();
List<QName> headerPath = new ArrayList<QName>();
headerPath.addAll(WSSConstants.WSSE_SECURITY_HEADER_PATH);
headerPath.add(WSSConstants.TAG_wsu_Timestamp);
requiredElementSecurityEvent.setElementPath(headerPath);
policyEnforcer.registerSecurityEvent(requiredElementSecurityEvent);
SecurityContextTokenSecurityEvent initiatorTokenSecurityEvent = new SecurityContextTokenSecurityEvent();
SecureConversationSecurityTokenImpl securityToken =
new SecureConversationSecurityTokenImpl(
null, "1", WSSecurityTokenConstants.KeyIdentifier_SecurityTokenDirectReference);
securityToken.addTokenUsage(WSSecurityTokenConstants.TokenUsage_MainSignature);
initiatorTokenSecurityEvent.setSecurityToken(securityToken);
policyEnforcer.registerSecurityEvent(initiatorTokenSecurityEvent);
SecurityContextTokenSecurityEvent recipientTokenSecurityEvent = new SecurityContextTokenSecurityEvent();
securityToken = new SecureConversationSecurityTokenImpl(
null, "1", WSSecurityTokenConstants.KeyIdentifier_SecurityTokenDirectReference);
securityToken.addTokenUsage(WSSecurityTokenConstants.TokenUsage_MainEncryption);
recipientTokenSecurityEvent.setSecurityToken(securityToken);
policyEnforcer.registerSecurityEvent(recipientTokenSecurityEvent);
List<XMLSecurityConstants.ContentType> protectionOrder = new LinkedList<XMLSecurityConstants.ContentType>();
protectionOrder.add(XMLSecurityConstants.ContentType.SIGNATURE);
protectionOrder.add(XMLSecurityConstants.ContentType.ENCRYPTION);
EncryptedElementSecurityEvent encryptedElementSecurityEvent = new EncryptedElementSecurityEvent(null, true, protectionOrder);
headerPath = new ArrayList<QName>();
headerPath.addAll(WSSConstants.WSSE_SECURITY_HEADER_PATH);
headerPath.add(WSSConstants.TAG_dsig_Signature);
encryptedElementSecurityEvent.setElementPath(headerPath);
policyEnforcer.registerSecurityEvent(encryptedElementSecurityEvent);
encryptedElementSecurityEvent = new EncryptedElementSecurityEvent(null, true, protectionOrder);
headerPath = new ArrayList<QName>();
headerPath.addAll(WSSConstants.WSSE_SECURITY_HEADER_PATH);
headerPath.add(WSSConstants.TAG_wsse11_SignatureConfirmation);
encryptedElementSecurityEvent.setElementPath(headerPath);
policyEnforcer.registerSecurityEvent(encryptedElementSecurityEvent);
OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent();
operationSecurityEvent.setOperation(new QName("definitions"));
policyEnforcer.registerSecurityEvent(operationSecurityEvent);
SignedPartSecurityEvent signedPartSecurityEvent = new SignedPartSecurityEvent(null, true, protectionOrder);
signedPartSecurityEvent.setXmlSecEvent(XMLSecEventFactory.createXmlSecStartElement(WSSConstants.TAG_soap11_Body, null, null));
signedPartSecurityEvent.setElementPath(WSSConstants.SOAP_11_BODY_PATH);
policyEnforcer.registerSecurityEvent(signedPartSecurityEvent);
policyEnforcer.doFinal();
}