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


Java RequestData.setUsername方法代码示例

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


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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: testWSS170

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * A test for "SignatureAction does not set DigestAlgorithm on WSSecSignature instance"
 */
public void
testWSS170() throws Exception {
    final WSSConfig cfg = WSSConfig.getNewInstance();
    final int action = WSConstants.SIGN;
    final RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);
    reqData.setUsername("16c73ab6-b892-458f-abf5-2f875f74882e");
    java.util.Map config = new java.util.TreeMap();
    config.put(WSHandlerConstants.SIG_PROP_FILE, "crypto.properties");
    config.put("password", "security");
    config.put(
        WSHandlerConstants.SIG_ALGO, 
        "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
    );
    config.put(
        WSHandlerConstants.SIG_DIGEST_ALGO, 
        "http://www.w3.org/2001/04/xmlenc#sha256"
    );
    reqData.setMsgContext(config);
    
    final java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(action));
    final Document doc = unsignedEnvelope.getAsDocument();
    MyHandler handler = new MyHandler();
    handler.doit(
        action, 
        doc, 
        reqData, 
        actions
    );
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Signed message:");
        LOG.debug(outputString);
    }
    assertTrue(
        outputString.indexOf("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256") != -1
    );
    assertTrue(
        outputString.indexOf("http://www.w3.org/2001/04/xmlenc#sha256") != -1
    );
    
    verify(doc);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:49,代码来源:TestWSSecurityNew18.java

示例12: testHandlerSignature

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * Test using a UsernameToken derived key for signing a SOAP body via WSHandler
 */
public void testHandlerSignature() throws Exception {
    
    final WSSConfig cfg = WSSConfig.getNewInstance();
    RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);
    java.util.Map messageContext = new java.util.TreeMap();
    messageContext.put(WSHandlerConstants.PW_CALLBACK_REF, this);
    messageContext.put(WSHandlerConstants.USE_DERIVED_KEY, "true");
    reqData.setMsgContext(messageContext);
    reqData.setUsername("bob");
    
    final java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(WSConstants.UT_SIGN));
    
    Document doc = unsignedEnvelope.getAsDocument();
    MyHandler handler = new MyHandler();
    handler.send(
        WSConstants.UT_SIGN, 
        doc, 
        reqData, 
        actions,
        true
    );
    
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
    assertTrue(outputString.indexOf("wsse:Username") != -1);
    assertTrue(outputString.indexOf("wsse:Password") == -1);
    assertTrue(outputString.indexOf("wsse11:Salt") != -1);
    assertTrue(outputString.indexOf("wsse11:Iteration") != -1);
    if (LOG.isDebugEnabled()) {
        LOG.debug(outputString);
    }
    
    Vector results = verify(doc);
    WSSecurityEngineResult actionResult =
        WSSecurityUtil.fetchActionResult(results, WSConstants.UT_SIGN);
    java.security.Principal principal = 
        (java.security.Principal) actionResult.get(WSSecurityEngineResult.TAG_PRINCIPAL);
    assertTrue(principal.getName().indexOf("bob") != -1);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:45,代码来源:TestWSSecurityUTSignature.java

示例13: testHandlerSignatureIterations

import org.apache.ws.security.handler.RequestData; //导入方法依赖的package包/类
/**
 * Test using a UsernameToken derived key for signing a SOAP body via WSHandler
 */
public void testHandlerSignatureIterations() throws Exception {
    
    final WSSConfig cfg = WSSConfig.getNewInstance();
    RequestData reqData = new RequestData();
    reqData.setWssConfig(cfg);
    java.util.Map messageContext = new java.util.TreeMap();
    messageContext.put(WSHandlerConstants.PW_CALLBACK_REF, this);
    messageContext.put(WSHandlerConstants.USE_DERIVED_KEY, "true");
    messageContext.put(WSHandlerConstants.DERIVED_KEY_ITERATIONS, "1234");
    reqData.setMsgContext(messageContext);
    reqData.setUsername("bob");
    
    final java.util.Vector actions = new java.util.Vector();
    actions.add(new Integer(WSConstants.UT_SIGN));
    
    Document doc = unsignedEnvelope.getAsDocument();
    MyHandler handler = new MyHandler();
    handler.send(
        WSConstants.UT_SIGN, 
        doc, 
        reqData, 
        actions,
        true
    );
    
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
    assertTrue(outputString.indexOf("wsse:Username") != -1);
    assertTrue(outputString.indexOf("wsse:Password") == -1);
    assertTrue(outputString.indexOf("wsse11:Salt") != -1);
    assertTrue(outputString.indexOf("wsse11:Iteration") != -1);
    assertTrue(outputString.indexOf("1234") != -1);
    if (LOG.isDebugEnabled()) {
        LOG.debug(outputString);
    }
    
    Vector results = verify(doc);
    WSSecurityEngineResult actionResult =
        WSSecurityUtil.fetchActionResult(results, WSConstants.UT_SIGN);
    java.security.Principal principal = 
        (java.security.Principal) actionResult.get(WSSecurityEngineResult.TAG_PRINCIPAL);
    assertTrue(principal.getName().indexOf("bob") != -1);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:47,代码来源:TestWSSecurityUTSignature.java


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