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


Java WSSecUsernameToken.getId方法代码示例

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


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

示例1: testDerivedKeyEncryption

import org.apache.ws.security.message.WSSecUsernameToken; //导入方法依赖的package包/类
/**
 * Test using a UsernameToken derived key for encrypting a SOAP body
 */
public void testDerivedKeyEncryption() throws Exception {
    Document doc = unsignedEnvelope.getAsDocument();
    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);
    
    WSSecUsernameToken builder = new WSSecUsernameToken();
    builder.setUserInfo("bob", "security");
    builder.addDerivedKey(false, null, 1000);
    builder.prepare(doc);
    
    byte[] derivedKey = builder.getDerivedKey();
    assertTrue(derivedKey.length == 20);
    
    String tokenIdentifier = builder.getId();
    
    //
    // Derived key encryption
    //
    WSSecDKEncrypt encrBuilder = new WSSecDKEncrypt();
    encrBuilder.setSymmetricEncAlgorithm(WSConstants.AES_128);
    encrBuilder.setExternalKey(derivedKey, tokenIdentifier);
    Document encryptedDoc = encrBuilder.build(doc, secHeader);
    
    builder.prependToHeader(secHeader);
    
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(encryptedDoc);
    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("testMethod") == -1);
    if (LOG.isDebugEnabled()) {
        LOG.debug(outputString);
    }
    
    verify(encryptedDoc);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:42,代码来源:TestWSSecurityUTDK.java

示例2: testDerivedKeyBadUserSignature

import org.apache.ws.security.message.WSSecUsernameToken; //导入方法依赖的package包/类
/**
 * Test using a UsernameToken derived key for signing a SOAP body. In this test the
 * user is "alice" rather than "bob", and so signature verification should fail.
 */
public void testDerivedKeyBadUserSignature() throws Exception {
    Document doc = unsignedEnvelope.getAsDocument();
    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);
    
    WSSecUsernameToken builder = new WSSecUsernameToken();
    builder.setUserInfo("alice", "security");
    builder.addDerivedKey(true, null, 1000);
    builder.prepare(doc);
    
    byte[] derivedKey = builder.getDerivedKey();
    assertTrue(derivedKey.length == 20);
    
    String tokenIdentifier = builder.getId();
    
    //
    // Derived key signature
    //
    WSSecDKSign sigBuilder = new WSSecDKSign();
    sigBuilder.setExternalKey(derivedKey, tokenIdentifier);
    sigBuilder.setSignatureAlgorithm(XMLSignature.ALGO_ID_MAC_HMAC_SHA1);
    Document signedDoc = sigBuilder.build(doc, secHeader);
    
    builder.prependToHeader(secHeader);
    
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc);
    if (LOG.isDebugEnabled()) {
        LOG.debug(outputString);
    }

    try {
        verify(signedDoc);
        throw new Exception("Failure expected on a bad derived signature");
    } catch (WSSecurityException ex) {
        assertTrue(ex.getErrorCode() == WSSecurityException.FAILED_AUTHENTICATION);
        // expected
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:44,代码来源:TestWSSecurityUTDK.java

示例3: testDerivedKeyEncryptionWithEncodedPassword

import org.apache.ws.security.message.WSSecUsernameToken; //导入方法依赖的package包/类
/**
 * Test using a UsernameToken derived key for encrypting a SOAP body
 */
public void testDerivedKeyEncryptionWithEncodedPassword() throws Exception {
    Document doc = unsignedEnvelope.getAsDocument();
    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);
    
    WSSecUsernameToken builder = new WSSecUsernameToken();
    builder.setPasswordsAreEncoded(true);
    builder.setUserInfo("bob", Base64.encode(MessageDigest.getInstance("SHA-1").digest("security".getBytes("UTF-8"))));
    builder.addDerivedKey(false, null, 1000);
    builder.prepare(doc);
    
    byte[] derivedKey = builder.getDerivedKey();
    assertTrue(derivedKey.length == 20);
    
    String tokenIdentifier = builder.getId();
    
    //
    // Derived key encryption
    //
    WSSecDKEncrypt encrBuilder = new WSSecDKEncrypt();
    encrBuilder.setSymmetricEncAlgorithm(WSConstants.AES_128);
    encrBuilder.setExternalKey(derivedKey, tokenIdentifier);
    Document encryptedDoc = encrBuilder.build(doc, secHeader);
    
    builder.prependToHeader(secHeader);
    
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(encryptedDoc);
    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("testMethod") == -1);
    if (LOG.isDebugEnabled()) {
        LOG.debug(outputString);
    }
    
    boolean passwordsAreEnabledOrig = WSSecurityEngine.getInstance().getWssConfig().getPasswordsAreEncoded();
    try {
        WSSecurityEngine.getInstance().getWssConfig().setPasswordsAreEncoded(true);
        verify(encryptedDoc);
    } finally {
        WSSecurityEngine.getInstance().getWssConfig().setPasswordsAreEncoded(passwordsAreEnabledOrig);
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:49,代码来源:TestWSSecurityUTDK.java

示例4: testDerivedKeyChangedEncryption

import org.apache.ws.security.message.WSSecUsernameToken; //导入方法依赖的package包/类
/**
 * Test using a UsernameToken derived key for encrypting a SOAP body. In this test the
 * derived key is modified before encryption, and so decryption should fail.
 */
public void testDerivedKeyChangedEncryption() throws Exception {
    Document doc = unsignedEnvelope.getAsDocument();
    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);
    
    WSSecUsernameToken builder = new WSSecUsernameToken();
    builder.setUserInfo("bob", "security");
    builder.addDerivedKey(false, null, 1000);
    builder.prepare(doc);
    
    byte[] derivedKey = builder.getDerivedKey();
    derivedKey[5] = 12;
    assertTrue(derivedKey.length == 20);
    
    String tokenIdentifier = builder.getId();
    
    //
    // Derived key encryption
    //
    WSSecDKEncrypt encrBuilder = new WSSecDKEncrypt();
    encrBuilder.setSymmetricEncAlgorithm(WSConstants.AES_128);
    encrBuilder.setExternalKey(derivedKey, tokenIdentifier);
    Document encryptedDoc = encrBuilder.build(doc, secHeader);
    
    builder.prependToHeader(secHeader);
    
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(encryptedDoc);
    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("testMethod") == -1);
    if (LOG.isDebugEnabled()) {
        LOG.debug(outputString);
    }
    
    try {
        verify(encryptedDoc);
        throw new Exception("Failure expected on a bad derived encryption");
    } catch (WSSecurityException ex) {
        assertTrue(ex.getErrorCode() == WSSecurityException.FAILED_CHECK);
        // expected
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:50,代码来源:TestWSSecurityUTDK.java

示例5: testDerivedKeyBadUserEncryption

import org.apache.ws.security.message.WSSecUsernameToken; //导入方法依赖的package包/类
/**
 * Test using a UsernameToken derived key for encrypting a SOAP body. In this test the
 * user is "alice" rather than "bob", and so decryption should fail.
 */
public void testDerivedKeyBadUserEncryption() throws Exception {
    Document doc = unsignedEnvelope.getAsDocument();
    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);
    
    WSSecUsernameToken builder = new WSSecUsernameToken();
    builder.setUserInfo("alice", "security");
    builder.addDerivedKey(false, null, 1000);
    builder.prepare(doc);
    
    byte[] derivedKey = builder.getDerivedKey();
    assertTrue(derivedKey.length == 20);
    
    String tokenIdentifier = builder.getId();
    
    //
    // Derived key encryption
    //
    WSSecDKEncrypt encrBuilder = new WSSecDKEncrypt();
    encrBuilder.setSymmetricEncAlgorithm(WSConstants.AES_128);
    encrBuilder.setExternalKey(derivedKey, tokenIdentifier);
    Document encryptedDoc = encrBuilder.build(doc, secHeader);
    
    builder.prependToHeader(secHeader);
    
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(encryptedDoc);
    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("testMethod") == -1);
    if (LOG.isDebugEnabled()) {
        LOG.debug(outputString);
    }
    
    try {
        verify(encryptedDoc);
        throw new Exception("Failure expected on a bad derived encryption");
    } catch (WSSecurityException ex) {
        assertTrue(ex.getErrorCode() == WSSecurityException.FAILED_AUTHENTICATION);
        // expected
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:49,代码来源:TestWSSecurityUTDK.java

示例6: testDerivedKeySignature

import org.apache.ws.security.message.WSSecUsernameToken; //导入方法依赖的package包/类
/**
 * Test using a UsernameToken derived key for signing a SOAP body
 */
public void testDerivedKeySignature() throws Exception {
    Document doc = unsignedEnvelope.getAsDocument();
    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);
    
    WSSecUsernameToken builder = new WSSecUsernameToken();
    builder.setUserInfo("bob", "security");
    builder.addDerivedKey(true, null, 1000);
    builder.prepare(doc);
    
    byte[] derivedKey = builder.getDerivedKey();
    assertTrue(derivedKey.length == 20);
    
    String tokenIdentifier = builder.getId();
    
    //
    // Derived key signature
    //
    WSSecDKSign sigBuilder = new WSSecDKSign();
    sigBuilder.setExternalKey(derivedKey, tokenIdentifier);
    sigBuilder.setSignatureAlgorithm(XMLSignature.ALGO_ID_MAC_HMAC_SHA1);
    Document signedDoc = sigBuilder.build(doc, secHeader);
    
    builder.prependToHeader(secHeader);
    
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc);
    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(signedDoc);
    WSSecurityEngineResult actionResult =
        WSSecurityUtil.fetchActionResult(results, WSConstants.SIGN);
    java.security.Principal principal = 
        (java.security.Principal) actionResult.get(WSSecurityEngineResult.TAG_PRINCIPAL);
    //System.out.println(principal.getName());
    assertTrue(principal.getName().indexOf("derivedKey") != -1);
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:47,代码来源:TestWSSecurityUTDK.java

