reta commented on code in PR #3812:
URL: https://github.com/apache/cxf/pull/3812#discussion_r4769646674


##########
rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/SamlTokenInterceptorCertConstraintsTest.java:
##########
@@ -0,0 +1,148 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.ws.security.wss4j;
+
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.util.Collections;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.cxf.binding.soap.SoapFault;
+import org.apache.cxf.binding.soap.SoapHeader;
+import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.security.SecurityContext;
+import org.apache.cxf.ws.policy.AssertionInfoMap;
+import org.apache.cxf.ws.security.SecurityConstants;
+import org.apache.wss4j.common.WSS4JConstants;
+import org.apache.wss4j.common.crypto.Crypto;
+import org.apache.wss4j.common.crypto.Merlin;
+import org.apache.wss4j.common.saml.SAMLCallback;
+import org.apache.wss4j.common.saml.SamlAssertionWrapper;
+import org.apache.wss4j.common.saml.bean.SubjectBean;
+import org.apache.wss4j.common.saml.bean.Version;
+import org.apache.wss4j.common.saml.builder.SAML2Constants;
+import org.apache.wss4j.dom.engine.WSSConfig;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
+
+/**
+ * Check that SecurityConstants.SUBJECT_CERT_CONSTRAINTS is applied by the 
SamlTokenInterceptor when validating
+ * the signature of a received SAML Assertion.
+ */
+public class SamlTokenInterceptorCertConstraintsTest {
+
+    private static Crypto signingCrypto;
+    private static Crypto caOnlyCrypto;
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        WSSConfig.init();
+
+        KeyStore keyStore = KeyStore.getInstance("JKS");
+        try (InputStream is =
+                 
SamlTokenInterceptorCertConstraintsTest.class.getResourceAsStream("/alice.jks"))
 {
+            keyStore.load(is, "password".toCharArray());
+        }
+        Merlin merlin = new Merlin();
+        merlin.setKeyStore(keyStore);
+        signingCrypto = merlin;
+
+        // Only trust the CA, so that the signing certificate is validated via 
chain trust
+        KeyStore trustStore = KeyStore.getInstance("JKS");
+        trustStore.load(null, null);
+        trustStore.setCertificateEntry("cxfca", 
keyStore.getCertificate("cxfca"));
+        Merlin caMerlin = new Merlin();
+        caMerlin.setTrustStore(trustStore);
+        caOnlyCrypto = caMerlin;
+    }
+
+    @Test
+    public void testNoConstraints() throws Exception {
+        assertPrincipal(process(null));
+    }
+
+    @Test
+    public void testMatchingConstraint() throws Exception {
+        assertPrincipal(process(".*CN=alice.*"));

Review Comment:
   Do we have a test with a list of constraints? Would be good to have one, 
thanks @coheigea 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to