Search in sources :

Example 1 with BSPRule

use of org.apache.wss4j.common.bsp.BSPRule in project testcases by coheigea.

the class SignatureAlgorithmBenchmark method doSignature.

private void doSignature(String c14nAlgo, boolean addInclusivePrefixes, String digestAlgo, String sigAlgo, Crypto verifyingCrypto) throws Exception {
    Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
    WSSecHeader secHeader = new WSSecHeader(doc);
    secHeader.insertSecurityHeader();
    WSSecSignature builder = new WSSecSignature(secHeader);
    builder.setUserInfo("myclientkey", "ckpass");
    builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
    builder.setSigCanonicalization(c14nAlgo);
    builder.setDigestAlgo(digestAlgo);
    builder.setSignatureAlgorithm(sigAlgo);
    builder.setAddInclusivePrefixes(addInclusivePrefixes);
    Document signedDoc = builder.build(clientCrypto);
    WSSecurityEngine engine = new WSSecurityEngine();
    RequestData data = new RequestData();
    data.setWssConfig(WSSConfig.getNewInstance());
    data.setSigVerCrypto(verifyingCrypto);
    data.setSubjectCertConstraints(Collections.singletonList(certConstraint));
    List<BSPRule> ignoredRules = new ArrayList<BSPRule>();
    ignoredRules.add(BSPRule.R5404);
    ignoredRules.add(BSPRule.R5406);
    data.setIgnoredBSPRules(ignoredRules);
    Element securityHeader = WSSecurityUtil.getSecurityHeader(signedDoc, "");
    Assert.assertNotNull(securityHeader);
    WSHandlerResult results = engine.processSecurityHeader(securityHeader, data);
    WSSecurityEngineResult actionResult = results.getActionResults().get(WSConstants.SIGN).get(0);
    Assert.assertNotNull(actionResult.get(WSSecurityEngineResult.TAG_X509_CERTIFICATE));
    Assert.assertNotNull(actionResult.get(WSSecurityEngineResult.TAG_X509_REFERENCE_TYPE));
}
Also used : BSPRule(org.apache.wss4j.common.bsp.BSPRule) WSSecHeader(org.apache.wss4j.dom.message.WSSecHeader) RequestData(org.apache.wss4j.dom.handler.RequestData) WSSecSignature(org.apache.wss4j.dom.message.WSSecSignature) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) WSSecurityEngine(org.apache.wss4j.dom.engine.WSSecurityEngine) Document(org.w3c.dom.Document) WSHandlerResult(org.apache.wss4j.dom.handler.WSHandlerResult) WSSecurityEngineResult(org.apache.wss4j.dom.engine.WSSecurityEngineResult)

Aggregations

ArrayList (java.util.ArrayList)1 BSPRule (org.apache.wss4j.common.bsp.BSPRule)1 WSSecurityEngine (org.apache.wss4j.dom.engine.WSSecurityEngine)1 WSSecurityEngineResult (org.apache.wss4j.dom.engine.WSSecurityEngineResult)1 RequestData (org.apache.wss4j.dom.handler.RequestData)1 WSHandlerResult (org.apache.wss4j.dom.handler.WSHandlerResult)1 WSSecHeader (org.apache.wss4j.dom.message.WSSecHeader)1 WSSecSignature (org.apache.wss4j.dom.message.WSSecSignature)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1