You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2015/12/19 12:11:55 UTC
svn commit: r1720895 [34/34] - in /webservices/wss4j/branches/2_1_x-fixes:
bindings/src/main/java/org/apache/wss4j/binding/wss10/
bindings/src/main/java/org/apache/wss4j/binding/wss11/
bindings/src/main/java/org/apache/wss4j/binding/wssc13/ bindings/sr...
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureEncryptionTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureEncryptionTest.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureEncryptionTest.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureEncryptionTest.java Sat Dec 19 11:11:50 2015
@@ -82,7 +82,7 @@ public class SignatureEncryptionTest ext
securityProperties.loadSignatureKeyStore(this.getClass().getClassLoader().getResource("transmitter.jks"), "default".toCharArray());
securityProperties.setSignatureUser("transmitter");
securityProperties.setCallbackHandler(new CallbackHandlerImpl());
-
+
securityProperties.addSignaturePart(
new SecurePart(new QName(WSSConstants.NS_WSU10, "Timestamp"), SecurePart.Modifier.Element)
);
@@ -102,7 +102,7 @@ public class SignatureEncryptionTest ext
doInboundSecurityWithWSS4J(documentBuilderFactory.newDocumentBuilder().parse(new ByteArrayInputStream(baos.toByteArray())), action);
}
}
-
+
@Test
public void testEncryptionSymmetricOutbound() throws Exception {
@@ -115,11 +115,11 @@ public class SignatureEncryptionTest ext
securityProperties.setActions(actions);
securityProperties.loadEncryptionKeystore(this.getClass().getClassLoader().getResource("transmitter.jks"), "default".toCharArray());
securityProperties.setEncryptionUser("receiver");
-
+
OutboundWSSec wsSecOut = WSSec.getOutboundWSSec(securityProperties);
-
+
// Symmetric Key
- String keyAlgorithm =
+ String keyAlgorithm =
JCEAlgorithmMapper.getJCEKeyAlgorithmFromURI(WSSConstants.NS_XENC_AES128);
KeyGenerator keyGen;
try {
@@ -134,7 +134,7 @@ public class SignatureEncryptionTest ext
final String ekId = IDGenerator.generateID(null);
- final GenericOutboundSecurityToken encryptedKeySecurityToken =
+ final GenericOutboundSecurityToken encryptedKeySecurityToken =
new GenericOutboundSecurityToken(ekId, WSSecurityTokenConstants.EncryptedKeyToken, symmetricKey);
final SecurityTokenProvider<OutboundSecurityToken> encryptedKeySecurityTokenProvider =
@@ -153,15 +153,15 @@ public class SignatureEncryptionTest ext
final OutboundSecurityContextImpl outboundSecurityContext = new OutboundSecurityContextImpl();
outboundSecurityContext.putList(SecurityEvent.class, new ArrayList<SecurityEvent>());
-
+
// Save Token on the security context
outboundSecurityContext.registerSecurityTokenProvider(encryptedKeySecurityTokenProvider.getId(), encryptedKeySecurityTokenProvider);
outboundSecurityContext.put(WSSConstants.PROP_USE_THIS_TOKEN_ID_FOR_ENCRYPTION, encryptedKeySecurityTokenProvider.getId());
InputStream sourceDocument = this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml");
-
+
baos = new ByteArrayOutputStream();
- XMLStreamWriter xmlStreamWriter =
+ XMLStreamWriter xmlStreamWriter =
wsSecOut.processOutMessage(baos, StandardCharsets.UTF_8.name(), outboundSecurityContext);
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(sourceDocument);
XmlReaderToWriter.writeAll(xmlStreamReader, xmlStreamWriter);
@@ -176,7 +176,7 @@ public class SignatureEncryptionTest ext
doInboundSecurityWithWSS4J(documentBuilderFactory.newDocumentBuilder().parse(new ByteArrayInputStream(baos.toByteArray())), action);
}
}
-
+
@Test
public void testSignatureEncryptionSymmetricOutbound() throws Exception {
@@ -190,27 +190,27 @@ public class SignatureEncryptionTest ext
securityProperties.setActions(actions);
securityProperties.loadEncryptionKeystore(this.getClass().getClassLoader().getResource("transmitter.jks"), "default".toCharArray());
securityProperties.setEncryptionUser("receiver");
-
+
securityProperties.loadSignatureKeyStore(this.getClass().getClassLoader().getResource("transmitter.jks"), "default".toCharArray());
securityProperties.setSignatureUser("transmitter");
securityProperties.setCallbackHandler(new CallbackHandlerImpl());
-
+
securityProperties.setSignatureAlgorithm(WSSConstants.NS_XMLDSIG_HMACSHA1);
securityProperties.setSignatureKeyIdentifier(
WSSecurityTokenConstants.KeyIdentifier_EncryptedKey
);
-
+
securityProperties.addSignaturePart(
new SecurePart(new QName(WSSConstants.NS_WSU10, "Timestamp"), SecurePart.Modifier.Element)
);
securityProperties.addSignaturePart(
new SecurePart(new QName(WSSConstants.NS_SOAP11, "Body"), SecurePart.Modifier.Element)
);
-
+
OutboundWSSec wsSecOut = WSSec.getOutboundWSSec(securityProperties);
-
+
// Symmetric Key
- String keyAlgorithm =
+ String keyAlgorithm =
JCEAlgorithmMapper.getJCEKeyAlgorithmFromURI(WSSConstants.NS_XENC_AES128);
KeyGenerator keyGen;
try {
@@ -224,8 +224,8 @@ public class SignatureEncryptionTest ext
final Key symmetricKey = keyGen.generateKey();
final String ekId = IDGenerator.generateID(null);
-
- final GenericOutboundSecurityToken encryptedKeySecurityToken =
+
+ final GenericOutboundSecurityToken encryptedKeySecurityToken =
new GenericOutboundSecurityToken(ekId, WSSecurityTokenConstants.EncryptedKeyToken, symmetricKey);
final SecurityTokenProvider<OutboundSecurityToken> encryptedKeySecurityTokenProvider =
@@ -244,16 +244,16 @@ public class SignatureEncryptionTest ext
final OutboundSecurityContextImpl outboundSecurityContext = new OutboundSecurityContextImpl();
outboundSecurityContext.putList(SecurityEvent.class, new ArrayList<SecurityEvent>());
-
+
// Save Token on the security context
outboundSecurityContext.registerSecurityTokenProvider(encryptedKeySecurityTokenProvider.getId(), encryptedKeySecurityTokenProvider);
outboundSecurityContext.put(WSSConstants.PROP_USE_THIS_TOKEN_ID_FOR_ENCRYPTION, encryptedKeySecurityTokenProvider.getId());
outboundSecurityContext.put(WSSConstants.PROP_USE_THIS_TOKEN_ID_FOR_SIGNATURE, encryptedKeySecurityTokenProvider.getId());
InputStream sourceDocument = this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml");
-
+
baos = new ByteArrayOutputStream();
- XMLStreamWriter xmlStreamWriter =
+ XMLStreamWriter xmlStreamWriter =
wsSecOut.processOutMessage(baos, StandardCharsets.UTF_8.name(), outboundSecurityContext);
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(sourceDocument);
XmlReaderToWriter.writeAll(xmlStreamReader, xmlStreamWriter);
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureTest.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureTest.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/SignatureTest.java Sat Dec 19 11:11:50 2015
@@ -154,7 +154,7 @@ public class SignatureTest extends Abstr
Assert.assertEquals(nodeList.item(0).getParentNode().getLocalName(), WSSConstants.TAG_wsse_Security.getLocalPart());
}
}
-
+
@Test
public void testSignatureCryptoPropertiesOutbound() throws Exception {
@@ -164,7 +164,7 @@ public class SignatureTest extends Abstr
List<WSSConstants.Action> actions = new ArrayList<WSSConstants.Action>();
actions.add(WSSConstants.SIGNATURE);
securityProperties.setActions(actions);
- Properties properties =
+ Properties properties =
CryptoFactory.getProperties("transmitter-crypto.properties", this.getClass().getClassLoader());
securityProperties.setSignatureCryptoProperties(properties);
securityProperties.setSignatureUser("transmitter");
@@ -221,7 +221,7 @@ public class SignatureTest extends Abstr
//done signature; now test sig-verification:
{
WSSSecurityProperties securityProperties = new WSSSecurityProperties();
- Properties properties =
+ Properties properties =
CryptoFactory.getProperties("receiver-crypto.properties", this.getClass().getClassLoader());
securityProperties.setSignatureVerificationCryptoProperties(properties);
InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties);
@@ -481,7 +481,7 @@ public class SignatureTest extends Abstr
Assert.assertEquals(nodeList.item(0).getParentNode().getLocalName(), WSSConstants.TAG_wsse_Security.getLocalPart());
}
}
-
+
/**
* Since WSS4J hardcoded the C14N algo for References, we test against our framework
*
@@ -610,7 +610,7 @@ public class SignatureTest extends Abstr
Assert.assertEquals(nodeList.item(0).getParentNode().getLocalName(), WSSConstants.TAG_wsse_Security.getLocalPart());
}
}
-
+
@Test
public void testSignatureKeyIdentifierIssuerSerialIncludeTokenOutbound() throws Exception {
@@ -1035,7 +1035,7 @@ public class SignatureTest extends Abstr
Assert.assertEquals(nodeList.item(0).getParentNode().getLocalName(), WSSConstants.TAG_wsse_Security.getLocalPart());
}
}
-
+
@Test
public void testSignatureKeyIdentifierThumbprintIncludeTokenOutbound() throws Exception {
@@ -1202,7 +1202,7 @@ public class SignatureTest extends Abstr
@Test
public void testSignatureUsePKIPathOutbound() throws Exception {
-
+
// Needs BouncyCastle to work properly...
if (Security.getProvider("BC") == null) {
return;
@@ -1433,7 +1433,7 @@ public class SignatureTest extends Abstr
@Test
public void testSignatureECKeyValue() throws Exception {
-
+
//
// This test fails with the IBM JDK and with JDK 1.8
// TODO - Re-enable with JDK 1.8 when we fix Santuario
@@ -1444,7 +1444,7 @@ public class SignatureTest extends Abstr
|| System.getProperty("java.version").startsWith("1.6"))) {
return;
}
-
+
if (Security.getProvider("BC") == null) {
return;
}
@@ -1534,7 +1534,7 @@ public class SignatureTest extends Abstr
}
}
}
-
+
@Test
public void testInboundRequiredAlgorithm() throws Exception {
@@ -1567,7 +1567,7 @@ public class SignatureTest extends Abstr
Assert.assertEquals(nodeList.getLength(), 1);
Assert.assertEquals(nodeList.item(0).getParentNode().getLocalName(), WSSConstants.TAG_wsse_Security.getLocalPart());
}
-
+
// This should fail as we require another signature algorithm
{
WSSSecurityProperties securityProperties = new WSSSecurityProperties();
@@ -1584,7 +1584,7 @@ public class SignatureTest extends Abstr
}
}
}
-
+
@Test
public void testSignaturePropertiesOutbound() throws Exception {
@@ -1666,7 +1666,7 @@ public class SignatureTest extends Abstr
@Test
public void testElementToSignNotFound() throws Exception {
-
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
{
WSSSecurityProperties securityProperties = new WSSSecurityProperties();
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/TimestampTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/TimestampTest.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/TimestampTest.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/TimestampTest.java Sat Dec 19 11:11:50 2015
@@ -303,7 +303,7 @@ public class TimestampTest extends Abstr
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), xmlStreamReader);
}
}
-
+
@Test
public void testTimestampInFutureInbound() throws Exception {
@@ -354,7 +354,7 @@ public class TimestampTest extends Abstr
Assert.assertEquals(((WSSecurityException) e.getCause()).getFaultCode(), WSSecurityException.MESSAGE_EXPIRED);
}
}
-
+
// now allow future TTL of 2 hours +
{
WSSSecurityProperties securityProperties = new WSSSecurityProperties();
@@ -556,7 +556,7 @@ public class TimestampTest extends Abstr
// expected
}
}
-
+
// No Timestamp Expires Element required - should pass
{
WSSSecurityProperties securityProperties = new WSSSecurityProperties();
@@ -571,7 +571,7 @@ public class TimestampTest extends Abstr
Assert.assertEquals(nodeList.item(0).getParentNode().getLocalName(), WSSConstants.TAG_wsse_Security.getLocalPart());
}
}
-
+
@Test
public void testTimestampNoChildsInbound() throws Exception {
@@ -660,7 +660,7 @@ public class TimestampTest extends Abstr
}
}
}
-
+
@Test
public void testTimestampPropertiesOutbound() throws Exception {
@@ -668,7 +668,7 @@ public class TimestampTest extends Abstr
{
Map<String, Object> config = new HashMap<String, Object>();
config.put(ConfigurationConstants.ACTION, ConfigurationConstants.TIMESTAMP);
-
+
WSSSecurityProperties securityProperties = ConfigurationConverter.convert(config);
OutboundWSSec wsSecOut = WSSec.getOutboundWSSec(securityProperties);
XMLStreamWriter xmlStreamWriter = wsSecOut.processOutMessage(baos, StandardCharsets.UTF_8.name(), new ArrayList<SecurityEvent>());
@@ -727,7 +727,7 @@ public class TimestampTest extends Abstr
config.put(ConfigurationConstants.ACTION, ConfigurationConstants.TIMESTAMP);
WSSSecurityProperties securityProperties = ConfigurationConverter.convert(config);
InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties);
-
+
XMLStreamReader xmlStreamReader = wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray())));
Document document = StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), xmlStreamReader);
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/UsernameTokenTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/UsernameTokenTest.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/UsernameTokenTest.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/UsernameTokenTest.java Sat Dec 19 11:11:50 2015
@@ -180,7 +180,7 @@ public class UsernameTokenTest extends A
if (securityEvent instanceof UsernameTokenSecurityEvent) {
UsernameTokenSecurityEvent usernameTokenSecurityEvent = (UsernameTokenSecurityEvent) securityEvent;
if (!"username".equals(usernameTokenSecurityEvent.getSecurityToken().getPrincipal().getName())) {
- throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
+ throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
new Object[] {"Wrong username"});
}
}
@@ -237,15 +237,15 @@ public class UsernameTokenTest extends A
@Test
public void testReusedNonce() throws Exception {
-
- XMLGregorianCalendar created =
+
+ XMLGregorianCalendar created =
WSSConstants.datatypeFactory.newXMLGregorianCalendar(new GregorianCalendar());
String createdString = created.toXMLFormat();
- String digest =
+ String digest =
org.apache.wss4j.dom.message.token.UsernameToken.doPasswordDigest(
"Ex2YESUvsa1qne1m6TM8XA==", createdString, "default"
);
-
+
String req = "<?xml version=\"1.0\" encoding=\"UTF_8\"?>" +
"<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
" <env:Header>" +
@@ -276,25 +276,25 @@ public class UsernameTokenTest extends A
Assert.assertEquals(((WSSecurityException) e.getCause()).getFaultCode(), WSSecurityException.FAILED_AUTHENTICATION);
}
}
-
+
/**
* This is a test for processing an "old" UsernameToken, i.e. one with a "Created" element that is
* out of date
*/
@Test
public void testOldUsernameToken() throws Exception {
-
+
GregorianCalendar createdCalendar = new GregorianCalendar();
createdCalendar.add(Calendar.SECOND, -301);
- XMLGregorianCalendar created =
+ XMLGregorianCalendar created =
WSSConstants.datatypeFactory.newXMLGregorianCalendar(createdCalendar);
String createdString = created.toXMLFormat();
-
- String digest =
+
+ String digest =
org.apache.wss4j.dom.message.token.UsernameToken.doPasswordDigest(
"Ex2YEKVvsa1qne1m6TM8XA==", createdString, "default"
);
-
+
String req = "<?xml version=\"1.0\" encoding=\"UTF_8\"?>" +
"<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
" <env:Header>" +
@@ -316,7 +316,7 @@ public class UsernameTokenTest extends A
InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties, false, true);
try {
- XMLStreamReader xmlStreamReader =
+ XMLStreamReader xmlStreamReader =
wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(req.getBytes())));
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), xmlStreamReader);
Assert.fail("Expected XMLStreamException");
@@ -325,7 +325,7 @@ public class UsernameTokenTest extends A
}
}
- /**
+ /**
* This is a test for processing a UsernameToken where the "Created" element is in the (near)
* future. It should be accepted by default when it is created 30 seconds in the future.
*/
@@ -333,15 +333,15 @@ public class UsernameTokenTest extends A
public void testNearFutureCreated() throws Exception {
GregorianCalendar createdCalendar = new GregorianCalendar();
createdCalendar.add(Calendar.SECOND, 30);
- XMLGregorianCalendar created =
+ XMLGregorianCalendar created =
WSSConstants.datatypeFactory.newXMLGregorianCalendar(createdCalendar);
String createdString = created.toXMLFormat();
-
- String digest =
+
+ String digest =
org.apache.wss4j.dom.message.token.UsernameToken.doPasswordDigest(
"Ex2YEKVvSa1qne1m6TM8XA==", createdString, "default"
);
-
+
String req = "<?xml version=\"1.0\" encoding=\"UTF_8\"?>" +
"<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
" <env:Header>" +
@@ -364,8 +364,8 @@ public class UsernameTokenTest extends A
XMLStreamReader xmlStreamReader = wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(req.getBytes())));
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), xmlStreamReader);
}
-
- /**
+
+ /**
* This is a test for processing a UsernameToken where the "Created" element is in the future.
* A UsernameToken that is 120 seconds in the future should be rejected by default.
*/
@@ -373,15 +373,15 @@ public class UsernameTokenTest extends A
public void testFutureCreated() throws Exception {
GregorianCalendar createdCalendar = new GregorianCalendar();
createdCalendar.add(Calendar.SECOND, 120);
- XMLGregorianCalendar created =
+ XMLGregorianCalendar created =
WSSConstants.datatypeFactory.newXMLGregorianCalendar(createdCalendar);
String createdString = created.toXMLFormat();
-
- String digest =
+
+ String digest =
org.apache.wss4j.dom.message.token.UsernameToken.doPasswordDigest(
"Ex2YEKVvsa1Qne1m6TM8XA==", createdString, "default"
);
-
+
String req = "<?xml version=\"1.0\" encoding=\"UTF_8\"?>" +
"<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
" <env:Header>" +
@@ -403,7 +403,7 @@ public class UsernameTokenTest extends A
InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties, false, true);
try {
- XMLStreamReader xmlStreamReader =
+ XMLStreamReader xmlStreamReader =
wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(req.getBytes())));
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), xmlStreamReader);
Assert.fail("Expected XMLStreamException");
@@ -411,7 +411,7 @@ public class UsernameTokenTest extends A
Assert.assertEquals(((WSSecurityException) e.getCause()).getFaultCode(), WSSecurityException.MESSAGE_EXPIRED);
}
}
-
+
@Test
public void testDefaultConfigurationOutbound() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -478,7 +478,7 @@ public class UsernameTokenTest extends A
//done UsernameToken; now verification:
{
String action = WSHandlerConstants.USERNAME_TOKEN;
-
+
Document document = documentBuilderFactory.newDocumentBuilder().parse(new ByteArrayInputStream(baos.toByteArray()));
Properties properties = new Properties();
properties.put(WSHandlerConstants.ALLOW_USERNAMETOKEN_NOPASSWORD, "true");
@@ -567,7 +567,7 @@ public class UsernameTokenTest extends A
doInboundSecurityWithWSS4J(documentBuilderFactory.newDocumentBuilder().parse(new ByteArrayInputStream(baos.toByteArray())), action);
}
}
-
+
@Test
public void testInboundSign() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -596,7 +596,7 @@ public class UsernameTokenTest extends A
securityProperties.setAllowUsernameTokenNoPassword(true);
InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties);
- XMLStreamReader xmlStreamReader =
+ XMLStreamReader xmlStreamReader =
wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray())), null);
Document document = StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), xmlStreamReader);
@@ -638,21 +638,21 @@ public class UsernameTokenTest extends A
}
//done UsernameToken; now verification:
-
+
// Failure expected on no password
try {
WSSSecurityProperties securityProperties = new WSSSecurityProperties();
securityProperties.setCallbackHandler(new CallbackHandlerImpl());
InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties, false, true);
XMLStreamReader xmlStreamReader = wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray())));
-
+
xmlStreamReader = wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray())));
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), xmlStreamReader);
Assert.fail("Expected XMLStreamException");
} catch (XMLStreamException e) {
Assert.assertEquals(((WSSecurityException) e.getCause()).getFaultCode(), WSSecurityException.FAILED_AUTHENTICATION);
}
-
+
// Now set the appropriate boolean and it should pass
{
WSSSecurityProperties securityProperties = new WSSSecurityProperties();
@@ -669,7 +669,7 @@ public class UsernameTokenTest extends A
Assert.assertEquals(nodeList.item(0).getParentNode().getLocalName(), WSSConstants.TAG_wsse_Security.getLocalPart());
}
}
-
+
@Test
public void testInboundTextNonceCreated() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -710,7 +710,7 @@ public class UsernameTokenTest extends A
Assert.assertEquals(nodeList.item(0).getParentNode().getLocalName(), WSSConstants.TAG_wsse_Security.getLocalPart());
}
}
-
+
@Test
public void testOutboundTextNonceCreated() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -781,7 +781,7 @@ public class UsernameTokenTest extends A
doInboundSecurityWithWSS4J(documentBuilderFactory.newDocumentBuilder().parse(new ByteArrayInputStream(baos.toByteArray())), action);
}
}
-
+
@Test
public void testPropertiesInbound() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/VulnerabliltyVectorsTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/VulnerabliltyVectorsTest.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/VulnerabliltyVectorsTest.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/VulnerabliltyVectorsTest.java Sat Dec 19 11:11:50 2015
@@ -224,7 +224,7 @@ public class VulnerabliltyVectorsTest ex
Element headerElement = (Element) xPathExpression.evaluate(securedDocument, XPathConstants.NODE);
Element newElement = securedDocument.createElement("test");
headerElement.appendChild(newElement);
-
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream dtd = this.getClass().getClassLoader().getResourceAsStream("testdata/recursiveDTD.txt");
@@ -339,12 +339,12 @@ public class VulnerabliltyVectorsTest ex
@Test
public void testMaximumAllowedTransformsPerReference() throws Exception {
-
+
if (getJavaSpecificationVersion() > 1.7) {
System.out.println("testMaximumAllowedTransformsPerReference skipped");
return;
}
-
+
InputStream sourceDocument = this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml");
String action = WSHandlerConstants.TIMESTAMP + " " + WSHandlerConstants.SIGNATURE + " " + WSHandlerConstants.ENCRYPT;
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/XOPAttachmentTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/XOPAttachmentTest.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/XOPAttachmentTest.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/XOPAttachmentTest.java Sat Dec 19 11:11:50 2015
@@ -75,7 +75,7 @@ public class XOPAttachmentTest extends A
return byteArrayOutputStream.toByteArray();
}
- // Set up a test to encrypt the SOAP Body + an attachment, which is the same content as
+ // Set up a test to encrypt the SOAP Body + an attachment, which is the same content as
// the SOAP Body. Then replace the encrypted SOAP Body with a xop:Include to the attachment,
// and modify the request to remove the encryption stuff pointing to the attachment.
@org.junit.Test
@@ -83,11 +83,11 @@ public class XOPAttachmentTest extends A
Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
List<Attachment> attachments = createEncryptedBodyInAttachment(doc);
// System.out.println("DOC: " + DOM2Writer.nodeToString(doc));
-
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
javax.xml.transform.Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
transformer.transform(new DOMSource(doc), new StreamResult(baos));
-
+
//done signature; now test sig-verification:
AttachmentCallbackHandler attachmentCallbackHandler = new AttachmentCallbackHandler(attachments);
{
@@ -105,12 +105,12 @@ public class XOPAttachmentTest extends A
}
Assert.assertFalse(attachmentCallbackHandler.getResponseAttachments().isEmpty());
Attachment responseAttachment = attachmentCallbackHandler.getResponseAttachments().get(0);
-
+
byte[] attachmentBytes = readInputStream(responseAttachment.getSourceStream());
Assert.assertTrue(Arrays.equals(attachmentBytes, SOAPUtil.SAMPLE_SOAP_MSG.getBytes(StandardCharsets.UTF_8)));
Assert.assertEquals("text/xml", responseAttachment.getMimeType());
}
-
+
private List<Attachment> createEncryptedBodyInAttachment(Document doc) throws Exception {
WSSecEncrypt encrypt = new WSSecEncrypt();
encrypt.setUserInfo("receiver", "default");
@@ -127,7 +127,7 @@ public class XOPAttachmentTest extends A
attachment.setId(attachmentId);
attachment.setSourceStream(new ByteArrayInputStream(SOAPUtil.SAMPLE_SOAP_MSG.getBytes(StandardCharsets.UTF_8)));
- AttachmentCallbackHandler attachmentCallbackHandler =
+ AttachmentCallbackHandler attachmentCallbackHandler =
new AttachmentCallbackHandler(Collections.singletonList(attachment));
encrypt.setAttachmentCallbackHandler(attachmentCallbackHandler);
List<Attachment> encryptedAttachments = attachmentCallbackHandler.getResponseAttachments();
@@ -138,41 +138,41 @@ public class XOPAttachmentTest extends A
sigProperties.setProperty("org.apache.wss4j.crypto.merlin.keystore.password", "default");
Crypto crypto = new Merlin(sigProperties, this.getClass().getClassLoader(), null);
Document encryptedDoc = encrypt.build(doc, crypto, secHeader);
-
+
// Find the SOAP Body + replace with a xop:Include to the attachment!
Element soapBody = WSSecurityUtil.findBodyElement(encryptedDoc);
assertNotNull(soapBody);
- Element encryptedData =
+ Element encryptedData =
XMLUtils.getDirectChildElement(soapBody, "EncryptedData", WSConstants.ENC_NS);
encryptedData.removeAttributeNS(null, "Type");
- Element cipherData =
+ Element cipherData =
XMLUtils.getDirectChildElement(encryptedData, "CipherData", WSConstants.ENC_NS);
assertNotNull(cipherData);
- Element cipherValue =
+ Element cipherValue =
XMLUtils.getDirectChildElement(cipherData, "CipherValue", WSConstants.ENC_NS);
assertNotNull(cipherValue);
-
+
XMLUtils.setNamespace(cipherValue, WSS4JConstants.XOP_NS, "xop");
-
+
Element cipherValueChild = encryptedDoc.createElementNS(WSConstants.XOP_NS, "Include");
cipherValueChild.setAttributeNS(null, "href", "cid:" + encryptedAttachments.get(0).getId());
cipherValue.replaceChild(cipherValueChild, cipherValue.getFirstChild());
-
+
// Remove EncryptedData structure from the security header (which encrypted the attachment
// in the first place)
- Element securityHeader =
+ Element securityHeader =
WSSecurityUtil.findWsseSecurityHeaderBlock(encryptedDoc, encryptedDoc.getDocumentElement(), false);
- Element encryptedAttachmentData =
+ Element encryptedAttachmentData =
XMLUtils.getDirectChildElement(securityHeader, "EncryptedData", WSConstants.ENC_NS);
assertNotNull(encryptedAttachmentData);
String encryptedDataId = encryptedAttachmentData.getAttributeNS(null, "Id");
securityHeader.removeChild(encryptedAttachmentData);
// Now get EncryptedKey + remove the reference to the EncryptedData above
- Element encryptedKey =
+ Element encryptedKey =
XMLUtils.getDirectChildElement(securityHeader, "EncryptedKey", WSConstants.ENC_NS);
assertNotNull(encryptedKey);
- Element referenceList =
+ Element referenceList =
XMLUtils.getDirectChildElement(encryptedKey, "ReferenceList", WSConstants.ENC_NS);
assertNotNull(referenceList);
Node child = referenceList.getFirstChild();
@@ -187,8 +187,8 @@ public class XOPAttachmentTest extends A
}
child = child.getNextSibling();
}
-
+
return encryptedAttachments;
}
-
+
}
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SAMLCallbackHandlerImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SAMLCallbackHandlerImpl.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SAMLCallbackHandlerImpl.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SAMLCallbackHandlerImpl.java Sat Dec 19 11:11:50 2015
@@ -280,7 +280,7 @@ public class SAMLCallbackHandlerImpl imp
public void setIssuer(String issuer) {
this.issuer = issuer;
}
-
+
public void setIssuerFormat(String issuerFormat) {
this.issuerFormat = issuerFormat;
}
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SAMLTokenHOKTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SAMLTokenHOKTest.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SAMLTokenHOKTest.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SAMLTokenHOKTest.java Sat Dec 19 11:11:50 2015
@@ -490,7 +490,7 @@ public class SAMLTokenHOKTest extends Ab
secHeader.insertSecurityHeader();
Document securedDocument = wsSign.build(doc, samlAssertion, secHeader);
-
+
//some test that we can really sure we get what we want from WSS4J
NodeList nodeList = securedDocument.getElementsByTagNameNS(WSSConstants.TAG_dsig_Signature.getNamespaceURI(), WSSConstants.TAG_dsig_Signature.getLocalPart());
Assert.assertEquals(nodeList.getLength(), 1);
@@ -506,7 +506,7 @@ public class SAMLTokenHOKTest extends Ab
javax.xml.transform.Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
transformer.transform(new DOMSource(securedDocument), new StreamResult(baos));
}
-
+
//done signature; now test sig-verification:
{
WSSSecurityProperties securityProperties = new WSSSecurityProperties();
@@ -1023,5 +1023,5 @@ public class SAMLTokenHOKTest extends Ab
Assert.assertEquals(nodeList.item(0).getParentNode().getLocalName(), WSSConstants.TAG_saml_Assertion.getLocalPart());
}
}
-
+
}
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SAMLTokenTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SAMLTokenTest.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SAMLTokenTest.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SAMLTokenTest.java Sat Dec 19 11:11:50 2015
@@ -760,7 +760,7 @@ public class SAMLTokenTest extends Abstr
conditions.setNotBefore(newNotBefore);
conditions.setNotOnOrAfter(newNotBefore.plusMinutes(5));
- XMLObjectBuilder<XSAny> xsAnyBuilder =
+ XMLObjectBuilder<XSAny> xsAnyBuilder =
(XMLObjectBuilder<XSAny>)builderFactory.getBuilder(XSAny.TYPE_NAME);
XSAny attributeValue = xsAnyBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
attributeValue.getUnknownXMLObjects().add(conditions);
@@ -768,7 +768,7 @@ public class SAMLTokenTest extends Abstr
List<Object> attributeValues = new ArrayList<Object>();
attributeValues.add(attributeValue);
callbackHandler.setCustomAttributeValues(attributeValues);
-
+
securityProperties.setSamlCallbackHandler(callbackHandler);
OutboundWSSec wsSecOut = WSSec.getOutboundWSSec(securityProperties);
@@ -864,7 +864,7 @@ public class SAMLTokenTest extends Abstr
Assert.assertEquals(nodeList.getLength(), 1);
}
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 authentication assertion, which
* is encrypted in a saml2:EncryptedAssertion Element in the security header
@@ -876,11 +876,11 @@ public class SAMLTokenTest extends Abstr
Crypto crypto = CryptoFactory.getInstance("wss40.properties");
{
InputStream sourceDocument = this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml");
-
+
SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setIssuer("www.example.com");
-
+
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
SamlAssertionWrapper samlAssertion = new SamlAssertionWrapper(samlCallback);
@@ -890,16 +890,16 @@ public class SAMLTokenTest extends Abstr
Document doc = SOAPUtil.toSOAPPart(sourceDocument);
WSSecHeader secHeader = new WSSecHeader(doc);
secHeader.insertSecurityHeader();
-
+
wsSign.prepare(doc, samlAssertion);
-
+
// Get the Element + add it to the security header as an EncryptedAssertion
Element assertionElement = wsSign.getElement();
- Element encryptedAssertionElement =
+ Element encryptedAssertionElement =
doc.createElementNS(WSConstants.SAML2_NS, WSConstants.ENCRYPED_ASSERTION_LN);
encryptedAssertionElement.appendChild(assertionElement);
secHeader.getSecurityHeader().appendChild(encryptedAssertionElement);
-
+
// Encrypt the Assertion
KeyGenerator keygen = KeyGenerator.getInstance("AES");
keygen.init(128);
@@ -908,10 +908,10 @@ public class SAMLTokenTest extends Abstr
cryptoType.setAlias("wss40");
X509Certificate[] certs = crypto.getX509Certificates(cryptoType);
assertTrue(certs != null && certs.length > 0 && certs[0] != null);
-
+
encryptElement(doc, assertionElement, WSConstants.AES_128, secretKey,
WSConstants.KEYTRANSPORT_RSAOEP, certs[0], false);
-
+
javax.xml.transform.Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
transformer.transform(new DOMSource(doc), new StreamResult(baos));
}
@@ -926,12 +926,12 @@ public class SAMLTokenTest extends Abstr
Document document = StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), xmlStreamReader);
// Decrypted Assertion element must be there
- NodeList nodeList =
+ NodeList nodeList =
document.getElementsByTagNameNS(WSSConstants.TAG_saml2_Assertion.getNamespaceURI(), WSSConstants.TAG_saml2_Assertion.getLocalPart());
Assert.assertEquals(nodeList.getLength(), 1);
}
}
-
+
@Test
public void testRequiredSubjectConfirmationMethod() throws Exception {
@@ -962,12 +962,12 @@ public class SAMLTokenTest extends Abstr
WSSSecurityProperties securityProperties = new WSSSecurityProperties();
securityProperties.loadSignatureVerificationKeystore(this.getClass().getClassLoader().getResource("receiver.jks"), "default".toCharArray());
securityProperties.setSamlCallbackHandler(new SAMLCallbackHandlerImpl());
-
+
SamlTokenValidatorImpl validator = new SamlTokenValidatorImpl();
validator.setRequiredSubjectConfirmationMethod(SAML2Constants.CONF_SENDER_VOUCHES);
securityProperties.addValidator(WSSConstants.TAG_saml2_Assertion, validator);
securityProperties.addValidator(WSSConstants.TAG_saml_Assertion, validator);
-
+
InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties);
XMLStreamReader xmlStreamReader = wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray())));
@@ -977,7 +977,7 @@ public class SAMLTokenTest extends Abstr
NodeList nodeList = document.getElementsByTagNameNS(WSSConstants.TAG_dsig_Signature.getNamespaceURI(), WSSConstants.TAG_dsig_Signature.getLocalPart());
Assert.assertEquals(nodeList.getLength(), 1);
}
-
+
baos = new ByteArrayOutputStream();
// Now create a Bearer assertion
{
@@ -1007,12 +1007,12 @@ public class SAMLTokenTest extends Abstr
WSSSecurityProperties securityProperties = new WSSSecurityProperties();
securityProperties.loadSignatureVerificationKeystore(this.getClass().getClassLoader().getResource("receiver.jks"), "default".toCharArray());
securityProperties.setSamlCallbackHandler(new SAMLCallbackHandlerImpl());
-
+
SamlTokenValidatorImpl validator = new SamlTokenValidatorImpl();
validator.setRequiredSubjectConfirmationMethod(SAML2Constants.CONF_SENDER_VOUCHES);
securityProperties.addValidator(WSSConstants.TAG_saml2_Assertion, validator);
securityProperties.addValidator(WSSConstants.TAG_saml_Assertion, validator);
-
+
InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties);
XMLStreamReader xmlStreamReader = wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray())));
@@ -1024,7 +1024,7 @@ public class SAMLTokenTest extends Abstr
}
}
}
-
+
@Test
public void testStandardSubjectConfirmationMethod() throws Exception {
@@ -1056,7 +1056,7 @@ public class SAMLTokenTest extends Abstr
WSSSecurityProperties securityProperties = new WSSSecurityProperties();
securityProperties.loadSignatureVerificationKeystore(this.getClass().getClassLoader().getResource("receiver.jks"), "default".toCharArray());
securityProperties.setSamlCallbackHandler(new SAMLCallbackHandlerImpl());
-
+
InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties);
XMLStreamReader xmlStreamReader = wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray())));
@@ -1067,25 +1067,25 @@ public class SAMLTokenTest extends Abstr
// expected
}
}
-
+
// Validate again - disable the standard subject confirmation method check
{
WSSSecurityProperties securityProperties = new WSSSecurityProperties();
securityProperties.loadSignatureVerificationKeystore(this.getClass().getClassLoader().getResource("receiver.jks"), "default".toCharArray());
securityProperties.setSamlCallbackHandler(new SAMLCallbackHandlerImpl());
-
+
SamlTokenValidatorImpl validator = new SamlTokenValidatorImpl();
validator.setRequireStandardSubjectConfirmationMethod(false);
securityProperties.addValidator(WSSConstants.TAG_saml2_Assertion, validator);
securityProperties.addValidator(WSSConstants.TAG_saml_Assertion, validator);
-
+
InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties);
XMLStreamReader xmlStreamReader = wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray())));
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), xmlStreamReader);
}
}
-
+
@Test
public void testUnsignedBearer() throws Exception {
@@ -1117,7 +1117,7 @@ public class SAMLTokenTest extends Abstr
WSSSecurityProperties securityProperties = new WSSSecurityProperties();
securityProperties.loadSignatureVerificationKeystore(this.getClass().getClassLoader().getResource("receiver.jks"), "default".toCharArray());
securityProperties.setSamlCallbackHandler(new SAMLCallbackHandlerImpl());
-
+
InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties);
XMLStreamReader xmlStreamReader = wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray())));
@@ -1128,25 +1128,25 @@ public class SAMLTokenTest extends Abstr
// expected
}
}
-
+
// Validate again - disable the signed Bearer check
{
WSSSecurityProperties securityProperties = new WSSSecurityProperties();
securityProperties.loadSignatureVerificationKeystore(this.getClass().getClassLoader().getResource("receiver.jks"), "default".toCharArray());
securityProperties.setSamlCallbackHandler(new SAMLCallbackHandlerImpl());
-
+
SamlTokenValidatorImpl validator = new SamlTokenValidatorImpl();
validator.setRequireBearerSignature(false);
securityProperties.addValidator(WSSConstants.TAG_saml2_Assertion, validator);
securityProperties.addValidator(WSSConstants.TAG_saml_Assertion, validator);
-
+
InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties);
XMLStreamReader xmlStreamReader = wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray())));
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), xmlStreamReader);
}
}
-
+
@Test
public void testSAML2IssuerFormatOutbound() throws Exception {
@@ -1180,7 +1180,7 @@ public class SAMLTokenTest extends Abstr
doInboundSecurityWithWSS4J(documentBuilderFactory.newDocumentBuilder().parse(new ByteArrayInputStream(baos.toByteArray())), action);
}
}
-
+
private void encryptElement(
Document document,
Element elementToEncrypt,
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SamlAuthnTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SamlAuthnTest.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SamlAuthnTest.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SamlAuthnTest.java Sat Dec 19 11:11:50 2015
@@ -59,7 +59,7 @@ public class SamlAuthnTest extends Abstr
createDOMMessageAndVerifyStAX(callbackHandler, true);
}
-
+
@Test
public void testSAML2AuthnAssertion() throws Exception {
@@ -70,7 +70,7 @@ public class SamlAuthnTest extends Abstr
createDOMMessageAndVerifyStAX(callbackHandler, true);
}
-
+
@Test
public void testSAML1FutureAuthnInstant() throws Exception {
@@ -78,12 +78,12 @@ public class SamlAuthnTest extends Abstr
callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHN);
callbackHandler.setConfirmationMethod(SAML1Constants.CONF_HOLDER_KEY);
callbackHandler.setIssuer("www.example.com");
-
+
callbackHandler.setAuthenticationInstant(new DateTime().plusMinutes(70));
createDOMMessageAndVerifyStAX(callbackHandler, false);
}
-
+
@Test
public void testSAML2FutureAuthnInstant() throws Exception {
@@ -91,12 +91,12 @@ public class SamlAuthnTest extends Abstr
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setConfirmationMethod(SAML2Constants.CONF_HOLDER_KEY);
callbackHandler.setIssuer("www.example.com");
-
+
callbackHandler.setAuthenticationInstant(new DateTime().plusMinutes(70));
createDOMMessageAndVerifyStAX(callbackHandler, false);
}
-
+
@Test
public void testSAML2StaleSessionNotOnOrAfter() throws Exception {
@@ -104,12 +104,12 @@ public class SamlAuthnTest extends Abstr
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setConfirmationMethod(SAML2Constants.CONF_HOLDER_KEY);
callbackHandler.setIssuer("www.example.com");
-
+
callbackHandler.setSessionNotOnOrAfter(new DateTime().minusMinutes(70));
-
+
createDOMMessageAndVerifyStAX(callbackHandler, false);
}
-
+
@Test
public void testSAML1ValidSubjectLocality() throws Exception {
@@ -117,12 +117,12 @@ public class SamlAuthnTest extends Abstr
callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHN);
callbackHandler.setConfirmationMethod(SAML1Constants.CONF_HOLDER_KEY);
callbackHandler.setIssuer("www.example.com");
-
+
callbackHandler.setSubjectLocality("127.0.0.1", "xyz.ws.apache.org");
createDOMMessageAndVerifyStAX(callbackHandler, true);
}
-
+
@Test
public void testSAML2ValidSubjectLocality() throws Exception {
@@ -130,12 +130,12 @@ public class SamlAuthnTest extends Abstr
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setConfirmationMethod(SAML2Constants.CONF_HOLDER_KEY);
callbackHandler.setIssuer("www.example.com");
-
+
callbackHandler.setSubjectLocality("127.0.0.1", "xyz.ws.apache.org");
createDOMMessageAndVerifyStAX(callbackHandler, true);
}
-
+
@Test
public void testSAML1InvalidSubjectLocality() throws Exception {
@@ -143,12 +143,12 @@ public class SamlAuthnTest extends Abstr
callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHN);
callbackHandler.setConfirmationMethod(SAML1Constants.CONF_HOLDER_KEY);
callbackHandler.setIssuer("www.example.com");
-
+
callbackHandler.setSubjectLocality("xyz.ws.apache.org", "xyz.ws.apache.org");
createDOMMessageAndVerifyStAX(callbackHandler, false);
}
-
+
@Test
public void testSAML2InvalidSubjectLocality() throws Exception {
@@ -156,12 +156,12 @@ public class SamlAuthnTest extends Abstr
callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
callbackHandler.setConfirmationMethod(SAML2Constants.CONF_HOLDER_KEY);
callbackHandler.setIssuer("www.example.com");
-
+
callbackHandler.setSubjectLocality("xyz.ws.apache.org", "xyz.ws.apache.org");
createDOMMessageAndVerifyStAX(callbackHandler, false);
}
-
+
private void createDOMMessageAndVerifyStAX(
CallbackHandler samlCallbackHandler, boolean success
) throws Exception {
@@ -172,26 +172,26 @@ public class SamlAuthnTest extends Abstr
Properties properties = new Properties();
properties.put(WSHandlerConstants.SAML_CALLBACK_REF, samlCallbackHandler);
Document securedDocument = doOutboundSecurityWithWSS4J(sourceDocument, action, properties);
-
+
//some test that we can really sure we get what we want from WSS4J
NodeList nodeList = securedDocument.getElementsByTagNameNS(WSSConstants.TAG_dsig_Signature.getNamespaceURI(), WSSConstants.TAG_dsig_Signature.getLocalPart());
Assert.assertEquals(nodeList.getLength(), 2);
Assert.assertEquals(nodeList.item(0).getParentNode().getLocalName(), WSSConstants.TAG_saml_Assertion.getLocalPart());
Assert.assertEquals(nodeList.item(1).getParentNode().getLocalName(), WSSConstants.TAG_wsse_Security.getLocalPart());
-
+
javax.xml.transform.Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
transformer.transform(new DOMSource(securedDocument), new StreamResult(baos));
}
-
+
//done signature; now test sig-verification:
{
WSSSecurityProperties securityProperties = new WSSSecurityProperties();
securityProperties.loadSignatureVerificationKeystore(this.getClass().getClassLoader().getResource("receiver.jks"), "default".toCharArray());
InboundWSSec wsSecIn = WSSec.getInboundWSSec(securityProperties);
XMLStreamReader xmlStreamReader = wsSecIn.processInMessage(xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray())));
-
+
try {
- Document document =
+ Document document =
StAX2DOM.readDoc(documentBuilderFactory.newDocumentBuilder(), xmlStreamReader);
if (!success) {
Assert.fail("XMLStreamException expected");
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SamlConditionsTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SamlConditionsTest.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SamlConditionsTest.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SamlConditionsTest.java Sat Dec 19 11:11:50 2015
@@ -252,7 +252,7 @@ public class SamlConditionsTest extends
}
}
}
-
+
@Test
public void testSAML2FutureNotBefore() throws Exception {
@@ -293,7 +293,7 @@ public class SamlConditionsTest extends
}
}
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 authentication assertion
* with an (invalid) custom Conditions statement.
@@ -378,7 +378,7 @@ public class SamlConditionsTest extends
Assert.assertNotNull(document);
}
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 authentication assertion
* with a OneTimeUse Element
@@ -394,7 +394,7 @@ public class SamlConditionsTest extends
ConditionsBean conditions = new ConditionsBean();
conditions.setTokenPeriodMinutes(5);
conditions.setOneTimeUse(true);
-
+
callbackHandler.setConditions(conditions);
InputStream sourceDocument = this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml");
@@ -418,7 +418,7 @@ public class SamlConditionsTest extends
Assert.assertNotNull(document);
}
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 authentication assertion
* with a ProxyRestriction Element
@@ -440,7 +440,7 @@ public class SamlConditionsTest extends
proxyRestriction.getAudienceURIs().addAll(audiences);
proxyRestriction.setCount(5);
conditions.setProxyRestriction(proxyRestriction);
-
+
callbackHandler.setConditions(conditions);
InputStream sourceDocument = this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml");
@@ -464,7 +464,7 @@ public class SamlConditionsTest extends
Assert.assertNotNull(document);
}
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 authentication assertion
* with an AudienceRestriction Element
@@ -485,7 +485,7 @@ public class SamlConditionsTest extends
AudienceRestrictionBean audienceRestrictionBean = new AudienceRestrictionBean();
audienceRestrictionBean.setAudienceURIs(audiences);
conditions.setAudienceRestrictions(Collections.singletonList(audienceRestrictionBean));
-
+
callbackHandler.setConditions(conditions);
InputStream sourceDocument = this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml");
@@ -509,7 +509,7 @@ public class SamlConditionsTest extends
Assert.assertNotNull(document);
}
}
-
+
// Now test AudienceRestrictions with supplied restrictions
@org.junit.Test
public void testSAML2AudienceRestrictionValidation() throws Exception {
@@ -527,7 +527,7 @@ public class SamlConditionsTest extends
AudienceRestrictionBean audienceRestrictionBean = new AudienceRestrictionBean();
audienceRestrictionBean.setAudienceURIs(audiences);
conditions.setAudienceRestrictions(Collections.singletonList(audienceRestrictionBean));
-
+
callbackHandler.setConditions(conditions);
InputStream sourceDocument = this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml");
@@ -557,7 +557,7 @@ public class SamlConditionsTest extends
Assert.assertNotNull(e.getCause());
}
}
-
+
// Now add the correct audience back in...
audiences.add("http://apache.org/one");
{
@@ -571,7 +571,7 @@ public class SamlConditionsTest extends
Assert.assertNotNull(document);
}
}
-
+
// Now test AudienceRestrictions with supplied restrictions
@org.junit.Test
public void testSAML1AudienceRestrictionValidation() throws Exception {
@@ -589,7 +589,7 @@ public class SamlConditionsTest extends
AudienceRestrictionBean audienceRestrictionBean = new AudienceRestrictionBean();
audienceRestrictionBean.setAudienceURIs(audiences);
conditions.setAudienceRestrictions(Collections.singletonList(audienceRestrictionBean));
-
+
callbackHandler.setConditions(conditions);
InputStream sourceDocument = this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml");
@@ -619,7 +619,7 @@ public class SamlConditionsTest extends
Assert.assertNotNull(e.getCause());
}
}
-
+
// Now add the correct audience back in...
audiences.add("http://apache.org/one");
{
@@ -633,7 +633,7 @@ public class SamlConditionsTest extends
Assert.assertNotNull(document);
}
}
-
+
/**
* Test that creates, sends and processes an unsigned SAML 2 authentication assertion
* with two AudienceRestriction Elements
@@ -648,8 +648,8 @@ public class SamlConditionsTest extends
ConditionsBean conditions = new ConditionsBean();
conditions.setTokenPeriodMinutes(5);
-
- List<AudienceRestrictionBean> audiencesRestrictions =
+
+ List<AudienceRestrictionBean> audiencesRestrictions =
new ArrayList<AudienceRestrictionBean>();
AudienceRestrictionBean audienceRestrictionBean = new AudienceRestrictionBean();
audienceRestrictionBean.setAudienceURIs(Collections.singletonList("http://apache.org/one"));
@@ -660,7 +660,7 @@ public class SamlConditionsTest extends
audiencesRestrictions.add(audienceRestrictionBean);
conditions.setAudienceRestrictions(audiencesRestrictions);
-
+
callbackHandler.setConditions(conditions);
InputStream sourceDocument = this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml");
@@ -684,7 +684,7 @@ public class SamlConditionsTest extends
Assert.assertNotNull(document);
}
}
-
+
// Now test AudienceRestrictions with supplied restrictions
@org.junit.Test
public void testSAML1AudienceRestrictionSeparateRestrictionsValidation() throws Exception {
@@ -696,8 +696,8 @@ public class SamlConditionsTest extends
ConditionsBean conditions = new ConditionsBean();
conditions.setTokenPeriodMinutes(5);
-
- List<AudienceRestrictionBean> audiencesRestrictions =
+
+ List<AudienceRestrictionBean> audiencesRestrictions =
new ArrayList<AudienceRestrictionBean>();
AudienceRestrictionBean audienceRestrictionBean = new AudienceRestrictionBean();
audienceRestrictionBean.setAudienceURIs(Collections.singletonList("http://apache.org/one"));
@@ -708,7 +708,7 @@ public class SamlConditionsTest extends
audiencesRestrictions.add(audienceRestrictionBean);
conditions.setAudienceRestrictions(audiencesRestrictions);
-
+
callbackHandler.setConditions(conditions);
InputStream sourceDocument = this.getClass().getClassLoader().getResourceAsStream("testdata/plain-soap-1.1.xml");
@@ -738,7 +738,7 @@ public class SamlConditionsTest extends
Assert.assertNotNull(e.getCause());
}
}
-
+
// Now add the correct audience back in...
audiences.add("http://apache.org/one");
{
Modified: webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SamlTokenDerivedTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SamlTokenDerivedTest.java?rev=1720895&r1=1720894&r2=1720895&view=diff
==============================================================================
--- webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SamlTokenDerivedTest.java (original)
+++ webservices/wss4j/branches/2_1_x-fixes/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/saml/SamlTokenDerivedTest.java Sat Dec 19 11:11:50 2015
@@ -185,7 +185,7 @@ public class SamlTokenDerivedTest extend
crypto.getPrivateKey("transmitter", "default");
sigBuilder.setExternalKey(key.getEncoded(), secToken.getElement());
sigBuilder.setSignatureAlgorithm(WSConstants.HMAC_SHA1);
-
+
String soapNamespace = WSSecurityUtil.getSOAPNamespace(doc.getDocumentElement());
WSEncryptionPart encP =
new WSEncryptionPart(