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 2013/07/26 16:30:38 UTC

svn commit: r1507331 - in /webservices/wss4j/branches/1_6_x-fixes/src: main/java/org/apache/ws/security/action/ main/java/org/apache/ws/security/handler/ main/java/org/apache/ws/security/saml/ main/resources/org/apache/ws/security/saml/ test/java/org/a...

Author: coheigea
Date: Fri Jul 26 14:30:37 2013
New Revision: 1507331

URL: http://svn.apache.org/r1507331
Log:
[WSS-418] - Cannot configure SAML properties in WSS4JOutInterceptor without having to add that config file in the classpath

Removed:
    webservices/wss4j/branches/1_6_x-fixes/src/main/resources/org/apache/ws/security/saml/saml.properties
Modified:
    webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/action/SAMLTokenSignedAction.java
    webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/handler/WSHandlerConstants.java
    webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/saml/SAMLIssuerFactory.java
    webservices/wss4j/branches/1_6_x-fixes/src/test/java/org/apache/ws/security/saml/SamlTokenTest.java

Modified: webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/action/SAMLTokenSignedAction.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/action/SAMLTokenSignedAction.java?rev=1507331&r1=1507330&r2=1507331&view=diff
==============================================================================
--- webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/action/SAMLTokenSignedAction.java (original)
+++ webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/action/SAMLTokenSignedAction.java Fri Jul 26 14:30:37 2013
@@ -19,6 +19,8 @@
 
 package org.apache.ws.security.action;
 
+import java.util.Properties;
+
 import javax.security.auth.callback.CallbackHandler;
 
 import org.apache.ws.security.WSPasswordCallback;
@@ -31,7 +33,6 @@ import org.apache.ws.security.saml.SAMLI
 import org.apache.ws.security.saml.SAMLIssuerFactory;
 import org.apache.ws.security.saml.WSSecSignatureSAML;
 import org.apache.ws.security.saml.ext.AssertionWrapper;
