You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by gi...@apache.org on 2012/01/08 12:44:18 UTC
svn commit: r1228829 [8/11] - in /webservices/wss4j/branches/swssf:
bindings/wss10-binding/src/etc/ bindings/wss11-binding/src/etc/
bindings/wsu10-binding/src/etc/
rampart-policy/src/main/java/org/apache/ws/secpolicy/model/
streaming-ws-policy/src/main...
Modified: webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/TransportBindingTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/TransportBindingTest.java?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/TransportBindingTest.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/TransportBindingTest.java Sun Jan 8 11:44:13 2012
@@ -27,6 +27,8 @@ import org.swssf.wss.securityEvent.*;
import org.testng.Assert;
import org.testng.annotations.Test;
+import javax.xml.namespace.QName;
+
/**
* @author $Author$
* @version $Revision$ $Date$
@@ -42,23 +44,37 @@ public class TransportBindingTest extend
"</wsp:Policy>\n" +
"</sp:TransportBinding>";
PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString);
- TimestampSecurityEvent timestampSecurityEvent = new TimestampSecurityEvent(SecurityEvent.Event.Timestamp);
+ TimestampSecurityEvent timestampSecurityEvent = new TimestampSecurityEvent();
policyEnforcer.registerSecurityEvent(timestampSecurityEvent);
- HttpsTokenSecurityEvent httpsTokenSecurityEvent = new HttpsTokenSecurityEvent(SecurityEvent.Event.HttpsToken);
- httpsTokenSecurityEvent.setSecurityToken(new HttpsSecurityToken(true, "username"));
+
+ RequiredElementSecurityEvent requiredElementSecurityEvent = new RequiredElementSecurityEvent();
+ requiredElementSecurityEvent.setElement(WSSConstants.TAG_wsu_Timestamp);
+ policyEnforcer.registerSecurityEvent(requiredElementSecurityEvent);
+
+ HttpsTokenSecurityEvent httpsTokenSecurityEvent = new HttpsTokenSecurityEvent();
+ httpsTokenSecurityEvent.setSecurityToken(new HttpsSecurityToken(true, "username", null));
httpsTokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Signature);
policyEnforcer.registerSecurityEvent(httpsTokenSecurityEvent);
+
httpsTokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Encryption);
policyEnforcer.registerSecurityEvent(httpsTokenSecurityEvent);
- EncryptedElementSecurityEvent encryptedElementSecurityEvent = new EncryptedElementSecurityEvent(SecurityEvent.Event.EncryptedElement, true);
+
+ OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent();
+ operationSecurityEvent.setOperation(new QName("definitions"));
+ policyEnforcer.registerSecurityEvent(operationSecurityEvent);
+
+ EncryptedElementSecurityEvent encryptedElementSecurityEvent = new EncryptedElementSecurityEvent(null, true, false);
encryptedElementSecurityEvent.setElement(WSSConstants.TAG_dsig_Signature);
policyEnforcer.registerSecurityEvent(encryptedElementSecurityEvent);
- encryptedElementSecurityEvent = new EncryptedElementSecurityEvent(SecurityEvent.Event.EncryptedElement, true);
+
+ encryptedElementSecurityEvent = new EncryptedElementSecurityEvent(null, true, false);
encryptedElementSecurityEvent.setElement(WSSConstants.TAG_wsse11_SignatureConfirmation);
policyEnforcer.registerSecurityEvent(encryptedElementSecurityEvent);
- SignedPartSecurityEvent signedPartSecurityEvent = new SignedPartSecurityEvent(SecurityEvent.Event.SignedPart, true);
+
+ SignedPartSecurityEvent signedPartSecurityEvent = new SignedPartSecurityEvent(null, true);
signedPartSecurityEvent.setElement(WSSConstants.TAG_soap12_Body);
policyEnforcer.registerSecurityEvent(signedPartSecurityEvent);
+
policyEnforcer.doFinal();
}
@@ -70,15 +86,23 @@ public class TransportBindingTest extend
"</wsp:Policy>\n" +
"</sp:TransportBinding>";
PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString);
- HttpsTokenSecurityEvent httpsTokenSecurityEvent = new HttpsTokenSecurityEvent(SecurityEvent.Event.HttpsToken);
- httpsTokenSecurityEvent.setSecurityToken(new HttpsSecurityToken(true, "username"));
+
+ HttpsTokenSecurityEvent httpsTokenSecurityEvent = new HttpsTokenSecurityEvent();
+ httpsTokenSecurityEvent.setSecurityToken(new HttpsSecurityToken(true, "username", null));
httpsTokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Signature);
policyEnforcer.registerSecurityEvent(httpsTokenSecurityEvent);
+
httpsTokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Encryption);
policyEnforcer.registerSecurityEvent(httpsTokenSecurityEvent);
- TimestampSecurityEvent timestampSecurityEvent = new TimestampSecurityEvent(SecurityEvent.Event.Timestamp);
+
+ TimestampSecurityEvent timestampSecurityEvent = new TimestampSecurityEvent();
+ policyEnforcer.registerSecurityEvent(timestampSecurityEvent);
+
+ OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent();
+ operationSecurityEvent.setOperation(new QName("definitions"));
+
try {
- policyEnforcer.registerSecurityEvent(timestampSecurityEvent);
+ policyEnforcer.registerSecurityEvent(operationSecurityEvent);
Assert.fail("Exception expected");
} catch (WSSecurityException e) {
Assert.assertTrue(e.getCause() instanceof PolicyViolationException);
@@ -94,17 +118,30 @@ public class TransportBindingTest extend
"</wsp:Policy>\n" +
"</sp:TransportBinding>";
PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString);
- TimestampSecurityEvent timestampSecurityEvent = new TimestampSecurityEvent(SecurityEvent.Event.Timestamp);
+
+ TimestampSecurityEvent timestampSecurityEvent = new TimestampSecurityEvent();
policyEnforcer.registerSecurityEvent(timestampSecurityEvent);
- HttpsTokenSecurityEvent httpsTokenSecurityEvent = new HttpsTokenSecurityEvent(SecurityEvent.Event.HttpsToken);
- httpsTokenSecurityEvent.setSecurityToken(new HttpsSecurityToken(true, "username"));
+
+ RequiredElementSecurityEvent requiredElementSecurityEvent = new RequiredElementSecurityEvent();
+ requiredElementSecurityEvent.setElement(WSSConstants.TAG_wsu_Timestamp);
+ policyEnforcer.registerSecurityEvent(requiredElementSecurityEvent);
+
+ HttpsTokenSecurityEvent httpsTokenSecurityEvent = new HttpsTokenSecurityEvent();
+ httpsTokenSecurityEvent.setSecurityToken(new HttpsSecurityToken(true, "username", null));
httpsTokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Signature);
policyEnforcer.registerSecurityEvent(httpsTokenSecurityEvent);
+
httpsTokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Encryption);
policyEnforcer.registerSecurityEvent(httpsTokenSecurityEvent);
- EncryptedElementSecurityEvent encryptedElementSecurityEvent = new EncryptedElementSecurityEvent(SecurityEvent.Event.EncryptedElement, false);
+
+ EncryptedElementSecurityEvent encryptedElementSecurityEvent = new EncryptedElementSecurityEvent(null, false, false);
encryptedElementSecurityEvent.setElement(WSSConstants.TAG_dsig_Signature);
policyEnforcer.registerSecurityEvent(encryptedElementSecurityEvent);
+
+ OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent();
+ operationSecurityEvent.setOperation(new QName("definitions"));
+ policyEnforcer.registerSecurityEvent(operationSecurityEvent);
+
policyEnforcer.doFinal();
}
@@ -117,23 +154,37 @@ public class TransportBindingTest extend
"</wsp:Policy>\n" +
"</sp:TransportBinding>";
PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString);
- TimestampSecurityEvent timestampSecurityEvent = new TimestampSecurityEvent(SecurityEvent.Event.Timestamp);
+ TimestampSecurityEvent timestampSecurityEvent = new TimestampSecurityEvent();
policyEnforcer.registerSecurityEvent(timestampSecurityEvent);
- HttpsTokenSecurityEvent httpsTokenSecurityEvent = new HttpsTokenSecurityEvent(SecurityEvent.Event.HttpsToken);
- httpsTokenSecurityEvent.setSecurityToken(new HttpsSecurityToken(true, "username"));
+
+ RequiredElementSecurityEvent requiredElementSecurityEvent = new RequiredElementSecurityEvent();
+ requiredElementSecurityEvent.setElement(WSSConstants.TAG_wsu_Timestamp);
+ policyEnforcer.registerSecurityEvent(requiredElementSecurityEvent);
+
+ HttpsTokenSecurityEvent httpsTokenSecurityEvent = new HttpsTokenSecurityEvent();
+ httpsTokenSecurityEvent.setSecurityToken(new HttpsSecurityToken(true, "username", null));
httpsTokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Signature);
policyEnforcer.registerSecurityEvent(httpsTokenSecurityEvent);
+
httpsTokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Encryption);
policyEnforcer.registerSecurityEvent(httpsTokenSecurityEvent);
- EncryptedElementSecurityEvent encryptedElementSecurityEvent = new EncryptedElementSecurityEvent(SecurityEvent.Event.EncryptedElement, true);
+
+ EncryptedElementSecurityEvent encryptedElementSecurityEvent = new EncryptedElementSecurityEvent(null, true, false);
encryptedElementSecurityEvent.setElement(WSSConstants.TAG_dsig_Signature);
policyEnforcer.registerSecurityEvent(encryptedElementSecurityEvent);
- encryptedElementSecurityEvent = new EncryptedElementSecurityEvent(SecurityEvent.Event.EncryptedElement, true);
+
+ encryptedElementSecurityEvent = new EncryptedElementSecurityEvent(null, true, false);
encryptedElementSecurityEvent.setElement(WSSConstants.TAG_wsse11_SignatureConfirmation);
policyEnforcer.registerSecurityEvent(encryptedElementSecurityEvent);
- SignedPartSecurityEvent signedPartSecurityEvent = new SignedPartSecurityEvent(SecurityEvent.Event.SignedPart, false);
+
+ OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent();
+ operationSecurityEvent.setOperation(new QName("definitions"));
+ policyEnforcer.registerSecurityEvent(operationSecurityEvent);
+
+ SignedPartSecurityEvent signedPartSecurityEvent = new SignedPartSecurityEvent(null, false);
signedPartSecurityEvent.setElement(WSSConstants.TAG_soap12_Body);
policyEnforcer.registerSecurityEvent(signedPartSecurityEvent);
+
policyEnforcer.doFinal();
}
}
Modified: webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/UsernameTokenTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/UsernameTokenTest.java?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/UsernameTokenTest.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/UsernameTokenTest.java Sun Jan 8 11:44:13 2012
@@ -21,54 +21,148 @@ package org.swssf.policy.test;
import org.swssf.policy.PolicyEnforcer;
import org.swssf.policy.PolicyViolationException;
import org.swssf.wss.ext.WSSConstants;
+import org.swssf.wss.ext.WSSecurityContext;
import org.swssf.wss.ext.WSSecurityException;
-import org.swssf.wss.securityEvent.SecurityEvent;
-import org.swssf.wss.securityEvent.UsernameTokenSecurityEvent;
+import org.swssf.wss.impl.securityToken.UsernameSecurityToken;
+import org.swssf.wss.securityEvent.*;
import org.testng.Assert;
import org.testng.annotations.Test;
+import javax.xml.namespace.QName;
+import java.util.Date;
+
/**
- * @author $Author: giger $
- * @version $Revision: 1181995 $ $Date: 2011-10-11 20:03:00 +0200 (Tue, 11 Oct 2011) $
+ * @author $Author$
+ * @version $Revision$ $Date$
*/
public class UsernameTokenTest extends AbstractPolicyTestBase {
@Test
public void testPolicy() throws Exception {
String policyString =
- "<sp:UsernameToken xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" " +
- "xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" +
- "<sp:IssuerName>xs:anyURI</sp:IssuerName>\n" +
+ "<sp:SymmetricBinding xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" +
"<wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
- "<sp:HashPassword/>\n" +
- "<sp:WssUsernameToken11/>\n" +
+ "<sp:EncryptionToken>\n" +
+ " <wsp:Policy>\n" +
+ " <sp:UsernameToken>\n" +
+ " <sp:IssuerName>xs:anyURI</sp:IssuerName>\n" +
+ " <wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
+ " <sp:HashPassword/>\n" +
+ " <sp:WssUsernameToken11/>\n" +
+ " </wsp:Policy>\n" +
+ " </sp:UsernameToken>\n" +
+ " </wsp:Policy>\n" +
+ "</sp:EncryptionToken>\n" +
+ "<sp:SignatureToken>\n" +
+ " <wsp:Policy>\n" +
+ " <sp:UsernameToken>\n" +
+ " <sp:IssuerName>xs:anyURI</sp:IssuerName>\n" +
+ " <wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
+ " <sp:HashPassword/>\n" +
+ " <sp:WssUsernameToken11/>\n" +
+ " </wsp:Policy>\n" +
+ " </sp:UsernameToken>\n" +
+ " </wsp:Policy>\n" +
+ "</sp:SignatureToken>\n" +
"</wsp:Policy>\n" +
- "</sp:UsernameToken>";
+ "</sp:SymmetricBinding>";
+
PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString);
- UsernameTokenSecurityEvent usernameTokenSecurityEvent = new UsernameTokenSecurityEvent(SecurityEvent.Event.UsernameToken);
- usernameTokenSecurityEvent.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
- usernameTokenSecurityEvent.setUsernameTokenProfile(WSSConstants.NS_USERNAMETOKEN_PROFILE11);
- policyEnforcer.registerSecurityEvent(usernameTokenSecurityEvent);
+ UsernameTokenSecurityEvent initiatorTokenSecurityEvent = new UsernameTokenSecurityEvent();
+ initiatorTokenSecurityEvent.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
+ initiatorTokenSecurityEvent.setUsernameTokenProfile(WSSConstants.NS_USERNAMETOKEN_PROFILE11);
+ initiatorTokenSecurityEvent.setSecurityToken(new UsernameSecurityToken(
+ "username", "password", new Date().toString(), new byte[10], new byte[10], Long.valueOf(10),
+ (WSSecurityContext) null, null, null));
+ initiatorTokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Signature);
+ policyEnforcer.registerSecurityEvent(initiatorTokenSecurityEvent);
+
+ UsernameTokenSecurityEvent recipientTokenSecurityEvent = new UsernameTokenSecurityEvent();
+ recipientTokenSecurityEvent.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
+ recipientTokenSecurityEvent.setUsernameTokenProfile(WSSConstants.NS_USERNAMETOKEN_PROFILE11);
+ recipientTokenSecurityEvent.setSecurityToken(new UsernameSecurityToken(
+ "username", "password", new Date().toString(), new byte[10], new byte[10], Long.valueOf(10),
+ (WSSecurityContext) null, null, null));
+ recipientTokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Encryption);
+ policyEnforcer.registerSecurityEvent(recipientTokenSecurityEvent);
+
+ SignedPartSecurityEvent signedPartSecurityEvent = new SignedPartSecurityEvent(recipientTokenSecurityEvent.getSecurityToken(), true);
+ signedPartSecurityEvent.setElement(WSSConstants.TAG_soap11_Body);
+ policyEnforcer.registerSecurityEvent(signedPartSecurityEvent);
+
+ ContentEncryptedElementSecurityEvent contentEncryptedElementSecurityEvent = new ContentEncryptedElementSecurityEvent(recipientTokenSecurityEvent.getSecurityToken(), true, true);
+ contentEncryptedElementSecurityEvent.setElement(WSSConstants.TAG_soap11_Body);
+ policyEnforcer.registerSecurityEvent(contentEncryptedElementSecurityEvent);
+
+ OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent();
+ operationSecurityEvent.setOperation(new QName("definitions"));
+ policyEnforcer.registerSecurityEvent(operationSecurityEvent);
+
policyEnforcer.doFinal();
}
@Test
public void testPolicyNegative() throws Exception {
String policyString =
- "<sp:UsernameToken xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" " +
- "xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" +
- "<sp:IssuerName>xs:anyURI</sp:IssuerName>\n" +
+ "<sp:SymmetricBinding xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" +
"<wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
- "<sp:HashPassword/>\n" +
- "<sp:WssUsernameToken11/>\n" +
+ "<sp:EncryptionToken>\n" +
+ " <wsp:Policy>\n" +
+ " <sp:UsernameToken>\n" +
+ " <sp:IssuerName>xs:anyURI</sp:IssuerName>\n" +
+ " <wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
+ " <sp:HashPassword/>\n" +
+ " <sp:WssUsernameToken11/>\n" +
+ " </wsp:Policy>\n" +
+ " </sp:UsernameToken>\n" +
+ " </wsp:Policy>\n" +
+ "</sp:EncryptionToken>\n" +
+ "<sp:SignatureToken>\n" +
+ " <wsp:Policy>\n" +
+ " <sp:UsernameToken>\n" +
+ " <sp:IssuerName>xs:anyURI</sp:IssuerName>\n" +
+ " <wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
+ " <sp:HashPassword/>\n" +
+ " <sp:WssUsernameToken11/>\n" +
+ " </wsp:Policy>\n" +
+ " </sp:UsernameToken>\n" +
+ " </wsp:Policy>\n" +
+ "</sp:SignatureToken>\n" +
"</wsp:Policy>\n" +
- "</sp:UsernameToken>";
+ "</sp:SymmetricBinding>";
+
PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString);
- UsernameTokenSecurityEvent usernameTokenSecurityEvent = new UsernameTokenSecurityEvent(SecurityEvent.Event.UsernameToken);
+ UsernameTokenSecurityEvent usernameTokenSecurityEvent = new UsernameTokenSecurityEvent();
usernameTokenSecurityEvent.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
usernameTokenSecurityEvent.setUsernameTokenProfile(WSSConstants.NS_USERNAMETOKEN_PROFILE11);
+ usernameTokenSecurityEvent.setSecurityToken(new UsernameSecurityToken(
+ "username", "password", new Date().toString(), new byte[10], new byte[10], Long.valueOf(10),
+ (WSSecurityContext) null, null, null));
+ usernameTokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Signature);
+ policyEnforcer.registerSecurityEvent(usernameTokenSecurityEvent);
+
+ UsernameTokenSecurityEvent recipientTokenSecurityEvent = new UsernameTokenSecurityEvent();
+ recipientTokenSecurityEvent.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
+ recipientTokenSecurityEvent.setUsernameTokenProfile(WSSConstants.NS_USERNAMETOKEN_PROFILE11);
+ recipientTokenSecurityEvent.setSecurityToken(new UsernameSecurityToken(
+ "username", "password", new Date().toString(), new byte[10], new byte[10], Long.valueOf(10),
+ (WSSecurityContext) null, null, null));
+ recipientTokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Encryption);
+ policyEnforcer.registerSecurityEvent(recipientTokenSecurityEvent);
+
+ SignedPartSecurityEvent signedPartSecurityEvent = new SignedPartSecurityEvent(recipientTokenSecurityEvent.getSecurityToken(), true);
+ signedPartSecurityEvent.setElement(WSSConstants.TAG_soap11_Body);
+ policyEnforcer.registerSecurityEvent(signedPartSecurityEvent);
+
+ ContentEncryptedElementSecurityEvent contentEncryptedElementSecurityEvent = new ContentEncryptedElementSecurityEvent(recipientTokenSecurityEvent.getSecurityToken(), true, true);
+ contentEncryptedElementSecurityEvent.setElement(WSSConstants.TAG_soap11_Body);
+ policyEnforcer.registerSecurityEvent(contentEncryptedElementSecurityEvent);
+
+ OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent();
+ operationSecurityEvent.setOperation(new QName("definitions"));
+
try {
- policyEnforcer.registerSecurityEvent(usernameTokenSecurityEvent);
+ policyEnforcer.registerSecurityEvent(operationSecurityEvent);
Assert.fail("Exception expected");
} catch (WSSecurityException e) {
Assert.assertTrue(e.getCause() instanceof PolicyViolationException);
Propchange: webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/UsernameTokenTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/VulnerabliltyVectorsTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/VulnerabliltyVectorsTest.java?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/VulnerabliltyVectorsTest.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/VulnerabliltyVectorsTest.java Sun Jan 8 11:44:13 2012
@@ -109,6 +109,8 @@ public class VulnerabliltyVectorsTest ex
soapEnvElement.removeChild(bodyElement);
Element newBody = securedDocument.createElementNS(WSSConstants.NS_SOAP11, WSSConstants.TAG_soap_Body_LocalName);
+ Element operationElement = securedDocument.createElementNS("http://schemas.xmlsoap.org/wsdl/", "definitions");
+ newBody.appendChild(operationElement);
soapEnvElement.appendChild(newBody);
xPathExpression = getXPath("/env:Envelope/env:Header");
Modified: webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/X509TokenTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/X509TokenTest.java?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/X509TokenTest.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/X509TokenTest.java Sun Jan 8 11:44:13 2012
@@ -19,18 +19,16 @@
package org.swssf.policy.test;
import org.swssf.policy.PolicyEnforcer;
-import org.swssf.policy.PolicyViolationException;
import org.swssf.wss.ext.WSSConstants;
import org.swssf.wss.ext.WSSecurityException;
-import org.swssf.wss.impl.securityToken.DelegatingSecurityToken;
import org.swssf.wss.impl.securityToken.X509SecurityToken;
-import org.swssf.wss.securityEvent.SecurityEvent;
-import org.swssf.wss.securityEvent.X509TokenSecurityEvent;
+import org.swssf.wss.securityEvent.*;
import org.swssf.xmlsec.ext.XMLSecurityConstants;
import org.swssf.xmlsec.ext.XMLSecurityException;
import org.testng.Assert;
import org.testng.annotations.Test;
+import javax.xml.namespace.QName;
import java.security.Key;
import java.security.KeyStore;
import java.security.PublicKey;
@@ -38,8 +36,8 @@ import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
/**
- * @author $Author: giger $
- * @version $Revision: 1181995 $ $Date: 2011-10-11 20:03:00 +0200 (Tue, 11 Oct 2011) $
+ * @author $Author$
+ * @version $Revision$ $Date$
*/
public class X509TokenTest extends AbstractPolicyTestBase {
@@ -48,7 +46,7 @@ public class X509TokenTest extends Abstr
final KeyStore keyStore = KeyStore.getInstance("jks");
keyStore.load(this.getClass().getClassLoader().getResourceAsStream("transmitter.jks"), "default".toCharArray());
- return new X509SecurityToken(tokenType, null, null, null, "", null) {
+ return new X509SecurityToken(tokenType, null, null, null, "", WSSConstants.KeyIdentifierType.THUMBPRINT_IDENTIFIER, null) {
@Override
protected String getAlias() throws XMLSecurityException {
return "transmitter";
@@ -64,7 +62,7 @@ public class X509TokenTest extends Abstr
}
@Override
- public PublicKey getPublicKey(XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+ public PublicKey getPublicKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
try {
return keyStore.getCertificate("transmitter").getPublicKey();
} catch (Exception e) {
@@ -94,44 +92,175 @@ public class X509TokenTest extends Abstr
@Test
public void testPolicy() throws Exception {
String policyString =
- "<sp:X509Token xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" " +
- "xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" +
- "<sp:IssuerName>CN=transmitter,OU=swssf,C=CH</sp:IssuerName>\n" +
+ "<sp:AsymmetricBinding xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" +
"<wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
- "<sp:RequireThumbprintReference/>\n" +
- "<sp:WssX509V3Token11/>\n" +
+ "<sp:InitiatorToken>\n" +
+ " <wsp:Policy>\n" +
+ " <sp:X509Token>\n" +
+ " <sp:IssuerName>CN=transmitter,OU=swssf,C=CH</sp:IssuerName>\n" +
+ " <wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
+ " <sp:RequireThumbprintReference/>\n" +
+ " <sp:WssX509V3Token11/>\n" +
+ " </wsp:Policy>\n" +
+ " </sp:X509Token>\n" +
+ " </wsp:Policy>\n" +
+ "</sp:InitiatorToken>\n" +
+ "<sp:RecipientToken>\n" +
+ " <wsp:Policy>\n" +
+ " <sp:X509Token>\n" +
+ " <sp:IssuerName>CN=transmitter,OU=swssf,C=CH</sp:IssuerName>\n" +
+ " <wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
+ " <sp:RequireThumbprintReference/>\n" +
+ " <sp:WssX509V3Token11/>\n" +
+ " </wsp:Policy>\n" +
+ " </sp:X509Token>\n" +
+ " </wsp:Policy>\n" +
+ "</sp:RecipientToken>\n" +
"</wsp:Policy>\n" +
- "</sp:X509Token>";
+ "</sp:AsymmetricBinding>";
+
PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString);
- X509TokenSecurityEvent x509TokenSecurityEvent = new X509TokenSecurityEvent(SecurityEvent.Event.X509Token);
- x509TokenSecurityEvent.setSecurityToken(
- new DelegatingSecurityToken(WSSConstants.KeyIdentifierType.THUMBPRINT_IDENTIFIER,
- getX509Token(WSSConstants.X509V3Token)));
- policyEnforcer.registerSecurityEvent(x509TokenSecurityEvent);
+ X509TokenSecurityEvent initiatorX509TokenSecurityEvent = new X509TokenSecurityEvent();
+ initiatorX509TokenSecurityEvent.setSecurityToken(getX509Token(WSSConstants.X509V3Token));
+ initiatorX509TokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Signature);
+ policyEnforcer.registerSecurityEvent(initiatorX509TokenSecurityEvent);
+
+ X509TokenSecurityEvent recipientX509TokenSecurityEvent = new X509TokenSecurityEvent();
+ recipientX509TokenSecurityEvent.setSecurityToken(getX509Token(WSSConstants.X509V3Token));
+ recipientX509TokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Encryption);
+ policyEnforcer.registerSecurityEvent(recipientX509TokenSecurityEvent);
+
+ SignedPartSecurityEvent signedPartSecurityEvent = new SignedPartSecurityEvent(recipientX509TokenSecurityEvent.getSecurityToken(), true);
+ signedPartSecurityEvent.setElement(WSSConstants.TAG_soap11_Body);
+ policyEnforcer.registerSecurityEvent(signedPartSecurityEvent);
+
+ ContentEncryptedElementSecurityEvent contentEncryptedElementSecurityEvent = new ContentEncryptedElementSecurityEvent(recipientX509TokenSecurityEvent.getSecurityToken(), true, true);
+ contentEncryptedElementSecurityEvent.setElement(WSSConstants.TAG_soap11_Body);
+ policyEnforcer.registerSecurityEvent(contentEncryptedElementSecurityEvent);
+
+ OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent();
+ operationSecurityEvent.setOperation(new QName("definitions"));
+ policyEnforcer.registerSecurityEvent(operationSecurityEvent);
+
policyEnforcer.doFinal();
}
@Test
public void testPolicyNegative() throws Exception {
String policyString =
- "<sp:X509Token xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" " +
- "xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" +
- "<sp:IssuerName>CN=transmitter,OU=swssf,C=CH</sp:IssuerName>\n" +
+ "<sp:AsymmetricBinding xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" +
"<wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
- "<sp:RequireThumbprintReference/>\n" +
- "<sp:WssX509V3Token11/>\n" +
+ "<sp:InitiatorToken>\n" +
+ " <wsp:Policy>\n" +
+ " <sp:X509Token>\n" +
+ " <sp:IssuerName>CN=transmitter,OU=swssf,C=CH</sp:IssuerName>\n" +
+ " <wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
+ " <sp:RequireThumbprintReference/>\n" +
+ " <sp:WssX509V3Token11/>\n" +
+ " </wsp:Policy>\n" +
+ " </sp:X509Token>\n" +
+ " </wsp:Policy>\n" +
+ "</sp:InitiatorToken>\n" +
+ "<sp:RecipientToken>\n" +
+ " <wsp:Policy>\n" +
+ " <sp:X509Token>\n" +
+ " <sp:IssuerName>CN=transmitter,OU=swssf,C=CH</sp:IssuerName>\n" +
+ " <wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
+ " <sp:RequireThumbprintReference/>\n" +
+ " <sp:WssX509V3Token11/>\n" +
+ " </wsp:Policy>\n" +
+ " </sp:X509Token>\n" +
+ " </wsp:Policy>\n" +
+ "</sp:RecipientToken>\n" +
"</wsp:Policy>\n" +
- "</sp:X509Token>";
+ "</sp:AsymmetricBinding>";
+
+ PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString);
+ X509TokenSecurityEvent initiatorX509TokenSecurityEvent = new X509TokenSecurityEvent();
+ initiatorX509TokenSecurityEvent.setSecurityToken(getX509Token(WSSConstants.X509V1Token));
+ initiatorX509TokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Signature);
+ policyEnforcer.registerSecurityEvent(initiatorX509TokenSecurityEvent);
+
+ X509TokenSecurityEvent recipientX509TokenSecurityEvent = new X509TokenSecurityEvent();
+ recipientX509TokenSecurityEvent.setSecurityToken(getX509Token(WSSConstants.X509V3Token));
+ recipientX509TokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Encryption);
+ policyEnforcer.registerSecurityEvent(recipientX509TokenSecurityEvent);
+
+ SignedPartSecurityEvent signedPartSecurityEvent = new SignedPartSecurityEvent(recipientX509TokenSecurityEvent.getSecurityToken(), true);
+ signedPartSecurityEvent.setElement(WSSConstants.TAG_soap11_Body);
+ policyEnforcer.registerSecurityEvent(signedPartSecurityEvent);
+
+ ContentEncryptedElementSecurityEvent contentEncryptedElementSecurityEvent = new ContentEncryptedElementSecurityEvent(recipientX509TokenSecurityEvent.getSecurityToken(), true, true);
+ contentEncryptedElementSecurityEvent.setElement(WSSConstants.TAG_soap11_Body);
+ policyEnforcer.registerSecurityEvent(contentEncryptedElementSecurityEvent);
+
+ OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent();
+ operationSecurityEvent.setOperation(new QName("definitions"));
+
+ try {
+ policyEnforcer.registerSecurityEvent(operationSecurityEvent);
+ Assert.fail("Exception expected");
+ } catch (WSSecurityException e) {
+ Assert.assertEquals(e.getMessage(), "An error was discovered processing the <wsse:Security> header; nested exception is: \n" +
+ "\torg.swssf.policy.PolicyViolationException: No policy alternative could be satisfied");
+ }
+ }
+
+ @Test
+ public void testSupportingTokenPolicy() throws Exception {
+ String policyString =
+ "<sp:SupportingTokens xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" +
+ "<wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
+ " <sp:X509Token>\n" +
+ " <sp:IssuerName>CN=transmitter,OU=swssf,C=CH</sp:IssuerName>\n" +
+ " <wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
+ " <sp:RequireThumbprintReference/>\n" +
+ " <sp:WssX509V3Token11/>\n" +
+ " </wsp:Policy>\n" +
+ " </sp:X509Token>\n" +
+ " </wsp:Policy>\n" +
+ "</sp:SupportingTokens>";
+
PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString);
- X509TokenSecurityEvent x509TokenSecurityEvent = new X509TokenSecurityEvent(SecurityEvent.Event.X509Token);
- x509TokenSecurityEvent.setSecurityToken(
- new DelegatingSecurityToken(WSSConstants.KeyIdentifierType.THUMBPRINT_IDENTIFIER,
- getX509Token(WSSConstants.X509V1Token)));
+ X509TokenSecurityEvent x509TokenSecurityEvent = new X509TokenSecurityEvent();
+ x509TokenSecurityEvent.setSecurityToken(getX509Token(WSSConstants.X509V3Token));
+ policyEnforcer.registerSecurityEvent(x509TokenSecurityEvent);
+
+ OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent();
+ operationSecurityEvent.setOperation(new QName("definitions"));
+ policyEnforcer.registerSecurityEvent(operationSecurityEvent);
+
+ policyEnforcer.doFinal();
+ }
+
+ @Test
+ public void testSupportingTokenPolicyNegative() throws Exception {
+ String policyString =
+ "<sp:SupportingTokens xmlns:sp=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702\" xmlns:sp3=\"http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200802\">\n" +
+ "<wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
+ " <sp:X509Token>\n" +
+ " <sp:IssuerName>CN=transmitter,OU=swssf,C=CH</sp:IssuerName>\n" +
+ " <wsp:Policy xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">\n" +
+ " <sp:RequireThumbprintReference/>\n" +
+ " <sp:WssX509V3Token11/>\n" +
+ " </wsp:Policy>\n" +
+ " </sp:X509Token>\n" +
+ " </wsp:Policy>\n" +
+ "</sp:SupportingTokens>";
+
+ PolicyEnforcer policyEnforcer = buildAndStartPolicyEngine(policyString);
+ X509TokenSecurityEvent x509TokenSecurityEvent = new X509TokenSecurityEvent();
+ x509TokenSecurityEvent.setSecurityToken(getX509Token(WSSConstants.X509V1Token));
+ policyEnforcer.registerSecurityEvent(x509TokenSecurityEvent);
+
+ OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent();
+ operationSecurityEvent.setOperation(new QName("definitions"));
try {
- policyEnforcer.registerSecurityEvent(x509TokenSecurityEvent);
+ policyEnforcer.registerSecurityEvent(operationSecurityEvent);
Assert.fail("Exception expected");
} catch (WSSecurityException e) {
- Assert.assertTrue(e.getCause() instanceof PolicyViolationException);
+ Assert.assertEquals(e.getMessage(), "An error was discovered processing the <wsse:Security> header; nested exception is: \n" +
+ "\torg.swssf.policy.PolicyViolationException: No policy alternative could be satisfied");
}
}
}
Propchange: webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/java/org/swssf/policy/test/X509TokenTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/resources/testdata/wsdl/actionSpoofing.wsdl
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/resources/testdata/wsdl/actionSpoofing.wsdl?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/resources/testdata/wsdl/actionSpoofing.wsdl (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-policy/src/test/resources/testdata/wsdl/actionSpoofing.wsdl Sun Jan 8 11:44:13 2012
@@ -34,9 +34,9 @@
<sp:SignedParts>
<sp:Body/>
</sp:SignedParts>
- <sp:EncryptedParts>
- <spBody/>
- </sp:EncryptedParts>
+ <!--<sp:EncryptedParts>
+ <sp:Body/>
+ </sp:EncryptedParts>-->
</wsp12:All>
</wsp12:ExactlyOne>
</wsp12:Policy>
Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSConstants.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSConstants.java?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSConstants.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSConstants.java Sun Jan 8 11:44:13 2012
@@ -212,6 +212,7 @@ public class WSSConstants extends XMLSec
}
}
+ //todo rename KeyUsage because C14N, etc are not keys...
public static final KeyUsage Sym_Sig = new KeyUsage(XMLSecurityConstants.Sym_Sig.toString());
public static final KeyUsage Asym_Sig = new KeyUsage(XMLSecurityConstants.Asym_Sig.toString());
public static final KeyUsage Enc = new KeyUsage(XMLSecurityConstants.Enc.toString());
@@ -249,6 +250,7 @@ public class WSSConstants extends XMLSec
public static final TokenType SpnegoContextToken = new TokenType("SpnegoContextToken");
public static final TokenType RelToken = new TokenType("RelToken");
public static final TokenType KeyValueToken = new TokenType("KeyValueToken");
+ public static final TokenType DerivedKeyToken = new TokenType("DerivedKeyToken");
public static class TokenType extends XMLSecurityConstants.TokenType {
protected TokenType(String name) {
Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSUtils.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSUtils.java?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSUtils.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSUtils.java Sun Jan 8 11:44:13 2012
@@ -338,9 +338,6 @@ public class WSSUtils extends XMLSecurit
}
public static TokenSecurityEvent createTokenSecurityEvent(SecurityToken securityToken) throws WSSecurityException {
- while (securityToken.getKeyWrappingToken() != null) {
- securityToken = securityToken.getKeyWrappingToken();
- }
WSSConstants.TokenType tokenType = (WSSConstants.TokenType) securityToken.getTokenType();
TokenSecurityEvent tokenSecurityEvent;
@@ -348,30 +345,33 @@ public class WSSUtils extends XMLSecurit
|| tokenType == WSSConstants.X509V3Token
|| tokenType == WSSConstants.X509Pkcs7Token
|| tokenType == WSSConstants.X509PkiPathV1Token) {
- //todo parameter to *TokenSecurityEvent can most probably be eliminated
- tokenSecurityEvent = new X509TokenSecurityEvent(SecurityEvent.Event.X509Token);
+ tokenSecurityEvent = new X509TokenSecurityEvent();
} else if (tokenType == WSSConstants.UsernameToken) {
- tokenSecurityEvent = new UsernameTokenSecurityEvent(SecurityEvent.Event.UsernameToken);
+ tokenSecurityEvent = new UsernameTokenSecurityEvent();
} else if (tokenType == WSSConstants.IssuedToken) {
- tokenSecurityEvent = new IssuedTokenSecurityEvent(SecurityEvent.Event.IssuedToken);
+ tokenSecurityEvent = new IssuedTokenSecurityEvent();
} else if (tokenType == WSSConstants.KerberosToken) {
- tokenSecurityEvent = new KerberosTokenSecurityEvent(SecurityEvent.Event.KerberosToken);
+ tokenSecurityEvent = new KerberosTokenSecurityEvent();
} else if (tokenType == WSSConstants.SpnegoContextToken) {
- tokenSecurityEvent = new SpnegoContextTokenSecurityEvent(SecurityEvent.Event.SpnegoContextToken);
+ tokenSecurityEvent = new SpnegoContextTokenSecurityEvent();
} else if (tokenType == WSSConstants.SecurityContextToken) {
- tokenSecurityEvent = new SecurityContextTokenSecurityEvent(SecurityEvent.Event.SecurityContextToken);
+ tokenSecurityEvent = new SecurityContextTokenSecurityEvent();
} else if (tokenType == WSSConstants.SecureConversationToken) {
- tokenSecurityEvent = new SecureConversationTokenSecurityEvent(SecurityEvent.Event.SecureConversationToken);
+ tokenSecurityEvent = new SecureConversationTokenSecurityEvent();
} else if (tokenType == WSSConstants.Saml10Token
|| tokenType == WSSConstants.Saml11Token
|| tokenType == WSSConstants.Saml20Token) {
- tokenSecurityEvent = new SamlTokenSecurityEvent(SecurityEvent.Event.SamlToken);
+ tokenSecurityEvent = new SamlTokenSecurityEvent();
} else if (tokenType == WSSConstants.RelToken) {
- tokenSecurityEvent = new RelTokenSecurityEvent(SecurityEvent.Event.RelToken);
+ tokenSecurityEvent = new RelTokenSecurityEvent();
} else if (tokenType == WSSConstants.HttpsToken) {
- tokenSecurityEvent = new HttpsTokenSecurityEvent(SecurityEvent.Event.HttpsToken);
+ tokenSecurityEvent = new HttpsTokenSecurityEvent();
} else if (tokenType == WSSConstants.KeyValueToken) {
- tokenSecurityEvent = new KeyValueTokenSecurityEvent(SecurityEvent.Event.KeyValueToken);
+ tokenSecurityEvent = new DerivedKeyTokenSecurityEvent();
+ } else if (tokenType == WSSConstants.DerivedKeyToken) {
+ tokenSecurityEvent = new DerivedKeyTokenSecurityEvent();
+ } else if (tokenType == WSSConstants.EncryptedKeyToken) {
+ tokenSecurityEvent = new EncryptedKeyTokenSecurityEvent();
} else {
throw new WSSecurityException(WSSecurityException.ErrorCode.UNSUPPORTED_SECURITY_TOKEN);
}
Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/WSSDocumentContextImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/WSSDocumentContextImpl.java?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/WSSDocumentContextImpl.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/WSSDocumentContextImpl.java Sun Jan 8 11:44:13 2012
@@ -73,8 +73,7 @@ public class WSSDocumentContextImpl exte
documentContext.setEncoding(this.getEncoding());
documentContext.setPath(subPath);
documentContext.setInSecurityHeader(isInSecurityHeader());
- documentContext.setActualEncryptedContentCounter(this.getActualEncryptedContentCounter());
- documentContext.setActualSignedContentCounter(this.getActualSignedContentCounter());
+ documentContext.setContentTypeDeque(getContentTypeDeque());
return documentContext;
}
}
Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/WSSecurityContextImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/WSSecurityContextImpl.java?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/WSSecurityContextImpl.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/WSSecurityContextImpl.java Sun Jan 8 11:44:13 2012
@@ -40,8 +40,9 @@ public class WSSecurityContextImpl exten
}
public synchronized void registerSecurityEvent(SecurityEvent securityEvent) throws WSSecurityException {
- if (securityEventListener != null) {
- securityEventListener.registerSecurityEvent(securityEvent);
+ if (securityEventListener == null) {
+ return;
}
+ securityEventListener.registerSecurityEvent(securityEvent);
}
}
Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/BinarySecurityTokenInputHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/BinarySecurityTokenInputHandler.java?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/BinarySecurityTokenInputHandler.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/BinarySecurityTokenInputHandler.java Sun Jan 8 11:44:13 2012
@@ -19,7 +19,6 @@
package org.swssf.wss.impl.processor.input;
import org.swssf.binding.wss10.BinarySecurityTokenType;
-import org.swssf.wss.ext.WSSSecurityProperties;
import org.swssf.wss.impl.securityToken.SecurityTokenFactoryImpl;
import org.swssf.xmlsec.crypto.Crypto;
import org.swssf.xmlsec.ext.*;
@@ -39,11 +38,12 @@ import java.util.UUID;
*/
public class BinarySecurityTokenInputHandler extends AbstractInputSecurityHeaderHandler {
- public BinarySecurityTokenInputHandler(final InputProcessorChain inputProcessorChain,
- final WSSSecurityProperties securityProperties,
- Deque<XMLEvent> eventQueue, Integer index) throws XMLSecurityException {
+ @Override
+ public void handle(final InputProcessorChain inputProcessorChain, final XMLSecurityProperties securityProperties,
+ Deque<XMLEvent> eventQueue, Integer index) throws XMLSecurityException {
- final BinarySecurityTokenType binarySecurityTokenType = ((JAXBElement<BinarySecurityTokenType>) parseStructure(eventQueue, index)).getValue();
+ final BinarySecurityTokenType binarySecurityTokenType =
+ ((JAXBElement<BinarySecurityTokenType>) parseStructure(eventQueue, index)).getValue();
if (binarySecurityTokenType.getId() == null) {
binarySecurityTokenType.setId(UUID.randomUUID().toString());
@@ -58,7 +58,12 @@ public class BinarySecurityTokenInputHan
if (securityToken != null) {
return securityToken;
}
- securityToken = SecurityTokenFactoryImpl.getSecurityToken(binarySecurityTokenType, inputProcessorChain.getSecurityContext(), crypto, securityProperties.getCallbackHandler(), null);
+ securityToken = SecurityTokenFactoryImpl.getSecurityToken(
+ binarySecurityTokenType,
+ inputProcessorChain.getSecurityContext(),
+ crypto,
+ securityProperties.getCallbackHandler(),
+ null);
securityTokens.put(crypto, securityToken);
return securityToken;
}
@@ -69,6 +74,5 @@ public class BinarySecurityTokenInputHan
};
inputProcessorChain.getSecurityContext().registerSecurityTokenProvider(binarySecurityTokenType.getId(), securityTokenProvider);
-
}
}
Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/DecryptInputProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/DecryptInputProcessor.java?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/DecryptInputProcessor.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/DecryptInputProcessor.java Sun Jan 8 11:44:13 2012
@@ -23,11 +23,12 @@ import org.swssf.binding.xmlenc.Encrypte
import org.swssf.binding.xmlenc.ReferenceList;
import org.swssf.wss.ext.WSSDocumentContext;
import org.swssf.wss.ext.WSSSecurityProperties;
+import org.swssf.wss.ext.WSSUtils;
import org.swssf.wss.ext.WSSecurityContext;
import org.swssf.wss.securityEvent.ContentEncryptedElementSecurityEvent;
import org.swssf.wss.securityEvent.EncryptedElementSecurityEvent;
import org.swssf.wss.securityEvent.EncryptedPartSecurityEvent;
-import org.swssf.wss.securityEvent.SecurityEvent;
+import org.swssf.wss.securityEvent.TokenSecurityEvent;
import org.swssf.xmlsec.ext.*;
import org.swssf.xmlsec.impl.processor.input.AbstractDecryptInputProcessor;
@@ -52,18 +53,20 @@ public class DecryptInputProcessor exten
super(keyInfoType, referenceList, securityProperties);
}
- protected void encryptedContentEvent(InputProcessorChain inputProcessorChain, XMLEvent xmlEvent) throws XMLSecurityException {
+ protected void handleEncryptedContent(
+ InputProcessorChain inputProcessorChain, XMLEvent xmlEvent, SecurityToken securityToken) throws XMLSecurityException {
+
QName parentElement = inputProcessorChain.getDocumentContext().getParentElement(xmlEvent.getEventType());
if (inputProcessorChain.getDocumentContext().getDocumentLevel() == 3
&& ((WSSDocumentContext) inputProcessorChain.getDocumentContext()).isInSOAPBody()) {
//soap:body content encryption counts as EncryptedPart
EncryptedPartSecurityEvent encryptedPartSecurityEvent =
- new EncryptedPartSecurityEvent(SecurityEvent.Event.EncryptedPart, true);
+ new EncryptedPartSecurityEvent(securityToken, true, isInSignedContent(inputProcessorChain));
encryptedPartSecurityEvent.setElement(parentElement);
((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(encryptedPartSecurityEvent);
} else {
ContentEncryptedElementSecurityEvent contentEncryptedElementSecurityEvent =
- new ContentEncryptedElementSecurityEvent(SecurityEvent.Event.ContentEncrypted, true);
+ new ContentEncryptedElementSecurityEvent(securityToken, true, isInSignedContent(inputProcessorChain));
contentEncryptedElementSecurityEvent.setElement(parentElement);
((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(contentEncryptedElementSecurityEvent);
}
@@ -72,11 +75,29 @@ public class DecryptInputProcessor exten
@Override
protected AbstractDecryptedEventReaderInputProcessor newDecryptedEventReaderInputProccessor(
boolean encryptedHeader, List<ComparableNamespace>[] comparableNamespaceList,
- List<ComparableAttribute>[] comparableAttributeList, EncryptedDataType currentEncryptedDataType) {
+ List<ComparableAttribute>[] comparableAttributeList, EncryptedDataType currentEncryptedDataType, SecurityToken securityToken) {
return new DecryptedEventReaderInputProcessor(getSecurityProperties(),
SecurePart.Modifier.getModifier(currentEncryptedDataType.getType()),
encryptedHeader, comparableNamespaceList, comparableAttributeList,
- this);
+ this,
+ securityToken);
+ }
+
+ @Override
+ protected void handleSecurityToken(
+ SecurityToken securityToken, SecurityContext securityContext, EncryptedDataType encryptedDataType) throws XMLSecurityException {
+ TokenSecurityEvent tokenSecurityEvent = WSSUtils.createTokenSecurityEvent(securityToken);
+ tokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Encryption);
+ ((WSSecurityContext) securityContext).registerSecurityEvent(tokenSecurityEvent);
+
+ /*AlgorithmSuiteSecurityEvent algorithmSuiteSecurityEvent = new AlgorithmSuiteSecurityEvent();
+ algorithmSuiteSecurityEvent.setAlgorithmURI(encryptedDataType.getEncryptionMethod().getAlgorithm());
+ if (securityToken.isAsymmetric()) {
+ algorithmSuiteSecurityEvent.setKeyUsage(WSSConstants.Asym_Key_Wrap);
+ } else {
+ algorithmSuiteSecurityEvent.setKeyUsage(WSSConstants.Sym_Key_Wrap);
+ }
+ ((WSSecurityContext) securityContext).registerSecurityEvent(algorithmSuiteSecurityEvent);*/
}
/*
@@ -105,25 +126,33 @@ public class DecryptInputProcessor exten
XMLSecurityProperties securityProperties, SecurePart.Modifier encryptionModifier,
boolean encryptedHeader, List<ComparableNamespace>[] namespaceList,
List<ComparableAttribute>[] attributeList,
- DecryptInputProcessor decryptInputProcessor
+ DecryptInputProcessor decryptInputProcessor,
+ SecurityToken securityToken
) {
- super(securityProperties, encryptionModifier, encryptedHeader, namespaceList, attributeList, decryptInputProcessor);
+ super(securityProperties, encryptionModifier, encryptedHeader, namespaceList, attributeList, decryptInputProcessor, securityToken);
}
- protected void encryptedElementEvent(InputProcessorChain inputProcessorChain, XMLEvent xmlEvent) throws XMLSecurityException {
+ protected void handleEncryptedElement(InputProcessorChain inputProcessorChain, XMLEvent xmlEvent, SecurityToken securityToken) throws XMLSecurityException {
//fire a SecurityEvent:
if (inputProcessorChain.getDocumentContext().getDocumentLevel() == 3
&& ((WSSDocumentContext) inputProcessorChain.getDocumentContext()).isInSOAPHeader()) {
EncryptedPartSecurityEvent encryptedPartSecurityEvent =
- new EncryptedPartSecurityEvent(SecurityEvent.Event.EncryptedPart, true);
+ new EncryptedPartSecurityEvent(securityToken, true, isInSignedContent(inputProcessorChain));
encryptedPartSecurityEvent.setElement(xmlEvent.asStartElement().getName());
((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(encryptedPartSecurityEvent);
} else {
EncryptedElementSecurityEvent encryptedElementSecurityEvent =
- new EncryptedElementSecurityEvent(SecurityEvent.Event.EncryptedElement, true);
+ new EncryptedElementSecurityEvent(securityToken, true, isInSignedContent(inputProcessorChain));
encryptedElementSecurityEvent.setElement(xmlEvent.asStartElement().getName());
((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(encryptedElementSecurityEvent);
}
}
}
+
+ public static boolean isInSignedContent(InputProcessorChain inputProcessorChain) {
+ //todo. Also todo: ProtectionOrderAssertionState
+ //how can we find out if a signature is done over plaintext or over ciphertext.
+ //problem contentEncryptedElements, the signature occurs always firstly...
+ return false;
+ }
}
Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/DerivedKeyTokenInputHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/DerivedKeyTokenInputHandler.java?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/DerivedKeyTokenInputHandler.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/DerivedKeyTokenInputHandler.java Sun Jan 8 11:44:13 2012
@@ -20,10 +20,10 @@ package org.swssf.wss.impl.processor.inp
import org.swssf.binding.wssc.AbstractDerivedKeyTokenType;
import org.swssf.wss.ext.WSSConstants;
-import org.swssf.wss.ext.WSSSecurityProperties;
+import org.swssf.wss.ext.WSSecurityContext;
import org.swssf.wss.ext.WSSecurityException;
import org.swssf.wss.impl.derivedKey.DerivedKeyUtils;
-import org.swssf.wss.impl.securityToken.AbstractAlgorithmSuiteSecurityEventFiringSecurityToken;
+import org.swssf.wss.impl.securityToken.AbstractSecurityToken;
import org.swssf.wss.impl.securityToken.SAMLSecurityToken;
import org.swssf.wss.impl.securityToken.SecurityTokenFactoryImpl;
import org.swssf.wss.impl.securityToken.UsernameSecurityToken;
@@ -35,6 +35,7 @@ import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.JAXBElement;
import javax.xml.stream.events.XMLEvent;
import java.security.Key;
+import java.security.PublicKey;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
@@ -48,12 +49,13 @@ import java.util.UUID;
*/
public class DerivedKeyTokenInputHandler extends AbstractInputSecurityHeaderHandler {
- public DerivedKeyTokenInputHandler(final InputProcessorChain inputProcessorChain,
- final WSSSecurityProperties securityProperties,
- Deque<XMLEvent> eventQueue, Integer index) throws XMLSecurityException {
+ @Override
+ public void handle(final InputProcessorChain inputProcessorChain, final XMLSecurityProperties securityProperties,
+ Deque<XMLEvent> eventQueue, Integer index) throws XMLSecurityException {
@SuppressWarnings("unchecked")
- final AbstractDerivedKeyTokenType derivedKeyTokenType = ((JAXBElement<AbstractDerivedKeyTokenType>) parseStructure(eventQueue, index)).getValue();
+ final AbstractDerivedKeyTokenType derivedKeyTokenType =
+ ((JAXBElement<AbstractDerivedKeyTokenType>) parseStructure(eventQueue, index)).getValue();
if (derivedKeyTokenType.getId() == null) {
derivedKeyTokenType.setId(UUID.randomUUID().toString());
}
@@ -80,14 +82,15 @@ public class DerivedKeyTokenInputHandler
null
);
- securityToken = new AbstractAlgorithmSuiteSecurityEventFiringSecurityToken(inputProcessorChain.getSecurityContext(), derivedKeyTokenType.getId()) {
+ securityToken = new AbstractSecurityToken(
+ (WSSecurityContext) inputProcessorChain.getSecurityContext(), null, null,
+ derivedKeyTokenType.getId(), null, null) {
public boolean isAsymmetric() {
return false;
}
- public Key getSecretKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
- super.getSecretKey(algorithmURI, keyUsage);
+ protected Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
byte[] secret;
if (referencedSecurityToken != null) {
if (referencedSecurityToken instanceof UsernameSecurityToken) {
@@ -102,7 +105,13 @@ public class DerivedKeyTokenInputHandler
secret = samlSecurityToken.getSamlKeyInfo().getSecret();
} else {
//todo is this the correct algo and KeyUsage?
- secret = referencedSecurityToken.getSecretKey(algorithmURI, WSSConstants.Sig_KD).getEncoded();
+ WSSConstants.KeyUsage newKeyUsage;
+ if (keyUsage == WSSConstants.Sym_Sig || keyUsage == WSSConstants.Asym_Sig || keyUsage == WSSConstants.Sig_KD) {
+ newKeyUsage = WSSConstants.Sig_KD;
+ } else {
+ newKeyUsage = WSSConstants.Enc_KD;
+ }
+ secret = referencedSecurityToken.getSecretKey(algorithmURI, keyUsage).getEncoded();
}
} else {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_CHECK, "unsupportedKeyId");
@@ -123,6 +132,11 @@ public class DerivedKeyTokenInputHandler
return new SecretKeySpec(keyBytes, algo);
}
+ @Override
+ protected PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+ return null;
+ }
+
public SecurityToken getKeyWrappingToken() {
return referencedSecurityToken;
}
@@ -133,8 +147,7 @@ public class DerivedKeyTokenInputHandler
}
public WSSConstants.TokenType getTokenType() {
- //todo?
- return null;
+ return WSSConstants.DerivedKeyToken;
}
};
securityTokens.put(crypto, securityToken);
Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/EncryptedKeyInputHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/EncryptedKeyInputHandler.java?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/EncryptedKeyInputHandler.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/EncryptedKeyInputHandler.java Sun Jan 8 11:44:13 2012
@@ -24,7 +24,7 @@ import org.swssf.binding.wss10.SecurityT
import org.swssf.binding.xmldsig.KeyInfoType;
import org.swssf.binding.xmlenc.EncryptedKeyType;
import org.swssf.wss.ext.*;
-import org.swssf.wss.impl.securityToken.AbstractAlgorithmSuiteSecurityEventFiringSecurityToken;
+import org.swssf.wss.impl.securityToken.AbstractSecurityToken;
import org.swssf.wss.impl.securityToken.SecurityTokenFactoryImpl;
import org.swssf.wss.securityEvent.TokenSecurityEvent;
import org.swssf.xmlsec.config.JCEAlgorithmMapper;
@@ -39,10 +39,7 @@ import javax.crypto.NoSuchPaddingExcepti
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.JAXBElement;
import javax.xml.stream.events.XMLEvent;
-import java.security.InvalidKeyException;
-import java.security.Key;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
+import java.security.*;
import java.util.*;
/**
@@ -53,9 +50,9 @@ import java.util.*;
*/
public class EncryptedKeyInputHandler extends AbstractInputSecurityHeaderHandler {
- public EncryptedKeyInputHandler(final InputProcessorChain inputProcessorChain,
- final WSSSecurityProperties securityProperties,
- Deque<XMLEvent> eventQueue, Integer index) throws XMLSecurityException {
+ @Override
+ public void handle(final InputProcessorChain inputProcessorChain, final XMLSecurityProperties securityProperties,
+ Deque<XMLEvent> eventQueue, Integer index) throws XMLSecurityException {
@SuppressWarnings("unchecked")
final EncryptedKeyType encryptedKeyType = ((JAXBElement<EncryptedKeyType>) parseStructure(eventQueue, index)).getValue();
@@ -94,7 +91,15 @@ public class EncryptedKeyInputHandler ex
inputProcessorChain.getSecurityContext(),
this
);
- cipher.init(Cipher.DECRYPT_MODE, wrappingSecurityToken.getSecretKey(algorithmURI, wrappingSecurityToken.isAsymmetric() ? WSSConstants.Asym_Key_Wrap : WSSConstants.Sym_Key_Wrap));
+ WSSConstants.KeyUsage keyUsage;
+ if (wrappingSecurityToken.isAsymmetric()) {
+ keyUsage = WSSConstants.Asym_Key_Wrap;
+ } else {
+ keyUsage = WSSConstants.Sym_Key_Wrap;
+ }
+ cipher.init(Cipher.DECRYPT_MODE,
+ wrappingSecurityToken.getSecretKey(algorithmURI, keyUsage)
+ );
secretToken = cipher.doFinal(encryptedKeyType.getCipherData().getCipherValue());
@@ -120,7 +125,9 @@ public class EncryptedKeyInputHandler ex
final String algorithm = algorithmURI;
- securityToken = new AbstractAlgorithmSuiteSecurityEventFiringSecurityToken(inputProcessorChain.getSecurityContext(), encryptedKeyType.getId()) {
+ securityToken = new AbstractSecurityToken(
+ (WSSecurityContext) inputProcessorChain.getSecurityContext(), null, null,
+ encryptedKeyType.getId(), null, null) {
private Map<String, Key> keyTable = new Hashtable<String, Key>();
@@ -128,8 +135,7 @@ public class EncryptedKeyInputHandler ex
return false;
}
- public Key getSecretKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
- super.getSecretKey(algorithmURI, keyUsage);
+ public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
if (keyTable.containsKey(algorithmURI)) {
return keyTable.get(algorithmURI);
} else {
@@ -140,6 +146,11 @@ public class EncryptedKeyInputHandler ex
}
}
+ @Override
+ public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+ return null;
+ }
+
public SecurityToken getKeyWrappingToken() {
return wrappingSecurityToken;
}
@@ -162,11 +173,8 @@ public class EncryptedKeyInputHandler ex
};
final SecurityToken securityToken = securityTokenProvider.getSecurityToken(securityProperties.getDecryptionCrypto());
-
- //fire a RecipientSecurityTokenEvent
+ //fire a securityTokenEvent
TokenSecurityEvent tokenSecurityEvent = WSSUtils.createTokenSecurityEvent(securityToken);
- //todo: is this always the main encryption?
- tokenSecurityEvent.setTokenUsage(TokenSecurityEvent.TokenUsage.Encryption);
((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(tokenSecurityEvent);
//register the key token for decryption:
@@ -182,7 +190,9 @@ public class EncryptedKeyInputHandler ex
ObjectFactory objectFactory = new ObjectFactory();
securityTokenReferenceType.getAny().add(objectFactory.createReference(referenceType));
keyInfoType.getContent().add(objectFactory.createSecurityTokenReference(securityTokenReferenceType));
- inputProcessorChain.addProcessor(new org.swssf.wss.impl.processor.input.DecryptInputProcessor(keyInfoType, encryptedKeyType.getReferenceList(), securityProperties));
+ inputProcessorChain.addProcessor(
+ new DecryptInputProcessor(keyInfoType, encryptedKeyType.getReferenceList(), (WSSSecurityProperties) securityProperties)
+ );
}
}
Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/ReferenceListInputHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/ReferenceListInputHandler.java?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/ReferenceListInputHandler.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/ReferenceListInputHandler.java Sun Jan 8 11:44:13 2012
@@ -23,6 +23,7 @@ import org.swssf.wss.ext.WSSSecurityProp
import org.swssf.xmlsec.ext.AbstractInputSecurityHeaderHandler;
import org.swssf.xmlsec.ext.InputProcessorChain;
import org.swssf.xmlsec.ext.XMLSecurityException;
+import org.swssf.xmlsec.ext.XMLSecurityProperties;
import javax.xml.stream.events.XMLEvent;
import java.util.Deque;
@@ -35,13 +36,13 @@ import java.util.Deque;
*/
public class ReferenceListInputHandler extends AbstractInputSecurityHeaderHandler {
- public ReferenceListInputHandler(InputProcessorChain inputProcessorChain,
- final WSSSecurityProperties securityProperties,
- Deque<XMLEvent> eventQueue, Integer index) throws XMLSecurityException {
+ @Override
+ public void handle(final InputProcessorChain inputProcessorChain, final XMLSecurityProperties securityProperties,
+ Deque<XMLEvent> eventQueue, Integer index) throws XMLSecurityException {
final ReferenceList referenceList = (ReferenceList) parseStructure(eventQueue, index);
//instantiate a new DecryptInputProcessor and add it to the chain
- inputProcessorChain.addProcessor(new org.swssf.wss.impl.processor.input.DecryptInputProcessor(referenceList, securityProperties));
+ inputProcessorChain.addProcessor(new DecryptInputProcessor(referenceList, (WSSSecurityProperties) securityProperties));
}
}
Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/SAMLTokenInputHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/SAMLTokenInputHandler.java?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/SAMLTokenInputHandler.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/SAMLTokenInputHandler.java Sun Jan 8 11:44:13 2012
@@ -24,9 +24,7 @@ import org.swssf.wss.ext.WSSecurityConte
import org.swssf.wss.ext.WSSecurityException;
import org.swssf.wss.impl.saml.SAMLAssertionWrapper;
import org.swssf.wss.impl.saml.SAMLKeyInfo;
-import org.swssf.wss.impl.securityToken.SecurityTokenFactoryImpl;
-import org.swssf.wss.securityEvent.SamlTokenSecurityEvent;
-import org.swssf.wss.securityEvent.SecurityEvent;
+import org.swssf.wss.impl.securityToken.SAMLSecurityToken;
import org.swssf.xmlsec.crypto.Crypto;
import org.swssf.xmlsec.ext.*;
import org.w3c.dom.Attr;
@@ -56,19 +54,21 @@ public class SAMLTokenInputHandler exten
documentBuilderFactory.setNamespaceAware(true);
}
- public SAMLTokenInputHandler(final InputProcessorChain inputProcessorChain, final WSSSecurityProperties securityProperties, Deque<XMLEvent> eventQueue, Integer index) throws XMLSecurityException {
+ @Override
+ public void handle(final InputProcessorChain inputProcessorChain, final XMLSecurityProperties securityProperties,
+ Deque<XMLEvent> eventQueue, Integer index) throws XMLSecurityException {
final Document samlTokenDocument = (Document) parseStructure(eventQueue, index);
final SAMLAssertionWrapper samlAssertionWrapper = new SAMLAssertionWrapper(samlTokenDocument.getDocumentElement());
if (samlAssertionWrapper.isSigned()) {
- SAMLKeyInfo samlIssuerKeyInfo = samlAssertionWrapper.verifySignature(securityProperties);
+ SAMLKeyInfo samlIssuerKeyInfo = samlAssertionWrapper.verifySignature((WSSSecurityProperties) securityProperties);
// Verify trust on the signature
- samlAssertionWrapper.verifySignedAssertion(samlIssuerKeyInfo, securityProperties);
+ samlAssertionWrapper.verifySignedAssertion(samlIssuerKeyInfo, (WSSSecurityProperties) securityProperties);
}
// Parse the HOK subject if it exists
- final SAMLKeyInfo samlSubjectKeyInfo = samlAssertionWrapper.parseHOKSubject(securityProperties);
+ final SAMLKeyInfo samlSubjectKeyInfo = samlAssertionWrapper.parseHOKSubject((WSSSecurityProperties) securityProperties);
if (logger.isDebugEnabled()) {
logger.debug("SAML Assertion issuer " + samlAssertionWrapper.getIssuerString());
@@ -84,10 +84,11 @@ public class SAMLTokenInputHandler exten
return securityToken;
}
- securityToken = SecurityTokenFactoryImpl.getSecurityToken(
- samlAssertionWrapper.getSAMLVersion(), samlSubjectKeyInfo,
- inputProcessorChain.getSecurityContext(), crypto,
+ securityToken = new SAMLSecurityToken(samlAssertionWrapper.getSAMLVersion(), samlSubjectKeyInfo,
+ samlAssertionWrapper.getIssuerString(),
+ (WSSecurityContext) inputProcessorChain.getSecurityContext(), crypto,
securityProperties.getCallbackHandler(), samlAssertionWrapper.getId(), null);
+
securityTokens.put(crypto, securityToken);
return securityToken;
}
@@ -98,11 +99,13 @@ public class SAMLTokenInputHandler exten
};
inputProcessorChain.getSecurityContext().registerSecurityTokenProvider(samlAssertionWrapper.getId(), securityTokenProvider);
- SamlTokenSecurityEvent samlTokenSecurityEvent = new SamlTokenSecurityEvent(SecurityEvent.Event.SamlToken);
+/*
+ SamlTokenSecurityEvent samlTokenSecurityEvent = new SamlTokenSecurityEvent();
samlTokenSecurityEvent.setIssuerName(samlAssertionWrapper.getIssuerString());
samlTokenSecurityEvent.setSamlVersion(samlAssertionWrapper.getSAMLVersion());
samlTokenSecurityEvent.setSecurityToken(securityTokenProvider.getSecurityToken(null));
((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(samlTokenSecurityEvent);
+*/
}
@Override
@@ -157,7 +160,10 @@ public class SAMLTokenInputHandler exten
}
break;
case XMLEvent.PROCESSING_INSTRUCTION:
- Node piNode = document.createProcessingInstruction(((ProcessingInstruction) xmlEvent).getTarget(), ((ProcessingInstruction) xmlEvent).getTarget());
+ Node piNode = document.createProcessingInstruction(
+ ((ProcessingInstruction) xmlEvent).getTarget(),
+ ((ProcessingInstruction) xmlEvent).getTarget()
+ );
currentNode.appendChild(piNode);
break;
case XMLEvent.CHARACTERS:
@@ -173,7 +179,9 @@ public class SAMLTokenInputHandler exten
case XMLEvent.END_DOCUMENT:
return currentNode;
case XMLEvent.ATTRIBUTE:
- Attr attributeNode = document.createAttributeNS(((Attribute) xmlEvent).getName().getNamespaceURI(), ((Attribute) xmlEvent).getName().getLocalPart());
+ Attr attributeNode = document.createAttributeNS(
+ ((Attribute) xmlEvent).getName().getNamespaceURI(), ((Attribute) xmlEvent).getName().getLocalPart()
+ );
attributeNode.setPrefix(((Attribute) xmlEvent).getName().getPrefix());
attributeNode.setValue(((Attribute) xmlEvent).getValue());
((Element) currentNode).setAttributeNodeNS(attributeNode);
Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/SecurityContextTokenInputHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/SecurityContextTokenInputHandler.java?rev=1228829&r1=1228828&r2=1228829&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/SecurityContextTokenInputHandler.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/SecurityContextTokenInputHandler.java Sun Jan 8 11:44:13 2012
@@ -20,9 +20,7 @@ package org.swssf.wss.impl.processor.inp
import org.swssf.binding.wssc.AbstractSecurityContextTokenType;
import org.swssf.wss.ext.*;
-import org.swssf.wss.impl.securityToken.AbstractAlgorithmSuiteSecurityEventFiringSecurityToken;
-import org.swssf.wss.securityEvent.SecurityContextTokenSecurityEvent;
-import org.swssf.wss.securityEvent.SecurityEvent;
+import org.swssf.wss.impl.securityToken.AbstractSecurityToken;
import org.swssf.xmlsec.config.JCEAlgorithmMapper;
import org.swssf.xmlsec.crypto.Crypto;
import org.swssf.xmlsec.ext.*;
@@ -32,6 +30,7 @@ import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import javax.xml.stream.events.XMLEvent;
import java.security.Key;
+import java.security.PublicKey;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
@@ -45,9 +44,9 @@ import java.util.UUID;
*/
public class SecurityContextTokenInputHandler extends AbstractInputSecurityHeaderHandler {
- public SecurityContextTokenInputHandler(InputProcessorChain inputProcessorChain,
- final WSSSecurityProperties securityProperties,
- Deque<XMLEvent> eventQueue, Integer index) throws XMLSecurityException {
+ @Override
+ public void handle(InputProcessorChain inputProcessorChain, final XMLSecurityProperties securityProperties,
+ Deque<XMLEvent> eventQueue, Integer index) throws XMLSecurityException {
@SuppressWarnings("unchecked")
JAXBElement<AbstractSecurityContextTokenType> securityContextTokenTypeJAXBElement =
@@ -60,37 +59,43 @@ public class SecurityContextTokenInputHa
final String identifier = (String) XMLSecurityUtils.getQNameType(securityContextTokenType.getAny(),
new QName(securityContextTokenTypeJAXBElement.getName().getNamespaceURI(), WSSConstants.TAG_wsc0502_Identifier.getLocalPart()));
- final SecurityToken securityContextToken = new AbstractAlgorithmSuiteSecurityEventFiringSecurityToken(
- inputProcessorChain.getSecurityContext(), securityContextTokenType.getId()) {
-
- public boolean isAsymmetric() {
- return false;
- }
-
- public Key getSecretKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
- super.getSecretKey(algorithmURI, keyUsage);
- String algo = JCEAlgorithmMapper.translateURItoJCEID(algorithmURI);
- WSPasswordCallback passwordCallback = new WSPasswordCallback(identifier, WSPasswordCallback.Usage.SECURITY_CONTEXT_TOKEN);
- WSSUtils.doSecretKeyCallback(securityProperties.getCallbackHandler(), passwordCallback, null);
- if (passwordCallback.getKey() == null) {
- throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "noKey", securityContextTokenType.getId());
- }
- return new SecretKeySpec(passwordCallback.getKey(), algo);
- }
-
- public SecurityToken getKeyWrappingToken() {
- return null;
- }
-
- public String getKeyWrappingTokenAlgorithm() {
- return null;
- }
-
- public WSSConstants.TokenType getTokenType() {
- //todo and set externalUriRef
- return WSSConstants.SecurityContextToken;
- }
- };
+ final SecurityToken securityContextToken =
+ new AbstractSecurityToken(
+ (WSSecurityContext) inputProcessorChain.getSecurityContext(), null,
+ null, securityContextTokenType.getId(), null, this) {
+
+ public boolean isAsymmetric() {
+ return false;
+ }
+
+ public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+ String algo = JCEAlgorithmMapper.translateURItoJCEID(algorithmURI);
+ WSPasswordCallback passwordCallback = new WSPasswordCallback(identifier, WSPasswordCallback.Usage.SECURITY_CONTEXT_TOKEN);
+ WSSUtils.doSecretKeyCallback(securityProperties.getCallbackHandler(), passwordCallback, null);
+ if (passwordCallback.getKey() == null) {
+ throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "noKey", securityContextTokenType.getId());
+ }
+ return new SecretKeySpec(passwordCallback.getKey(), algo);
+ }
+
+ @Override
+ public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage) throws XMLSecurityException {
+ return null;
+ }
+
+ public SecurityToken getKeyWrappingToken() {
+ return null;
+ }
+
+ public String getKeyWrappingTokenAlgorithm() {
+ return null;
+ }
+
+ public WSSConstants.TokenType getTokenType() {
+ //todo and set externalUriRef
+ return WSSConstants.SecurityContextToken;
+ }
+ };
SecurityTokenProvider securityTokenProvider = new SecurityTokenProvider() {
@@ -131,11 +136,13 @@ public class SecurityContextTokenInputHa
};
inputProcessorChain.getSecurityContext().registerSecurityTokenProvider(identifier, securityTokenProviderDirectReference);
- SecurityContextTokenSecurityEvent securityContextTokenSecurityEvent = new SecurityContextTokenSecurityEvent(SecurityEvent.Event.SecurityContextToken);
+ /* todo remove me?
+ SecurityContextTokenSecurityEvent securityContextTokenSecurityEvent = new SecurityContextTokenSecurityEvent();
securityContextTokenSecurityEvent.setSecurityToken(securityContextToken);
//todo how to find the issuer?
securityContextTokenSecurityEvent.setIssuerName(identifier);
securityContextTokenSecurityEvent.setExternalUriRef(identifier != null);
((WSSecurityContext) inputProcessorChain.getSecurityContext()).registerSecurityEvent(securityContextTokenSecurityEvent);
+ */
}
}