本文整理汇总了Java中org.apache.ws.security.WSConstants类的典型用法代码示例。如果您正苦于以下问题:Java WSConstants类的具体用法?Java WSConstants怎么用?Java WSConstants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WSConstants类属于org.apache.ws.security包,在下文中一共展示了WSConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testX509SignatureIS
import org.apache.ws.security.WSConstants; //导入依赖的package包/类
/**
* The test uses the ThumbprintSHA1 key identifier type.
* <p/>
*
* @throws java.lang.Exception Thrown when there is any problem in signing or verification
*/
public void testX509SignatureIS() throws Exception {
WSSecSignature builder = new WSSecSignature();
builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
LOG.info("Before Signing IS....");
Document doc = unsignedEnvelope.getAsDocument();
WSSecHeader secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
Document signedDoc = builder.build(doc, crypto, secHeader);
if (LOG.isDebugEnabled()) {
LOG.debug("Signed message with IssuerSerial key identifier:");
String outputString =
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc);
LOG.debug(outputString);
}
LOG.info("After Signing IS....");
verify(signedDoc);
}
示例2: getUsernameTokenPrincipal
import org.apache.ws.security.WSConstants; //导入依赖的package包/类
/**
* Returns the UsernameTokenPrincipal from the security results.
*
* @param mc The message context of the message
* @return the UsernameTokenPrincipal from the security results as an
* <code>org.apache.ws.security.WSUsernameTokenPrincipal</code>.
* If a wsse:UsernameToken was not present in the wsse:Security header then
* <code>null</code> will be returned.
* @throws Exception If there are no security results.
* @see org.apache.ws.security.WSUsernameTokenPrincipal
*/
public static WSUsernameTokenPrincipal getUsernameTokenPrincipal(
MessageContext mc) throws Exception {
Vector results;
if ((results = (Vector) mc.getProperty(WSHandlerConstants.RECV_RESULTS)) == null) {
throw new Exception("No security results available in the message context");
} else {
for (int i = 0; i < results.size(); i++) {
WSHandlerResult rResult = (WSHandlerResult) results.get(i);
Vector wsSecEngineResults = rResult.getResults();
for (int j = 0; j < wsSecEngineResults.size(); j++) {
WSSecurityEngineResult wser =
(WSSecurityEngineResult) wsSecEngineResults.get(j);
Integer actInt = (Integer) wser
.get(WSSecurityEngineResult.TAG_ACTION);
if (actInt.intValue() == WSConstants.UT) {
return (WSUsernameTokenPrincipal) wser
.get(WSSecurityEngineResult.TAG_PRINCIPAL);
}
}
}
}
return null;
}
示例3: setTimeStampPayloads
import org.apache.ws.security.WSConstants; //导入依赖的package包/类
@Override
public void setTimeStampPayloads( Element pay )
{
setDetectionPayElement( pay );
for ( Node cur = getDetectionPayElement().getFirstChild(); cur != null; cur = cur.getNextSibling() )
{
if ( cur.getNodeType() == Node.ELEMENT_NODE )
{
if ( WSConstants.CREATED_LN.equals( cur.getLocalName() )
&& WSConstants.WSU_NS.equals( cur.getNamespaceURI() ) )
{
setCreatedPayload( (Element) cur );
}
if ( WSConstants.EXPIRES_LN.equals( cur.getLocalName() )
&& WSConstants.WSU_NS.equals( cur.getNamespaceURI() ) )
{
setExpiresPayload( (Element) cur );
}
}
}
}
示例4: detectTimestampElement
import org.apache.ws.security.WSConstants; //导入依赖的package包/类
private void detectTimestampElement()
throws XPathExpressionException, ParseException
{
// detectionReport hinzufügen
List<Element> timestampList;
// TODO: SAML
timestampList =
(List<Element>) DomUtilities.evaluateXPath( m_InputFilter, "//*[local-name()='"
+ WSConstants.TIMESTAMP_TOKEN_LN + "' " + "and namespace-uri()='" + WSConstants.WSU_NS + "']" );
if ( 1 == timestampList.size() )
{
TimestampElement timestamp = new TimestampElement( timestampList.get( 0 ) );
( (TimestampInfo) m_OutputFilter ).setTimestamp( timestamp );
detectTimeDifference();
}
else if ( 1 < timestampList.size() )
{
LOG.warn( "multiple timestamps not supported yet" );
}
}
示例5: testBadRSAKeyValue
import org.apache.ws.security.WSConstants; //导入依赖的package包/类
/**
* Failed RSAKeyValue test, where a message is signed using a key-pair which doesn't
* correspond to the public key in the "trust"-store.
*/
public void testBadRSAKeyValue() throws Exception {
WSSecSignature builder = new WSSecSignature();
builder.setUserInfo("wss86", "security");
builder.setKeyIdentifierType(WSConstants.KEY_VALUE);
Document doc = unsignedEnvelope.getAsDocument();
WSSecHeader secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
Document signedDoc =
builder.build(doc, CryptoFactory.getInstance("wss86.properties"), secHeader);
String outputString =
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc);
if (LOG.isDebugEnabled()) {
LOG.debug(outputString);
}
assertTrue(outputString.indexOf("RSAKeyValue") != -1);
try {
verify(signedDoc);
fail("Failure expected on bad public key");
} catch (Exception ex) {
// expected
}
}
示例6: getKeyLength
import org.apache.ws.security.WSConstants; //导入依赖的package包/类
/**
* Returns the length of the key in # of bytes
*
* @param algorithm
* @return the key length
*/
public static int getKeyLength(String algorithm) throws WSSecurityException {
if (algorithm.equals(WSConstants.TRIPLE_DES)) {
return 24;
} else if (algorithm.equals(WSConstants.AES_128)) {
return 16;
} else if (algorithm.equals(WSConstants.AES_192)) {
return 24;
} else if (algorithm.equals(WSConstants.AES_256)) {
return 32;
} else if (XMLSignature.ALGO_ID_MAC_HMAC_SHA1.equals(algorithm)) {
return 20;
} else if (XMLSignature.ALGO_ID_MAC_HMAC_SHA256.equals(algorithm)) {
return 32;
} else if (XMLSignature.ALGO_ID_MAC_HMAC_SHA384.equals(algorithm)) {
return 48;
} else if (XMLSignature.ALGO_ID_MAC_HMAC_SHA512.equals(algorithm)) {
return 64;
} else if (XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5.equals(algorithm)) {
return 16;
} else {
throw new WSSecurityException(
WSSecurityException.UNSUPPORTED_ALGORITHM, null, null, null
);
}
}
示例7: testSignatureOID
import org.apache.ws.security.WSConstants; //导入依赖的package包/类
/**
* Test signing a SOAP message using a cert with an OID
*/
public void testSignatureOID() throws Exception {
SOAPEnvelope unsignedEnvelope = message.getSOAPEnvelope();
WSSecSignature sign = new WSSecSignature();
sign.setUserInfo("wss86", "security");
sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
Document doc = unsignedEnvelope.getAsDocument();
WSSecHeader secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
Document signedDoc = sign.build(doc, crypto, secHeader);
if (LOG.isDebugEnabled()) {
String outputString =
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc);
LOG.debug(outputString);
}
verify(signedDoc);
}
示例8: testEncryptionSHA1Symmetric
import org.apache.ws.security.WSConstants; //导入依赖的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.
*
* @throws java.lang.Exception Thrown when there is any problem in encryption or decryption
*/
public void testEncryptionSHA1Symmetric() throws Exception {
WSSecEncrypt builder = new WSSecEncrypt();
builder.setKeyIdentifierType(WSConstants.ENCRYPTED_KEY_SHA1_IDENTIFIER);
builder.setSymmetricKey(key);
builder.setEncryptSymmKey(false);
builder.setUseKeyIdentifier(true);
LOG.info("Before Encrypting EncryptedKeySHA1....");
Document doc = unsignedEnvelope.getAsDocument();
WSSecHeader secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
Document encryptedDoc = builder.build(doc, crypto, secHeader);
String outputString =
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(encryptedDoc);
if (LOG.isDebugEnabled()) {
LOG.debug("Encrypted message with ENCRYPTED_KEY_SHA1_IDENTIFIER:");
LOG.debug(outputString);
}
assertTrue(outputString.indexOf("#EncryptedKeySHA1") != -1);
LOG.info("After Encrypting EncryptedKeySHA1....");
verify(encryptedDoc);
}
示例9: setWsuId
import org.apache.ws.security.WSConstants; //导入依赖的package包/类
protected String setWsuId(Element bodyElement) {
String id = bodyElement.getAttributeNS(WSConstants.WSU_NS, "Id");
String newAttrNs = WSConstants.WSU_NS;
String newAttrPrefix = WSConstants.WSU_PREFIX;
if ((id == null || id.length() == 0)
&& WSConstants.ENC_NS.equals(bodyElement.getNamespaceURI())
&& (WSConstants.ENC_DATA_LN.equals(bodyElement.getLocalName())
|| WSConstants.ENC_KEY_LN.equals(bodyElement.getLocalName()))
) {
// If it is an XML-Enc derived element, it may already have an ID,
// plus it is not schema valid to add an additional ID.
id = bodyElement.getAttribute("Id");
newAttrPrefix = WSConstants.ENC_PREFIX;
newAttrNs = WSConstants.ENC_NS;
}
if ((id == null) || (id.length() == 0)) {
id = wssConfig.getIdAllocator().createId("id-", bodyElement);
String prefix =
WSSecurityUtil.setNamespace(bodyElement, newAttrNs, newAttrPrefix);
bodyElement.setAttributeNS(newAttrNs, prefix + ":Id", id);
}
return id;
}
示例10: testInvalidSecurityToken
import org.apache.ws.security.WSConstants; //导入依赖的package包/类
/**
* 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));
}
}
示例11: testX509EncryptionThumb
import org.apache.ws.security.WSConstants; //导入依赖的package包/类
/**
* Test that encrypts and decrypts a WS-Security envelope.
* The test uses the ThumbprintSHA1 key identifier type.
* <p/>
*
* @throws java.lang.Exception Thrown when there is any problem in encryption or decryption
*/
public void testX509EncryptionThumb() throws Exception {
WSSecEncrypt builder = new WSSecEncrypt();
builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
builder.setKeyIdentifierType(WSConstants.THUMBPRINT_IDENTIFIER);
LOG.info("Before Encrypting ThumbprintSHA1....");
Document doc = unsignedEnvelope.getAsDocument();
WSSecHeader secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
Document encryptedDoc = builder.build(doc, crypto, secHeader);
String outputString =
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(encryptedDoc);
if (LOG.isDebugEnabled()) {
LOG.debug("Encrypted message with THUMBPRINT_IDENTIFIER:");
LOG.debug(outputString);
}
assertTrue(outputString.indexOf("#ThumbprintSHA1") != -1);
LOG.info("After Encrypting ThumbprintSHA1....");
verify(encryptedDoc);
}
示例12: testUsernameTokenDigestText
import org.apache.ws.security.WSConstants; //导入依赖的package包/类
/**
* Test that adds a UserNameToken with a digested password but with type of
* password test.
*/
public void testUsernameTokenDigestText() throws Exception {
WSSecUsernameToken builder = new WSSecUsernameToken();
builder.setPasswordType(WSConstants.PASSWORD_TEXT);
byte[] password = "verySecret".getBytes();
MessageDigest sha = MessageDigest.getInstance("MD5");
sha.reset();
sha.update(password);
String passwdDigest = Base64.encode(sha.digest());
builder.setUserInfo("wernerd", passwdDigest);
LOG.info("Before adding UsernameToken PW Text....");
Document doc = unsignedEnvelope.getAsDocument();
WSSecHeader secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
Document signedDoc = builder.build(doc, secHeader);
if (LOG.isDebugEnabled()) {
LOG.debug("Message with UserNameToken PW Text:");
String outputString =
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc);
LOG.debug(outputString);
}
}
示例13: testEncryptionSHA1SymmetricBytes
import org.apache.ws.security.WSConstants; //导入依赖的package包/类
/**
* Test that encrypts using EncryptedKeySHA1, where it uses a symmetric key (bytes),
* rather than a generated session key which is then encrypted using a public key.
*
* @throws java.lang.Exception Thrown when there is any problem in encryption or decryption
*/
public void testEncryptionSHA1SymmetricBytes() throws Exception {
WSSecEncrypt builder = new WSSecEncrypt();
builder.setKeyIdentifierType(WSConstants.ENCRYPTED_KEY_SHA1_IDENTIFIER);
builder.setEphemeralKey(keyData);
builder.setEncryptSymmKey(false);
builder.setUseKeyIdentifier(true);
LOG.info("Before Encrypting EncryptedKeySHA1....");
Document doc = unsignedEnvelope.getAsDocument();
WSSecHeader secHeader = new WSSecHeader();
secHeader.insertSecurityHeader(doc);
Document encryptedDoc = builder.build(doc, crypto, secHeader);
String outputString =
org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(encryptedDoc);
if (LOG.isDebugEnabled()) {
LOG.debug("Encrypted message with ENCRYPTED_KEY_SHA1_IDENTIFIER:");
LOG.debug(outputString);
}
assertTrue(outputString.indexOf("#EncryptedKeySHA1") != -1);
LOG.info("After Encrypting EncryptedKeySHA1....");
verify(encryptedDoc);
}
示例14: testFailedAuthentication
import org.apache.ws.security.WSConstants; //导入依赖的package包/类
/**
* 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));
}
}
示例15: handleToken
import org.apache.ws.security.WSConstants; //导入依赖的package包/类
public final void
handleToken(
final org.w3c.dom.Element elem,
final Crypto crypto,
final Crypto decCrypto,
final javax.security.auth.callback.CallbackHandler cb,
final WSDocInfo wsDocInfo,
final java.util.Vector returnResults,
final WSSConfig config
) throws WSSecurityException {
final java.util.Map result =
new WSSecurityEngineResult(
WSConstants.UT_SIGN,
(SecurityContextToken) null
);
result.put("foo", this);
returnResults.add(result);
}