当前位置: 首页>>代码示例>>Java>>正文


Java RequestData.setMsgContext方法代码示例

本文整理汇总了Java中org.apache.ws.security.handler.RequestData.setMsgContext方法的典型用法代码示例。如果您正苦于以下问题:Java RequestData.setMsgContext方法的具体用法?Java RequestData.setMsgContext怎么用?Java RequestData.setMsgContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.ws.security.handler.RequestData的用法示例。


在下文中一共展示了RequestData.setMsgContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testUsernameTokenWSHandler

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * Test that adds a UserNameToken via WSHandler
 */
public void testUsernameTokenWSHandler() throws Exception {
    MyHandler handler = new MyHandler();
    Document doc = unsignedEnvelope.getAsDocument();
    
    RequestData reqData = new RequestData();
    java.util.Map config = new java.util.TreeMap();
    config.put("password", "verySecret");
    config.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    reqData.setUsername("wernerd");
    reqData.setMsgContext(config);
    
    java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(WSConstants.UT));
    
    handler.send(WSConstants.UT, doc, reqData, actions, true);
    
    if (LOG.isDebugEnabled()) {
        LOG.debug("Username Token via WSHandler");
        String outputString = 
            org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
        LOG.debug(outputString);
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:27,代码来源:TestWSSecurityNew5.java

示例2: testUsernameTokenWSHandlerEmptyPassword

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * Test that adds a UserNameToken with an empty password via WSHandler
 */
public void testUsernameTokenWSHandlerEmptyPassword() throws Exception {
    MyHandler handler = new MyHandler();
    Document doc = unsignedEnvelope.getAsDocument();
    
    RequestData reqData = new RequestData();
    java.util.Map config = new java.util.TreeMap();
    config.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    config.put(WSHandlerConstants.PW_CALLBACK_REF, this);
    reqData.setUsername("emptyuser");
    reqData.setMsgContext(config);
    
    java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(WSConstants.UT));
    
    handler.send(WSConstants.UT, doc, reqData, actions, true);
    
    if (LOG.isDebugEnabled()) {
        LOG.debug("Username Token with an empty password via WSHandler");
        String outputString = 
            org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
        LOG.debug(outputString);
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:27,代码来源:TestWSSecurityNew5.java

示例3: testGetPasswordRequestContextUnit

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * A unit test for {@link WSHandler#getPassword(String, int, String, String, RequestData)},
 * where the password is obtained from the Message Context.
 */
public void
testGetPasswordRequestContextUnit() throws Exception {
    
    final WSSConfig cfg = WSSConfig.getNewInstance();
    final RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);
    java.util.Map messageContext = new java.util.TreeMap();
    messageContext.put("password", "securityPassword");
    reqData.setMsgContext(messageContext);
    
    WSHandler handler = new MyHandler();
    WSPasswordCallback callback = 
        handler.getPassword(
            "bob", 
            WSConstants.UT, 
            "SomeCallbackTag", 
            "SomeCallbackRef",
            reqData
        );
    assertTrue("bob".equals(callback.getIdentifier()));
    assertTrue("securityPassword".equals(callback.getPassword()));
    assertTrue(WSPasswordCallback.USERNAME_TOKEN == callback.getUsage());
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:28,代码来源:TestWSSecurityGetPassword.java

示例4: testCustomAction

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * Test to see that a custom action configured through a
 * WSSConfig instance is called
 */
public void
testCustomAction() throws Exception {
    
    final WSSConfig cfg = WSSConfig.getNewInstance();
    final int action = 0xDEADF000;
    cfg.setAction(action, "wssec.MyAction");
    final RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);
    reqData.setMsgContext(new java.util.TreeMap());
    
    final java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(action));
    final Document doc = unsignedEnvelope.getAsDocument();
    MyHandler handler = new MyHandler();
    reqData.setMsgContext("bread");
    assertEquals(reqData.getMsgContext(), "bread");
    handler.doit(
        action, 
        doc, 
        reqData, 
        actions
    );
    assertEquals(reqData.getMsgContext(), "crumb");
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:29,代码来源:TestWSSecurityUserProcessor.java

示例5: testCustomActionObject

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * Test to see that a custom action object configured through a
 * WSSConfig instance is called
 */
public void
testCustomActionObject() throws Exception {
    
    final WSSConfig cfg = WSSConfig.getNewInstance();
    final int action = 0xDEADF000;
    cfg.setAction(action, new wssec.MyAction());
    final RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);
    reqData.setMsgContext(new java.util.TreeMap());
    
    final java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(action));
    final Document doc = unsignedEnvelope.getAsDocument();
    MyHandler handler = new MyHandler();
    reqData.setMsgContext("bread");
    assertEquals(reqData.getMsgContext(), "bread");
    handler.doit(
        action, 
        doc, 
        reqData, 
        actions
    );
    assertEquals(reqData.getMsgContext(), "crumb");
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:29,代码来源:TestWSSecurityUserProcessor.java

示例6: execute

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
public void 
execute(
    WSHandler handler, 
    int actionToDo, 
    org.w3c.dom.Document doc,
    RequestData reqData
) throws WSSecurityException {
    //
    // leave a breadcrumb, if asked...
    //
    if (reqData.getMsgContext().equals("bread")) {
        reqData.setMsgContext("crumb");
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:15,代码来源:MyAction.java

示例7: testEncryptionSHA1SymmetricBytesHandler

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * Test that encrypts using EncryptedKeySHA1, where it uses a symmetric key, rather than a 
 * generated session key which is then encrypted using a public key. The request is generated
 * using WSHandler, instead of coding it.
 * 
 * @throws java.lang.Exception Thrown when there is any problem in encryption or decryption
 * 
 */
public void testEncryptionSHA1SymmetricBytesHandler() throws Exception {
    final WSSConfig cfg = WSSConfig.getNewInstance();
    final RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);
    java.util.Map messageContext = new java.util.TreeMap();
    messageContext.put(WSHandlerConstants.ENC_SYM_ENC_KEY, "false");
    messageContext.put(WSHandlerConstants.ENC_KEY_ID, "EncryptedKeySHA1");
    messageContext.put(WSHandlerConstants.PW_CALLBACK_REF, this);
    reqData.setMsgContext(messageContext);
    reqData.setUsername("");
    
    final java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(WSConstants.ENCR));
    
    Document doc = unsignedEnvelope.getAsDocument();
    MyHandler handler = new MyHandler();
    handler.send(
        WSConstants.ENCR, 
        doc, 
        reqData, 
        actions,
        true
    );
    
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
    if (LOG.isDebugEnabled()) {
        LOG.debug(outputString);
    }
    
    verify(doc);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:41,代码来源:TestWSSecurityNew14.java

示例8: testGetPasswordRequestContext

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * A WSHandler test for {@link WSHandler#getPassword(String, int, String, String, RequestData)},
 * where the password is obtained from the Message Context.
 */
public void
testGetPasswordRequestContext() throws Exception {
    
    final WSSConfig cfg = WSSConfig.getNewInstance();
    final RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);
    reqData.setUsername("bob");
    reqData.setPwType(WSConstants.PASSWORD_TEXT);
    java.util.Map messageContext = new java.util.TreeMap();
    messageContext.put("password", "securityPassword");
    reqData.setMsgContext(messageContext);
    
    final java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(WSConstants.UT));
    Document doc = unsignedEnvelope.getAsDocument();
    MyHandler handler = new MyHandler();
    handler.doit(
        WSConstants.UT, 
        doc, 
        reqData, 
        actions
    );
    
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
    if (LOG.isDebugEnabled()) {
        LOG.debug(outputString);
    }
    assertTrue(outputString.indexOf("bob") != -1);
    assertTrue(outputString.indexOf("securityPassword") != -1);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:36,代码来源:TestWSSecurityGetPassword.java

示例9: testGetPasswordCallbackHandlerRef

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * A test for {@link WSHandler#getPassword(String, int, String, String, RequestData)},
 * where the password is obtained from a Callback Handler, which is placed on the 
 * Message Context using a reference.
 */
public void
testGetPasswordCallbackHandlerRef() throws Exception {
    
    final WSSConfig cfg = WSSConfig.getNewInstance();
    final RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);
    reqData.setUsername("bob");
    reqData.setPwType(WSConstants.PASSWORD_TEXT);
    java.util.Map messageContext = new java.util.TreeMap();
    messageContext.put(
        WSHandlerConstants.PW_CALLBACK_REF, 
        new MyCallbackHandler()
    );
    reqData.setMsgContext(messageContext);
    
    final java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(WSConstants.UT));
    Document doc = unsignedEnvelope.getAsDocument();
    MyHandler handler = new MyHandler();
    handler.doit(
        WSConstants.UT, 
        doc, 
        reqData, 
        actions
    );
    
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
    if (LOG.isDebugEnabled()) {
        LOG.debug(outputString);
    }
    assertTrue(outputString.indexOf("bob") != -1);
    assertTrue(outputString.indexOf("securityPassword") != -1);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:40,代码来源:TestWSSecurityGetPassword.java

示例10: testMessageContextRef

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * A test for {@link WSHandler#getPassword(String, int, String, String, RequestData)},
 * where the password is obtained from a Callback Handler, which is placed on the 
 * Message Context using a reference.
 */
public void
testMessageContextRef() throws Exception {
    
    final WSSConfig cfg = WSSConfig.getNewInstance();
    final RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);
    reqData.setUsername("bob");
    reqData.setPwType(WSConstants.PASSWORD_TEXT);
    java.util.Map messageContext = new java.util.TreeMap();
    messageContext.put(
        WSHandlerConstants.PW_CALLBACK_REF, 
        new MyCallbackHandler()
    );
    reqData.setMsgContext(messageContext);
    
    final java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(WSConstants.UT));
    Document doc = unsignedEnvelope.getAsDocument();
    MyHandler handler = new MyHandler();
    handler.send(
        WSConstants.UT, 
        doc, 
        reqData, 
        actions,
        true
    );
    
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
    if (LOG.isDebugEnabled()) {
        LOG.debug(outputString);
    }
    assertTrue(outputString.indexOf("bob") != -1);
    assertTrue(outputString.indexOf("securityPassword") != -1);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:41,代码来源:TestWSSecurityWSS245.java

示例11: testHandlerOptionRef

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * A test for {@link WSHandler#getPassword(String, int, String, String, RequestData)},
 * where the password is obtained from a Callback Handler, which is obtained from the
 * handler options using a ref.
 */
public void
testHandlerOptionRef() throws Exception {
    
    final WSSConfig cfg = WSSConfig.getNewInstance();
    final RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);
    reqData.setUsername("bob");
    reqData.setPwType(WSConstants.PASSWORD_TEXT);
    reqData.setMsgContext(new java.util.TreeMap());
    
    final java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(WSConstants.UT));
    Document doc = unsignedEnvelope.getAsDocument();
    MyHandler handler = new MyHandler();
    handler.setOption(WSHandlerConstants.PW_CALLBACK_REF, new MyCallbackHandler());
    handler.send(
        WSConstants.UT, 
        doc, 
        reqData, 
        actions,
        true
    );
    
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
    if (LOG.isDebugEnabled()) {
        LOG.debug(outputString);
    }
    assertTrue(outputString.indexOf("bob") != -1);
    assertTrue(outputString.indexOf("securityPassword") != -1);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:37,代码来源:TestWSSecurityWSS245.java

示例12: testWSS226Handler

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * Test that uses a 32 byte key length for the secret key, instead of the default 16 bytes.
 * This test configures the key length via WSHandler.
 */
public void testWSS226Handler() throws Exception {
    MyHandler handler = new MyHandler();
    Document doc = unsignedEnvelope.getAsDocument();
    
    RequestData reqData = new RequestData();
    reqData.setWssConfig(WSSConfig.getNewInstance());
    java.util.Map config = new java.util.TreeMap();
    config.put("password", "verySecret");
    config.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    config.put(WSHandlerConstants.WSE_SECRET_KEY_LENGTH, "32");
    reqData.setUsername("wernerd");
    reqData.setMsgContext(config);
    
    java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(WSConstants.UT_SIGN));
    
    handler.send(WSConstants.UT_SIGN, doc, reqData, actions, true);
    
    if (LOG.isDebugEnabled()) {
        LOG.debug("Username Token Signature via WSHandler");
        String outputString = 
            org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
        LOG.debug(outputString);
    }
    
    //
    // It should fail on the default key length of 16...
    //
    try {
        secEngine.processSecurityHeader(doc, null, this, null);
        fail ("An error was expected on verifying the signature");
    } catch (Exception ex) {
        // expected
    }
    
    handler.receive(WSConstants.UT_SIGN, reqData);
    
    WSSecurityEngine wss226SecurityEngine = new WSSecurityEngine();
    wss226SecurityEngine.setWssConfig(reqData.getWssConfig());
    wss226SecurityEngine.processSecurityHeader(doc, null, this, null);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:46,代码来源:TestWSSecurityNew13.java

示例13: testUsernameTokenSignatureHandler

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * Test involving adding a Username Token to a SOAP message and signing it, where the
 * private key for signature is extracted from the KeyStore using a different username/alias
 * to the UsernameToken. 
 */
public void 
testUsernameTokenSignatureHandler() throws Exception {
    final WSSConfig cfg = WSSConfig.getNewInstance();
    final RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);
    reqData.setUsername("alice");
    reqData.setPwType(WSConstants.PASSWORD_DIGEST);
    java.util.Map messageContext = new java.util.TreeMap();
    messageContext.put(
        WSHandlerConstants.PW_CALLBACK_REF, 
        this
    );
    messageContext.put(WSHandlerConstants.SIGNATURE_USER, "wss86");
    messageContext.put(WSHandlerConstants.SIG_PROP_FILE, "wss86.properties");
    messageContext.put(
        WSHandlerConstants.SIGNATURE_PARTS, 
        "{}{" + WSConstants.WSSE_NS + "}" + "UsernameToken"
    );
    messageContext.put(WSHandlerConstants.SIG_KEY_ID, "DirectReference");
    reqData.setMsgContext(messageContext);
    
    final java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(WSConstants.UT));
    actions.add(new Integer(WSConstants.SIGN));
    final Document doc = unsignedEnvelope.getAsDocument();
    MyHandler handler = new MyHandler();
    handler.send(
        WSConstants.UT | WSConstants.SIGN, 
        doc, 
        reqData, 
        actions,
        true
    );
    
    if (LOG.isDebugEnabled()) {
        LOG.debug("After Signing....");
        String outputString = 
            org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
        LOG.debug(outputString);
    }
    
    verify(doc);
    
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:50,代码来源:TestWSSecurityWSS194.java

示例14: testWSS62

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * A test for WSS-62: "the crypto file not being retrieved in the doReceiverAction
 * method for the Saml Signed Token"
 * 
 * https://issues.apache.org/jira/browse/WSS-62
 */
public void testWSS62() throws Exception {
    SOAPEnvelope unsignedEnvelope = message.getSOAPEnvelope();
    SAMLIssuer saml = SAMLIssuerFactory.getInstance("saml.properties");

    SAMLAssertion assertion = saml.newAssertion();

    String issuerKeyName = saml.getIssuerKeyName();
    String issuerKeyPW = saml.getIssuerKeyPassword();
    Crypto issuerCrypto = saml.getIssuerCrypto();
    WSSecSignatureSAML wsSign = new WSSecSignatureSAML();
    wsSign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
    
    Document doc = unsignedEnvelope.getAsDocument();

    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);
    
    Document signedDoc = 
        wsSign.build(doc, null, assertion, issuerCrypto, issuerKeyName, issuerKeyPW, secHeader);
    
    //
    // Now verify it but first call Handler#doReceiverAction
    //
    final WSSConfig cfg = WSSConfig.getNewInstance();
    final RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);
    reqData.setMsgContext(new java.util.TreeMap());
    java.util.Map msgContext = new java.util.HashMap();
    msgContext.put(WSHandlerConstants.SIG_PROP_FILE, "crypto.properties");
    reqData.setMsgContext(msgContext);
    
    MyHandler handler = new MyHandler();
    handler.doit(WSConstants.ST_SIGNED, reqData);
    
    secEngine.processSecurityHeader(
        signedDoc, null, this, reqData.getSigCrypto(), reqData.getDecCrypto()
    );
    
    //
    // Negative test
    //
    msgContext.put(WSHandlerConstants.SIG_PROP_FILE, "crypto.properties.na");
    reqData.setMsgContext(msgContext);
    
    handler = new MyHandler();
    try {
        handler.doit(WSConstants.ST_SIGNED, reqData);
        fail("Failure expected on a bad crypto properties file");
    } catch (RuntimeException ex) {
        // expected
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:59,代码来源:TestWSSecurityNewST2.java

示例15: testMultipleCertsWSHandler

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * A test for "SignatureAction does not set DigestAlgorithm on WSSecSignature instance"
 */
public void testMultipleCertsWSHandler() throws Exception {
    final WSSConfig cfg = WSSConfig.getNewInstance();
    final int action = WSConstants.SIGN;
    final RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);
    reqData.setUsername("wss40");
    java.util.Map config = new java.util.TreeMap();
    config.put(WSHandlerConstants.SIG_PROP_FILE, "wss40.properties");
    config.put("password", "security");
    config.put(WSHandlerConstants.SIG_KEY_ID, "DirectReference");
    config.put(WSHandlerConstants.USE_SINGLE_CERTIFICATE, "false");
    reqData.setMsgContext(config);
    
    final java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(action));
    Document doc = unsignedEnvelope.getAsDocument();
    MyHandler handler = new MyHandler();
    handler.send(
        action, 
        doc, 
        reqData, 
        actions,
        true
    );
    
    //
    // Verify the signature
    //
    Vector results = verify(doc, cryptoCA);
    WSSecurityEngineResult result = 
        WSSecurityUtil.fetchActionResult(results, WSConstants.SIGN);
    X509Certificate cert = 
        (X509Certificate)result.get(WSSecurityEngineResult.TAG_X509_CERTIFICATE);
    assertTrue (cert != null);
    X509Certificate[] certs = 
        (X509Certificate[])result.get(WSSecurityEngineResult.TAG_X509_CERTIFICATES);
    assertTrue (certs != null && certs.length == 2);
    
    assertTrue(handler.verifyTrust(certs, reqData));
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:44,代码来源:TestWSSecurityWSS40.java


注:本文中的org.apache.ws.security.handler.RequestData.setMsgContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。