-
 import org.w3c.dom.Document;
 
 public class SAMLTokenSignedAction implements Action {
@@ -110,9 +111,26 @@ public class SAMLTokenSignedAction imple
         WSHandler handler, 
         RequestData reqData
     ) throws WSSecurityException {
-        String samlPropFile = 
-            handler.getString(WSHandlerConstants.SAML_PROP_FILE, reqData.getMsgContext());
-        SAMLIssuer samlIssuer = SAMLIssuerFactory.getInstance(samlPropFile);
+        SAMLIssuer samlIssuer = null;
+        // Try the Property Ref Id first
+        String refId = 
+            handler.getString(WSHandlerConstants.SAML_PROP_REF_ID, reqData.getMsgContext());
+        if (refId != null) {
+            Object obj = handler.getProperty(reqData.getMsgContext(), refId);
+            if (obj instanceof Properties) {
+                samlIssuer = SAMLIssuerFactory.getInstance((Properties)obj);
+            } else if (obj instanceof SAMLIssuer) {
+                samlIssuer = (SAMLIssuer)obj;
+            }
+        }
+        
+        // Now try the properties file
+        if (samlIssuer == null) {
+            String samlPropFile = 
+                handler.getString(WSHandlerConstants.SAML_PROP_FILE, reqData.getMsgContext());
+            samlIssuer = SAMLIssuerFactory.getInstance(samlPropFile);
+        }
+        
         CallbackHandler callbackHandler = 
             handler.getCallbackHandler(
                 WSHandlerConstants.SAML_CALLBACK_CLASS,

Modified: webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/handler/WSHandlerConstants.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/handler/WSHandlerConstants.java?rev=1507331&r1=1507330&r2=1507331&view=diff
==============================================================================
--- webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/handler/WSHandlerConstants.java (original)
+++ webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/handler/WSHandlerConstants.java Fri Jul 26 14:30:37 2013
@@ -330,6 +330,15 @@ public final class WSHandlerConstants {
      */
     public static final String SAML_PROP_FILE = "samlPropFile";
     
+    /**
+     * The key that holds a reference to the object holding complete information about 
+     * the SAML Issuer configuration. This object can either be a SAMLIssuer instance or a
+     * <code>java.util.Properties</code> Object.
+     * 
+     * Refer to documentation of {@link #SAML_PROP_FILE}.
+     */
+    public static final String SAML_PROP_REF_ID = "samlPropRefId";
+    
     //
     // Boolean configuration tags, e.g. the value should be "true" or "false".
     //

Modified: webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/saml/SAMLIssuerFactory.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/saml/SAMLIssuerFactory.java?rev=1507331&r1=1507330&r2=1507331&view=diff
==============================================================================
--- webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/saml/SAMLIssuerFactory.java (original)
+++ webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/saml/SAMLIssuerFactory.java Fri Jul 26 14:30:37 2013
@@ -81,24 +81,7 @@ public abstract class SAMLIssuerFactory 
         return loadClass(samlClass, properties);
     }
 
-    /**
-     * getInstance
-     * <p/>
-     * Returns an instance of SAMLIssuer. This method uses the specified filename
-     * to load a property file. This file shall use the property
-     * <code>org.apache.ws.security.saml.issuerClass</code>
-     * to define the classname of the SAMLIssuer implementation. The file
-     * may contain other property definitions as well. These properties are
-     * handed over to the SAMLIssuer implementation. The specified file
-     * is loaded with the <code>Loader.getResource()</code> method.
-     * <p/>
-     *
-     * @param propFilename The name of the property file to load
-     * @return The SAMLIssuer implementation that was defined
-     * @throws WSSecurityException if there is an error in loading the crypto properties
-     */
-    public static SAMLIssuer getInstance(String propFilename) throws WSSecurityException {
-        Properties properties = getProperties(propFilename);
+    public static SAMLIssuer getInstance(Properties properties) throws WSSecurityException {
         String samlClassName = 
             properties.getProperty("org.apache.ws.security.saml.issuerClass");
         Class<? extends SAMLIssuer> samlIssuerClass = null;
@@ -119,6 +102,26 @@ public abstract class SAMLIssuerFactory 
 
         return loadClass(samlIssuerClass, properties);
     }
+    
+    /**
+     * getInstance
+     * <p/>
+     * Returns an instance of SAMLIssuer. This method uses the specified filename
+     * to load a property file. This file shall use the property
+     * <code>org.apache.ws.security.saml.issuerClass</code>
+     * to define the classname of the SAMLIssuer implementation. The file
+     * may contain other property definitions as well. These properties are
+     * handed over to the SAMLIssuer implementation. The specified file
+     * is loaded with the <code>Loader.getResource()</code> method.
+     * <p/>
+     *
+     * @param propFilename The name of the property file to load
+     * @return The SAMLIssuer implementation that was defined
+     * @throws WSSecurityException if there is an error in loading the crypto properties
+     */
+    public static SAMLIssuer getInstance(String propFilename) throws WSSecurityException {
+        return getInstance(getProperties(propFilename));
+    }
 
     private static SAMLIssuer loadClass(
         Class<? extends SAMLIssuer> samlIssuerClass, 

Modified: webservices/wss4j/branches/1_6_x-fixes/src/test/java/org/apache/ws/security/saml/SamlTokenTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_6_x-fixes/src/test/java/org/apache/ws/security/saml/SamlTokenTest.java?rev=1507331&r1=1507330&r2=1507331&view=diff
==============================================================================
--- webservices/wss4j/branches/1_6_x-fixes/src/test/java/org/apache/ws/security/saml/SamlTokenTest.java (original)
+++ webservices/wss4j/branches/1_6_x-fixes/src/test/java/org/apache/ws/security/saml/SamlTokenTest.java Fri Jul 26 14:30:37 2013
@@ -39,7 +39,6 @@ import org.apache.ws.security.saml.ext.S
 import org.apache.ws.security.saml.ext.bean.SubjectConfirmationDataBean;
 import org.apache.ws.security.saml.ext.builder.SAML1Constants;
 import org.apache.ws.security.util.WSSecurityUtil;
-
 import org.joda.time.DateTime;
 import org.opensaml.Configuration;
 import org.opensaml.common.SAMLObjectBuilder;
@@ -52,6 +51,7 @@ import org.w3c.dom.Document;
 
 import java.util.Collections;
 import java.util.List;
+import java.util.Properties;
 
 /**
  * Test-case for sending and processing an unsigned (sender vouches) SAML Assertion.
@@ -410,6 +410,58 @@ public class SamlTokenTest extends org.j
     }
     
     /**
+     * This test checks that an unsigned SAML1 sender-vouches authentication assertion
+     * can be created by the WSHandler implementation 
+     */
+    @org.junit.Test
+    public void testSaml1ActionRef() throws Exception {
+        final WSSConfig cfg = WSSConfig.getNewInstance();
+        final int action = WSConstants.ST_UNSIGNED;
+        final RequestData reqData = new RequestData();
+        reqData.setWssConfig(cfg);
+        java.util.Map<String, Object> config = new java.util.TreeMap<String, Object>();
+        
+        Properties props = new Properties();
+        props.put("org.apache.ws.security.saml.issuerClass", 
+                  "org.apache.ws.security.saml.SAMLIssuerImpl");
+        props.put("org.apache.ws.security.saml.issuer",
+                  "www.example.com");
+        props.put("org.apache.ws.security.saml.callback",
+                  "org.apache.ws.security.common.SAML1CallbackHandler");
+        
+        config.put(WSHandlerConstants.SAML_PROP_REF_ID, "RefId-" + props.hashCode());
+        reqData.setMsgContext(config);
+        
+        final java.util.List<Integer> actions = new java.util.ArrayList<Integer>();
+        actions.add(Integer.valueOf(action));
+        final Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
+        CustomHandler handler = new CustomHandler();
+        handler.setProperty(config, "RefId-" + props.hashCode(), props);
+        handler.send(
+            action, 
+            doc, 
+            reqData, 
+            actions,
+            true
+        );
+        String outputString = 
+            org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Unsigned SAML 1.1 authentication assertion via an Action:");
+            LOG.debug(outputString);
+        }
+        assertFalse (outputString.contains("Signature"));
+        
+        List<WSSecurityEngineResult> results = verify(doc);
+        WSSecurityEngineResult actionResult =
+            WSSecurityUtil.fetchActionResult(results, WSConstants.ST_UNSIGNED);
+        AssertionWrapper receivedAssertion = 
+            (AssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
+        assertTrue(receivedAssertion != null);
+        assertTrue(!receivedAssertion.isSigned());
+    }
+    
+    /**
      * Test that creates, sends and processes an unsigned SAML 1.1 authentication assertion.
      * The issuer is different from what the custom Validator is expecting, so it throws an
      * exception.