You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wss4j-dev@ws.apache.org by co...@apache.org on 2009/02/26 13:47:45 UTC
svn commit: r748120 [2/2] - in
/webservices/wss4j/trunk/src/org/apache/ws/security: components/crypto/
message/ message/token/ util/
Modified: webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSignature.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSignature.java?rev=748120&r1=748119&r2=748120&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSignature.java (original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSignature.java Thu Feb 26 12:47:45 2009
@@ -61,11 +61,9 @@
* Creates a Signature according to WS Specification, X509 profile.
*
* This class is a re-factored implementation of the previous WSS4J class
- * <code>WSSignEnvlope</code>. This new class allows better control of
+ * <code>WSSignEnvelope</code>. This new class allows better control of
* the process to create a Signature and to add it to the Security header.
*
- * <br/>
- *
* The flexibility and fine granular control is required to implement a handler
* that uses WSSecurityPolicy files to control the setup of a Security header.
*
@@ -150,8 +148,7 @@
* algorithm to use is performed during the <code>prepare()</code>
* method. Refer to WSConstants which algorithms are supported.
*
- * @param algo
- * Is the name of the signature algorithm
+ * @param algo Is the name of the signature algorithm
* @see WSConstants#RSA
* @see WSConstants#DSA
*/
@@ -179,8 +176,7 @@
* XML Canonicalization is used by default Refer to WSConstants which
* algorithms are supported.
*
- * @param algo
- * Is the name of the signature algorithm
+ * @param algo Is the name of the signature algorithm
* @see WSConstants#C14N_OMIT_COMMENTS
* @see WSConstants#C14N_WITH_COMMENTS
* @see WSConstants#C14N_EXCL_OMIT_COMMENTS
@@ -220,8 +216,7 @@
/**
- * @param usernameToken
- * The usernameToken to set.
+ * @param usernameToken The usernameToken to set.
*/
public void setUsernameToken(WSSecUsernameToken usernameToken) {
this.usernameToken = usernameToken;
@@ -261,10 +256,9 @@
* BinaruSecurityToken element.
*/
public String getBSTTokenId() {
- if(this.bstToken == null) {
+ if (this.bstToken == null) {
return null;
}
-
return this.bstToken.getID();
}
@@ -275,42 +269,35 @@
* relevant information was set. After setup of the references to elements
* to sign may be added. After all references are added they can be signed.
*
- * <p/>
- *
* This method does not add the Signature element to the security header.
* See <code>prependSignatureElementToHeader()</code> method.
*
- * @param doc
- * The SOAP envelope as <code>Document</code>
- * @param cr
- * An instance of the Crypto API to handle keystore and
- * certificates
- * @param secHeader
- * The security header that will hold the Signature. This is used
- * to construct namespace prefixes for Signature. This method
+ * @param doc The SOAP envelope as <code>Document</code>
+ * @param cr An instance of the Crypto API to handle keystore and certificates
+ * @param secHeader The security header that will hold the Signature. This is used
+ * to construct namespace prefixes for Signature. This method
* @throws WSSecurityException
*/
public void prepare(Document doc, Crypto cr, WSSecHeader secHeader)
- throws WSSecurityException {
- /*
- * Gather some info about the document to process and store it for
- * retrieval
- */
+ throws WSSecurityException {
+ //
+ // Gather some info about the document to process and store it for
+ // retrieval
+ //
crypto = cr;
document = doc;
-
wsDocInfo = new WSDocInfo(doc.hashCode());
wsDocInfo.setCrypto(cr);
- /*
- * At first get the security token (certificate) according to the
- * parameters.
- */
+ //
+ // At first get the security token (certificate) according to the
+ // parameters.
+ //
X509Certificate[] certs = null;
if (keyIdentifierType != WSConstants.UT_SIGNING
- && keyIdentifierType != WSConstants.CUSTOM_SYMM_SIGNING
- && keyIdentifierType != WSConstants.CUSTOM_SYMM_SIGNING_DIRECT
- && keyIdentifierType != WSConstants.ENCRYPTED_KEY_SHA1_IDENTIFIER) {
+ && keyIdentifierType != WSConstants.CUSTOM_SYMM_SIGNING
+ && keyIdentifierType != WSConstants.CUSTOM_SYMM_SIGNING_DIRECT
+ && keyIdentifierType != WSConstants.ENCRYPTED_KEY_SHA1_IDENTIFIER) {
certs = crypto.getCertificates(user);
if (certs == null || certs.length <= 0) {
throw new WSSecurityException(
@@ -320,10 +307,10 @@
);
}
certUri = "CertId-" + certs[0].hashCode();
- /*
- * If no signature algo was set try to detect it according to the
- * data stored in the certificate.
- */
+ //
+ // If no signature algorithm was set try to detect it according to the
+ // data stored in the certificate.
+ //
if (sigAlgo == null) {
String pubKeyAlgo = certs[0].getPublicKey().getAlgorithm();
log.debug("automatic sig algo detection: " + pubKeyAlgo);
@@ -335,37 +322,29 @@
throw new WSSecurityException(
WSSecurityException.FAILURE,
"unknownSignatureAlgorithm",
- new Object[] {
- pubKeyAlgo
- }
+ new Object[] {pubKeyAlgo}
);
}
}
}
- /*
- * Get an initialized XMLSignature element.
- */
+ //
+ // Get an initialized XMLSignature element.
+ //
if (canonAlgo.equals(WSConstants.C14N_EXCL_OMIT_COMMENTS)) {
- Element canonElem = XMLUtils.createElementInSignatureSpace(doc,
- Constants._TAG_CANONICALIZATIONMETHOD);
-
+ Element canonElem =
+ XMLUtils.createElementInSignatureSpace(doc, Constants._TAG_CANONICALIZATIONMETHOD);
canonElem.setAttributeNS(null, Constants._ATT_ALGORITHM, canonAlgo);
if (wssConfig.isWsiBSPCompliant()) {
Set prefixes = getInclusivePrefixes(secHeader.getSecurityHeader(), false);
-
- InclusiveNamespaces inclusiveNamespaces = new InclusiveNamespaces(
- doc, prefixes);
-
+ InclusiveNamespaces inclusiveNamespaces = new InclusiveNamespaces(doc, prefixes);
canonElem.appendChild(inclusiveNamespaces.getElement());
}
try {
- SignatureAlgorithm signatureAlgorithm = new SignatureAlgorithm(
- doc, sigAlgo);
- sig = new XMLSignature(doc, null, signatureAlgorithm
- .getElement(), canonElem);
+ SignatureAlgorithm signatureAlgorithm = new SignatureAlgorithm(doc, sigAlgo);
+ sig = new XMLSignature(doc, null, signatureAlgorithm.getElement(), canonElem);
} catch (XMLSecurityException e) {
log.error("", e);
throw new WSSecurityException(
@@ -395,17 +374,16 @@
strUri = "STRId-" + secRef.hashCode();
secRef.setID(strUri);
- /*
- * Prepare and setup the token references for this Signature
- */
+ //
+ // Prepare and setup the token references for this Signature
+ //
switch (keyIdentifierType) {
case WSConstants.BST_DIRECT_REFERENCE:
Reference ref = new Reference(document);
ref.setURI("#" + certUri);
if (!useSingleCert) {
bstToken = new PKIPathSecurity(document);
- ((PKIPathSecurity) bstToken).setX509Certificates(certs, false,
- crypto);
+ ((PKIPathSecurity) bstToken).setX509Certificates(certs, false, crypto);
} else {
bstToken = new X509Security(document);
((X509Security) bstToken).setX509Certificate(certs[0]);
@@ -417,8 +395,7 @@
break;
case WSConstants.ISSUER_SERIAL:
- XMLX509IssuerSerial data = new XMLX509IssuerSerial(document,
- certs[0]);
+ XMLX509IssuerSerial data = new XMLX509IssuerSerial(document, certs[0]);
X509Data x509Data = new X509Data(document);
x509Data.add(data);
secRef.setX509IssuerSerial(x509Data);
@@ -462,8 +439,7 @@
secRef.setReference(refCustd);
break;
default:
- throw new WSSecurityException(WSSecurityException.FAILURE,
- "unsupportedKeyId");
+ throw new WSSecurityException(WSSecurityException.FAILURE, "unsupportedKeyId");
}
keyInfo.addUnknownElement(secRef.getElement());
@@ -477,137 +453,126 @@
* times to add references as required. <code>addReferencesToSign()</code>
* can be called any time after <code>prepare</code>.
*
- * @param references
- * A vector containing <code>WSEncryptionPart</code> objects
- * that define the parts to sign.
- * @param secHeader
- * Used to compute namespaces to be inserted by
- * InclusiveNamespaces to be WSI compliant.
+ * @param references A vector containing <code>WSEncryptionPart</code> objects
+ * that define the parts to sign.
+ * @param secHeader Used to compute namespaces to be inserted by
+ * InclusiveNamespaces to be WSI compliant.
* @throws WSSecurityException
*/
public void addReferencesToSign(Vector references, WSSecHeader secHeader)
- throws WSSecurityException {
- Transforms transforms = null;
-
+ throws WSSecurityException {
Element envelope = document.getDocumentElement();
for (int part = 0; part < references.size(); part++) {
WSEncryptionPart encPart = (WSEncryptionPart) references.get(part);
String idToSign = encPart.getId();
-
String elemName = encPart.getName();
String nmSpace = encPart.getNamespace();
- /*
- * Set up the elements to sign. There are two reserved element
- * names: "Token" and "STRTransform" "Token": Setup the Signature to
- * either sign the information that points to the security token or
- * the token itself. If its a direct reference sign the token,
- * otherwise sign the KeyInfo Element. "STRTransform": Setup the
- * ds:Reference to use STR Transform
- *
- */
- transforms = new Transforms(document);
+ //
+ // Set up the elements to sign. There are two reserved element
+ // names: "Token" and "STRTransform" "Token": Setup the Signature to
+ // either sign the information that points to the security token or
+ // the token itself. If its a direct reference sign the token,
+ // otherwise sign the KeyInfo Element. "STRTransform": Setup the
+ // ds:Reference to use STR Transform
+ //
+ Transforms transforms = new Transforms(document);
try {
if (idToSign != null) {
- Element toSignById = WSSecurityUtil.findElementById(
- document.getDocumentElement(), idToSign,
- WSConstants.WSU_NS);
+ Element toSignById =
+ WSSecurityUtil.findElementById(
+ document.getDocumentElement(), idToSign, WSConstants.WSU_NS
+ );
if (toSignById == null) {
- toSignById = WSSecurityUtil.findElementById(document
- .getDocumentElement(), idToSign, null);
+ toSignById =
+ WSSecurityUtil.findElementById(
+ document.getDocumentElement(), idToSign, null
+ );
}
- transforms
- .addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
+ transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
if (wssConfig.isWsiBSPCompliant()) {
transforms.item(0).getElement().appendChild(
- new InclusiveNamespaces(document,
- getInclusivePrefixes(toSignById))
- .getElement());
+ new InclusiveNamespaces(
+ document, getInclusivePrefixes(toSignById)).getElement()
+ );
}
sig.addDocument("#" + idToSign, transforms, digestAlgo);
} else if (elemName.equals("Token")) {
- transforms
- .addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
+ transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
if (keyIdentifierType == WSConstants.BST_DIRECT_REFERENCE) {
if (wssConfig.isWsiBSPCompliant()) {
- transforms
- .item(0)
- .getElement()
- .appendChild(
- new InclusiveNamespaces(
- document,
- getInclusivePrefixes(secHeader.getSecurityHeader()))
- .getElement());
+ transforms.item(0).getElement().appendChild(
+ new InclusiveNamespaces(
+ document,
+ getInclusivePrefixes(secHeader.getSecurityHeader())).getElement()
+ );
}
sig.addDocument("#" + certUri, transforms, digestAlgo);
} else {
if (wssConfig.isWsiBSPCompliant()) {
transforms.item(0).getElement().appendChild(
- new InclusiveNamespaces(document,
- getInclusivePrefixes(keyInfo
- .getElement()))
- .getElement());
+ new InclusiveNamespaces(
+ document, getInclusivePrefixes(keyInfo.getElement())).getElement()
+ );
}
sig.addDocument("#" + keyInfoUri, transforms, digestAlgo);
}
} else if (elemName.equals("STRTransform")) { // STRTransform
Element ctx = createSTRParameter(document);
- transforms.addTransform(
- STRTransform.implementedTransformURI, ctx);
+ transforms.addTransform(STRTransform.implementedTransformURI, ctx);
sig.addDocument("#" + strUri, transforms, digestAlgo);
} else if (elemName.equals("Assertion")) { // Assertion
-
String id = null;
id = SAMLUtil.getAssertionId(envelope, elemName, nmSpace);
- Element body = (Element) WSSecurityUtil.findElement(
- envelope, elemName, nmSpace);
+ Element body =
+ (Element) WSSecurityUtil.findElement(envelope, elemName, nmSpace);
if (body == null) {
throw new WSSecurityException(
- WSSecurityException.FAILURE, "noEncElement",
- new Object[] { nmSpace + ", " + elemName });
+ WSSecurityException.FAILURE, "noEncElement",
+ new Object[] {nmSpace + ", " + elemName}
+ );
}
- transforms
- .addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
+ transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
if (wssConfig.isWsiBSPCompliant()) {
transforms.item(0).getElement().appendChild(
- new InclusiveNamespaces(document,
- getInclusivePrefixes(body))
- .getElement());
+ new InclusiveNamespaces(
+ document, getInclusivePrefixes(body)).getElement()
+ );
}
- String prefix = WSSecurityUtil.setNamespace(body,
- WSConstants.WSU_NS, WSConstants.WSU_PREFIX);
+ String prefix =
+ WSSecurityUtil.setNamespace(body, WSConstants.WSU_NS, WSConstants.WSU_PREFIX);
body.setAttributeNS(WSConstants.WSU_NS, prefix + ":Id", id);
sig.addDocument("#" + id, transforms, digestAlgo);
-
} else {
- Element body = (Element) WSSecurityUtil.findElement(
- envelope, elemName, nmSpace);
+ Element body =
+ (Element)WSSecurityUtil.findElement(envelope, elemName, nmSpace);
if (body == null) {
throw new WSSecurityException(
- WSSecurityException.FAILURE, "noEncElement",
- new Object[] { nmSpace + ", " + elemName });
+ WSSecurityException.FAILURE,
+ "noEncElement",
+ new Object[] {nmSpace + ", " + elemName}
+ );
}
- transforms
- .addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
+ transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
if (wssConfig.isWsiBSPCompliant()) {
transforms.item(0).getElement().appendChild(
- new InclusiveNamespaces(document,
- getInclusivePrefixes(body))
- .getElement());
+ new InclusiveNamespaces(
+ document, getInclusivePrefixes(body)).getElement()
+ );
}
sig.addDocument("#" + setWsuId(body), transforms, digestAlgo);
}
} catch (TransformationException e1) {
throw new WSSecurityException(
- WSSecurityException.FAILED_SIGNATURE, "noXMLSig", null,
- e1);
+ WSSecurityException.FAILED_SIGNATURE, "noXMLSig", null, e1
+ );
} catch (XMLSignatureException e1) {
throw new WSSecurityException(
- WSSecurityException.FAILED_SIGNATURE, "noXMLSig", null,
- e1);
+ WSSecurityException.FAILED_SIGNATURE, "noXMLSig", null, e1
+ );
}
}
}
@@ -620,8 +585,7 @@
* This allows to insert the Signature element at any position in the
* Security header.
*
- * @param secHeader
- * The secHeader that holds the Signature element.
+ * @param secHeader The secHeader that holds the Signature element.
*/
public void prependToHeader(WSSecHeader secHeader) {
WSSecurityUtil.prependChildElement(secHeader.getSecurityHeader(), sig.getElement());
@@ -635,8 +599,7 @@
* This allows to insert the Signature element at any position in the
* Security header.
*
- * @param secHeader
- * The secHeader that holds the Signature element.
+ * @param secHeader The secHeader that holds the Signature element.
*/
public void appendToHeader(WSSecHeader secHeader) {
Element secHeaderElement = secHeader.getSecurityHeader();
@@ -651,8 +614,7 @@
* This allows to insert the BST element at any position in the Security
* header.
*
- * @param secHeader
- * The security header that holds the BST element.
+ * @param secHeader The security header that holds the BST element.
*/
public void prependBSTElementToHeader(WSSecHeader secHeader) {
if (bstToken != null) {
@@ -676,11 +638,10 @@
* @return the BST Token element
*/
public Element getBinarySecurityTokenElement() {
- if(this.bstToken != null) {
+ if (this.bstToken != null) {
return this.bstToken.getElement();
- } else {
- return null;
}
+ return null;
}
public void appendBSTElementToHeader(WSSecHeader secHeader) {
@@ -706,18 +667,20 @@
if (keyIdentifierType == WSConstants.UT_SIGNING ||
keyIdentifierType == WSConstants.CUSTOM_SYMM_SIGNING ||
keyIdentifierType == WSConstants.CUSTOM_SYMM_SIGNING_DIRECT ||
- keyIdentifierType == WSConstants.ENCRYPTED_KEY_SHA1_IDENTIFIER) {
+ keyIdentifierType == WSConstants.ENCRYPTED_KEY_SHA1_IDENTIFIER) {
sig.sign(sig.createSecretKey(secretKey));
} else {
sig.sign(crypto.getPrivateKey(user, password));
}
signatureValue = sig.getSignatureValue();
} catch (XMLSignatureException e1) {
- throw new WSSecurityException(WSSecurityException.FAILED_SIGNATURE,
- null, null, e1);
+ throw new WSSecurityException(
+ WSSecurityException.FAILED_SIGNATURE, null, null, e1
+ );
} catch (Exception e1) {
- throw new WSSecurityException(WSSecurityException.FAILED_SIGNATURE,
- null, null, e1);
+ throw new WSSecurityException(
+ WSSecurityException.FAILED_SIGNATURE, null, null, e1
+ );
} finally {
WSDocInfoStore.delete(wsDocInfo);
}
@@ -733,18 +696,14 @@
* This method is compatible with the build method of the previous version
* with the exception of the additional WSSecHeader parameter.
*
- * @param doc
- * The unsigned SOAP envelope as <code>Document</code>
- * @param cr
- * An instance of the Crypto API to handle keystore and
- * certificates
- * @param secHeader
- * the security header element to hold the encrypted key element.
+ * @param doc The unsigned SOAP envelope as <code>Document</code>
+ * @param cr An instance of the Crypto API to handle keystore and certificates
+ * @param secHeader the security header element to hold the encrypted key element.
* @return A signed SOAP envelope as <code>Document</code>
* @throws WSSecurityException
*/
public Document build(Document doc, Crypto cr, WSSecHeader secHeader)
- throws WSSecurityException {
+ throws WSSecurityException {
doDebug = log.isDebugEnabled();
if (doDebug) {
@@ -752,26 +711,26 @@
}
prepare(doc, cr, secHeader);
-
- SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc
- .getDocumentElement());
+ SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());
if (parts == null) {
parts = new Vector();
- WSEncryptionPart encP = new WSEncryptionPart(soapConstants
- .getBodyQName().getLocalPart(), soapConstants
- .getEnvelopeURI(), "Content");
+ WSEncryptionPart encP =
+ new WSEncryptionPart(
+ soapConstants.getBodyQName().getLocalPart(),
+ soapConstants.getEnvelopeURI(),
+ "Content"
+ );
parts.add(encP);
}
addReferencesToSign(parts, secHeader);
-
prependToHeader(secHeader);
- /*
- * if we have a BST prepend it in front of the Signature according to
- * strict layout rules.
- */
+ //
+ // if we have a BST prepend it in front of the Signature according to
+ // strict layout rules.
+ //
if (bstToken != null) {
prependBSTElementToHeader(secHeader);
}
@@ -782,20 +741,27 @@
}
protected Element createSTRParameter(Document doc) {
- Element transformParam = doc.createElementNS(WSConstants.WSSE_NS,
- WSConstants.WSSE_PREFIX + ":TransformationParameters");
-
- WSSecurityUtil.setNamespace(transformParam, WSConstants.WSSE_NS,
- WSConstants.WSSE_PREFIX);
-
- Element canonElem = doc.createElementNS(WSConstants.SIG_NS,
- WSConstants.SIG_PREFIX + ":CanonicalizationMethod");
-
- WSSecurityUtil.setNamespace(canonElem, WSConstants.SIG_NS,
- WSConstants.SIG_PREFIX);
+ Element transformParam =
+ doc.createElementNS(
+ WSConstants.WSSE_NS,
+ WSConstants.WSSE_PREFIX + ":TransformationParameters"
+ );
+
+ WSSecurityUtil.setNamespace(
+ transformParam, WSConstants.WSSE_NS, WSConstants.WSSE_PREFIX
+ );
+
+ Element canonElem =
+ doc.createElementNS(
+ WSConstants.SIG_NS,
+ WSConstants.SIG_PREFIX + ":CanonicalizationMethod"
+ );
+
+ WSSecurityUtil.setNamespace(
+ canonElem, WSConstants.SIG_NS, WSConstants.SIG_PREFIX
+ );
- canonElem.setAttributeNS(null, "Algorithm",
- Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
+ canonElem.setAttributeNS(null, "Algorithm", Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
transformParam.appendChild(canonElem);
return transformParam;
}
@@ -807,16 +773,16 @@
protected Set getInclusivePrefixes(Element target, boolean excludeVisible) {
Set result = new HashSet();
Node parent = target;
- NamedNodeMap attributes;
- Node attribute;
while (!(parent.getParentNode() instanceof Document)) {
parent = parent.getParentNode();
- attributes = parent.getAttributes();
+ NamedNodeMap attributes = parent.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
- attribute = attributes.item(i);
+ Node attribute = attributes.item(i);
if (attribute.getNamespaceURI() != null
- && attribute.getNamespaceURI().equals(
- org.apache.ws.security.WSConstants.XMLNS_NS)) {
+ && attribute.getNamespaceURI().equals(
+ org.apache.ws.security.WSConstants.XMLNS_NS
+ )
+ ) {
if (attribute.getNodeName().equals("xmlns")) {
result.add("#default");
} else {
@@ -827,12 +793,14 @@
}
if (excludeVisible == true) {
- attributes = target.getAttributes();
+ NamedNodeMap attributes = target.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
- attribute = attributes.item(i);
+ Node attribute = attributes.item(i);
if (attribute.getNamespaceURI() != null
- && attribute.getNamespaceURI().equals(
- org.apache.ws.security.WSConstants.XMLNS_NS)) {
+ && attribute.getNamespaceURI().equals(
+ org.apache.ws.security.WSConstants.XMLNS_NS
+ )
+ ) {
if (attribute.getNodeName().equals("xmlns")) {
result.remove("#default");
} else {
Modified: webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSignatureConfirmation.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSignatureConfirmation.java?rev=748120&r1=748119&r2=748120&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSignatureConfirmation.java (original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecSignatureConfirmation.java Thu Feb 26 12:47:45 2009
@@ -47,9 +47,7 @@
/**
* Set the Signature value to store in this SignatureConfirmation.
*
- * @param signatureValue
- * The Signature value to store in the SignatureConfirmation
- * element
+ * @param signatureValue The Signature value to store in the SignatureConfirmation element
*/
public void setSignatureValue(byte[] signatureValue) {
this.signatureValue = signatureValue;
@@ -63,8 +61,7 @@
* the relevant information was set. Before calling <code>prepare()</code> the
* filed <code>signatureValue</code> must be set
*
- * @param doc
- * The SOAP envelope as W3C document
+ * @param doc The SOAP envelope as W3C document
*/
public void prepare(Document doc) {
sc = new SignatureConfirmation(doc, signatureValue);
@@ -80,8 +77,7 @@
* This allows to insert the SignatureConfirmation element at any position in the
* Security header.
*
- * @param secHeader
- * The security header that holds the Signature element.
+ * @param secHeader The security header that holds the Signature element.
*/
public void prependToHeader(WSSecHeader secHeader) {
WSSecurityUtil.prependChildElement(secHeader.getSecurityHeader(), sc.getElement());
@@ -93,14 +89,10 @@
* A complete <code>SignatureConfirmation</code> is constructed and added
* to the <code>wsse:Security</code> header.
*
- * @param doc
- * The SOAP envelope as W3C document
- * @param sigVal
- * the Signature value. This will be the content of the "Value"
- * attribute.
- * @param secHeader
- * The security header that holds the Signature element.
- * @return Document with SignatureConfirmation added
+ * @param doc The SOAP envelope as W3C document
+ * @param sigVal the Signature value. This will be the content of the "Value" attribute.
+ * @param secHeader The security header that holds the Signature element.
+ * @return Document with SignatureConfirmation added
*/
public Document build(Document doc, byte[] sigVal, WSSecHeader secHeader) {
log.debug("Begin add signature confirmation...");
Modified: webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecTimestamp.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecTimestamp.java?rev=748120&r1=748119&r2=748120&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecTimestamp.java (original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecTimestamp.java Thu Feb 26 12:47:45 2009
@@ -50,8 +50,7 @@
* <code>Created</code> and the <code>Expires</code> in
* <code>Timestamp</code>. <p/>
*
- * @param ttl
- * The time to live in second
+ * @param ttl The time to live in second
*/
public void setTimeToLive(int ttl) {
timeToLive = ttl;
@@ -65,8 +64,7 @@
* parameter such as <code>timeToLive</code> can be set if the default
* value is not suitable.
*
- * @param doc
- * The SOAP envelope as W3C document
+ * @param doc The SOAP envelope as W3C document
*/
public void prepare(Document doc) {
ts = new Timestamp(wssConfig.isPrecisionInMilliSeconds(), doc, timeToLive);
@@ -82,8 +80,7 @@
* allows to insert the Timestamp element at any position in the Security
* header.
*
- * @param secHeader
- * The security header that holds the Signature element.
+ * @param secHeader The security header that holds the Signature element.
*/
public void prependToHeader(WSSecHeader secHeader) {
WSSecurityUtil.prependChildElement(secHeader.getSecurityHeader(), ts.getElement());
@@ -95,10 +92,8 @@
* A complete <code>Timestamp</code> is constructed and added to the
* <code>wsse:Security</code> header.
*
- * @param doc
- * The SOAP envelope as W3C document
- * @param secHeader
- * The security header that hold this Timestamp
+ * @param doc The SOAP envelope as W3C document
+ * @param secHeader The security header that hold this Timestamp
* @return Document with Timestamp added
* @throws Exception
*/
Modified: webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecUsernameToken.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecUsernameToken.java?rev=748120&r1=748119&r2=748120&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecUsernameToken.java (original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/message/WSSecUsernameToken.java Thu Feb 26 12:47:45 2009
@@ -122,9 +122,8 @@
}
if (useDerivedKey) {
return UsernameToken.generateDerivedKey(password, saltValue, iteration);
- } else {
- return ut.getSecretKey();
}
+ return ut.getSecretKey();
}
/**
@@ -168,12 +167,10 @@
* passwordType etc. must be set. A complete <code>UsernameToken</code> is
* constructed.
*
- * @param doc
- * The SOAP envelope as W3C document
+ * @param doc The SOAP envelope as W3C document
*/
public void prepare(Document doc) {
- ut = new UsernameToken(wssConfig.isPrecisionInMilliSeconds(), doc,
- passwordType);
+ ut = new UsernameToken(wssConfig.isPrecisionInMilliSeconds(), doc, passwordType);
ut.setName(user);
if (useDerivedKey) {
saltValue = ut.addSalt(doc, saltValue, useMac);
@@ -199,8 +196,7 @@
* This allows to insert the UsernameToken element at any position in the
* Security header.
*
- * @param secHeader
- * The security header that holds the Signature element.
+ * @param secHeader The security header that holds the Signature element.
*/
public void prependToHeader(WSSecHeader secHeader) {
WSSecurityUtil.prependChildElement(secHeader.getSecurityHeader(), ut.getElement());
@@ -214,8 +210,7 @@
* This allows to insert the UsernameToken element at any position in the
* Security header.
*
- * @param secHeader
- * The security header that holds the Signature element.
+ * @param secHeader The security header that holds the Signature element.
*/
public void appendToHeader(WSSecHeader secHeader) {
Element secHeaderElement = secHeader.getSecurityHeader();
@@ -230,10 +225,8 @@
* <code>UsernameToken</code> is constructed and added to the
* <code>wsse:Security</code> header.
*
- * @param doc
- * The SOAP envelope as W3C document
- * @param secHeader
- * The security header inside the SOAP envelope
+ * @param doc The SOAP envelope as W3C document
+ * @param secHeader The security header inside the SOAP envelope
* @return Document with UsernameToken added
*/
public Document build(Document doc, WSSecHeader secHeader) {
Modified: webservices/wss4j/trunk/src/org/apache/ws/security/message/token/UsernameToken.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/message/token/UsernameToken.java?rev=748120&r1=748119&r2=748120&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/message/token/UsernameToken.java (original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/message/token/UsernameToken.java Thu Feb 26 12:47:45 2009
@@ -666,7 +666,6 @@
* Perform the 1st up to iteration-1 hash rounds
*/
for (int i = 1; i < iteration; i++) {
- sha.reset();
K = sha.digest(K);
}
return K;
Modified: webservices/wss4j/trunk/src/org/apache/ws/security/util/WSSecurityUtil.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/util/WSSecurityUtil.java?rev=748120&r1=748119&r2=748120&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/util/WSSecurityUtil.java (original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/util/WSSecurityUtil.java Thu Feb 26 12:47:45 2009
@@ -77,34 +77,30 @@
* @return the <code>wsse:Security</code> element or <code>null</code>
* if not such element found
*/
- public static Element getSecurityHeader(Document doc, String actor,
- SOAPConstants sc) {
- Element soapHeaderElement = (Element) getDirectChild(doc
- .getDocumentElement(), sc.getHeaderQName().getLocalPart(), sc
- .getEnvelopeURI());
-
+ public static Element getSecurityHeader(Document doc, String actor, SOAPConstants sc) {
+ Element soapHeaderElement =
+ (Element) getDirectChild(
+ doc.getDocumentElement(),
+ sc.getHeaderQName().getLocalPart(),
+ sc.getEnvelopeURI()
+ );
if (soapHeaderElement == null) { // no SOAP header at all
return null;
}
// get all wsse:Security nodes
- NodeList list = null;
- int len = 0;
- list = soapHeaderElement.getElementsByTagNameNS(WSConstants.WSSE_NS,
- WSConstants.WSSE_LN);
+ NodeList list =
+ soapHeaderElement.getElementsByTagNameNS(WSConstants.WSSE_NS, WSConstants.WSSE_LN);
if (list == null) {
return null;
- } else {
- len = list.getLength();
}
- Element elem;
- Attr attr;
- String hActor;
- for (int i = 0; i < len; i++) {
- elem = (Element) list.item(i);
- attr = elem.getAttributeNodeNS(sc.getEnvelopeURI(), sc
- .getRoleAttributeQName().getLocalPart());
- hActor = (attr != null) ? attr.getValue() : null;
+ for (int i = 0; i < list.getLength(); i++) {
+ Element elem = (Element) list.item(i);
+ Attr attr =
+ elem.getAttributeNodeNS(
+ sc.getEnvelopeURI(), sc.getRoleAttributeQName().getLocalPart()
+ );
+ String hActor = (attr != null) ? attr.getValue() : null;
if (WSSecurityUtil.isActorEqual(actor, hActor)) {
return elem;
}
@@ -118,36 +114,42 @@
*
* @param actor
* @param hActor
- * @return TODO
+ * @return true is the actor arguments are equal
*/
public static boolean isActorEqual(String actor, String hActor) {
- if ((((hActor == null) || (hActor.length() == 0)) && ((actor == null) || (actor
- .length() == 0)))
- || ((hActor != null) && (actor != null) && hActor
- .equalsIgnoreCase(actor))) {
+
+ if (((hActor == null) || (hActor.length() == 0))
+ && ((actor == null) || (actor.length() == 0))) {
return true;
- } else {
- return false;
}
+
+ if ((hActor != null) && (actor != null) && hActor.equalsIgnoreCase(actor)) {
+ return true;
+ }
+
+ return false;
}
/**
* Gets a direct child with specified localname and namespace. <p/>
*
- * @param fNode
- * the node where to start the search
- * @param localName
- * local name of the child to get
- * @param namespace
- * the namespace of the child to get
+ * @param fNode the node where to start the search
+ * @param localName local name of the child to get
+ * @param namespace the namespace of the child to get
* @return the node or <code>null</code> if not such node found
*/
- public static Node getDirectChild(Node fNode, String localName,
- String namespace) {
- for (Node currentChild = fNode.getFirstChild(); currentChild != null; currentChild = currentChild
- .getNextSibling()) {
+ public static Node getDirectChild(
+ Node fNode,
+ String localName,
+ String namespace
+ ) {
+ for (
+ Node currentChild = fNode.getFirstChild();
+ currentChild != null;
+ currentChild = currentChild.getNextSibling()
+ ) {
if (localName.equals(currentChild.getLocalName())
- && namespace.equals(currentChild.getNamespaceURI())) {
+ && namespace.equals(currentChild.getNamespaceURI())) {
return currentChild;
}
}
@@ -162,9 +164,12 @@
* contain a SOAP body
*/
public static Element findBodyElement(Document doc, SOAPConstants sc) {
- Element soapBodyElement = (Element) WSSecurityUtil.getDirectChild(doc
- .getFirstChild(), sc.getBodyQName().getLocalPart(), sc
- .getEnvelopeURI());
+ Element soapBodyElement =
+ (Element) WSSecurityUtil.getDirectChild(
+ doc.getFirstChild(),
+ sc.getBodyQName().getLocalPart(),
+ sc.getEnvelopeURI()
+ );
return soapBodyElement;
}
@@ -174,20 +179,16 @@
* <code>//name</code> with the given namespace. It's somewhat faster than
* XPath, and we do not deal with prefixes, just with the real namespace URI
*
- * @param startNode
- * Where to start the search
- * @param name
- * Local name of the element
- * @param namespace
- * Namespace URI of the element
+ * @param start Node Where to start the search
+ * @param name Local name of the element
+ * @param namespace Namespace URI of the element
* @return The found element or <code>null</code>
*/
public static Node findElement(Node startNode, String name, String namespace) {
-
- /*
- * Replace the formerly recursive implementation with a depth-first-loop
- * lookup
- */
+ //
+ // Replace the formerly recursive implementation with a depth-first-loop
+ // lookup
+ //
if (startNode == null) {
return null;
}
@@ -197,14 +198,14 @@
while (startNode != null) {
// start node processing at this point
if (startNode.getNodeType() == Node.ELEMENT_NODE
- && startNode.getLocalName().equals(name)) {
+ && startNode.getLocalName().equals(name)) {
String ns = startNode.getNamespaceURI();
if (ns != null && ns.equals(namespace)) {
return startNode;
}
if ((namespace == null || namespace.length() == 0)
- && (ns == null || ns.length() == 0)) {
+ && (ns == null || ns.length() == 0)) {
return startNode;
}
}
@@ -240,23 +241,19 @@
* If there are multiple elements, we log a warning and return null as this
* can be used to get around the signature checking.
*
- * @param startNode
- * Where to start the search
- * @param value
- * Value of the Id attribute
- * @param namespace
- * Namespace URI of the Id
+ * @param startNode Where to start the search
+ * @param value Value of the Id attribute
+ * @param namespace Namespace URI of the Id
* @return The found element if there was exactly one match, or
* <code>null</code> otherwise
*/
- public static Element findElementById(Node startNode, String value,
- String namespace) {
+ public static Element findElementById(Node startNode, String value, String namespace) {
Element foundElement = null;
- /*
- * Replace the formerly recursive implementation with a depth-first-loop
- * lookup
- */
+ //
+ // Replace the formerly recursive implementation with a depth-first-loop
+ // lookup
+ //
if (startNode == null) {
return null;
}
@@ -268,10 +265,9 @@
if (startNode.getNodeType() == Node.ELEMENT_NODE) {
Element se = (Element) startNode;
if (se.hasAttributeNS(namespace, "Id")
- && value.equals(se.getAttributeNS(namespace, "Id"))) {
+ && value.equals(se.getAttributeNS(namespace, "Id"))) {
if (foundElement == null) {
- foundElement = se; // Continue searching to find
- // duplicates
+ foundElement = se; // Continue searching to find duplicates
} else {
log.warn("Multiple elements with the same 'Id' attribute value!");
return null;
@@ -312,8 +308,7 @@
* @param prefix
* @return the prefix associated with the set namespace
*/
- public static String setNamespace(Element element, String namespace,
- String prefix) {
+ public static String setNamespace(Element element, String namespace, String prefix) {
String pre = getPrefixNS(namespace, element);
if (pre != null) {
return pre;
@@ -323,17 +318,15 @@
}
/*
- * The following methods were copied over from axis.utils.XMLUtils and
- * adapted
+ * The following methods were copied over from axis.utils.XMLUtils and adapted
*/
public static String getPrefixNS(String uri, Node e) {
while (e != null && (e.getNodeType() == Element.ELEMENT_NODE)) {
NamedNodeMap attrs = e.getAttributes();
for (int n = 0; n < attrs.getLength(); n++) {
Attr a = (Attr) attrs.item(n);
- String name;
- if ((name = a.getName()).startsWith("xmlns:")
- && a.getNodeValue().equals(uri)) {
+ String name = a.getName();
+ if (name.startsWith("xmlns:") && a.getNodeValue().equals(uri)) {
return name.substring(6);
}
}
@@ -348,11 +341,11 @@
if (prefix == null) {
attr = ((Element) e).getAttributeNode("xmlns");
} else {
- attr = ((Element) e).getAttributeNodeNS(WSConstants.XMLNS_NS,
- prefix);
+ attr = ((Element) e).getAttributeNodeNS(WSConstants.XMLNS_NS, prefix);
}
- if (attr != null)
+ if (attr != null) {
return attr.getValue();
+ }
e = e.getParentNode();
}
return null;
@@ -379,22 +372,24 @@
return getQNameFromString(str, e, true);
}
- private static QName getQNameFromString(String str, Node e,
- boolean defaultNS) {
- if (str == null || e == null)
+ private static QName getQNameFromString(String str, Node e, boolean defaultNS) {
+ if (str == null || e == null) {
return null;
+ }
int idx = str.indexOf(':');
if (idx > -1) {
String prefix = str.substring(0, idx);
String ns = getNamespace(prefix, e);
- if (ns == null)
+ if (ns == null) {
return null;
+ }
return new QName(ns, str.substring(idx + 1));
} else {
if (defaultNS) {
String ns = getNamespace(null, e);
- if (ns != null)
+ if (ns != null) {
return new QName(ns, str);
+ }
}
return new QName("", str);
}
@@ -419,25 +414,21 @@
return prefix + ":" + qname.getLocalPart();
}
- /* ** up to here */
+ /* up to here */
/**
* Search for an element given its wsu:id. <p/>
*
- * @param doc
- * the DOM document (SOAP request)
- * @param id
- * the Id of the element
+ * @param doc the DOM document (SOAP request)
+ * @param id the Id of the element
* @return the found element or null if no element with the Id exists
*/
public static Element getElementByWsuId(Document doc, String id) {
-
if (id == null) {
return null;
}
id = getIDFromReference(id);
- return WSSecurityUtil.findElementById(doc.getDocumentElement(), id,
- WSConstants.WSU_NS);
+ return WSSecurityUtil.findElementById(doc.getDocumentElement(), id, WSConstants.WSU_NS);
}
/**
@@ -470,10 +461,8 @@
/**
* Search for an element given its generic id. <p/>
*
- * @param doc
- * the DOM document (SOAP request)
- * @param id
- * the Id of the element
+ * @param doc the DOM document (SOAP request)
+ * @param id the Id of the element
* @return the found element or null if no element with the Id exists
*/
public static Element getElementByGenId(Document doc, String id) {
@@ -485,24 +474,18 @@
return null;
}
id = id.substring(1);
- return WSSecurityUtil.findElementById(doc.getDocumentElement(), id,
- null);
+ return WSSecurityUtil.findElementById(doc.getDocumentElement(), id, null);
}
/**
* create a new element in the same namespace <p/>
*
- * @param parent
- * for the new element
- * @param localName
- * of the new element
+ * @param parent for the new element
+ * @param localName of the new element
* @return the new element
*/
- private static Element createElementInSameNamespace(Element parent,
- String localName) {
-
+ private static Element createElementInSameNamespace(Element parent, String localName) {
String qName = localName;
-
String prefix = parent.getPrefix();
if (prefix != null && prefix.length() > 0) {
qName = prefix + ":" + localName;
@@ -515,16 +498,12 @@
/**
* find a child element with given namespace and local name <p/>
*
- * @param parent
- * the node to start the search
- * @param namespaceUri
- * of the element
- * @param localName
- * of the element
+ * @param parent the node to start the search
+ * @param namespaceUri of the element
+ * @param localName of the element
* @return the found element or null if the element does not exist
*/
- private static Element findChildElement(Element parent,
- String namespaceUri, String localName) {
+ private static Element findChildElement(Element parent, String namespaceUri, String localName) {
NodeList children = parent.getChildNodes();
int len = children.getLength();
for (int i = 0; i < len; i++) {
@@ -532,7 +511,7 @@
if (child.getNodeType() == Node.ELEMENT_NODE) {
Element elementChild = (Element) child;
if (namespaceUri.equals(elementChild.getNamespaceURI())
- && localName.equals(elementChild.getLocalName())) {
+ && localName.equals(elementChild.getLocalName())) {
return elementChild;
}
}
@@ -543,12 +522,9 @@
/**
* append a child element <p/>
*
- * @param doc
- * the DOM document (SOAP request)
- * @param parent
- * element of this child element
- * @param child
- * the element to append
+ * @param doc the DOM document (SOAP request)
+ * @param parent element of this child element
+ * @param child the element to append
* @deprecated use {@link Node#appendChild(Node)} instead
* @return the child element
*/
@@ -566,10 +542,8 @@
/**
* prepend a child element <p/>
*
- * @param parent
- * element of this child element
- * @param child
- * the element to append
+ * @param parent element of this child element
+ * @param child the element to append
* @return the child element
*/
public static Element prependChildElement(
@@ -588,20 +562,20 @@
/**
* prepend a child element <p/>
*
- * @param doc
- * the DOM document (SOAP request)
- * @param parent
- * element of this child element
- * @param child
- * the element to append
- * @param addWhitespace
- * if true prepend a newline before child
+ * @param doc the DOM document (SOAP request)
+ * @param parent element of this child element
+ * @param child the element to append
+ * @param addWhitespace if true prepend a newline before child
* @deprecated use {@link WSSecurityUtil#prependChildElement(Element, Element)}
* instead
* @return the child element
*/
- public static Element prependChildElement(Document doc, Element parent,
- Element child, boolean addWhitespace) {
+ public static Element prependChildElement(
+ Document doc,
+ Element parent,
+ Element child,
+ boolean addWhitespace
+ ) {
Node firstChild = parent.getFirstChild();
if (firstChild == null) {
parent.appendChild(child);
@@ -618,51 +592,50 @@
/**
* find the first ws-security header block <p/>
*
- * @param doc
- * the DOM document (SOAP request)
- * @param envelope
- * the SOAP envelope
- * @param doCreate
- * if true create a new WSS header block if none exists
+ * @param doc the DOM document (SOAP request)
+ * @param envelope the SOAP envelope
+ * @param doCreate if true create a new WSS header block if none exists
* @return the WSS header or null if none found and doCreate is false
*/
- public static Element findWsseSecurityHeaderBlock(Document doc,
- Element envelope, boolean doCreate) {
+ public static Element findWsseSecurityHeaderBlock(
+ Document doc,
+ Element envelope,
+ boolean doCreate
+ ) {
return findWsseSecurityHeaderBlock(doc, envelope, null, doCreate);
}
/**
* find a ws-security header block for a given actor <p/>
*
- * @param doc
- * the DOM document (SOAP request)
- * @param envelope
- * the SOAP envelope
- * @param actor
- * the actor (role) name of the WSS header
- * @param doCreate
- * if true create a new WSS header block if none exists
+ * @param doc the DOM document (SOAP request)
+ * @param envelope the SOAP envelope
+ * @param actot the actor (role) name of the WSS header
+ * @param doCreate if true create a new WSS header block if none exists
* @return the WSS header or null if none found and doCreate is false
*/
- public static Element findWsseSecurityHeaderBlock(Document doc,
- Element envelope, String actor, boolean doCreate) {
+ public static Element findWsseSecurityHeaderBlock(
+ Document doc,
+ Element envelope,
+ String actor,
+ boolean doCreate
+ ) {
SOAPConstants sc = getSOAPConstants(envelope);
Element wsseSecurity = getSecurityHeader(doc, actor, sc);
if (wsseSecurity != null) {
return wsseSecurity;
}
- Element header = findChildElement(envelope, sc.getEnvelopeURI(), sc
- .getHeaderQName().getLocalPart());
+ Element header =
+ findChildElement(envelope, sc.getEnvelopeURI(), sc.getHeaderQName().getLocalPart());
if (header == null && doCreate) {
- header = createElementInSameNamespace(envelope, sc
- .getHeaderQName().getLocalPart());
+ header =
+ createElementInSameNamespace(envelope, sc.getHeaderQName().getLocalPart());
header = prependChildElement(envelope, header);
}
if (doCreate) {
- wsseSecurity = header.getOwnerDocument().createElementNS(
- WSConstants.WSSE_NS, "wsse:Security");
- wsseSecurity.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse",
- WSConstants.WSSE_NS);
+ wsseSecurity =
+ header.getOwnerDocument().createElementNS(WSConstants.WSSE_NS, "wsse:Security");
+ wsseSecurity.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
return prependChildElement(header, wsseSecurity);
}
return null;
@@ -671,10 +644,8 @@
/**
* create a base64 test node <p/>
*
- * @param doc
- * the DOM document (SOAP request)
- * @param data
- * to encode
+ * @param doc the DOM document (SOAP request)
+ * @param data to encode
* @return a Text node containing the base64 encoded data
*/
public static Text createBase64EncodedTextNode(Document doc, byte data[]) {
@@ -682,8 +653,8 @@
}
public static SecretKey prepareSecretKey(String symEncAlgo, byte[] rawKey) {
- SecretKeySpec keySpec = new SecretKeySpec(rawKey, JCEMapper
- .getJCEKeyAlgorithmFromURI(symEncAlgo));
+ SecretKeySpec keySpec =
+ new SecretKeySpec(rawKey, JCEMapper.getJCEKeyAlgorithmFromURI(symEncAlgo));
return (SecretKey) keySpec;
}
@@ -692,24 +663,23 @@
String ns = doc.getDocumentElement().getNamespaceURI();
if (WSConstants.URI_SOAP12_ENV.equals(ns)) {
return new SOAP12Constants();
- } else {
- return new SOAP11Constants();
}
+ return new SOAP11Constants();
}
public static Cipher getCipherInstance(String cipherAlgo)
- throws WSSecurityException {
+ throws WSSecurityException {
Cipher cipher = null;
try {
if (cipherAlgo.equalsIgnoreCase(WSConstants.KEYTRANSPORT_RSA15)) {
cipher = Cipher.getInstance("RSA/NONE/PKCS1PADDING");
- } else if (cipherAlgo
- .equalsIgnoreCase(WSConstants.KEYTRANSPORT_RSAOEP)) {
+ } else if (cipherAlgo.equalsIgnoreCase(WSConstants.KEYTRANSPORT_RSAOEP)) {
cipher = Cipher.getInstance("RSA/NONE/OAEPPADDING");
} else {
throw new WSSecurityException(
- WSSecurityException.UNSUPPORTED_ALGORITHM,
- "unsupportedKeyTransp", new Object[] { cipherAlgo });
+ WSSecurityException.UNSUPPORTED_ALGORITHM,
+ "unsupportedKeyTransp", new Object[] {cipherAlgo}
+ );
}
} catch (NoSuchPaddingException ex) {
throw new WSSecurityException(
@@ -728,22 +698,17 @@
/**
* Fetch the result of a given action from a given result vector <p/>
*
- * @param wsResultVector
- * The result vector to fetch an action from
- * @param action
- * The action to fetch
+ * @param wsResultVector The result vector to fetch an action from
+ * @param action The action to fetch
* @return The result fetched from the result vector, null if the result
* could not be found
*/
- public static WSSecurityEngineResult fetchActionResult(
- Vector wsResultVector, int action) {
+ public static WSSecurityEngineResult fetchActionResult(Vector wsResultVector, int action) {
WSSecurityEngineResult wsResult = null;
// Find the part of the security result that matches the given action
-
for (int i = 0; i < wsResultVector.size(); i++) {
- // Check the result of every action whether it matches the given
- // action
+ // Check the result of every action whether it matches the given action
WSSecurityEngineResult result =
(WSSecurityEngineResult) wsResultVector.get(i);
int resultAction =
@@ -759,18 +724,17 @@
/**
* Fetch the result of a given action from a given result vector <p/>
*
- * @param wsResultVector
- * The result vector to fetch an action from
- * @param action
- * The action to fetch
- * @param results
- * where to store the found results data for the action
+ * @param wsResultVector The result vector to fetch an action from
+ * @param action The action to fetch
+ * @param results where to store the found results data for the action
* @return The result fetched from the result vector, null if the result
* could not be found
*/
- public static Vector fetchAllActionResults(Vector wsResultVector,
- int action, Vector results) {
-
+ public static Vector fetchAllActionResults(
+ Vector wsResultVector,
+ int action,
+ Vector results
+ ) {
// Find the parts of the security result that matches the given action
for (int i = 0; i < wsResultVector.size(); i++) {
// Check the result of every action whether it matches the given
@@ -786,11 +750,9 @@
return results;
}
- static public int decodeAction(String action, Vector actions)
- throws WSSecurityException {
+ public static int decodeAction(String action, Vector actions) throws WSSecurityException {
int doAction = 0;
-
if (action == null) {
return doAction;
}
@@ -825,7 +787,8 @@
actions.add(new Integer(WSConstants.UT_SIGN));
} else {
throw new WSSecurityException(
- "WSDoAllSender: Unknown action defined" + single[i]);
+ "WSDoAllSender: Unknown action defined" + single[i]
+ );
}
}
return doAction;
@@ -854,12 +817,12 @@
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)) {
+ } else if (XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5.equals(algorithm)) {
return 16;
} else {
throw new WSSecurityException(
- WSSecurityException.UNSUPPORTED_ALGORITHM, null, null, null);
+ WSSecurityException.UNSUPPORTED_ALGORITHM, null, null, null
+ );
}
}
@@ -880,7 +843,8 @@
return temp;
} catch (Exception e) {
throw new WSSecurityException(
- "Error in generating nonce of length " + length, e);
+ "Error in generating nonce of length " + length, e
+ );
}
}
@@ -893,24 +857,23 @@
* transformation such as XPath filtering the validation is carried out
* in signature verification itself.
*
- * @param results
- * results (e.g., as stored as WSHandlerConstants.RECV_RESULTS on
- * an Axis MessageContext)
- * @param elements
- * the elements to check
+ * @param results results (e.g., as stored as WSHandlerConstants.RECV_RESULTS on
+ * an Axis MessageContext)
+ * @param elements the elements to check
* @return the identity of the signer
- * @throws WSSecurityException
- * if no suitable signature could be found or if any element
- * didn't have a wsu:Id attribute
+ * @throws WSSecurityException if no suitable signature could be found or if any element
+ * didn't have a wsu:Id attribute
*/
- public static X509Certificate ensureSignedTogether(Iterator results,
- Element[] elements) throws WSSecurityException {
+ public static X509Certificate ensureSignedTogether(Iterator results, Element[] elements)
+ throws WSSecurityException {
log.debug("ensureSignedTogether()");
- if (results == null)
+ if (results == null) {
throw new IllegalArgumentException("No results vector");
- if (elements == null || elements.length == 0)
+ }
+ if (elements == null || elements.length == 0) {
throw new IllegalArgumentException("No elements to check!");
+ }
// Turn the list of required elements into a list of required wsu:Id
// strings
@@ -918,16 +881,17 @@
for (int i = 0; i < elements.length; i++) {
Element e = (Element) elements[i];
if (e == null) {
- throw new IllegalArgumentException("elements[" + i
- + "] is null!");
+ throw new IllegalArgumentException("elements[" + i + "] is null!");
}
requiredIDs[i] = e.getAttributeNS(WSConstants.WSU_NS, "Id");
if (requiredIDs[i] == null) {
- throw new WSSecurityException(WSSecurityException.FAILED_CHECK,
- "requiredElementNoID", new Object[] { e.getNodeName() });
+ throw new WSSecurityException(
+ WSSecurityException.FAILED_CHECK,
+ "requiredElementNoID",
+ new Object[] {e.getNodeName()}
+ );
}
- log.debug("Required element " + e.getNodeName() + " has wsu:Id "
- + requiredIDs[i]);
+ log.debug("Required element " + e.getNodeName() + " has wsu:Id " + requiredIDs[i]);
}
WSSecurityException fault = null;
@@ -970,16 +934,14 @@
* Ensure that this signature covers all required elements (identified by
* their wsu:Id attributes).
*
- * @param resultItem
- * the signature to check
- * @param requiredIDs
- * the list of wsu:Id values that must be covered
- * @throws WSSecurityException
- * if any required element is not included
+ * @param resultItem the signature to check
+ * @param requiredIDs the list of wsu:Id values that must be covered
+ * @throws WSSecurityException if any required element is not included
*/
private static void checkSignsAllElements(
- WSSecurityEngineResult resultItem, String[] requiredIDs)
- throws WSSecurityException {
+ WSSecurityEngineResult resultItem,
+ String[] requiredIDs
+ ) throws WSSecurityException {
int resultAction =
((java.lang.Integer)resultItem.get(WSSecurityEngineResult.TAG_ACTION)).intValue();
if (resultAction != WSConstants.SIGN) {
@@ -989,7 +951,8 @@
Set sigElems = (Set)resultItem.get(WSSecurityEngineResult.TAG_SIGNED_ELEMENT_IDS);
if (sigElems == null) {
throw new RuntimeException(
- "Missing signedElements set in WSSecurityEngineResult!");
+ "Missing signedElements set in WSSecurityEngineResult!"
+ );
}
log.debug("Found SIGN result...");
@@ -998,20 +961,20 @@
if(sigElement instanceof String) {
log.debug("Signature includes element with ID " + sigElement);
} else {
- log.debug("Signature includes element with null uri " +
- sigElement.toString());
+ log.debug("Signature includes element with null uri " + sigElement.toString());
}
}
log.debug("Checking required elements are in the signature...");
for (int i = 0; i < requiredIDs.length; i++) {
if (!sigElems.contains(requiredIDs[i])) {
- throw new WSSecurityException(WSSecurityException.FAILED_CHECK,
- "requiredElementNotSigned",
- new Object[] { requiredIDs[i] });
+ throw new WSSecurityException(
+ WSSecurityException.FAILED_CHECK,
+ "requiredElementNotSigned",
+ new Object[] {requiredIDs[i]}
+ );
}
- log.debug("Element with ID " + requiredIDs[i]
- + " was correctly signed");
+ log.debug("Element with ID " + requiredIDs[i] + " was correctly signed");
}
log.debug("All required elements are signed");
}
@@ -1028,8 +991,7 @@
/**
* @param algorithm
*
- *
- * @return a SecureRandom instance initialize with the identifier
+ * @return a SecureRandom instance initialized with the identifier
* specified in algorithm
*/
public synchronized static SecureRandom
---------------------------------------------------------------------
To unsubscribe, e-mail: wss4j-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: wss4j-dev-help@ws.apache.org