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 2011/12/04 21:33:12 UTC

svn commit: r1210203 [4/16] - in /webservices/wss4j/branches/swssf/rampart-policy: ./ src/main/java/META-INF/ src/main/java/org/apache/ws/secpolicy/ src/main/java/org/apache/ws/secpolicy/builders/ src/main/java/org/apache/ws/secpolicy/model/ src/main/j...

Modified: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/LayoutBuilder.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/LayoutBuilder.java?rev=1210203&r1=1197660&r2=1210203&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/LayoutBuilder.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/LayoutBuilder.java Sun Dec  4 20:33:05 2011
@@ -1,71 +1,57 @@
-/*
- * Copyright 2001-2004 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.
+/**
+ * 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.ws.secpolicy12.builders;
+package org.apache.ws.secpolicy.builders;
 
-import java.util.Iterator;
-import java.util.List;
-
-import javax.xml.namespace.QName;
-
-import org.apache.axiom.om.OMElement;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.AssertionBuilderFactory;
 import org.apache.neethi.Policy;
-import org.apache.neethi.PolicyEngine;
 import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.secpolicy.SP11Constants;
+import org.apache.ws.secpolicy.SP13Constants;
 import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.SP12Constants;
+import org.apache.ws.secpolicy.SPUtils;
 import org.apache.ws.secpolicy.model.Layout;
+import org.w3c.dom.Element;
 
-public class LayoutBuilder implements AssertionBuilder<OMElement> {
-    
-    public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
-        Layout layout = new Layout(SPConstants.SP_V12);
-        
-        Policy policy = PolicyEngine.getPolicy(element.getFirstElement());
-        policy = (Policy) policy.normalize(false);
-        
-        for (Iterator iterator = policy.getAlternatives(); iterator.hasNext(); ) {
-            processAlternative((List) iterator.next(), layout);         
-            break; // there should be only one alternative
-        }
-                        
+import javax.xml.namespace.QName;
+
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class LayoutBuilder implements AssertionBuilder<Element> {
+
+    public Assertion build(Element element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+
+        final SPConstants.SPVersion spVersion = SPConstants.SPVersion.getSPVersion(element.getNamespaceURI());
+        final Element nestedPolicyElement = SPUtils.getFirstPolicyChildElement(element);
+        final Policy nestedPolicy = nestedPolicyElement != null ? factory.getPolicyEngine().getPolicy(nestedPolicyElement) : new Policy();
+        Layout layout = new Layout(
+                spVersion,
+                nestedPolicy
+        );
+        layout.setOptional(SPUtils.isOptional(element));
+        layout.setIgnorable(SPUtils.isIgnorable(element));
         return layout;
     }
-    
-    public QName[] getKnownElements() {
-        return new QName[] {SP12Constants.LAYOUT};
-    }
 
-    public void processAlternative(List assertions, Layout parent) {
-        
-        for (Iterator iterator = assertions.iterator(); iterator.hasNext();) {
-            Assertion assertion = (Assertion) iterator.next();
-            QName qname = assertion.getName();
-            
-            if (SP12Constants.STRICT.equals(qname)) {
-                parent.setValue(SPConstants.LAYOUT_STRICT);
-            } else if (SP12Constants.LAX.equals(qname)) {
-                parent.setValue(SPConstants.LAYOUT_LAX);
-            } else if (SP12Constants.LAXTSFIRST.equals(qname)) {
-                parent.setValue(SPConstants.LAYOUT_LAX_TIMESTAMP_FIRST);
-            } else if (SP12Constants.LAXTSLAST.equals(qname)) {
-                parent.setValue(SPConstants.LAYOUT_LAX_TIMESTAMP_LAST);
-            }
-            
-        }
+    public QName[] getKnownElements() {
+        return new QName[]{SP13Constants.LAYOUT, SP11Constants.LAYOUT};
     }
 }

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/LayoutBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/ProtectionTokenBuilder.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/ProtectionTokenBuilder.java?rev=1210203&r1=1197660&r2=1210203&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/ProtectionTokenBuilder.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/ProtectionTokenBuilder.java Sun Dec  4 20:33:05 2011
@@ -1,61 +1,56 @@
-/*
- * Copyright 2001-2004 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.
+/**
+ * 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.ws.secpolicy12.builders;
+package org.apache.ws.secpolicy.builders;
 
-import java.util.Iterator;
-import java.util.List;
-
-import javax.xml.namespace.QName;
-
-import org.apache.axiom.om.OMElement;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.AssertionBuilderFactory;
 import org.apache.neethi.Policy;
-import org.apache.neethi.PolicyEngine;
 import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.secpolicy.SP11Constants;
+import org.apache.ws.secpolicy.SP13Constants;
 import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.SP12Constants;
+import org.apache.ws.secpolicy.SPUtils;
 import org.apache.ws.secpolicy.model.ProtectionToken;
-import org.apache.ws.secpolicy.model.Token;
+import org.w3c.dom.Element;
 
-public class ProtectionTokenBuilder implements AssertionBuilder<OMElement> {
+import javax.xml.namespace.QName;
 
-    public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
-        ProtectionToken protectionToken = new ProtectionToken(SPConstants.SP_V12);
-        
-        Policy policy = PolicyEngine.getPolicy(element.getFirstElement());
-        policy = (Policy) policy.normalize(false);
-        
-        for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
-            processAlternative((List) iterator.next(), protectionToken);
-            break; // since there should be only one alternative ..
-        }
-        
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class ProtectionTokenBuilder implements AssertionBuilder<Element> {
+
+    public Assertion build(Element element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+        final SPConstants.SPVersion spVersion = SPConstants.SPVersion.getSPVersion(element.getNamespaceURI());
+        final Element nestedPolicyElement = SPUtils.getFirstPolicyChildElement(element);
+        final Policy nestedPolicy = nestedPolicyElement != null ? factory.getPolicyEngine().getPolicy(nestedPolicyElement) : new Policy();
+        ProtectionToken protectionToken = new ProtectionToken(
+                spVersion,
+                nestedPolicy
+        );
+        protectionToken.setOptional(SPUtils.isOptional(element));
+        protectionToken.setIgnorable(SPUtils.isIgnorable(element));
         return protectionToken;
     }
-        
-    public QName[] getKnownElements() {
-        return new QName[] {SP12Constants.PROTECTION_TOKEN};
-    }
 
-    private void processAlternative(List assertions, ProtectionToken parent) {
-        Object token = assertions.get(0);
-        
-        if (token instanceof Token) {
-            parent.setToken((Token) token);
-        }
+    public QName[] getKnownElements() {
+        return new QName[]{SP13Constants.PROTECTION_TOKEN, SP11Constants.PROTECTION_TOKEN};
     }
 }

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/ProtectionTokenBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientEncryptionTokenBuilder.java (from r1197660, axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy12/builders/RecipientTokenBuilder.java)
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientEncryptionTokenBuilder.java?p2=webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientEncryptionTokenBuilder.java&p1=axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy12/builders/RecipientTokenBuilder.java&r1=1197660&r2=1210203&rev=1210203&view=diff
==============================================================================
--- axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy12/builders/RecipientTokenBuilder.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientEncryptionTokenBuilder.java Sun Dec  4 20:33:05 2011
@@ -1,72 +1,57 @@
-/*
- * Copyright 2001-2004 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.
+/**
+ * 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.ws.secpolicy12.builders;
+package org.apache.ws.secpolicy.builders;
 
-import java.util.Iterator;
-import java.util.List;
-
-import javax.xml.namespace.QName;
-
-import org.apache.axiom.om.OMElement;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.AssertionBuilderFactory;
 import org.apache.neethi.Policy;
-import org.apache.neethi.PolicyEngine;
 import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.secpolicy.SP13Constants;
 import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.SP12Constants;
-import org.apache.ws.secpolicy.model.RecipientToken;
-import org.apache.ws.secpolicy.model.Token;
-
-public class RecipientTokenBuilder implements AssertionBuilder<OMElement> {
-
-    public Assertion build(OMElement element, AssertionBuilderFactory factory)
-            throws IllegalArgumentException {
-        RecipientToken recipientToken = new RecipientToken(SPConstants.SP_V12);
-        
-        Policy policy = PolicyEngine.getPolicy(element.getFirstElement());
-        policy = (Policy) policy.normalize(false);
-        
-        for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
-            processAlternative((List) iterator.next(), recipientToken);
-            
-            /* 
-             * for the moment we will pick the first token specified in the policy
-             */
-            break;   
-        }
-        
-        return recipientToken;
-    }
+import org.apache.ws.secpolicy.SPUtils;
+import org.apache.ws.secpolicy.model.RecipientEncryptionToken;
+import org.w3c.dom.Element;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class RecipientEncryptionTokenBuilder implements AssertionBuilder<Element> {
 
-    private void processAlternative(List assertions, RecipientToken parent) {
-        
-        Assertion assertion;
-        
-        for (Iterator iterator = assertions.iterator(); iterator.hasNext();) {
-            assertion = (Assertion) iterator.next();
-            
-            if (assertion instanceof Token) {
-                parent.setToken((Token) assertion);
-            }
-        }        
+    public Assertion build(Element element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+
+        final SPConstants.SPVersion spVersion = SPConstants.SPVersion.getSPVersion(element.getNamespaceURI());
+        final Element nestedPolicyElement = SPUtils.getFirstPolicyChildElement(element);
+        final Policy nestedPolicy = nestedPolicyElement != null ? factory.getPolicyEngine().getPolicy(nestedPolicyElement) : new Policy();
+        RecipientEncryptionToken recipientEncryptionToken = new RecipientEncryptionToken(
+                spVersion,
+                nestedPolicy
+        );
+        recipientEncryptionToken.setOptional(SPUtils.isOptional(element));
+        recipientEncryptionToken.setIgnorable(SPUtils.isIgnorable(element));
+        return recipientEncryptionToken;
     }
-    
+
     public QName[] getKnownElements() {
-        return new QName[] {SP12Constants.RECIPIENT_TOKEN};
+        return new QName[]{SP13Constants.RECIPIENT_ENCRYPTION_TOKEN};
     }
 
 }

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientEncryptionTokenBuilder.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientEncryptionTokenBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientSignatureTokenBuilder.java (from r1197660, axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy12/builders/RecipientTokenBuilder.java)
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientSignatureTokenBuilder.java?p2=webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientSignatureTokenBuilder.java&p1=axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy12/builders/RecipientTokenBuilder.java&r1=1197660&r2=1210203&rev=1210203&view=diff
==============================================================================
--- axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy12/builders/RecipientTokenBuilder.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientSignatureTokenBuilder.java Sun Dec  4 20:33:05 2011
@@ -1,72 +1,57 @@
-/*
- * Copyright 2001-2004 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.
+/**
+ * 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.ws.secpolicy12.builders;
+package org.apache.ws.secpolicy.builders;
 
-import java.util.Iterator;
-import java.util.List;
-
-import javax.xml.namespace.QName;
-
-import org.apache.axiom.om.OMElement;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.AssertionBuilderFactory;
 import org.apache.neethi.Policy;
-import org.apache.neethi.PolicyEngine;
 import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.secpolicy.SP13Constants;
 import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.SP12Constants;
-import org.apache.ws.secpolicy.model.RecipientToken;
-import org.apache.ws.secpolicy.model.Token;
-
-public class RecipientTokenBuilder implements AssertionBuilder<OMElement> {
-
-    public Assertion build(OMElement element, AssertionBuilderFactory factory)
-            throws IllegalArgumentException {
-        RecipientToken recipientToken = new RecipientToken(SPConstants.SP_V12);
-        
-        Policy policy = PolicyEngine.getPolicy(element.getFirstElement());
-        policy = (Policy) policy.normalize(false);
-        
-        for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
-            processAlternative((List) iterator.next(), recipientToken);
-            
-            /* 
-             * for the moment we will pick the first token specified in the policy
-             */
-            break;   
-        }
-        
-        return recipientToken;
-    }
+import org.apache.ws.secpolicy.SPUtils;
+import org.apache.ws.secpolicy.model.RecipientSignatureToken;
+import org.w3c.dom.Element;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class RecipientSignatureTokenBuilder implements AssertionBuilder<Element> {
 
-    private void processAlternative(List assertions, RecipientToken parent) {
-        
-        Assertion assertion;
-        
-        for (Iterator iterator = assertions.iterator(); iterator.hasNext();) {
-            assertion = (Assertion) iterator.next();
-            
-            if (assertion instanceof Token) {
-                parent.setToken((Token) assertion);
-            }
-        }        
+    public Assertion build(Element element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+
+        final SPConstants.SPVersion spVersion = SPConstants.SPVersion.getSPVersion(element.getNamespaceURI());
+        final Element nestedPolicyElement = SPUtils.getFirstPolicyChildElement(element);
+        final Policy nestedPolicy = nestedPolicyElement != null ? factory.getPolicyEngine().getPolicy(nestedPolicyElement) : new Policy();
+        RecipientSignatureToken recipientSignatureToken = new RecipientSignatureToken(
+                spVersion,
+                nestedPolicy
+        );
+        recipientSignatureToken.setOptional(SPUtils.isOptional(element));
+        recipientSignatureToken.setIgnorable(SPUtils.isIgnorable(element));
+        return recipientSignatureToken;
     }
-    
+
     public QName[] getKnownElements() {
-        return new QName[] {SP12Constants.RECIPIENT_TOKEN};
+        return new QName[]{SP13Constants.RECIPIENT_SIGNATURE_TOKEN};
     }
 
 }

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientSignatureTokenBuilder.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientSignatureTokenBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientTokenBuilder.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientTokenBuilder.java?rev=1210203&r1=1197660&r2=1210203&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientTokenBuilder.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientTokenBuilder.java Sun Dec  4 20:33:05 2011
@@ -1,72 +1,58 @@
-/*
- * Copyright 2001-2004 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.
+/**
+ * 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.ws.secpolicy12.builders;
+package org.apache.ws.secpolicy.builders;
 
-import java.util.Iterator;
-import java.util.List;
-
-import javax.xml.namespace.QName;
-
-import org.apache.axiom.om.OMElement;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.AssertionBuilderFactory;
 import org.apache.neethi.Policy;
-import org.apache.neethi.PolicyEngine;
 import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.secpolicy.SP11Constants;
+import org.apache.ws.secpolicy.SP13Constants;
 import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.SP12Constants;
+import org.apache.ws.secpolicy.SPUtils;
 import org.apache.ws.secpolicy.model.RecipientToken;
-import org.apache.ws.secpolicy.model.Token;
+import org.w3c.dom.Element;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class RecipientTokenBuilder implements AssertionBuilder<Element> {
 
-public class RecipientTokenBuilder implements AssertionBuilder<OMElement> {
+    public Assertion build(Element element, AssertionBuilderFactory factory) throws IllegalArgumentException {
 
-    public Assertion build(OMElement element, AssertionBuilderFactory factory)
-            throws IllegalArgumentException {
-        RecipientToken recipientToken = new RecipientToken(SPConstants.SP_V12);
-        
-        Policy policy = PolicyEngine.getPolicy(element.getFirstElement());
-        policy = (Policy) policy.normalize(false);
-        
-        for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
-            processAlternative((List) iterator.next(), recipientToken);
-            
-            /* 
-             * for the moment we will pick the first token specified in the policy
-             */
-            break;   
-        }
-        
+        final SPConstants.SPVersion spVersion = SPConstants.SPVersion.getSPVersion(element.getNamespaceURI());
+        final Element nestedPolicyElement = SPUtils.getFirstPolicyChildElement(element);
+        final Policy nestedPolicy = nestedPolicyElement != null ? factory.getPolicyEngine().getPolicy(nestedPolicyElement) : new Policy();
+        RecipientToken recipientToken = new RecipientToken(
+                spVersion,
+                nestedPolicy
+        );
+        recipientToken.setOptional(SPUtils.isOptional(element));
+        recipientToken.setIgnorable(SPUtils.isIgnorable(element));
         return recipientToken;
     }
 
