You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ws.apache.org by we...@apache.org on 2005/12/11 11:44:16 UTC

svn commit: r355956 - in /webservices/commons/trunk/policy/src/examples: PolicyExampleBindMsg.java SecurityPolicyBindings.xml SecurityPolicyMsg.xml SimplePolicyExample.java policy2.xml

Author: werner
Date: Sun Dec 11 02:44:09 2005
New Revision: 355956

URL: http://svn.apache.org/viewcvs?rev=355956&view=rev
Log:
Add a mor complex example to merge to policies. These policies
were copied from the WS-SecurityPolicy specification Appendix C.3

Added:
    webservices/commons/trunk/policy/src/examples/PolicyExampleBindMsg.java
    webservices/commons/trunk/policy/src/examples/SecurityPolicyBindings.xml
    webservices/commons/trunk/policy/src/examples/SecurityPolicyMsg.xml
Modified:
    webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java
    webservices/commons/trunk/policy/src/examples/policy2.xml

Added: webservices/commons/trunk/policy/src/examples/PolicyExampleBindMsg.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/examples/PolicyExampleBindMsg.java?rev=355956&view=auto
==============================================================================
--- webservices/commons/trunk/policy/src/examples/PolicyExampleBindMsg.java (added)
+++ webservices/commons/trunk/policy/src/examples/PolicyExampleBindMsg.java Sun Dec 11 02:44:09 2005
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package examples;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+
+import org.apache.ws.policy.model.Policy;
+import org.apache.ws.policy.util.PolicyReader;
+import org.apache.ws.policy.util.PolicyFactory;
+import org.apache.ws.policy.util.PolicyWriter;
+
+/**
+ * @author Werner Dittmann (werner@apache.org)
+ */
+
+public class PolicyExampleBindMsg {
+
+    public static void main(String[] args) throws Exception {
+
+        FileInputStream fisBinding = null;
+        if (args.length > 0) {
+            fisBinding = new FileInputStream(args[0]);
+        } else {
+            fisBinding = new FileInputStream("policy/src/examples/SecurityPolicyBindings.xml");
+        }
+
+        FileInputStream fisMsg = null;
+        if (args.length > 1) {
+            fisMsg = new FileInputStream(args[1]);
+        } else {
+            fisMsg = new FileInputStream("policy/src/examples/SecurityPolicyMsg.xml");
+        }
+        PolicyReader prdr = PolicyFactory
+                .getPolicyReader(PolicyFactory.OM_POLICY_READER);
+        PolicyWriter pwrt = PolicyFactory
+                .getPolicyWriter(PolicyFactory.StAX_POLICY_WRITER);
+
+        Policy binding = prdr.readPolicy(fisBinding);
+        binding = (Policy) binding.normalize();
+
+        Policy msg = prdr.readPolicy(fisMsg);
+        msg = (Policy) msg.normalize();
+        
+        Policy merged = (Policy) binding.merge(msg);
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        pwrt.writePolicy(merged, baos);
+
+        System.out.println(baos.toString());
+        System.out.println("-----\n");
+
+        fisBinding.close();
+        fisMsg.close();
+        /*
+         * Use standard Parser, w3c DOM
+         */
+//        if (args.length > 0) {
+//            fis = new FileInputStream(args[0]);
+//        } else {
+//            fis = new FileInputStream("policy/src/examples/policy2.xml");
+//        }
+//        prdr = PolicyFactory
+//                .getPolicyReader(PolicyFactory.DOM_POLICY_READER);
+//
+//        argOne = prdr.readPolicy(fis);
+//        norm = (Policy) argOne.normalize();
+//
+//        baos = new ByteArrayOutputStream();
+//        pwrt.writePolicy(norm, baos);
+//
+//        System.out.println("Policy Id: " + norm.getId());
+//        System.out.println("Policy base: " + norm.getBase());
+//        System.out.println(baos.toString());
+//
+//        fis.close();
+
+    }
+}

Added: webservices/commons/trunk/policy/src/examples/SecurityPolicyBindings.xml
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/examples/SecurityPolicyBindings.xml?rev=355956&view=auto
==============================================================================
--- webservices/commons/trunk/policy/src/examples/SecurityPolicyBindings.xml (added)
+++ webservices/commons/trunk/policy/src/examples/SecurityPolicyBindings.xml Sun Dec 11 02:44:09 2005
@@ -0,0 +1,50 @@
+
+<!-- Example Endpoint Policy --> 
+<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
+            xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"
+            xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
+<sp:AsymmetricBinding>
+ <wsp:Policy>
+ <sp:RecipientToken>
+ <wsp:Policy>
+ <sp:X509V3Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Always" />
+ </wsp:Policy> </sp:RecipientToken>
+ <sp:InitiatorToken>
+ <wsp:Policy>
+ <sp:X509V3Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Always" />
+ </wsp:Policy>
+ </sp:InitiatorToken>
+ <sp:AlgorithmSuite>
+ <wsp:Policy>
+ <sp:Basic256 />
+ </wsp:Policy>
+ </sp:AlgorithmSuite>
+ <sp:Layout>
+ <wsp:Policy>
+ <sp:Strict />
+ </wsp:Policy>
+ </sp:Layout>
+ <sp:IncludeTimestamp />
+ <sp:EncryptBeforeSigning />
+ <sp:EncryptSignature />
+ <sp:ProtectTokens />
+ <sp:SignedSupportingTokens>
+ <wsp:Policy>
+ <sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Once" />
+ </wsp:Policy>
+ </sp:SignedSupportingTokens>
+ <sp:SignedEndorsingSupportingTokens>
+ <wsp:Policy>
+ <sp:X509V3Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Once" />
+ </wsp:Policy>
+ </sp:SignedEndorsingSupportingTokens>
+ </wsp:Policy> 
+ </sp:AsymmetricBinding>
+ <sp:Wss11> 
+ <wsp:Policy>
+ <sp:RequireSignatureConfirmation />
+ </wsp:Policy>
+ </sp:Wss11>
+ </wsp:Policy>
+
+ 
\ No newline at end of file

Added: webservices/commons/trunk/policy/src/examples/SecurityPolicyMsg.xml
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/examples/SecurityPolicyMsg.xml?rev=355956&view=auto
==============================================================================
--- webservices/commons/trunk/policy/src/examples/SecurityPolicyMsg.xml (added)
+++ webservices/commons/trunk/policy/src/examples/SecurityPolicyMsg.xml Sun Dec 11 02:44:09 2005
@@ -0,0 +1,20 @@
+
+<!-- Example Endpoint Policy --> 
+<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
+            xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"
+            xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
+
+ <!-- Example Message Policy -->
+ <wsp:All>
+ <sp:SignedParts>
+ <sp:Header Name="Header1" Namespace="uri:namespace_1" />
+ <sp:Header Name="Header2" Namespace="uri:namespace_2" /> 
+ <sp:Body/>
+ </sp:SignedParts>
+ <sp:EncryptedParts>
+ <sp:Header Name="Header2" Namespace="uri:namespace_2" />
+ <sp:Body/>
+ </sp:EncryptedParts>
+ </wsp:All>
+ </wsp:Policy>
+ 
\ No newline at end of file

Modified: webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java?rev=355956&r1=355955&r2=355956&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java (original)
+++ webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java Sun Dec 11 02:44:09 2005
@@ -59,25 +59,25 @@
         /*
          * Use standard Parser, w3c DOM
          */
-        if (args.length > 0) {
-            fis = new FileInputStream(args[0]);
-        } else {
-            fis = new FileInputStream("policy/src/examples/policy2.xml");
-        }
-        prdr = PolicyFactory
-                .getPolicyReader(PolicyFactory.DOM_POLICY_READER);
-
-        argOne = prdr.readPolicy(fis);
-        norm = (Policy) argOne.normalize();
-
-        baos = new ByteArrayOutputStream();
-        pwrt.writePolicy(norm, baos);
-
-        System.out.println("Policy Id: " + norm.getId());
-        System.out.println("Policy base: " + norm.getBase());
-        System.out.println(baos.toString());
-
-        fis.close();
+//        if (args.length > 0) {
+//            fis = new FileInputStream(args[0]);
+//        } else {
+//            fis = new FileInputStream("policy/src/examples/policy2.xml");
+//        }
+//        prdr = PolicyFactory
+//                .getPolicyReader(PolicyFactory.DOM_POLICY_READER);
+//
+//        argOne = prdr.readPolicy(fis);
+//        norm = (Policy) argOne.normalize();
+//
+//        baos = new ByteArrayOutputStream();
+//        pwrt.writePolicy(norm, baos);
+//
+//        System.out.println("Policy Id: " + norm.getId());
+//        System.out.println("Policy base: " + norm.getBase());
+//        System.out.println(baos.toString());
+//
+//        fis.close();
 
     }
 }

Modified: webservices/commons/trunk/policy/src/examples/policy2.xml
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/examples/policy2.xml?rev=355956&r1=355955&r2=355956&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/examples/policy2.xml (original)
+++ webservices/commons/trunk/policy/src/examples/policy2.xml Sun Dec 11 02:44:09 2005
@@ -1,5 +1,5 @@
 <wsp:Policy xml:base="uri:thisBase" wsu:Id="myPolicy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
-            xmlns:sec="http://schemas.xmlsoap.org/ws/2002/12/secext"
+            xmlns:sec="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"
             xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" >
   <!-- 2 -->
   <sec:SecurityToken>