[WSS4J] wss4j/src/org/apache/ws/security/util WSSecurityUtil.java,1.14,1.15
[email protected] Wed, 21 Jan 2004 04:14:44 -0800
| Newsgroups | gmane.text.xml.wss4j |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/wss4j/wss4j/src/org/apache/ws/security/util
In directory sc8-pr-cvs1:/tmp/cvs-serv27132/src/org/apache/ws/security/util
Modified Files:
WSSecurityUtil.java
Log Message:
Add SOAP 1.2 handling. Most of the code shamelessly copied from Axis
and modified.
Index: WSSecurityUtil.java
===================================================================
RCS file: /cvsroot/wss4j/wss4j/src/org/apache/ws/security/util/WSSecurityUtil.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** WSSecurityUtil.java 2 Jan 2004 12:15:49 -0000 1.14
--- WSSecurityUtil.java 21 Jan 2004 12:14:42 -0000 1.15
***************
*** 58,61 ****
--- 58,64 ----
import org.apache.commons.logging.LogFactory;
import org.apache.ws.security.WSConstants;
+ import org.apache.ws.security.SOAPConstants;
+ import org.apache.ws.security.SOAP11Constants;
+ import org.apache.ws.security.SOAP12Constants;
import org.apache.xml.security.utils.Base64;
import org.apache.xpath.XPathAPI;
***************
*** 93,98 ****
* <code>null</code> if not such element found
*/
! public static Element getSecurityHeader(Document doc, String actor) {
! Element soapHeaderElement = (Element) getDirectChild(doc.getFirstChild(), "Header", WSConstants.SOAP_NS);
if (soapHeaderElement == null) { // no SOAP header at all
return null;
--- 96,104 ----
* <code>null</code> if not such element found
*/
! public static Element getSecurityHeader(Document doc, String actor, SOAPConstants sc) {
! Element soapHeaderElement =
! (Element) getDirectChild(doc.getFirstChild(),
! sc.getHeaderQName().getLocalPart(),
! sc.getEnvelopeURI());
if (soapHeaderElement == null) { // no SOAP header at all
return null;
***************
*** 107,111 ****
for (int i = 0; i < len; i++) {
elem = (Element) list.item(i);
! attr = elem.getAttributeNodeNS(WSConstants.SOAP_NS, "actor");
hActor = (attr != null) ? attr.getValue() : null;
if ((((hActor == null) || (hActor.length() == 0)) &&
--- 113,117 ----
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;
if ((((hActor == null) || (hActor.length() == 0)) &&
***************
*** 147,152 ****
* contain a SOAP body
*/
! public static Element findBodyElement(Document doc) {
! Element soapBodyElement = (Element) WSSecurityUtil.getDirectChild(doc.getFirstChild(), "Body", WSConstants.SOAP_NS);
return soapBodyElement;
}
--- 153,162 ----
* contain a SOAP body
*/
! public static Element findBodyElement(Document doc, SOAPConstants sc) {
! Element soapBodyElement =
! (Element) WSSecurityUtil.getDirectChild(
! doc.getFirstChild(),
! sc.getBodyQName().getLocalPart(),
! sc.getEnvelopeURI());
return soapBodyElement;
}
***************
*** 522,529 ****
*/
public static Element findWsseSecurityHeaderBlock(Document doc, Element envelope, boolean doCreate) {
! Element header = findChildElement(envelope, WSConstants.SOAP_NS, "Header");
if (header == null) {
if (doCreate) {
! header = createElementInSameNamespace(envelope, "Header");
header = prependChildElement(doc, envelope, header, true);
}
--- 532,540 ----
*/
public static Element findWsseSecurityHeaderBlock(Document doc, Element envelope, boolean doCreate) {
! SOAPConstants sc = getSOAPConstants(envelope);
! Element header = findChildElement(envelope, sc.getEnvelopeURI(), sc.getHeaderQName().getLocalPart());
if (header == null) {
if (doCreate) {
! header = createElementInSameNamespace(envelope, sc.getHeaderQName().getLocalPart());
header = prependChildElement(doc, envelope, header, true);
}
***************
*** 578,583 ****
*/
public static Element createNamespaceContext(Document doc) {
Element nsContext = doc.createElementNS(null, "namespaceContext");
! nsContext.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:env", WSConstants.SOAP_NS);
nsContext.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
nsContext.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsu", WSConstants.WSU_NS);
--- 589,595 ----
*/
public static Element createNamespaceContext(Document doc) {
+ SOAPConstants sc = getSOAPConstants(doc.getDocumentElement());
Element nsContext = doc.createElementNS(null, "namespaceContext");
! nsContext.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:env", sc.getEnvelopeURI());
nsContext.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsse", WSConstants.WSSE_NS);
nsContext.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsu", WSConstants.WSU_NS);
***************
*** 606,608 ****
--- 618,629 ----
}
+ public static SOAPConstants getSOAPConstants(Element startElement) {
+ if (getPrefix(WSConstants.URI_SOAP12_ENV, startElement) != null) {
+ return new SOAP12Constants();
+ }
+ else {
+ return new SOAP11Constants();
+ }
+ }
+
}
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn