You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ru...@apache.org on 2006/03/31 18:57:39 UTC
svn commit: r390457 - in
/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security:
rahas/ trust/impl/ util/
Author: ruchithf
Date: Fri Mar 31 08:57:37 2006
New Revision: 390457
URL: http://svn.apache.org/viewcvs?rev=390457&view=rev
Log:
- Got the following WS-SecureConversation+WS-Trust scenario working :-)
- Get an SCT from an STS enabled service (service returns the secret as an encrypted key)
- Send a request to that service by encrypting the body using a key derived from the SCT obtained
- Service responds with an encrypted message encrypted with a key derived from the same SCT
Added:
webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasCallbackHandler.java
Modified:
webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasConfiguration.java
webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasHandlerConstants.java
webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Receiver.java
webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/STSRequester.java
webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Sender.java
webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Util.java
webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/impl/SCTIssuer.java
webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java
Added: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasCallbackHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasCallbackHandler.java?rev=390457&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasCallbackHandler.java (added)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasCallbackHandler.java Fri Mar 31 08:57:37 2006
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.axis2.security.rahas;
+
+import org.apache.axis2.security.trust.Token;
+import org.apache.ws.security.WSPasswordCallback;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+import java.io.IOException;
+
+/**
+ *
+ * @author Ruchith Fernando (ruchith.fernando@gmail.com)
+ */
+public class RahasCallbackHandler implements CallbackHandler {
+
+ private RahasConfiguration config;
+
+ public RahasCallbackHandler(RahasConfiguration config) {
+ this.config = config;
+ }
+
+ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+ for (int i = 0; i < callbacks.length; i++) {
+
+ if (callbacks[i] instanceof WSPasswordCallback) {
+ WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
+ String id = pc.getIdentifer();
+ Token tok;
+ try {
+ tok = this.config.getTokenStore().getToken(id);
+ pc.setKey(tok.getSecret());
+ this.config.resgisterContext(id);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new IOException(e.getMessage());
+ }
+
+ } else {
+ throw new UnsupportedCallbackException(callbacks[i],
+ "Unrecognized Callback");
+ }
+ }
+ }
+
+}
Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasConfiguration.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasConfiguration.java?rev=390457&r1=390456&r2=390457&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasConfiguration.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasConfiguration.java Fri Mar 31 08:57:37 2006
@@ -24,7 +24,9 @@
import org.apache.axis2.context.OperationContext;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.security.trust.SimpleTokenStore;
+import org.apache.axis2.security.trust.Token;
import org.apache.axis2.security.trust.TokenStorage;
+import org.apache.axis2.security.trust.TrustException;
import org.apache.axis2.security.util.Axis2Util;
import org.apache.ws.security.WSSecurityException;
import org.apache.ws.security.components.crypto.Crypto;
@@ -32,6 +34,7 @@
import org.apache.ws.security.message.token.SecurityContextToken;
import org.apache.wsdl.WSDLConstants;
import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import javax.security.auth.callback.CallbackHandler;
import javax.xml.namespace.QName;
@@ -133,7 +136,7 @@
private SecurityContextToken sct;
public static RahasConfiguration load(MessageContext msgCtx, boolean sender)
- throws RahasException, WSSecurityException, AxisFault {
+ throws Exception {
Parameter param = msgCtx.getParameter(RAHAS_CONFIG);
if(param == null) {
param = (Parameter)msgCtx.getProperty(RAHAS_CONFIG);
@@ -150,6 +153,7 @@
RahasConfiguration config = new RahasConfiguration();
config.msgCtx = msgCtx;
+ msgCtx.setProperty(RAHAS_CONFIG, config);
config.scope = getStringValue(conFileElem.getFirstChildWithName(SCOPE));
@@ -171,10 +175,13 @@
//Get the action<->ctx-identifier map
config.contextMap = (Hashtable) msgCtx
.getProperty(RahasHandlerConstants.CONTEXT_MAP_KEY);
+
+ //Convert the Envelop to DOOM
+ config.doc = Axis2Util.getDocumentFromSOAPEnvelope(msgCtx.getEnvelope(), false);
//Token store
config.tokenStore = (TokenStorage) msgCtx
- .getProperty(RahasHandlerConstants.TOKEN_STORE_KEY);
+ .getProperty(TokenStorage.TOKEN_STORAGE_KEY);
// Context identifier
if(sender) {
@@ -191,6 +198,11 @@
config.contextIdentifier = (String) config.getContextMap()
.get(serviceAddress);
}
+ if(config.sct == null && config.contextIdentifier != null) {
+ OMElement tokElem = config.getTokenStore().getToken(config.contextIdentifier).getToken();
+ config.sct = new SecurityContextToken((Element)config.doc.importNode((Element)tokElem, true));
+ }
+
} else {
//Server side sender
OperationContext opCtx = msgCtx.getOperationContext();
@@ -201,9 +213,14 @@
}
if(inConfig != null && inConfig.contextIdentifier != null) {
config.contextIdentifier = inConfig.contextIdentifier;
+ config.tokenStore = inConfig.tokenStore;
+ OMElement token = config.tokenStore.getToken(config.contextIdentifier).getToken();
+ config.sct = new SecurityContextToken((Element)config.doc.importNode((Element)token, true));
} else {
throw new RahasException("canotFindContextIdentifier");
}
+
+ config.setClassLoader(msgCtx.getAxisService().getClassLoader());
}
}
@@ -219,9 +236,6 @@
config.sender = sender;
- //Convert the Envelop to DOOM
- config.doc = Axis2Util.getDocumentFromSOAPEnvelope(msgCtx.getEnvelope(), false);
-
return config;
} else {
throw new RahasException("missingConfiguration",
@@ -285,17 +299,19 @@
protected void resgisterContext(String identifier) throws RahasException {
+ this.contextIdentifier = identifier;
+
if(this.scope.equals(SCOPE_OPERATION)) {
String action = msgCtx.getSoapAction();
if(action != null) {
- this.contextMap.put(action, identifier);
+ this.getContextMap().put(action, identifier);
} else {
throw new RahasException("missingWSAAction");
}
} else {
String to = msgCtx.getTo().getAddress();
if(to != null) {
- this.contextMap.put(to, identifier);
+ this.getContextMap().put(to, identifier);
} else {
throw new RahasException("missingWSATo");
}
@@ -380,13 +396,33 @@
*/
protected TokenStorage getTokenStore() throws Exception {
if(this.tokenStore == null) {
- if(this.tokenStoreClass != null) {
- this.tokenStore = (TokenStorage) Class
- .forName(this.tokenStoreClass).newInstance();
+
+ //First check the context hierarchy
+ this.tokenStore = (TokenStorage) this.msgCtx
+ .getProperty(TokenStorage.TOKEN_STORAGE_KEY
+ + msgCtx.getWSAAction());
+ if(this.tokenStore == null) {
+ this.tokenStore = (TokenStorage) this.msgCtx
+ .getProperty(TokenStorage.TOKEN_STORAGE_KEY
+ + msgCtx.getAxisService().getName());
+ }
+
+ //Create a new store
+ if(this.tokenStore == null) {
+ if(this.tokenStoreClass != null) {
+ this.tokenStore = (TokenStorage) Class
+ .forName(this.tokenStoreClass).newInstance();
+ } else {
+ this.tokenStore = new SimpleTokenStore();
+ }
+ }
+
+ if(SCOPE_SERVICE.equals(this.scope)) {
this.msgCtx.getConfigurationContext().setProperty(
- RahasHandlerConstants.TOKEN_STORE_KEY, this.tokenStore);
+ TokenStorage.TOKEN_STORAGE_KEY, this.tokenStore);
} else {
- this.tokenStore = new SimpleTokenStore();
+ this.msgCtx.getConfigurationContext().setProperty(
+ TokenStorage.TOKEN_STORAGE_KEY, this.tokenStore);
}
}
return tokenStore;
@@ -406,12 +442,13 @@
return contextIdentifier;
}
- /**
- * @param contextIdentifier The contextIdentifier to set.
- */
- protected void setContextIdentifier(String contextIdentifier) {
- this.contextIdentifier = contextIdentifier;
- }
+// /**
+// * @param contextIdentifier The contextIdentifier to set.
+// */
+// protected void setContextIdentifier(String contextIdentifier) throws RahasException {
+// this.contextIdentifier = contextIdentifier;
+// this.resgisterContext(contextIdentifier);
+// }
/**
* @return Returns the cryptoProperties.
Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasHandlerConstants.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasHandlerConstants.java?rev=390457&r1=390456&r2=390457&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasHandlerConstants.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasHandlerConstants.java Fri Mar 31 08:57:37 2006
@@ -22,14 +22,6 @@
public interface RahasHandlerConstants {
/**
- * Key to hold the <code>TokenStore</code> to store the
- * <code>SecurityContextToken</code>s
- *
- * @see org.apache.axis2.security.trust.TokenStorage
- */
- public final static String TOKEN_STORE_KEY = "tokenStore";
-
- /**
* Key to hod the map of security context identifiers against the
* service epr addresses (service scope) or wsa:Action values (operation
* scope).
Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Receiver.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Receiver.java?rev=390457&r1=390456&r2=390457&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Receiver.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Receiver.java Fri Mar 31 08:57:37 2006
@@ -16,6 +16,7 @@
package org.apache.axis2.security.rahas;
+import org.apache.axiom.om.impl.dom.jaxp.DocumentBuilderFactoryImpl;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.HandlerDescription;
@@ -23,6 +24,8 @@
import org.apache.axis2.engine.Handler;
import org.apache.axis2.security.WSDoAllReceiver;
import org.apache.axis2.security.trust.Constants;
+import org.apache.axis2.security.util.Axis2Util;
+import org.apache.ws.security.WSSecurityEngine;
import javax.xml.namespace.QName;
@@ -30,22 +33,51 @@
*
* @author Ruchith Fernando (ruchith.fernando@gmail.com)
*/
-public class Receiver implements Handler {
+public class Receiver implements Handler {
private static final long serialVersionUID = 8450183308062119444L;
-
+
private HandlerDescription handlerDescription;
-
+
public void invoke(MessageContext msgContext) throws AxisFault {
- if(Constants.RST_ACTON_SCT.equals(msgContext.getWSAAction()) ||
- Constants.RSTR_ACTON_SCT.equals(msgContext.getWSAAction())) {
- WSDoAllReceiver secReceiver = new WSDoAllReceiver();
- secReceiver.init(this.handlerDescription);
- secReceiver.invoke(msgContext);
- return;
+ DocumentBuilderFactoryImpl.setDOOMRequired(true);
+
+ try {
+ if (Constants.RST_ACTON_SCT.equals(msgContext.getWSAAction())
+ || Constants.RSTR_ACTON_SCT.equals(msgContext
+ .getWSAAction())) {
+ WSDoAllReceiver secReceiver = new WSDoAllReceiver();
+ secReceiver.init(this.handlerDescription);
+ secReceiver.invoke(msgContext);
+ return;
+ }
+
+ // Parse the configuration
+ RahasConfiguration config = RahasConfiguration.load(msgContext,
+ false);
+ WSSecurityEngine secEngine = new WSSecurityEngine();
+ secEngine.processSecurityHeader(config.getDocument(), null,
+ new RahasCallbackHandler(config), config
+ .getCrypto());
+
+ //Convert back to llom since the inflow cannot use llom
+ msgContext.setEnvelope(Axis2Util.getSOAPEnvelopeFromDOOMDocument(
+ config.getDocument(), false));
+
+ } catch (Exception e) {
+ if (e instanceof RahasException) {
+ RahasException re = (RahasException) e;
+ throw new AxisFault(re.getFaultString(), re.getFaultCode());
+ } else {
+ throw new AxisFault(e.getMessage());
+ }
+ } finally {
+ DocumentBuilderFactoryImpl.setDOOMRequired(false);
+ Axis2Util.useDOOM(false);
}
+
}
-
+
public void cleanup() throws AxisFault {
}
Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/STSRequester.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/STSRequester.java?rev=390457&r1=390456&r2=390457&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/STSRequester.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/STSRequester.java Fri Mar 31 08:57:37 2006
@@ -16,7 +16,6 @@
package org.apache.axis2.security.rahas;
-import org.apache.axiom.om.OMDocument;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.impl.dom.DOOMAbstractFactory;
@@ -88,12 +87,14 @@
rst.setRequestType(new URI(Constants.REQ_TYPE_ISSUE));
rst.setTokenType(new URI(Constants.TOK_TYPE_SCT));
rst.setContext(new URI("http://get.optional.attrs.working"));
+
+ Axis2Util.useDOOM(false);
StAXOMBuilder builder = new StAXOMBuilder(rst
.getPullParser(new QName(Constants.WST_NS,
Constants.REQUEST_SECURITY_TOKEN_LN)));
-
+
OMElement tempResult = client.sendReceive(rstQn, builder.getDocumentElement());
-
+ Axis2Util.useDOOM(true);
OMElement tempelem = Axis2Util.toDOOM(DOOMAbstractFactory.getOMFactory(), tempResult);
OMElement elem = (OMElement)config.getDocument().importNode((Element)tempelem, true);
processRSTR(elem, config);
@@ -116,7 +117,7 @@
SecurityContextToken sct = new SecurityContextToken((Element)sctElem);
token = new Token(sct.getIdentifier(), sctElem);
config.setSecurityContextToken(sct);
- config.setContextIdentifier(sct.getIdentifier());
+ config.resgisterContext(sct.getIdentifier());
} else {
throw new RahasException("sctMissingInResponse");
}
Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Sender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Sender.java?rev=390457&r1=390456&r2=390457&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Sender.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Sender.java Fri Mar 31 08:57:37 2006
@@ -29,6 +29,7 @@
import org.apache.ws.security.components.crypto.Crypto;
import org.apache.ws.security.message.WSSecDKEncrypt;
import org.apache.ws.security.message.WSSecHeader;
+import org.apache.ws.security.message.token.SecurityContextToken;
import org.apache.ws.security.util.WSSecurityUtil;
import org.w3c.dom.Document;
@@ -44,7 +45,7 @@
private HandlerDescription handlerDescription;
public void invoke(MessageContext msgContext) throws AxisFault {
-
+ DocumentBuilderFactoryImpl.setDOOMRequired(true);
try {
if(Constants.RST_ACTON_SCT.equals(msgContext.getWSAAction()) ||
Constants.RSTR_ACTON_SCT.equals(msgContext.getWSAAction())) {
@@ -57,21 +58,30 @@
//Parse the configuration
RahasConfiguration config = RahasConfiguration.load(msgContext, true);
- if(config.getContextIdentifier() == null && config.getStsEPRAddress() != null) {
-
- String sts = config.getStsEPRAddress();
- if(sts != null) {
- //Use a security token service
- STSRequester.issueRequest(config);
- this.constructMessage(config);
- msgContext.setEnvelope((SOAPEnvelope) config.getDocument()
- .getDocumentElement());
+ if(config.getMsgCtx().isServerSide()) {
+ this.constructMessage(config);
+ msgContext.setEnvelope((SOAPEnvelope) config.getDocument()
+ .getDocumentElement());
+ } else {
+
+ if(config.getContextIdentifier() == null && config.getStsEPRAddress() != null && !config.getMsgCtx().isServerSide()) {
+
+ String sts = config.getStsEPRAddress();
+ if(sts != null) {
+ //Use a security token service
+ STSRequester.issueRequest(config);
+ this.constructMessage(config);
+ msgContext.setEnvelope((SOAPEnvelope) config.getDocument()
+ .getDocumentElement());
+ } else {
+ //Create a token
+ }
+
} else {
- //Create a token
+ this.constructMessage(config);
+ msgContext.setEnvelope((SOAPEnvelope) config.getDocument()
+ .getDocumentElement());
}
-
-
-
}
@@ -95,8 +105,6 @@
private void constructMessage(RahasConfiguration config) throws Exception {
- DocumentBuilderFactoryImpl.setDOOMRequired(true);
-
Crypto crypto = Util.getCryptoInstace(config);
Document doc = config.getDocument();
@@ -107,7 +115,11 @@
byte[] tempSecret = config.getTokenStore().getToken(
config.getContextIdentifier()).getSecret();
- String tokenId = config.getSecurityContextToken().getID();
+ SecurityContextToken sct = config.getSecurityContextToken();
+ if(sct == null) {
+
+ }
+ String tokenId = sct.getID();
// Derived key encryption
WSSecDKEncrypt encrBuilder = new WSSecDKEncrypt();
@@ -116,7 +128,7 @@
encrBuilder.build(doc, crypto, secHeader);
WSSecurityUtil.prependChildElement(doc, secHeader.getSecurityHeader(),
- config.getSecurityContextToken().getElement(), false);
+ sct.getElement(), false);
}
Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Util.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Util.java?rev=390457&r1=390456&r2=390457&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Util.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Util.java Fri Mar 31 08:57:37 2006
@@ -39,7 +39,11 @@
if(config.getCryptoClassName() != null && config.getCryptoProperties() != null) {
crypto = CryptoFactory.getInstance(config.getCryptoClassName(), config.getCryptoProperties());
} else if(config.getCryptoPropertiesFile() != null) {
- crypto = CryptoFactory.getInstance(config.getCryptoPropertiesFile());
+ if(config.getClassLoader() != null) {
+ crypto = CryptoFactory.getInstance(config.getCryptoPropertiesFile(), config.getClassLoader());
+ } else {
+ crypto = CryptoFactory.getInstance(config.getCryptoPropertiesFile());
+ }
} else {
throw new RahasException("cannotCrateCryptoInstance");
}
Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/impl/SCTIssuer.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/impl/SCTIssuer.java?rev=390457&r1=390456&r2=390457&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/impl/SCTIssuer.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/impl/SCTIssuer.java Fri Mar 31 08:57:37 2006
@@ -201,6 +201,7 @@
//Store the tokens
Token sctToken = new Token(sct.getIdentifier(), (OMElement)sct.getElement());
+ sctToken.setSecret(encrKeyBuilder.getEphemeralKey());
this.getTokenStore(msgCtx).add(sctToken);
return env;
@@ -244,12 +245,12 @@
* @return
*/
private TokenStorage getTokenStore(MessageContext msgCtx) {
- TokenStorage storage = (TokenStorage) msgCtx.getServiceContext()
- .getProperty(TokenStorage.TOKEN_STORAGE_KEY);
+ String tempKey = TokenStorage.TOKEN_STORAGE_KEY
+ + msgCtx.getAxisService().getName();
+ TokenStorage storage = (TokenStorage) msgCtx.getProperty(tempKey);
if (storage == null) {
storage = new SimpleTokenStore();
- msgCtx.getServiceContext().setProperty(
- TokenStorage.TOKEN_STORAGE_KEY, storage);
+ msgCtx.getConfigurationContext().setProperty(tempKey, storage);
}
return storage;
}
Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java?rev=390457&r1=390456&r2=390457&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java Fri Mar 31 08:57:37 2006
@@ -16,15 +16,19 @@
package org.apache.axis2.security.util;
+import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.impl.dom.DOOMAbstractFactory;
+import org.apache.axiom.om.impl.dom.factory.OMDOMFactory;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
+import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
+import org.apache.axiom.soap.impl.dom.soap12.SOAP12Factory;
import org.apache.axis2.security.handler.WSSHandlerConstants;
import org.apache.ws.security.WSSecurityException;
import org.apache.xml.security.utils.XMLUtils;
@@ -44,7 +48,31 @@
* Utility class for the Axis2-WSS4J Module
*/
public class Axis2Util {
-
+
+ private static ThreadLocal doomTacker = new ThreadLocal();
+
+ public static boolean isUseDOOM() {
+ Object value = doomTacker.get();
+ return (value != null);
+ }
+
+ public static void useDOOM(boolean isDOOMRequired) {
+ if(isDOOMRequired) {
+ if(isUseDOOM()) {
+ System.setProperty(OMAbstractFactory.SOAP11_FACTORY_NAME_PROPERTY, SOAP11Factory.class.getName());
+ System.setProperty(OMAbstractFactory.SOAP12_FACTORY_NAME_PROPERTY, SOAP12Factory.class.getName());
+ System.setProperty(OMAbstractFactory.OM_FACTORY_NAME_PROPERTY, OMDOMFactory.class.getName());
+ doomTacker.set(new Object());
+ }
+ } else {
+ System.getProperties().remove(OMAbstractFactory.SOAP11_FACTORY_NAME_PROPERTY);
+ System.getProperties().remove(OMAbstractFactory.SOAP12_FACTORY_NAME_PROPERTY);
+ System.getProperties().remove(OMAbstractFactory.OM_FACTORY_NAME_PROPERTY);
+ doomTacker.set(null);
+ }
+ }
+
+
/**
* Creates a DOM Document using the SOAP Envelope.
* @param env An org.apache.axiom.soap.SOAPEnvelope instance