-    private void processAlternative(List assertions, RecipientToken parent) {
-        
-        Assertion assertion;
-        
-        for (Iterator iterator = assertions.iterator(); iterator.hasNext();) {
-            assertion = (Assertion) iterator.next();
-            
-            if (assertion instanceof Token) {
-                parent.setToken((Token) assertion);
-            }
-        }        
-    }
-    
     public QName[] getKnownElements() {
-        return new QName[] {SP12Constants.RECIPIENT_TOKEN};
+        return new QName[]{SP13Constants.RECIPIENT_TOKEN, SP11Constants.RECIPIENT_TOKEN};
     }
 
 }

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RecipientTokenBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RelTokenBuilder.java (from r1197660, axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy12/builders/HttpsTokenBuilder.java)
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RelTokenBuilder.java?p2=webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RelTokenBuilder.java&p1=axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy12/builders/HttpsTokenBuilder.java&r1=1197660&r2=1210203&rev=1210203&view=diff
==============================================================================
--- axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy12/builders/HttpsTokenBuilder.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RelTokenBuilder.java Sun Dec  4 20:33:05 2011
@@ -1,102 +1,71 @@
-/*
- * Copyright 2001-2004 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.
+/**
+ * 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.ws.secpolicy12.builders;
+package org.apache.ws.secpolicy.builders;
 
-import org.apache.axiom.om.OMElement;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.AssertionBuilderFactory;
 import org.apache.neethi.Policy;
-import org.apache.neethi.PolicyEngine;
 import org.apache.neethi.builders.AssertionBuilder;
-import org.apache.ws.secpolicy.SP12Constants;
+import org.apache.ws.secpolicy.SP11Constants;
+import org.apache.ws.secpolicy.SP13Constants;
 import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.model.HttpsToken;
+import org.apache.ws.secpolicy.SPUtils;
+import org.apache.ws.secpolicy.model.RelToken;
+import org.w3c.dom.Element;
 
 import javax.xml.namespace.QName;
-import java.util.Iterator;
-import java.util.List;
 
 /**
- * This is a standard assertion builder implementation for the https token 
- * as specified by the ws security policy 1.2 specification. In order for this builder to be used
- * it is required that the security policy namespace uri is {@link SP12Constants#SP_NS} 
- * The builder will handle
- * <ul>
- *  <li><code>HttpBasicAuthentication</code></li>
- *  <li><code>HttpDigestAuthentication</code></li>
- *  <li><code>RequireClientCertificate</code></li>
- * </ul> 
- * alternatives in the HttpsToken considering both cases whether the policy is normalized or not.
- * 
+ * @author $Author$
+ * @version $Revision$ $Date$
  */
