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 fa...@apache.org on 2008/04/15 20:19:08 UTC
svn commit: r648361 - in /webservices/wss4j/trunk:
src/org/apache/ws/security/WSSConfig.java test/wssec/MyAction.java
test/wssec/MyProcessor.java test/wssec/TestWSSecurityUserProcessor.java
Author: fadushin
Date: Tue Apr 15 11:19:04 2008
New Revision: 648361
URL: http://svn.apache.org/viewvc?rev=648361&view=rev
Log:
WSS-74 WSS-116 Reverted some changes to processor cardinality
* Reverted to creating a processor-per-call behavior,
while preserving user processor replaceability
Added:
webservices/wss4j/trunk/test/wssec/MyAction.java (with props)
webservices/wss4j/trunk/test/wssec/MyProcessor.java (with props)
Modified:
webservices/wss4j/trunk/src/org/apache/ws/security/WSSConfig.java
webservices/wss4j/trunk/test/wssec/TestWSSecurityUserProcessor.java
Modified: webservices/wss4j/trunk/src/org/apache/ws/security/WSSConfig.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/WSSConfig.java?rev=648361&r1=648360&r2=648361&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/WSSConfig.java (original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/WSSConfig.java Tue Apr 15 11:19:04 2008
@@ -52,51 +52,35 @@
try {
tmp.put(
new Integer(WSConstants.UT),
- (Action) Loader.loadClass(
- org.apache.ws.security.action.UsernameTokenAction.class.getName()
- ).newInstance()
+ org.apache.ws.security.action.UsernameTokenAction.class.getName()
);
tmp.put(
new Integer(WSConstants.ENCR),
- (Action) Loader.loadClass(
- org.apache.ws.security.action.EncryptionAction.class.getName()
- ).newInstance()
+ org.apache.ws.security.action.EncryptionAction.class.getName()
);
tmp.put(
new Integer(WSConstants.SIGN),
- (Action) Loader.loadClass(
- org.apache.ws.security.action.SignatureAction.class.getName()
- ).newInstance()
+ org.apache.ws.security.action.SignatureAction.class.getName()
);
tmp.put(
new Integer(WSConstants.ST_SIGNED),
- (Action) Loader.loadClass(
- org.apache.ws.security.action.SAMLTokenSignedAction.class.getName()
- ).newInstance()
+ org.apache.ws.security.action.SAMLTokenSignedAction.class.getName()
);
tmp.put(
new Integer(WSConstants.ST_UNSIGNED),
- (Action) Loader.loadClass(
- org.apache.ws.security.action.SAMLTokenUnsignedAction.class.getName()
- ).newInstance()
+ org.apache.ws.security.action.SAMLTokenUnsignedAction.class.getName()
);
tmp.put(
new Integer(WSConstants.TS),
- (Action) Loader.loadClass(
- org.apache.ws.security.action.TimestampAction.class.getName()
- ).newInstance()
+ org.apache.ws.security.action.TimestampAction.class.getName()
);
tmp.put(
new Integer(WSConstants.UT_SIGN),
- (Action) Loader.loadClass(
- org.apache.ws.security.action.UsernameTokenSignedAction.class.getName()
- ).newInstance()
+ org.apache.ws.security.action.UsernameTokenSignedAction.class.getName()
);
tmp.put(
new Integer(WSConstants.SC),
- (Action) Loader.loadClass(
- org.apache.ws.security.action.SignatureConfirmationAction.class.getName()
- ).newInstance()
+ org.apache.ws.security.action.SignatureConfirmationAction.class.getName()
);
} catch (final Throwable t) {
t.printStackTrace();
@@ -113,51 +97,35 @@
try {
tmp.put(
WSSecurityEngine.SAML_TOKEN,
- (Processor) Loader.loadClass(
- org.apache.ws.security.processor.SAMLTokenProcessor.class.getName()
- ).newInstance()
+ org.apache.ws.security.processor.SAMLTokenProcessor.class.getName()
);
tmp.put(
WSSecurityEngine.ENCRYPTED_KEY,
- (Processor) Loader.loadClass(
- org.apache.ws.security.processor.EncryptedKeyProcessor.class.getName()
- ).newInstance()
+ org.apache.ws.security.processor.EncryptedKeyProcessor.class.getName()
);
tmp.put(
WSSecurityEngine.SIGNATURE,
- (Processor) Loader.loadClass(
- org.apache.ws.security.processor.SignatureProcessor.class.getName()
- ).newInstance()
+ org.apache.ws.security.processor.SignatureProcessor.class.getName()
);
tmp.put(
WSSecurityEngine.timeStamp,
- (Processor) Loader.loadClass(
- org.apache.ws.security.processor.TimestampProcessor.class.getName()
- ).newInstance()
+ org.apache.ws.security.processor.TimestampProcessor.class.getName()
);
tmp.put(
WSSecurityEngine.usernameToken,
- (Processor) Loader.loadClass(
- org.apache.ws.security.processor.UsernameTokenProcessor.class.getName()
- ).newInstance()
+ org.apache.ws.security.processor.UsernameTokenProcessor.class.getName()
);
tmp.put(
WSSecurityEngine.REFERENCE_LIST,
- (Processor) Loader.loadClass(
- org.apache.ws.security.processor.ReferenceListProcessor.class.getName()
- ).newInstance()
+ org.apache.ws.security.processor.ReferenceListProcessor.class.getName()
);
tmp.put(
WSSecurityEngine.signatureConfirmation,
- (Processor) Loader.loadClass(
- org.apache.ws.security.processor.SignatureConfirmationProcessor.class.getName()
- ).newInstance()
+ org.apache.ws.security.processor.SignatureConfirmationProcessor.class.getName()
);
tmp.put(
WSSecurityEngine.DERIVED_KEY_TOKEN_05_02,
- (Processor) Loader.loadClass(
- org.apache.ws.security.processor.DerivedKeyTokenProcessor.class.getName()
- ).newInstance()
+ org.apache.ws.security.processor.DerivedKeyTokenProcessor.class.getName()
);
tmp.put(
WSSecurityEngine.DERIVED_KEY_TOKEN_05_12,
@@ -165,9 +133,7 @@
);
tmp.put(
WSSecurityEngine.SECURITY_CONTEXT_TOKEN_05_02,
- (Processor) Loader.loadClass(
- org.apache.ws.security.processor.SecurityContextTokenProcessor.class.getName()
- ).newInstance()
+ org.apache.ws.security.processor.SecurityContextTokenProcessor.class.getName()
);
tmp.put(
WSSecurityEngine.SECURITY_CONTEXT_TOKEN_05_12,
@@ -175,15 +141,11 @@
);
tmp.put(
WSSecurityEngine.binaryToken,
- (Processor) Loader.loadClass(
- org.apache.ws.security.processor.BinarySecurityTokenProcessor.class.getName()
- ).newInstance()
+ org.apache.ws.security.processor.BinarySecurityTokenProcessor.class.getName()
);
tmp.put(
WSSecurityEngine.ENCRYPTED_DATA,
- (Processor) Loader.loadClass(
- org.apache.ws.security.processor.EncryptedDataProcessor.class.getName()
- ).newInstance()
+ org.apache.ws.security.processor.EncryptedDataProcessor.class.getName()
);
} catch (final Throwable t) {
t.printStackTrace();
@@ -382,8 +344,8 @@
* This operation allows applications to supply their own
* actions for well-known operations.
*/
- public Action setAction(int code, Action action) {
- return (Action) actionMap.put(new Integer(code), action);
+ public String setAction(int code, String action) {
+ return (String) actionMap.put(new Integer(code), action);
}
/**
@@ -395,31 +357,46 @@
*/
public Action getAction(int action) throws WSSecurityException {
Integer key = new Integer(action);
- Action ret = (Action) actionMap.get(key);
- if (ret == null) {
+ String name = (String) actionMap.get(key);
+ if (name == null) {
throw new WSSecurityException(WSSecurityException.FAILURE,
"unknownAction", new Object[] { key });
}
- return ret;
+ try {
+ return (Action) Loader.loadClass(name).newInstance();
+ } catch (Throwable t) {
+ throw new WSSecurityException(WSSecurityException.FAILURE,
+ "unableToLoadClass", new Object[] { name });
+ }
}
/**
- * Associate a SOAP processor with a specified SOAP Security header
+ * Associate a SOAP processor name with a specified SOAP Security header
* element QName. Processors registered under this QName will be
* called when processing header elements with the specified type.
*/
- public Processor setProcessor(QName el, Processor p) {
- return (Processor) processorMap.put(el, p);
+ public String setProcessor(QName el, String name) {
+ return (String) processorMap.put(el, name);
}
/**
* @return the SOAP processor associated with the specified
* QName. The QName is intended to refer to an element
- * in a SOAP security header.
+ * in a SOAP security header. This operation returns
+ * null if there is no processor associated with the
+ * specified QName.
*/
public Processor getProcessor(QName el) throws WSSecurityException {
- Processor p = (Processor) processorMap.get(el);
- return p;
+ final String name = (String) processorMap.get(el);
+ if (name != null) {
+ try {
+ return (Processor) Loader.loadClass(name).newInstance();
+ } catch (Throwable t) {
+ throw new WSSecurityException(WSSecurityException.FAILURE,
+ "unableToLoadClass", new Object[] { name });
+ }
+ }
+ return null;
}
private boolean loadProvider(String id, String className) {
Added: webservices/wss4j/trunk/test/wssec/MyAction.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/test/wssec/MyAction.java?rev=648361&view=auto
==============================================================================
--- webservices/wss4j/trunk/test/wssec/MyAction.java (added)
+++ webservices/wss4j/trunk/test/wssec/MyAction.java Tue Apr 15 11:19:04 2008
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2003-2004 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 wssec;
+
+import org.apache.ws.security.action.Action;
+import org.apache.ws.security.handler.WSHandler;
+import org.apache.ws.security.handler.RequestData;
+import org.apache.ws.security.WSSecurityException;
+
+/**
+ * a custom action that leaves a breadcumb
+ */
+public class MyAction implements Action {
+
+ public void
+ execute(
+ WSHandler handler,
+ int actionToDo,
+ org.w3c.dom.Document doc,
+ RequestData reqData
+ ) throws WSSecurityException {
+ //
+ // leave a breadcrumb, if asked...
+ //
+ if (reqData.getMsgContext().equals("bread")) {
+ reqData.setMsgContext("crumb");
+ }
+ }
+}
Propchange: webservices/wss4j/trunk/test/wssec/MyAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/wss4j/trunk/test/wssec/MyAction.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: webservices/wss4j/trunk/test/wssec/MyProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/test/wssec/MyProcessor.java?rev=648361&view=auto
==============================================================================
--- webservices/wss4j/trunk/test/wssec/MyProcessor.java (added)
+++ webservices/wss4j/trunk/test/wssec/MyProcessor.java Tue Apr 15 11:19:04 2008
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2003-2004 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 wssec;
+
+import org.apache.ws.security.components.crypto.Crypto;
+import org.apache.ws.security.message.token.SecurityContextToken;
+import org.apache.ws.security.processor.Processor;
+import org.apache.ws.security.WSConstants;
+import org.apache.ws.security.WSDocInfo;
+import org.apache.ws.security.WSSConfig;
+import org.apache.ws.security.WSSecurityEngineResult;
+import org.apache.ws.security.WSSecurityException;
+
+/**
+ * a custom processor that inserts itself into the results vector
+ */
+public class MyProcessor implements Processor {
+
+ 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);
+ }
+
+ public final String getId() {
+ return getClass().getName();
+ }
+}
Propchange: webservices/wss4j/trunk/test/wssec/MyProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/wss4j/trunk/test/wssec/MyProcessor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: webservices/wss4j/trunk/test/wssec/TestWSSecurityUserProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/test/wssec/TestWSSecurityUserProcessor.java?rev=648361&r1=648360&r2=648361&view=diff
==============================================================================
--- webservices/wss4j/trunk/test/wssec/TestWSSecurityUserProcessor.java (original)
+++ webservices/wss4j/trunk/test/wssec/TestWSSecurityUserProcessor.java Tue Apr 15 11:19:04 2008
@@ -165,7 +165,7 @@
// Check to make sure we can install/replace and use our own processor
//
WSSConfig cfg = WSSConfig.getNewInstance();
- Processor p = new MyProcessor();
+ String p = "wssec.MyProcessor";
cfg.setProcessor(
WSSecurityEngine.SIGNATURE,
p
@@ -179,7 +179,7 @@
final java.util.Map result = (java.util.Map) pos.next();
Object obj = result.get("foo");
if (obj != null) {
- if (obj == p) {
+ if (obj.getClass().getName().equals(p)) {
found = true;
}
}
@@ -196,8 +196,7 @@
final WSSConfig cfg = WSSConfig.getNewInstance();
final int action = 0xDEADF000;
- final MyAction myAction = new MyAction();
- cfg.setAction(action, myAction);
+ cfg.setAction(action, "wssec.MyAction");
final RequestData reqData = new RequestData();
reqData.setWssConfig(cfg);
reqData.setMsgContext(new java.util.TreeMap());
@@ -206,68 +205,21 @@
actions.add(new Integer(action));
final Document doc = unsignedEnvelope.getAsDocument();
MyHandler handler = new MyHandler();
+ reqData.setMsgContext("bread");
+ assertEquals(reqData.getMsgContext(), "bread");
handler.doit(
action,
doc,
reqData,
actions
);
- assertTrue(myAction.getCalled() == 1);
- }
-
- /**
- * a custom processor that inserts itself into the results vector
- */
- private static class MyProcessor implements Processor {
-
- public final void
- handleToken(
- org.w3c.dom.Element elem,
- org.apache.ws.security.components.crypto.Crypto crypto,
- org.apache.ws.security.components.crypto.Crypto decCrypto,
- javax.security.auth.callback.CallbackHandler cb,
- org.apache.ws.security.WSDocInfo wsDocInfo,
- java.util.Vector returnResults,
- org.apache.ws.security.WSSConfig config
- ) throws org.apache.ws.security.WSSecurityException {
- final java.util.Map result =
- new org.apache.ws.security.WSSecurityEngineResult(
- WSConstants.UT_SIGN,
- (org.apache.ws.security.message.token.SecurityContextToken) null
- );
- result.put("foo", this);
- returnResults.add(result);
- }
-
- public final String getId() {
- return getClass().getName();
- }
- }
-
- /**
- * a custom action that counts how many times it's been called
- */
- private static class MyAction implements Action {
-
- private int called = 0;
-
- public void
- execute(
- WSHandler handler,
- int actionToDo,
- Document doc,
- RequestData reqData
- ) throws org.apache.ws.security.WSSecurityException {
- ++called;
- }
-
- int getCalled(){ return called; }
+ assertEquals(reqData.getMsgContext(), "crumb");
}
/**
* a trivial extension of the WSHandler type
*/
- private static class MyHandler extends WSHandler {
+ public static class MyHandler extends WSHandler {
public Object
getOption(String key) {
---------------------------------------------------------------------
To unsubscribe, e-mail: wss4j-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: wss4j-dev-help@ws.apache.org