Search in sources :

Example 1 with REFERENCE_TYPE

use of org.apache.wss4j.dom.str.STRParser.REFERENCE_TYPE in project testcases by coheigea.

the class EncryptionReferenceBenchmark method doEncryption.

private void doEncryption(int identifier, REFERENCE_TYPE referenceType, Crypto verifyingCrypto) throws Exception {
    Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
    WSSecHeader secHeader = new WSSecHeader(doc);
    secHeader.insertSecurityHeader();
    WSSecEncrypt builder = new WSSecEncrypt(secHeader);
    builder.setUserInfo("myservicekey", "skpass");
    builder.setKeyIdentifierType(identifier);
    Document encryptedDoc = builder.build(serviceCrypto);
    WSSecurityEngine engine = new WSSecurityEngine();
    RequestData data = new RequestData();
    data.setWssConfig(WSSConfig.getNewInstance());
    data.setDecCrypto(verifyingCrypto);
    data.setCallbackHandler(new CommonCallbackHandler());
    Element securityHeader = WSSecurityUtil.getSecurityHeader(encryptedDoc, "");
    Assert.assertNotNull(securityHeader);
    WSHandlerResult results = engine.processSecurityHeader(securityHeader, data);
    WSSecurityEngineResult actionResult = results.getActionResults().get(WSConstants.ENCR).get(0);
    Assert.assertNotNull(actionResult.get(WSSecurityEngineResult.TAG_X509_CERTIFICATE));
    Assert.assertNotNull(actionResult.get(WSSecurityEngineResult.TAG_X509_REFERENCE_TYPE));
    REFERENCE_TYPE refType = (REFERENCE_TYPE) actionResult.get(WSSecurityEngineResult.TAG_X509_REFERENCE_TYPE);
    Assert.assertTrue(refType == referenceType);
}
Also used : WSSecHeader(org.apache.wss4j.dom.message.WSSecHeader) WSSecEncrypt(org.apache.wss4j.dom.message.WSSecEncrypt) RequestData(org.apache.wss4j.dom.handler.RequestData) REFERENCE_TYPE(org.apache.wss4j.dom.str.STRParser.REFERENCE_TYPE) Element(org.w3c.dom.Element) 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)

Example 2 with REFERENCE_TYPE

use of org.apache.wss4j.dom.str.STRParser.REFERENCE_TYPE in project testcases by coheigea.

the class SignatureReferenceBenchmark method doSignature.

private void doSignature(int identifier, REFERENCE_TYPE referenceType, 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(identifier);
    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));
    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));
    REFERENCE_TYPE refType = (REFERENCE_TYPE) actionResult.get(WSSecurityEngineResult.TAG_X509_REFERENCE_TYPE);
    Assert.assertTrue(refType == referenceType);
}
Also used : WSSecHeader(org.apache.wss4j.dom.message.WSSecHeader) RequestData(org.apache.wss4j.dom.handler.RequestData) REFERENCE_TYPE(org.apache.wss4j.dom.str.STRParser.REFERENCE_TYPE) WSSecSignature(org.apache.wss4j.dom.message.WSSecSignature) Element(org.w3c.dom.Element) 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

WSSecurityEngine (org.apache.wss4j.dom.engine.WSSecurityEngine)2 WSSecurityEngineResult (org.apache.wss4j.dom.engine.WSSecurityEngineResult)2 RequestData (org.apache.wss4j.dom.handler.RequestData)2 WSHandlerResult (org.apache.wss4j.dom.handler.WSHandlerResult)2 WSSecHeader (org.apache.wss4j.dom.message.WSSecHeader)2 REFERENCE_TYPE (org.apache.wss4j.dom.str.STRParser.REFERENCE_TYPE)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 WSSecEncrypt (org.apache.wss4j.dom.message.WSSecEncrypt)1 WSSecSignature (org.apache.wss4j.dom.message.WSSecSignature)1