-public class HttpsTokenBuilder implements AssertionBuilder<OMElement> {
-    
-    /**
-     * {@inheritDoc}
-     */
-    public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
-        HttpsToken httpsToken = new HttpsToken(SPConstants.SP_V12);
-
-        if (element.getFirstElement()!= null) {
-            Policy policy = PolicyEngine.getPolicy(element.getFirstElement());
-            policy = (Policy) policy.normalize(false);
-
-            for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
-                processAlternative((List) iterator.next(), httpsToken);
-                break; // since there should be only one alternative
-            }
-        }
+public class RelTokenBuilder implements AssertionBuilder<Element> {
 
-        return httpsToken;
+    public Assertion build(Element element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+
+        final SPConstants.SPVersion spVersion = SPConstants.SPVersion.getSPVersion(element.getNamespaceURI());
+        final String includeTokenValue = SPUtils.getAttribute(element, spVersion.getSPConstants().getIncludeToken());
+        final Element issuer = SPUtils.getFirstChildElement(element, spVersion.getSPConstants().getIssuer());
+        if (spVersion == SPConstants.SPVersion.SP11 && issuer != null) {
+            throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+        }
+        final String issuerName = SPUtils.getFirstChildElementText(element, spVersion.getSPConstants().getIssuerName());
+        if (spVersion == SPConstants.SPVersion.SP11 && issuerName != null) {
+            throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+        }
+        final Element nestedPolicyElement = SPUtils.getFirstPolicyChildElement(element);
+        final Element claims = SPUtils.getFirstChildElement(element, spVersion.getSPConstants().getClaims());
+        final Policy nestedPolicy = nestedPolicyElement != null ? factory.getPolicyEngine().getPolicy(nestedPolicyElement) : new Policy();
+        RelToken relToken = new RelToken(
+                spVersion,
+                spVersion.getSPConstants().getInclusionFromAttributeValue(includeTokenValue),
+                issuer,
+                issuerName,
+                claims,
+                nestedPolicy
+        );
+        relToken.setOptional(SPUtils.isOptional(element));
+        relToken.setIgnorable(SPUtils.isIgnorable(element));
+        return relToken;
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public QName[] getKnownElements() {
-        return new QName[] {SP12Constants.HTTPS_TOKEN};
-    }
-    
-    /**
-     * Process policy alternatives inside the HttpsToken element.
-     * Essentially this method will search for<br>
-     * <ul>
-     *  <li><code>HttpBasicAuthentication</code></li>
-     *  <li><code>HttpDigestAuthentication</code></li>
-     *  <li><code>RequireClientCertificate</code></li>
-     * </ul>
-     * elements.
-     * @param assertions the list of assertions to be searched through.
-     * @param parent the https token, that is to be populated with retrieved data.
-     */
-    private void processAlternative(List assertions, HttpsToken parent) {
-        
-        for (Iterator iterator = assertions.iterator(); iterator.hasNext();) {
-            Assertion primtive = (Assertion) iterator.next();
-            QName qname = primtive.getName();
-            
-            if (qname != null) {
-                if (SP12Constants.HTTP_BASIC_AUTHENTICATION.equals(qname)) {
-                    parent.setHttpBasicAuthentication(true);
-                } else if (SP12Constants.HTTP_DIGEST_AUTHENTICATION.equals(qname)) {
-                    parent.setHttpDigestAuthentication(true);
-                } else if (SP12Constants.REQUIRE_CLIENT_CERTIFICATE.equals(qname)) {
-                    parent.setRequireClientCertificate(true);
-                }
-            }
-        }
+        return new QName[]{SP13Constants.REL_TOKEN, SP11Constants.REL_TOKEN};
     }
 }

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RelTokenBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RequiredElementsBuilder.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RequiredElementsBuilder.java?rev=1210203&r1=1197660&r2=1210203&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RequiredElementsBuilder.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RequiredElementsBuilder.java Sun Dec  4 20:33:05 2011
@@ -1,68 +1,54 @@
-/*
- * Copyright 2001-2004 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.
+/**
+ * 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.ws.secpolicy12.builders;
+package org.apache.ws.secpolicy.builders;
 
-import java.util.Iterator;
-
-import javax.xml.namespace.QName;
-
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMNamespace;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.AssertionBuilderFactory;
-import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.secpolicy.SP11Constants;
+import org.apache.ws.secpolicy.SP13Constants;
 import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.SP12Constants;
-import org.apache.ws.secpolicy.model.ContentEncryptedElements;
+import org.apache.ws.secpolicy.SPUtils;
 import org.apache.ws.secpolicy.model.RequiredElements;
+import org.apache.ws.secpolicy.model.XPath;
+import org.w3c.dom.Element;
+
+import javax.xml.namespace.QName;
+import java.util.List;
 
-public class RequiredElementsBuilder implements AssertionBuilder<OMElement> {
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class RequiredElementsBuilder extends SignedElementsBuilder {
+
+    public Assertion build(Element element, AssertionBuilderFactory factory) throws IllegalArgumentException {
 
-    
-    public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
-        
-        RequiredElements requiredElements = new RequiredElements(SPConstants.SP_V12);
-        OMAttribute attrXPathVersion = element.getAttribute(SP12Constants.ATTR_XPATH_VERSION);
-        
-        if (attrXPathVersion != null) {
-            requiredElements.setXPathVersion(attrXPathVersion.getAttributeValue());
-        }
-        
-        for (Iterator iterator = element.getChildElements(); iterator.hasNext();) {
-            processElement((OMElement) iterator.next(),requiredElements);            
-        }
-        
+        final SPConstants.SPVersion spVersion = SPConstants.SPVersion.getSPVersion(element.getNamespaceURI());
+        final String xPathVersion = getXPathVersion(element);
+        final List<XPath> xPaths = getXPathExpressions(element, spVersion);
+        RequiredElements requiredElements = new RequiredElements(spVersion, xPathVersion, xPaths);
+        requiredElements.setOptional(SPUtils.isOptional(element));
+        requiredElements.setIgnorable(SPUtils.isIgnorable(element));
         return requiredElements;
     }
-        
-    public QName[] getKnownElements() {
-        return new QName[] {SP12Constants.REQUIRED_ELEMENTS};
-    }
 
-    private void processElement(OMElement element, RequiredElements parent) {
-        QName name = element.getQName();
-        if (SP12Constants.XPATH.equals(name)) {
-            parent.addXPathExpression(element.getText());
-            Iterator namespaces = element.getNamespacesInScope();
-            while (namespaces.hasNext()) {
-                OMNamespace nm = (OMNamespace) namespaces.next();
-                parent.addDeclaredNamespaces(nm.getNamespaceURI(), nm.getPrefix());
-            }
-        }
+    public QName[] getKnownElements() {
+        return new QName[]{SP13Constants.REQUIRED_ELEMENTS, SP11Constants.REQUIRED_ELEMENTS};
     }
-    
 }

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RequiredElementsBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RequiredPartsBuilder.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RequiredPartsBuilder.java?rev=1210203&r1=1197660&r2=1210203&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RequiredPartsBuilder.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RequiredPartsBuilder.java Sun Dec  4 20:33:05 2011
@@ -1,68 +1,76 @@
-/*
- * Copyright 2001-2004 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.
+/**
+ * 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.ws.secpolicy12.builders;
+package org.apache.ws.secpolicy.builders;
 
-import java.util.Iterator;
-
-import javax.xml.namespace.QName;
-
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMElement;
+import org.apache.commons.lang.StringUtils;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.AssertionBuilderFactory;
 import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.secpolicy.SP13Constants;
 import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.SP12Constants;
+import org.apache.ws.secpolicy.SPUtils;
 import org.apache.ws.secpolicy.model.Header;
 import org.apache.ws.secpolicy.model.RequiredParts;
-import org.apache.ws.secpolicy.model.SignedEncryptedParts;
+import org.w3c.dom.Element;
 
-public class RequiredPartsBuilder implements AssertionBuilder<OMElement> {
-        
-    public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
-        RequiredParts requiredParts = new RequiredParts(SPConstants.SP_V12);
-        
-        for (Iterator iterator = element.getChildElements(); iterator.hasNext();) {
-            processElement((OMElement) iterator.next(), requiredParts);
-        }
-        
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class RequiredPartsBuilder implements AssertionBuilder<Element> {
+
+    public Assertion build(Element element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+
+        final SPConstants.SPVersion spVersion = SPConstants.SPVersion.getSPVersion(element.getNamespaceURI());
+
+        final List<Header> headers = getHeaders(element, spVersion);
+        RequiredParts requiredParts = new RequiredParts(spVersion, headers);
+        requiredParts.setOptional(SPUtils.isOptional(element));
+        requiredParts.setIgnorable(SPUtils.isIgnorable(element));
         return requiredParts;
     }
-       
-    public QName[] getKnownElements() {
-        return new QName[] {SP12Constants.REQUIRED_PARTS};
-    }
 
-    private void processElement(OMElement element, RequiredParts parent) {
-        
-        QName name = element.getQName();
-        
-        if (SP12Constants.HEADER.equals(name)) {
-            Header header = new Header();
-            
-            OMAttribute nameAttribute = element.getAttribute(SPConstants.NAME);
-            if( nameAttribute != null ) {
-                header.setName(nameAttribute.getAttributeValue());
+    protected List<Header> getHeaders(Element element, SPConstants.SPVersion spVersion) {
+        List<Header> headers = new ArrayList<Header>();
+        Element child = SPUtils.getFirstChildElement(element);
+        while (child != null) {
+            if (SPConstants.HEADER.equals(child.getLocalName()) && spVersion.getNamespace().equals(child.getNamespaceURI())) {
+                String headerName = child.getAttribute(SPConstants.NAME);
+                if ("".equals(headerName)) {
+                    headerName = null;
+                }
+                String headerNamespace = child.getAttribute(SPConstants.NAMESPACE);
+                if (StringUtils.isEmpty(headerNamespace)) {
+                    throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+                }
+                headers.add(new Header(headerName, headerNamespace));
             }
-            
-            OMAttribute namespaceAttribute = element.getAttribute(SPConstants.NAMESPACE);
-            header.setNamespace(namespaceAttribute.getAttributeValue());
-            
-            parent.addHeader(header);
-            
+            child = SPUtils.getNextSiblingElement(child);
         }
+        return headers;
+    }
+
+    public QName[] getKnownElements() {
+        return new QName[]{SP13Constants.REQUIRED_PARTS};
     }
 }

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/RequiredPartsBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SamlTokenBuilder.java (from r1197660, axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy12/builders/HttpsTokenBuilder.java)
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SamlTokenBuilder.java?p2=webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SamlTokenBuilder.java&p1=axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy12/builders/HttpsTokenBuilder.java&r1=1197660&r2=1210203&rev=1210203&view=diff
==============================================================================
--- axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy12/builders/HttpsTokenBuilder.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SamlTokenBuilder.java Sun Dec  4 20:33:05 2011
@@ -1,102 +1,71 @@
-/*
- * Copyright 2001-2004 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.
+/**
+ * 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.ws.secpolicy12.builders;
+package org.apache.ws.secpolicy.builders;
 
-import org.apache.axiom.om.OMElement;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.AssertionBuilderFactory;
 import org.apache.neethi.Policy;
-import org.apache.neethi.PolicyEngine;
 import org.apache.neethi.builders.AssertionBuilder;
-import org.apache.ws.secpolicy.SP12Constants;
+import org.apache.ws.secpolicy.SP11Constants;
+import org.apache.ws.secpolicy.SP13Constants;
 import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.model.HttpsToken;
+import org.apache.ws.secpolicy.SPUtils;
+import org.apache.ws.secpolicy.model.SamlToken;
+import org.w3c.dom.Element;
 
 import javax.xml.namespace.QName;
-import java.util.Iterator;
-import java.util.List;
 
 /**
- * This is a standard assertion builder implementation for the https token 
- * as specified by the ws security policy 1.2 specification. In order for this builder to be used
- * it is required that the security policy namespace uri is {@link SP12Constants#SP_NS} 
- * The builder will handle
- * <ul>
- *  <li><code>HttpBasicAuthentication</code></li>
- *  <li><code>HttpDigestAuthentication</code></li>
- *  <li><code>RequireClientCertificate</code></li>
- * </ul> 
- * alternatives in the HttpsToken considering both cases whether the policy is normalized or not.
- * 
+ * @author $Author$
+ * @version $Revision$ $Date$
  */
-public class HttpsTokenBuilder implements AssertionBuilder<OMElement> {
-    
-    /**
-     * {@inheritDoc}
-     */
-    public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
-        HttpsToken httpsToken = new HttpsToken(SPConstants.SP_V12);
-
-        if (element.getFirstElement()!= null) {
-            Policy policy = PolicyEngine.getPolicy(element.getFirstElement());
-            policy = (Policy) policy.normalize(false);
-
-            for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
-                processAlternative((List) iterator.next(), httpsToken);
-                break; // since there should be only one alternative
-            }
-        }
+public class SamlTokenBuilder implements AssertionBuilder<Element> {
 
-        return httpsToken;
+    public Assertion build(Element element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+
+        final SPConstants.SPVersion spVersion = SPConstants.SPVersion.getSPVersion(element.getNamespaceURI());
+        final String includeTokenValue = SPUtils.getAttribute(element, spVersion.getSPConstants().getIncludeToken());
+        final Element issuer = SPUtils.getFirstChildElement(element, spVersion.getSPConstants().getIssuer());
+        if (spVersion == SPConstants.SPVersion.SP11 && issuer != null) {
+            throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+        }
+        final String issuerName = SPUtils.getFirstChildElementText(element, spVersion.getSPConstants().getIssuerName());
+        if (spVersion == SPConstants.SPVersion.SP11 && issuerName != null) {
+            throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+        }
+        final Element claims = SPUtils.getFirstChildElement(element, spVersion.getSPConstants().getClaims());
+        final Element nestedPolicyElement = SPUtils.getFirstPolicyChildElement(element);
+        final Policy nestedPolicy = nestedPolicyElement != null ? factory.getPolicyEngine().getPolicy(nestedPolicyElement) : new Policy();
+        SamlToken samlToken = new SamlToken(
+                spVersion,
+                spVersion.getSPConstants().getInclusionFromAttributeValue(includeTokenValue),
+                issuer,
+                issuerName,
+                claims,
+                nestedPolicy
+        );
+        samlToken.setOptional(SPUtils.isOptional(element));
+        samlToken.setIgnorable(SPUtils.isIgnorable(element));
+        return samlToken;
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public QName[] getKnownElements() {
-        return new QName[] {SP12Constants.HTTPS_TOKEN};
-    }
-    
-    /**
-     * Process policy alternatives inside the HttpsToken element.
-     * Essentially this method will search for<br>
-     * <ul>
-     *  <li><code>HttpBasicAuthentication</code></li>
-     *  <li><code>HttpDigestAuthentication</code></li>
-     *  <li><code>RequireClientCertificate</code></li>
-     * </ul>
-     * elements.
-     * @param assertions the list of assertions to be searched through.
-     * @param parent the https token, that is to be populated with retrieved data.
-     */
-    private void processAlternative(List assertions, HttpsToken parent) {
-        
-        for (Iterator iterator = assertions.iterator(); iterator.hasNext();) {
-            Assertion primtive = (Assertion) iterator.next();
-            QName qname = primtive.getName();
-            
-            if (qname != null) {
-                if (SP12Constants.HTTP_BASIC_AUTHENTICATION.equals(qname)) {
-                    parent.setHttpBasicAuthentication(true);
-                } else if (SP12Constants.HTTP_DIGEST_AUTHENTICATION.equals(qname)) {
-                    parent.setHttpDigestAuthentication(true);
-                } else if (SP12Constants.REQUIRE_CLIENT_CERTIFICATE.equals(qname)) {
-                    parent.setRequireClientCertificate(true);
-                }
-            }
-        }
+        return new QName[]{SP13Constants.SAML_TOKEN, SP11Constants.SAML_TOKEN};
     }
 }

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SamlTokenBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SecureConversationTokenBuilder.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SecureConversationTokenBuilder.java?rev=1210203&r1=1197660&r2=1210203&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SecureConversationTokenBuilder.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SecureConversationTokenBuilder.java Sun Dec  4 20:33:05 2011
@@ -1,86 +1,68 @@
-/*
- * Copyright 2001-2004 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.
+/**
+ * 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.ws.secpolicy12.builders;
+package org.apache.ws.secpolicy.builders;
 
-import javax.xml.namespace.QName;
-
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMElement;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.AssertionBuilderFactory;
 import org.apache.neethi.Policy;
-import org.apache.neethi.PolicyEngine;
 import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.secpolicy.SP11Constants;
+import org.apache.ws.secpolicy.SP13Constants;
 import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.SP12Constants;
+import org.apache.ws.secpolicy.SPUtils;
 import org.apache.ws.secpolicy.model.SecureConversationToken;
+import org.w3c.dom.Element;
 
-public class SecureConversationTokenBuilder implements AssertionBuilder<OMElement> {
+import javax.xml.namespace.QName;
 
-    public Assertion build(OMElement element, AssertionBuilderFactory factory)
-            throws IllegalArgumentException {
-        SecureConversationToken conversationToken = new SecureConversationToken(SPConstants.SP_V12);
-        
-        OMAttribute attribute = element.getAttribute(SP12Constants.INCLUDE_TOKEN);
-        if (attribute == null) {
-            throw new IllegalArgumentException(
-                    "SecurityContextToken doesn't contain any sp:IncludeToken attribute");
-        }
-        
-        String inclusionValue = attribute.getAttributeValue().trim();
-        
-        conversationToken.setInclusion(SP12Constants.getInclusionFromAttributeValue(inclusionValue));
-        
-        OMElement issuer = element.getFirstChildWithName(SP12Constants.ISSUER);
-        if ( issuer != null) {
-            conversationToken.setIssuerEpr(issuer.getFirstElement());
-        }
-        
-        element = element.getFirstChildWithName(SPConstants.POLICY);
-        if (element != null) {
-            if (element.getFirstChildWithName(SP12Constants.REQUIRE_DERIVED_KEYS) != null) {
-                conversationToken.setDerivedKeys(true);
-            } else if (element.getFirstChildWithName(SP12Constants.REQUIRE_IMPLIED_DERIVED_KEYS) != null) {
-                conversationToken.setImpliedDerivedKeys(true);
-            } else if (element.getFirstChildWithName(SP12Constants.REQUIRE_EXPLICIT_DERIVED_KEYS) != null) {
-                conversationToken.setExplicitDerivedKeys(true);
-            }
-
-            if (element
-                    .getFirstChildWithName(SP12Constants.REQUIRE_EXTERNAL_URI_REFERNCE) != null) {
-                conversationToken.setRequireExternalUriRef(true);
-            }
-
-            if (element
-                    .getFirstChildWithName(SP12Constants.SC10_SECURITY_CONTEXT_TOKEN) != null) {
-                conversationToken.setSc10SecurityContextToken(true);
-            }
-            
-            OMElement bootstrapPolicyElement = element.getFirstChildWithName(SP12Constants.BOOTSTRAP_POLICY);
-            if (bootstrapPolicyElement != null) {
-                Policy policy = PolicyEngine.getPolicy(bootstrapPolicyElement.getFirstElement());
-                conversationToken.setBootstrapPolicy(policy);
-            }
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class SecureConversationTokenBuilder implements AssertionBuilder<Element> {
+
+    public Assertion build(Element element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+
+        final SPConstants.SPVersion spVersion = SPConstants.SPVersion.getSPVersion(element.getNamespaceURI());
+        final String includeTokenValue = SPUtils.getAttribute(element, spVersion.getSPConstants().getIncludeToken());
+        final Element issuer = SPUtils.getFirstChildElement(element, spVersion.getSPConstants().getIssuer());
+        final String issuerName = SPUtils.getFirstChildElementText(element, spVersion.getSPConstants().getIssuerName());
+        if (spVersion == SPConstants.SPVersion.SP11 && issuerName != null) {
+            throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
         }
-        
-        return conversationToken;
+        final Element claims = SPUtils.getFirstChildElement(element, spVersion.getSPConstants().getClaims());
+        final Element nestedPolicyElement = SPUtils.getFirstPolicyChildElement(element);
+        final Policy nestedPolicy = nestedPolicyElement != null ? factory.getPolicyEngine().getPolicy(nestedPolicyElement) : new Policy();
+        SecureConversationToken secureConversationToken = new SecureConversationToken(
+                spVersion,
+                spVersion.getSPConstants().getInclusionFromAttributeValue(includeTokenValue),
+                issuer,
+                issuerName,
+                claims,
+                nestedPolicy
+        );
+        secureConversationToken.setOptional(SPUtils.isOptional(element));
+        secureConversationToken.setIgnorable(SPUtils.isIgnorable(element));
+        return secureConversationToken;
     }
 
     public QName[] getKnownElements() {
-        return new QName[] {SP12Constants.SECURE_CONVERSATION_TOKEN};
+        return new QName[]{SP13Constants.SECURE_CONVERSATION_TOKEN, SP11Constants.SECURE_CONVERSATION_TOKEN};
     }
-
 }

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SecureConversationTokenBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SecurityContextTokenBuilder.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SecurityContextTokenBuilder.java?rev=1210203&r1=1197660&r2=1210203&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SecurityContextTokenBuilder.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SecurityContextTokenBuilder.java Sun Dec  4 20:33:05 2011
@@ -1,68 +1,71 @@
-/*
- * Copyright 2001-2004 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.
+/**
+ * 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.ws.secpolicy12.builders;
+package org.apache.ws.secpolicy.builders;
 
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMElement;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.Policy;
 import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.secpolicy.SP11Constants;
+import org.apache.ws.secpolicy.SP13Constants;
 import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.SP12Constants;
+import org.apache.ws.secpolicy.SPUtils;
 import org.apache.ws.secpolicy.model.SecurityContextToken;
+import org.w3c.dom.Element;
 
 import javax.xml.namespace.QName;
 
-public class SecurityContextTokenBuilder implements AssertionBuilder<OMElement> {
-
-    public Assertion build(OMElement element, AssertionBuilderFactory factory)
-            throws IllegalArgumentException {
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class SecurityContextTokenBuilder implements AssertionBuilder<Element> {
 
-        SecurityContextToken contextToken = new SecurityContextToken(SPConstants.SP_V12);
+    public Assertion build(Element element, AssertionBuilderFactory factory) throws IllegalArgumentException {
 
-        OMAttribute  includeAttr = element.getAttribute(SP12Constants.INCLUDE_TOKEN);
-        if(includeAttr != null) {
-            int inclusion = SP12Constants.getInclusionFromAttributeValue(includeAttr.getAttributeValue());
-            contextToken.setInclusion(inclusion);
+        final SPConstants.SPVersion spVersion = SPConstants.SPVersion.getSPVersion(element.getNamespaceURI());
+        final String includeTokenValue = SPUtils.getAttribute(element, spVersion.getSPConstants().getIncludeToken());
+        final Element issuer = SPUtils.getFirstChildElement(element, spVersion.getSPConstants().getIssuer());
+        if (spVersion == SPConstants.SPVersion.SP11 && issuer != null) {
+            throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
         }
-
-        element = element.getFirstChildWithName(SPConstants.POLICY);
-
-        if (element != null) {
-
-            if (element.getFirstChildWithName(SP12Constants.REQUIRE_DERIVED_KEYS) != null) {
-                contextToken.setDerivedKeys(true);
-            }
-
-            if (element
-                    .getFirstChildWithName(SP12Constants.REQUIRE_EXTERNAL_URI_REFERNCE) != null) {
-                contextToken.setRequireExternalUriRef(true);
-            }
-
-            if (element
-                    .getFirstChildWithName(SP12Constants.SC10_SECURITY_CONTEXT_TOKEN) != null) {
-                contextToken.setSc10SecurityContextToken(true);
-            }
+        final String issuerName = SPUtils.getFirstChildElementText(element, spVersion.getSPConstants().getIssuerName());
+        if (spVersion == SPConstants.SPVersion.SP11 && issuerName != null) {
+            throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
         }
-
-        return contextToken;
+        final Element claims = SPUtils.getFirstChildElement(element, spVersion.getSPConstants().getClaims());
+        final Element nestedPolicyElement = SPUtils.getFirstPolicyChildElement(element);
+        final Policy nestedPolicy = nestedPolicyElement != null ? factory.getPolicyEngine().getPolicy(nestedPolicyElement) : new Policy();
+        SecurityContextToken securityContextToken = new SecurityContextToken(
+                spVersion,
+                spVersion.getSPConstants().getInclusionFromAttributeValue(includeTokenValue),
+                issuer,
+                issuerName,
+                claims,
+                nestedPolicy
+        );
+        securityContextToken.setOptional(SPUtils.isOptional(element));
+        securityContextToken.setIgnorable(SPUtils.isIgnorable(element));
+        return securityContextToken;
     }
 
     public QName[] getKnownElements() {
-        return new QName[] {SP12Constants.SECURITY_CONTEXT_TOKEN};
+        return new QName[]{SP13Constants.SECURITY_CONTEXT_TOKEN, SP11Constants.SECURITY_CONTEXT_TOKEN};
     }
-
 }

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SecurityContextTokenBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SignatureTokenBuilder.java (from r1197660, axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy12/builders/ProtectionTokenBuilder.java)
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SignatureTokenBuilder.java?p2=webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SignatureTokenBuilder.java&p1=axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy12/builders/ProtectionTokenBuilder.java&r1=1197660&r2=1210203&rev=1210203&view=diff
==============================================================================
--- axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy12/builders/ProtectionTokenBuilder.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SignatureTokenBuilder.java Sun Dec  4 20:33:05 2011
@@ -1,61 +1,56 @@
-/*
- * Copyright 2001-2004 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.
+/**
+ * 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.ws.secpolicy12.builders;
+package org.apache.ws.secpolicy.builders;
 
-import java.util.Iterator;
-import java.util.List;
-
-import javax.xml.namespace.QName;
-
-import org.apache.axiom.om.OMElement;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.AssertionBuilderFactory;
 import org.apache.neethi.Policy;
-import org.apache.neethi.PolicyEngine;
 import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.secpolicy.SP11Constants;
+import org.apache.ws.secpolicy.SP13Constants;
 import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.SP12Constants;
-import org.apache.ws.secpolicy.model.ProtectionToken;
-import org.apache.ws.secpolicy.model.Token;
+import org.apache.ws.secpolicy.SPUtils;
+import org.apache.ws.secpolicy.model.SignatureToken;
+import org.w3c.dom.Element;
 
-public class ProtectionTokenBuilder implements AssertionBuilder<OMElement> {
+import javax.xml.namespace.QName;
 
-    public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
-        ProtectionToken protectionToken = new ProtectionToken(SPConstants.SP_V12);
-        
-        Policy policy = PolicyEngine.getPolicy(element.getFirstElement());
-        policy = (Policy) policy.normalize(false);
-        
-        for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
-            processAlternative((List) iterator.next(), protectionToken);
-            break; // since there should be only one alternative ..
-        }
-        
-        return protectionToken;
-    }
-        
-    public QName[] getKnownElements() {
-        return new QName[] {SP12Constants.PROTECTION_TOKEN};
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class SignatureTokenBuilder implements AssertionBuilder<Element> {
+
+    public Assertion build(Element element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+        final SPConstants.SPVersion spVersion = SPConstants.SPVersion.getSPVersion(element.getNamespaceURI());
+        final Element nestedPolicyElement = SPUtils.getFirstPolicyChildElement(element);
+        final Policy nestedPolicy = nestedPolicyElement != null ? factory.getPolicyEngine().getPolicy(nestedPolicyElement) : new Policy();
+        SignatureToken signatureToken = new SignatureToken(
+                spVersion,
+                nestedPolicy
+        );
+        signatureToken.setOptional(SPUtils.isOptional(element));
+        signatureToken.setIgnorable(SPUtils.isIgnorable(element));
+        return signatureToken;
     }
 
-    private void processAlternative(List assertions, ProtectionToken parent) {
-        Object token = assertions.get(0);
-        
-        if (token instanceof Token) {
-            parent.setToken((Token) token);
-        }
+    public QName[] getKnownElements() {
+        return new QName[]{SP13Constants.SIGNATURE_TOKEN, SP11Constants.SIGNATURE_TOKEN};
     }
 }

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SignatureTokenBuilder.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SignatureTokenBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SignedElementsBuilder.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SignedElementsBuilder.java?rev=1210203&r1=1197660&r2=1210203&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SignedElementsBuilder.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SignedElementsBuilder.java Sun Dec  4 20:33:05 2011
@@ -1,74 +1,120 @@
-/*
- * Copyright 2001-2004 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.
+/**
+ * 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.ws.secpolicy12.builders;
+package org.apache.ws.secpolicy.builders;
 
-import java.util.Iterator;
-
-import javax.xml.namespace.QName;
-
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMNamespace;
+import org.apache.commons.lang.StringUtils;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.AssertionBuilderFactory;
-import org.apache.neethi.Constants;
 import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.secpolicy.SP11Constants;
+import org.apache.ws.secpolicy.SP13Constants;
 import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.SP12Constants;
-import org.apache.ws.secpolicy.model.SignedEncryptedElements;
+import org.apache.ws.secpolicy.SPUtils;
+import org.apache.ws.secpolicy.model.SignedElements;
+import org.apache.ws.secpolicy.model.XPath;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class SignedElementsBuilder implements AssertionBuilder<Element> {
 
-public class SignedElementsBuilder implements AssertionBuilder<OMElement> {
+    public Assertion build(Element element, AssertionBuilderFactory factory) throws IllegalArgumentException {
 
-    
-    public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
-        
-        SignedEncryptedElements signedEncryptedElements = new SignedEncryptedElements(true, SPConstants.SP_V12);
-        OMAttribute attrXPathVersion = element.getAttribute(SP12Constants.ATTR_XPATH_VERSION);
-        
-        if (attrXPathVersion != null) {
-            signedEncryptedElements.setXPathVersion(attrXPathVersion.getAttributeValue());
+        final SPConstants.SPVersion spVersion = SPConstants.SPVersion.getSPVersion(element.getNamespaceURI());
+        final String xPathVersion = getXPathVersion(element);
+        final List<XPath> xPaths = getXPathExpressions(element, spVersion);
+        final List<XPath> xPaths2 = getXPath2Expressions(element, spVersion);
+        xPaths.addAll(xPaths2);
+        SignedElements signedElements = new SignedElements(spVersion, xPathVersion, xPaths);
+        signedElements.setOptional(SPUtils.isOptional(element));
+        signedElements.setIgnorable(SPUtils.isIgnorable(element));
+        return signedElements;
+    }
+
+    protected List<XPath> getXPathExpressions(Element element, SPConstants.SPVersion spVersion) {
+        List<XPath> xPaths = new ArrayList<XPath>();
+
+        Element child = SPUtils.getFirstChildElement(element);
+        while (child != null) {
+            if (SPConstants.XPATH_EXPR.equals(child.getLocalName())
+                    && spVersion.getSPConstants().getXPathExpression().getNamespaceURI().equals(child.getNamespaceURI())) {
+                Map<String, String> declaredNamespaces = new HashMap<String, String>();
+                addDeclaredNamespaces(child, declaredNamespaces);
+                xPaths.add(new XPath(child.getTextContent(), XPath.Version.V1, null, declaredNamespaces));
+            }
+            child = SPUtils.getNextSiblingElement(child);
         }
-        
-        OMAttribute isOptional = element.getAttribute(Constants.Q_ELEM_OPTIONAL_ATTR);
-		if (isOptional != null) {
-			signedEncryptedElements.setOptional(Boolean.valueOf(isOptional.getAttributeValue())
-					.booleanValue());
-		}
-        
-        for (Iterator iterator = element.getChildElements(); iterator.hasNext();) {
-            processElement((OMElement) iterator.next(), signedEncryptedElements);            
+        return xPaths;
+    }
+
+    protected List<XPath> getXPath2Expressions(Element element, SPConstants.SPVersion spVersion) {
+        List<XPath> xPaths = new ArrayList<XPath>();
+
+        Element child = SPUtils.getFirstChildElement(element);
+        while (child != null) {
+            if (SPConstants.XPATH2_EXPR.equals(child.getLocalName())
+                    && spVersion.getSPConstants().getXPath2Expression().getNamespaceURI().equals(child.getNamespaceURI())) {
+                Map<String, String> declaredNamespaces = new HashMap<String, String>();
+                addDeclaredNamespaces(child, declaredNamespaces);
+                String filter = child.getAttribute(SPConstants.FILTER);
+                if (StringUtils.isEmpty(filter)) {
+                    throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+                }
+                xPaths.add(new XPath(child.getTextContent(), XPath.Version.V2, filter, declaredNamespaces));
+            }
+            child = SPUtils.getNextSiblingElement(child);
         }
-        
-        return signedEncryptedElements;
+        return xPaths;
     }
-        
-    public QName[] getKnownElements() {
-        return new QName[] {SP12Constants.SIGNED_ELEMENTS};
+
+    protected String getXPathVersion(Element element) {
+        String xPathVersion = element.getAttribute(SPConstants.XPATH_VERSION);
+        if (StringUtils.isEmpty(xPathVersion)) {
+            xPathVersion = "1.0";
+        }
+        return xPathVersion;
     }
 
-    private void processElement(OMElement element, SignedEncryptedElements parent) {
-        QName name = element.getQName();
-        if (SP12Constants.XPATH.equals(name)) {
-            parent.addXPathExpression(element.getText());
-            Iterator namespaces = element.getNamespacesInScope();
-            while (namespaces.hasNext()) {
-                OMNamespace nm = (OMNamespace) namespaces.next();
-                parent.addDeclaredNamespaces(nm.getNamespaceURI(), nm.getPrefix());
+    protected void addDeclaredNamespaces(Element element, Map<String, String> declaredNamespaces) {
+        if (element.getParentNode() != null && element.getParentNode() instanceof Element) {
+            addDeclaredNamespaces((Element) element.getParentNode(), declaredNamespaces);
+        }
+        NamedNodeMap map = element.getAttributes();
+        for (int x = 0; x < map.getLength(); x++) {
+            Attr attr = (Attr) map.item(x);
+            if ("xmlns".equals(attr.getPrefix())) {
+                declaredNamespaces.put(attr.getLocalName(), attr.getValue());
             }
         }
     }
-    
+
+    public QName[] getKnownElements() {
+        return new QName[]{SP13Constants.SIGNED_ELEMENTS, SP11Constants.SIGNED_ELEMENTS};
+    }
 }

Propchange: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/builders/SignedElementsBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision