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


Java WSConstants.WSSE_NS属性代码示例

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


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

示例1: testFailedCheck

/**
 * Test for the wsse:FailedCheck faultcode. This will fail due to a bad password in
 * the callback handler.
 */
public void testFailedCheck() throws Exception {
    WSSecEncrypt builder = new WSSecEncrypt();
    builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
    builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
    Document doc = unsignedEnvelope.getAsDocument();
    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);        
    Document encryptedDoc = builder.build(doc, crypto, secHeader);
    
    try {
        verify(encryptedDoc);
    } catch (WSSecurityException ex) {
        assertTrue(ex.getErrorCode() == 6);
        assertTrue(ex.getMessage().startsWith("The signature or decryption was invalid"));
        QName faultCode = new QName(WSConstants.WSSE_NS, "FailedCheck");
        assertTrue(ex.getFaultCode().equals(faultCode));
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:22,代码来源:TestWSSecurityFaultCodes.java

示例2: testMessageExpired

/**
 * Test for the wsse:MessageExpired faultcode. This will fail due to the argument
 * passed to setTimeToLive.
 */
public void testMessageExpired() throws Exception {
    WSSecTimestamp builder = new WSSecTimestamp();
    builder.setTimeToLive(-1);
    
    Document doc = unsignedEnvelope.getAsDocument();
    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);        
    Document timestampedDoc = builder.build(doc, secHeader);
    
    try {
        verify(timestampedDoc);
    } catch (WSSecurityException ex) {
        assertTrue(ex.getErrorCode() == 8);
        assertTrue(ex.getMessage().startsWith(
            "The message has expired"));
        QName faultCode = new QName(WSConstants.WSSE_NS, "MessageExpired");
        assertTrue(ex.getFaultCode().equals(faultCode));
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:23,代码来源:TestWSSecurityFaultCodes.java

示例3: testFailedAuthentication

/**
 * Test for the wsse:FailedAuthentication faultcode. This will fail due to a bad password in
 * the callback handler.
 */
public void testFailedAuthentication() throws Exception {
    WSSecUsernameToken builder = new WSSecUsernameToken();
    builder.addCreated();
    builder.addNonce();
    builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
    
    Document doc = unsignedEnvelope.getAsDocument();
    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);        
    Document timestampedDoc = builder.build(doc, secHeader);
    
    try {
        verify(timestampedDoc);
    } catch (WSSecurityException ex) {
        assertTrue(ex.getErrorCode() == 5);
        assertTrue(ex.getMessage().startsWith(
            "The security token could not be authenticated or authorized"));
        QName faultCode = new QName(WSConstants.WSSE_NS, "FailedAuthentication");
        assertTrue(ex.getFaultCode().equals(faultCode));
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:25,代码来源:TestWSSecurityFaultCodes.java

示例4: testInvalidSecurityToken

/**
 * Test for the wsse:InvalidSecurityToken faultcode. This will fail due to the fact
 * that a null username is used.
 */
public void testInvalidSecurityToken() throws Exception {
    WSSecUsernameToken builder = new WSSecUsernameToken();
    builder.addCreated();
    builder.addNonce();
    builder.setUserInfo(null, "security");
    
    Document doc = unsignedEnvelope.getAsDocument();
    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);        
    builder.build(doc, secHeader);
    
    try {
        new UsernameToken(doc.getDocumentElement());
    } catch (WSSecurityException ex) {
        assertTrue(ex.getErrorCode() == 4);
        assertTrue(ex.getMessage().startsWith(
            "An invalid security token was provided"));
        QName faultCode = new QName(WSConstants.WSSE_NS, "InvalidSecurityToken");
        assertTrue(ex.getFaultCode().equals(faultCode));
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:25,代码来源:TestWSSecurityFaultCodes.java

示例5: testUnsupportedAlgorithm

/**
 * Test for the wsse:UnsupportedAlgorithm faultcode. This will fail due to the argument
 * passed to getCipherInstance.
 */
public void testUnsupportedAlgorithm() throws Exception {
    try {
        WSSecurityUtil.getCipherInstance("Bad Algorithm");
    } catch (WSSecurityException ex) {
        assertTrue(ex.getErrorCode() == 2);
        assertTrue(ex.getMessage().startsWith(
            "An unsupported signature or encryption algorithm was used"));
        QName faultCode = new QName(WSConstants.WSSE_NS, "UnsupportedAlgorithm");
        assertTrue(ex.getFaultCode().equals(faultCode));
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:15,代码来源:TestWSSecurityFaultCodes.java

示例6: testSecurityTokenUnavailable

/**
 * Test for the wsse:SecurityTokenUnavailable faultcode. This will fail due to the 
 * argument to loadCertificate.
 */
public void testSecurityTokenUnavailable() throws Exception {
    try {
        crypto.loadCertificate(new java.io.ByteArrayInputStream(new byte[]{}));
    } catch (WSSecurityException ex) {
        assertTrue(ex.getErrorCode() == 7);
        assertTrue(ex.getMessage().startsWith(
            "Referenced security token could not be retrieved"));
        QName faultCode = new QName(WSConstants.WSSE_NS, "SecurityTokenUnavailable");
        assertTrue(ex.getFaultCode().equals(faultCode));
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:15,代码来源:TestWSSecurityFaultCodes.java

示例7: testInvalidSecurity

/**
 * Test for the wsse:InvalidSecurity faultcode. 
 */
public void testInvalidSecurity() throws Exception {
    try {
        new Reference((org.w3c.dom.Element)null);
    } catch (WSSecurityException ex) {
        assertTrue(ex.getErrorCode() == 3);
        assertTrue(ex.getMessage().startsWith(
            "An error was discovered processing the <wsse:Security> header"));
        QName faultCode = new QName(WSConstants.WSSE_NS, "InvalidSecurity");
        assertTrue(ex.getFaultCode().equals(faultCode));
    }
}
 
开发者ID:wso2,项目名称:wso2-wss4j,代码行数:14,代码来源:TestWSSecurityFaultCodes.java


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