示例7: testDerivedKeySignatureWithEncodedPassword

import org.apache.ws.security.message.WSSecUsernameToken; //导入方法依赖的package包/类
/**
 * Test using a UsernameToken derived key for signing a SOAP body
 */
public void testDerivedKeySignatureWithEncodedPassword() throws Exception {
    Document doc = unsignedEnvelope.getAsDocument();
    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);
    
    WSSecUsernameToken builder = new WSSecUsernameToken();
    builder.setPasswordsAreEncoded(true);
    builder.setUserInfo("bob", Base64.encode(MessageDigest.getInstance("SHA-1").digest("security".getBytes("UTF-8"))));
    builder.addDerivedKey(true, null, 1000);
    builder.prepare(doc);
    
    byte[] derivedKey = builder.getDerivedKey();
    assertTrue(derivedKey.length == 20);
    
    String tokenIdentifier = builder.getId();
    
    //
    // Derived key signature
    //
    WSSecDKSign sigBuilder = new WSSecDKSign();
    sigBuilder.setExternalKey(derivedKey, tokenIdentifier);
    sigBuilder.setSignatureAlgorithm(XMLSignature.ALGO_ID_MAC_HMAC_SHA1);
    Document signedDoc = sigBuilder.build(doc, secHeader);
    
    builder.prependToHeader(secHeader);
    
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc);
    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);
    }
    
    boolean passwordsAreEnabledOrig = WSSecurityEngine.getInstance().getWssConfig().getPasswordsAreEncoded();
    try {
        WSSecurityEngine.getInstance().getWssConfig().setPasswordsAreEncoded(true);
        Vector results = verify(signedDoc);
        WSSecurityEngineResult actionResult =
            WSSecurityUtil.fetchActionResult(results, WSConstants.SIGN);
        java.security.Principal principal = 
            (java.security.Principal) actionResult.get(WSSecurityEngineResult.TAG_PRINCIPAL);
        //System.out.println(principal.getName());
        assertTrue(principal.getName().indexOf("derivedKey") != -1);
    } finally {
        WSSecurityEngine.getInstance().getWssConfig().setPasswordsAreEncoded(passwordsAreEnabledOrig);
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:54,代码来源:TestWSSecurityUTDK.java

示例8: testDerivedKeyChangedSignature

import org.apache.ws.security.message.WSSecUsernameToken; //导入方法依赖的package包/类
/**
 * Test using a UsernameToken derived key for signing a SOAP body. In this test the
 * derived key is modified before signature, and so signature verification should
 * fail.
 */
public void testDerivedKeyChangedSignature() throws Exception {
    Document doc = unsignedEnvelope.getAsDocument();
    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);
    
    WSSecUsernameToken builder = new WSSecUsernameToken();
    builder.setUserInfo("bob", "security");
    builder.addDerivedKey(true, null, 1000);
    builder.prepare(doc);
    
    byte[] derivedKey = builder.getDerivedKey();
    derivedKey[5] = 12;
    assertTrue(derivedKey.length == 20);
    
    String tokenIdentifier = builder.getId();
    
    //
    // Derived key signature
    //
    WSSecDKSign sigBuilder = new WSSecDKSign();
    sigBuilder.setExternalKey(derivedKey, tokenIdentifier);
    sigBuilder.setSignatureAlgorithm(XMLSignature.ALGO_ID_MAC_HMAC_SHA1);
    Document signedDoc = sigBuilder.build(doc, secHeader);
    
    builder.prependToHeader(secHeader);
    
    String outputString = 
        org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc);
    if (LOG.isDebugEnabled()) {
        LOG.debug(outputString);
    }

    try {
        verify(signedDoc);
        throw new Exception("Failure expected on a bad derived signature");
    } catch (WSSecurityException ex) {
        assertTrue(ex.getErrorCode() == WSSecurityException.FAILED_CHECK);
        // expected
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:46,代码来源:TestWSSecurityUTDK.java


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