cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r675332 [2/6] - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/helpers/ rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/ rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/ rt/ws/security/src/m...
Date Wed, 09 Jul 2008 20:11:48 GMT
Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/EncryptedElementsBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/EncryptedElementsBuilder.java?rev=675332&r1=674910&r2=675332&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/EncryptedElementsBuilder.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/EncryptedElementsBuilder.java Wed Jul  9 13:11:45 2008
@@ -1,69 +1,101 @@
-/*
- * 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.secpolicy11.builders;
+package org.apache.cxf.ws.security.policy.builders;
 
-import java.util.Iterator;
+import java.util.Arrays;
+import java.util.List;
 
 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.SPConstants;
-import org.apache.ws.secpolicy.model.SignedEncryptedElements;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.ws.policy.AssertionBuilder;
+import org.apache.cxf.ws.policy.PolicyAssertion;
+import org.apache.cxf.ws.security.policy.SP11Constants;
+import org.apache.cxf.ws.security.policy.SP12Constants;
+import org.apache.cxf.ws.security.policy.SPConstants;
+import org.apache.cxf.ws.security.policy.model.SignedEncryptedElements;
+
 
 public class EncryptedElementsBuilder implements AssertionBuilder {
+    private static final List<QName> KNOWN_ELEMENTS 
+        = Arrays.asList(SP11Constants.ENCRYPTED_ELEMENTS, SP12Constants.ENCRYPTED_ELEMENTS);
 
-    public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
-        SignedEncryptedElements signedEncryptedElements = new SignedEncryptedElements(false, SPConstants.SP_V11);
+    public List<QName> getKnownElements() {
+        return KNOWN_ELEMENTS;
+    }
+     
+    public PolicyAssertion build(Element element)
+        throws IllegalArgumentException {
         
-        OMAttribute attribute = element.getAttribute(SP11Constants.ATTR_XPATH_VERSION);
+        SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
+            ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
+
+        SignedEncryptedElements signedEncryptedElements = new SignedEncryptedElements(false,
+                                                                                      consts);
+
+        String attribute = element.getAttributeNS(consts.getNamespace(), SPConstants.XPATH_VERSION);
         if (attribute != null) {
-            signedEncryptedElements.setXPathVersion(attribute.getAttributeValue());
+            signedEncryptedElements.setXPathVersion(attribute);
         }
-        
-        for (Iterator iterator = element.getChildElements(); iterator.hasNext();) {
-            processElement((OMElement) iterator.next(), signedEncryptedElements);
+
+        Node nd = element.getFirstChild();
+        while (nd != null) {
+            if (nd instanceof Element) {
+                processElement((Element)nd, signedEncryptedElements);                
+            }
+            nd = nd.getNextSibling();
         }
-        
         return signedEncryptedElements;
     }
-    
-    
-    
-    public QName[] getKnownElements() {
-        return new QName[] {SP11Constants.ENCRYPTED_ELEMENTS};
-    }
-
 
 
-    private void processElement(OMElement element, SignedEncryptedElements parent) {
-        if (SP11Constants.XPATH.equals(element.getQName())) {
-            parent.addXPathExpression(element.getText());   
-            Iterator namespaces = element.getAllDeclaredNamespaces();
-            while (namespaces.hasNext()) {
-                OMNamespace nm = (OMNamespace) namespaces.next();
-                parent.addDeclaredNamespaces(nm.getNamespaceURI(), nm.getPrefix());
+    private void processElement(Element element, SignedEncryptedElements parent) {
+        if (SPConstants.XPATH_EXPR.equals(element.getLocalName())) {
+            parent.addXPathExpression(DOMUtils.getRawContent(element));
+            addNamespaces(element, parent);
+        }
+    }
+    private void addNamespaces(Node element, SignedEncryptedElements parent) {
+        if (element.getParentNode() != null) {
+            addNamespaces(element.getParentNode(), parent);
+        }
+        if (element instanceof Element) {
+            Element el = (Element)element;
+            NamedNodeMap map = el.getAttributes();
+            for (int x = 0; x < map.getLength(); x++) {
+                Attr attr = (Attr)map.item(x);
+                if ("xmlns".equals(attr.getPrefix())) {
+                    parent.addDeclaredNamespaces(attr.getValue(), attr.getLocalName());
+                }
             }
         }
     }
     
-    
+
+    public PolicyAssertion buildCompatible(PolicyAssertion a, PolicyAssertion b) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
 }

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/EncryptedPartsBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/EncryptedPartsBuilder.java?rev=675332&r1=674910&r2=675332&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/EncryptedPartsBuilder.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/EncryptedPartsBuilder.java Wed Jul  9 13:11:45 2008
@@ -1,71 +1,91 @@
-/*
- * 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.cxf.ws.security.policy.builders;
 
-package org.apache.ws.secpolicy11.builders;
-
-import java.util.Iterator;
+import java.util.Arrays;
+import java.util.List;
 
 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.builders.AssertionBuilder;
-import org.apache.ws.secpolicy.SP11Constants;
-import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.model.Header;
-import org.apache.ws.secpolicy.model.SignedEncryptedParts;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.apache.cxf.ws.policy.AssertionBuilder;
+import org.apache.cxf.ws.policy.PolicyAssertion;
+import org.apache.cxf.ws.security.policy.SP11Constants;
+import org.apache.cxf.ws.security.policy.SP12Constants;
+import org.apache.cxf.ws.security.policy.SPConstants;
+import org.apache.cxf.ws.security.policy.model.Header;
+import org.apache.cxf.ws.security.policy.model.SignedEncryptedParts;
+
 
 public class EncryptedPartsBuilder implements AssertionBuilder {
-        
-    public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
-        
-        SignedEncryptedParts signedEncryptedParts = new SignedEncryptedParts(false, SPConstants.SP_V11);
-        
-        for (Iterator iterator = element.getChildElements(); iterator.hasNext();) {
-            processElement((OMElement) iterator.next(), signedEncryptedParts);
+    private static final List<QName> KNOWN_ELEMENTS 
+        = Arrays.asList(SP11Constants.ENCRYPTED_PARTS, SP12Constants.ENCRYPTED_PARTS);
+    
+    public List<QName> getKnownElements() {
+        return KNOWN_ELEMENTS;
+    }
+    
+    public PolicyAssertion build(Element element)
+        throws IllegalArgumentException {
+
+        SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
+            ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
+
+        SignedEncryptedParts signedEncryptedParts = new SignedEncryptedParts(false, consts);
+
+
+        Node nd = element.getFirstChild();
+        while (nd != null) {
+            if (nd instanceof Element) {
+                processElement((Element)nd, signedEncryptedParts);                
+            }
+            nd = nd.getNextSibling();
         }
         
         return signedEncryptedParts;
     }
-    
-    public QName[] getKnownElements() {
-        return new QName[] {SP11Constants.ENCRYPTED_PARTS};
-    }
 
-    private void processElement(OMElement element, SignedEncryptedParts parent) {
-        
-        QName name = element.getQName();
-        
-        if (SP11Constants.HEADER.equals(name)) {
+
+    private void processElement(Element element, SignedEncryptedParts parent) {
+
+        if ("Header".equals(element.getLocalName())) {
             Header header = new Header();
-            
-            OMAttribute nameAttribute = element.getAttribute(SPConstants.NAME);
-            if( nameAttribute != null ) {
-                header.setName(nameAttribute.getAttributeValue());
+
+            String nameAttribute = element.getAttribute(SPConstants.NAME);
+            if (nameAttribute != null) {
+                header.setName(nameAttribute);
             }
-            
-            OMAttribute namespaceAttribute = element.getAttribute(SPConstants.NAMESPACE);
-            header.setNamespace(namespaceAttribute.getAttributeValue());
-            
+
+            String namespaceAttribute = element.getAttribute(SPConstants.NAMESPACE);
+            header.setNamespace(namespaceAttribute);
+
             parent.addHeader(header);
-            
-        } else if (SP11Constants.BODY.equals(name)) {
-            parent.setBody(true);            
-        }        
+
+        } else if ("Body".equals(element.getLocalName())) {
+            parent.setBody(true);
+        }
+    }
+
+    public PolicyAssertion buildCompatible(PolicyAssertion a, PolicyAssertion b) {
+        // TODO Auto-generated method stub
+        return null;
     }
 }

Added: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/HttpsTokenBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/HttpsTokenBuilder.java?rev=675332&view=auto
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/HttpsTokenBuilder.java (added)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/HttpsTokenBuilder.java Wed Jul  9 13:11:45 2008
@@ -0,0 +1,116 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.ws.security.policy.builders;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.ws.policy.AssertionBuilder;
+import org.apache.cxf.ws.policy.PolicyAssertion;
+import org.apache.cxf.ws.policy.PolicyBuilder;
+import org.apache.cxf.ws.policy.builder.xml.XmlPrimitiveAssertion;
+import org.apache.cxf.ws.security.policy.SP12Constants;
+import org.apache.cxf.ws.security.policy.model.HttpsToken;
+import org.apache.neethi.Policy;
+
+
+/**
+ * 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.
+ * 
+ */
+public class HttpsTokenBuilder implements AssertionBuilder {
+    PolicyBuilder builder;
+    public HttpsTokenBuilder(PolicyBuilder b) {
+        builder = b;
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public PolicyAssertion build(Element element) {
+        HttpsToken httpsToken = new HttpsToken(SP12Constants.INSTANCE);
+        
+        Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
+        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
+        }
+        
+        return httpsToken;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<QName> getKnownElements() {
+        return Collections.singletonList(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();) {
+            XmlPrimitiveAssertion primtive = (XmlPrimitiveAssertion) 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);
+                }
+            }
+        }
+    }
+
+    public PolicyAssertion buildCompatible(PolicyAssertion a, PolicyAssertion b) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}

Propchange: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/HttpsTokenBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/HttpsTokenBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/HttpsTokenBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/InitiatorTokenBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/InitiatorTokenBuilder.java?rev=675332&r1=674910&r2=675332&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/InitiatorTokenBuilder.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/InitiatorTokenBuilder.java Wed Jul  9 13:11:45 2008
@@ -1,68 +1,91 @@
-/*
- * 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.secpolicy11.builders;
+package org.apache.cxf.ws.security.policy.builders;
 
+import java.util.Arrays;
 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.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.ws.policy.AssertionBuilder;
+import org.apache.cxf.ws.policy.PolicyAssertion;
+import org.apache.cxf.ws.policy.PolicyBuilder;
+import org.apache.cxf.ws.security.policy.SP11Constants;
+import org.apache.cxf.ws.security.policy.SP12Constants;
+import org.apache.cxf.ws.security.policy.SPConstants;
+import org.apache.cxf.ws.security.policy.model.InitiatorToken;
+import org.apache.cxf.ws.security.policy.model.Token;
 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.SPConstants;
-import org.apache.ws.secpolicy.model.InitiatorToken;
-import org.apache.ws.secpolicy.model.Token;
 
-public class InitiatorTokenBuilder implements AssertionBuilder {
 
-    public Assertion build(OMElement element, AssertionBuilderFactory factory)
-            throws IllegalArgumentException {
-        InitiatorToken initiatorToken = new InitiatorToken(SPConstants.SP_V11);
-        
-        Policy policy = PolicyEngine.getPolicy(element.getFirstElement());
-        policy = (Policy) policy.normalize(false); 
+public class InitiatorTokenBuilder implements AssertionBuilder {
+    private static final List<QName> KNOWN_ELEMENTS 
+        = Arrays.asList(SP11Constants.INITIATOR_TOKEN, SP12Constants.INITIATOR_TOKEN);
+    
+    PolicyBuilder builder;
+    public InitiatorTokenBuilder(PolicyBuilder b) {
+        builder = b;
+    }
+    public List<QName> getKnownElements() {
+        return KNOWN_ELEMENTS;
+    }
+    
+    
+    public PolicyAssertion build(Element element)
+        throws IllegalArgumentException {
         
+        SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
+            ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
+
+        InitiatorToken initiatorToken = new InitiatorToken(consts);
+
+        Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
+        policy = (Policy)policy.normalize(false);
+
         for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
-            processAlternative((List) iterator.next(), initiatorToken);
+            processAlternative((List)iterator.next(), initiatorToken);
             break; // TODO process all the token that must be set ..
         }
-        
+
         return initiatorToken;
     }
-    
+
     private void processAlternative(List assertions, InitiatorToken parent) {
-        
+
         Object token;
-        
+
         for (Iterator iterator = assertions.iterator(); iterator.hasNext();) {
             token = iterator.next();
-            
+
             if (token instanceof Token) {
-                parent.setInitiatorToken((Token) token);
+                parent.setInitiatorToken((Token)token);
             }
         }
     }
-
-    public QName[] getKnownElements() {
-        return new QName[] {SP11Constants.INITIATOR_TOKEN};
+    public PolicyAssertion buildCompatible(PolicyAssertion a, PolicyAssertion b) {
+        // TODO Auto-generated method stub
+        return null;
     }
 
+
 }

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/IssuedTokenBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/IssuedTokenBuilder.java?rev=675332&r1=674910&r2=675332&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/IssuedTokenBuilder.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/IssuedTokenBuilder.java Wed Jul  9 13:11:45 2008
@@ -1,91 +1,126 @@
-/*
- * 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.secpolicy11.builders;
+package org.apache.cxf.ws.security.policy.builders;
 
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.OMElement;
-import org.apache.axis2.addressing.AddressingConstants;
-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.SPConstants;
-import org.apache.ws.secpolicy.model.IssuedToken;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
 
 import javax.xml.namespace.QName;
 
-import java.util.Iterator;
-import java.util.List;
+import org.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.ws.policy.AssertionBuilder;
+import org.apache.cxf.ws.policy.PolicyAssertion;
+import org.apache.cxf.ws.policy.PolicyBuilder;
+import org.apache.cxf.ws.security.policy.SP11Constants;
+import org.apache.cxf.ws.security.policy.SP12Constants;
+import org.apache.cxf.ws.security.policy.SPConstants;
+import org.apache.cxf.ws.security.policy.model.IssuedToken;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
+
 
 public class IssuedTokenBuilder implements AssertionBuilder {
+    private static final String WSA_NAMESPACE_SUB = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
+    private static final String WSA_NAMESPACE = "http://www.w3.org/2005/08/addressing";
+    
+    private static final List<QName> KNOWN_ELEMENTS 
+        = Arrays.asList(SP11Constants.ISSUED_TOKEN, SP12Constants.ISSUED_TOKEN);
+    
+    PolicyBuilder builder;
+    public IssuedTokenBuilder(PolicyBuilder b) {
+        builder = b;
+    }
+    public List<QName> getKnownElements() {
+        return KNOWN_ELEMENTS;
+    }
+    
 
-    public Assertion build(OMElement element, AssertionBuilderFactory factory)
-            throws IllegalArgumentException {
-        IssuedToken issuedToken = new IssuedToken(SPConstants.SP_V11);
-
-        OMAttribute  includeAttr = element.getAttribute(SP11Constants.INCLUDE_TOKEN);
-        if(includeAttr != null) {
-            issuedToken.setInclusion(SP11Constants.getInclusionFromAttributeValue(includeAttr.getAttributeValue()));
+    public PolicyAssertion build(Element element)
+        throws IllegalArgumentException {
+        
+        SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
+            ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
+    
+
+        IssuedToken issuedToken = new IssuedToken(consts);
+
+        String includeAttr = DOMUtils.getAttribute(element, consts.getIncludeToken());
+        if (includeAttr != null) {
+            issuedToken.setInclusion(consts.getInclusionFromAttributeValue(includeAttr));
         }
         // Extract Issuer
-        OMElement issuerElem = element.getFirstChildWithName(SP11Constants.ISSUER);
-        if(issuerElem != null) {
-            OMElement issuerEpr = issuerElem.getFirstChildWithName(new QName(AddressingConstants.Final.WSA_NAMESPACE,"Address"));
-            
-            //try the other addressing namespace
+        Element issuerElem = DOMUtils.getFirstChildWithName(element, SP11Constants.ISSUER);
+        if (issuerElem != null) {
+            Element issuerEpr = DOMUtils
+                .getFirstChildWithName(issuerElem, 
+                                       new QName(WSA_NAMESPACE, "Address"));
+
+            // try the other addressing namespace
             if (issuerEpr == null) {
-                issuerEpr = issuerElem.getFirstChildWithName(new QName(AddressingConstants.Submission.WSA_NAMESPACE,"Address"));
+                issuerEpr = DOMUtils
+                    .getFirstChildWithName(issuerElem,
+                                           new QName(WSA_NAMESPACE_SUB,
+                                                     "Address"));
             }
-            
+
             issuedToken.setIssuerEpr(issuerEpr);
         }
-        
-        //TODO check why this returns an Address element
-        //iter = issuerElem.getChildrenWithLocalName("Metadata");
-        
-        if (issuerElem != null ) {
-            OMElement issuerMex = issuerElem.getFirstChildWithName(new QName(AddressingConstants.Final.WSA_NAMESPACE,"Metadata"));
-            
-          //try the other addressing namespace
+
+        // TODO check why this returns an Address element
+        // iter = issuerElem.getChildrenWithLocalName("Metadata");
+
+        if (issuerElem != null) {
+            Element issuerMex = DOMUtils
+                .getFirstChildWithName(issuerElem,
+                                       new QName(WSA_NAMESPACE, "Metadata"));
+
+            // try the other addressing namespace
             if (issuerMex == null) {
-                issuerMex = issuerElem.getFirstChildWithName(new QName(AddressingConstants.Submission.WSA_NAMESPACE,"Metadata"));
+                issuerMex = DOMUtils
+                    .getFirstChildWithName(issuerElem,
+                                           new QName(WSA_NAMESPACE_SUB, 
+                                                     "Metadata"));
             }
-                        
+
             issuedToken.setIssuerMex(issuerMex);
         }
-        
 
         // Extract RSTTemplate
-        OMElement rstTmplElem = element.getFirstChildWithName(SP11Constants.REQUEST_SECURITY_TOKEN_TEMPLATE);
+        Element rstTmplElem = DOMUtils.getFirstChildWithName(element, 
+                                                             SP11Constants.REQUEST_SECURITY_TOKEN_TEMPLATE);
         if (rstTmplElem != null) {
             issuedToken.setRstTemplate(rstTmplElem);
         }
 
-        OMElement policyElement = element.getFirstChildWithName(org.apache.neethi.Constants.Q_ELEM_POLICY);
+        Element policyElement = DOMUtils.getFirstChildWithName(element,
+                                                               org.apache.neethi.Constants.Q_ELEM_POLICY);
 
         if (policyElement != null) {
 
-            Policy policy = PolicyEngine.getPolicy(policyElement);
-            policy = (Policy) policy.normalize(false);
+            Policy policy = builder.getPolicy(policyElement);
+            policy = (Policy)policy.normalize(false);
 
-            for (Iterator iterator = policy.getAlternatives(); iterator
-                    .hasNext();) {
-                processAlternative((List) iterator.next(), issuedToken);
+            for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
+                processAlternative((List)iterator.next(), issuedToken);
                 break; // since there should be only one alternative ..
             }
         }
@@ -93,16 +128,13 @@
         return issuedToken;
     }
 
-    public QName[] getKnownElements() {
-        return new QName[] { SP11Constants.ISSUED_TOKEN };
-    }
 
     private void processAlternative(List assertions, IssuedToken parent) {
         Assertion assertion;
         QName name;
 
         for (Iterator iterator = assertions.iterator(); iterator.hasNext();) {
-            assertion = (Assertion) iterator.next();
+            assertion = (Assertion)iterator.next();
             name = assertion.getName();
 
             if (SP11Constants.REQUIRE_DERIVED_KEYS.equals(name)) {
@@ -115,4 +147,9 @@
         }
 
     }
+
+    public PolicyAssertion buildCompatible(PolicyAssertion a, PolicyAssertion b) {
+        // TODO Auto-generated method stub
+        return null;
+    }
 }

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/LayoutBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/LayoutBuilder.java?rev=675332&r1=674910&r2=675332&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/LayoutBuilder.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/LayoutBuilder.java Wed Jul  9 13:11:45 2008
@@ -1,73 +1,102 @@
-/*
- * 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.secpolicy11.builders;
+package org.apache.cxf.ws.security.policy.builders;
 
+
+import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
 import javax.xml.namespace.QName;
 
-import org.apache.axiom.om.OMElement;
+import org.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.ws.policy.AssertionBuilder;
+import org.apache.cxf.ws.policy.PolicyAssertion;
+import org.apache.cxf.ws.policy.PolicyBuilder;
+import org.apache.cxf.ws.security.policy.SP11Constants;
+import org.apache.cxf.ws.security.policy.SP12Constants;
+import org.apache.cxf.ws.security.policy.SPConstants;
+import org.apache.cxf.ws.security.policy.model.Layout;
 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.SPConstants;
-import org.apache.ws.secpolicy.model.Layout;
+
 
 public class LayoutBuilder implements AssertionBuilder {
+    private static final List<QName> KNOWN_ELEMENTS 
+        = Arrays.asList(SP11Constants.LAYOUT, SP12Constants.LAYOUT);
     
+    PolicyBuilder builder;
+    public LayoutBuilder(PolicyBuilder b) {
+        builder = b;
+    }
+    public List<QName> getKnownElements() {
+        return KNOWN_ELEMENTS;
+    }
     
-
-    public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
-        Layout layout = new Layout(SPConstants.SP_V11);
+    
+    public PolicyAssertion build(Element element)
+        throws IllegalArgumentException {
         
-        Policy policy = PolicyEngine.getPolicy(element.getFirstElement());
-        policy = (Policy) policy.normalize(false);
+        SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
+            ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
+
         
-        for (Iterator iterator = policy.getAlternatives(); iterator.hasNext(); ) {
-            processAlternative((List) iterator.next(), layout);         
+        Layout layout = new Layout(consts);
+
+        Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
+        policy = (Policy)policy.normalize(false);
+
+        for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
+            processAlternative((List)iterator.next(), layout, consts);
             break; // there should be only one alternative
         }
-                        
+
         return layout;
     }
-    
-    public QName[] getKnownElements() {
-        return new QName[] {SP11Constants.LAYOUT};
-    }
 
-    public void processAlternative(List assertions, Layout parent) {
-        
+    public void processAlternative(List assertions, Layout parent, SPConstants consts) {
+
         for (Iterator iterator = assertions.iterator(); iterator.hasNext();) {
-            Assertion assertion = (Assertion) iterator.next();
+            Assertion assertion = (Assertion)iterator.next();
             QName qname = assertion.getName();
+
+            if (!consts.getNamespace().equals(qname.getNamespaceURI())) {
+                continue;
+            }
+
             
-            if (SP11Constants.STRICT.equals(qname)) {
+            if (SPConstants.LAYOUT_STRICT.equals(qname.getLocalPart())) {
                 parent.setValue(SPConstants.LAYOUT_STRICT);
-            } else if (SP11Constants.LAX.equals(qname)) {
+            } else if (SPConstants.LAYOUT_LAX.equals(qname.getLocalPart())) {
                 parent.setValue(SPConstants.LAYOUT_LAX);
-            } else if (SP11Constants.LAXTSFIRST.equals(qname)) {
+            } else if (SPConstants.LAYOUT_LAX_TIMESTAMP_FIRST.equals(qname.getLocalPart())) {
                 parent.setValue(SPConstants.LAYOUT_LAX_TIMESTAMP_FIRST);
-            } else if (SP11Constants.LAXTSLAST.equals(qname)) {
+            } else if (SPConstants.LAYOUT_LAX_TIMESTAMP_LAST.equals(qname.getLocalPart())) {
                 parent.setValue(SPConstants.LAYOUT_LAX_TIMESTAMP_LAST);
             }
-            
+
         }
     }
+    public PolicyAssertion buildCompatible(PolicyAssertion a, PolicyAssertion b) {
+        // TODO Auto-generated method stub
+        return null;
+    }
 }

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/ProtectionTokenBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/ProtectionTokenBuilder.java?rev=675332&r1=674910&r2=675332&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/ProtectionTokenBuilder.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/ProtectionTokenBuilder.java Wed Jul  9 13:11:45 2008
@@ -1,61 +1,85 @@
-/*
- * 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.secpolicy11.builders;
+package org.apache.cxf.ws.security.policy.builders;
 
+import java.util.Arrays;
 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.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.ws.policy.AssertionBuilder;
+import org.apache.cxf.ws.policy.PolicyAssertion;
+import org.apache.cxf.ws.policy.PolicyBuilder;
+import org.apache.cxf.ws.security.policy.SP11Constants;
+import org.apache.cxf.ws.security.policy.SP12Constants;
+import org.apache.cxf.ws.security.policy.SPConstants;
+import org.apache.cxf.ws.security.policy.model.ProtectionToken;
+import org.apache.cxf.ws.security.policy.model.Token;
 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.SPConstants;
-import org.apache.ws.secpolicy.model.ProtectionToken;
-import org.apache.ws.secpolicy.model.Token;
 
-public class ProtectionTokenBuilder implements AssertionBuilder {
 
-    public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
-        ProtectionToken protectionToken = new ProtectionToken(SPConstants.SP_V11);
+public class ProtectionTokenBuilder implements AssertionBuilder {
+    private static final List<QName> KNOWN_ELEMENTS 
+        = Arrays.asList(SP11Constants.PROTECTION_TOKEN, SP12Constants.PROTECTION_TOKEN);
+    
+    PolicyBuilder builder;
+    public ProtectionTokenBuilder(PolicyBuilder b) {
+        builder = b;
+    }
+    public List<QName> getKnownElements() {
+        return KNOWN_ELEMENTS;
+    }
+    
+    
+    public PolicyAssertion build(Element element)
+        throws IllegalArgumentException {
+        SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
+            ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
         
-        Policy policy = PolicyEngine.getPolicy(element.getFirstElement());
-        policy = (Policy) policy.normalize(false);
         
+        ProtectionToken protectionToken = new ProtectionToken(consts);
+
+        Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
+        policy = (Policy)policy.normalize(false);
+
         for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
-            processAlternative((List) iterator.next(), protectionToken);
+            processAlternative((List)iterator.next(), protectionToken);
             break; // since there should be only one alternative ..
         }
-        
+
         return protectionToken;
     }
-        
-    public QName[] getKnownElements() {
-        return new QName[] {SP11Constants.PROTECTION_TOKEN};
-    }
+
 
     private void processAlternative(List assertions, ProtectionToken parent) {
         Object token = assertions.get(0);
-        
+
         if (token instanceof Token) {
-            parent.setToken((Token) token);
+            parent.setToken((Token)token);
         }
     }
+    public PolicyAssertion buildCompatible(PolicyAssertion a, PolicyAssertion b) {
+        // TODO Auto-generated method stub
+        return null;
+    }
 }

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/RecipientTokenBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/RecipientTokenBuilder.java?rev=675332&r1=674910&r2=675332&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/RecipientTokenBuilder.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/RecipientTokenBuilder.java Wed Jul  9 13:11:45 2008
@@ -1,72 +1,95 @@
-/*
- * 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.secpolicy11.builders;
+package org.apache.cxf.ws.security.policy.builders;
 
+import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
 import javax.xml.namespace.QName;
 
-import org.apache.axiom.om.OMElement;
+import org.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.ws.policy.AssertionBuilder;
+import org.apache.cxf.ws.policy.PolicyAssertion;
+import org.apache.cxf.ws.policy.PolicyBuilder;
+import org.apache.cxf.ws.security.policy.SP11Constants;
+import org.apache.cxf.ws.security.policy.SP12Constants;
+import org.apache.cxf.ws.security.policy.SPConstants;
+import org.apache.cxf.ws.security.policy.model.RecipientToken;
+import org.apache.cxf.ws.security.policy.model.Token;
 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.SPConstants;
-import org.apache.ws.secpolicy.model.RecipientToken;
-import org.apache.ws.secpolicy.model.Token;
+
 
 public class RecipientTokenBuilder implements AssertionBuilder {
+    private static final List<QName> KNOWN_ELEMENTS 
+        = Arrays.asList(SP11Constants.RECIPIENT_TOKEN, SP12Constants.RECIPIENT_TOKEN);
 
-    public Assertion build(OMElement element, AssertionBuilderFactory factory)
-            throws IllegalArgumentException {
-        RecipientToken recipientToken = new RecipientToken(SPConstants.SP_V11);
-        
-        Policy policy = PolicyEngine.getPolicy(element.getFirstElement());
-        policy = (Policy) policy.normalize(false);
+    PolicyBuilder builder;
+    public RecipientTokenBuilder(PolicyBuilder b) {
+        builder = b;
+    }
+    public List<QName> getKnownElements() {
+        return KNOWN_ELEMENTS;
+    }
+    
+    public PolicyAssertion build(Element element)
+        throws IllegalArgumentException {
         
+        SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
+            ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
+    
+
+        RecipientToken recipientToken = new RecipientToken(consts);
+
+        Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
+        policy = (Policy)policy.normalize(false);
+
         for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
-            processAlternative((List) iterator.next(), recipientToken);
-            
-            /* 
+            processAlternative((List)iterator.next(), recipientToken);
+
+            /*
              * for the moment we will pick the first token specified in the policy
              */
-            break;   
+            break;
         }
-        
+
         return recipientToken;
     }
 
     private void processAlternative(List assertions, RecipientToken parent) {
-        
+
         Assertion assertion;
-        
+
         for (Iterator iterator = assertions.iterator(); iterator.hasNext();) {
-            assertion = (Assertion) iterator.next();
-            
+            assertion = (Assertion)iterator.next();
+
             if (assertion instanceof Token) {
-                parent.setToken((Token) assertion);
+                parent.setToken((Token)assertion);
             }
-        }        
+        }
     }
-    
-    public QName[] getKnownElements() {
-        return new QName[] {SP11Constants.RECIPIENT_TOKEN};
+    public PolicyAssertion buildCompatible(PolicyAssertion a, PolicyAssertion b) {
+        // TODO Auto-generated method stub
+        return null;
     }
 
 }

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/RequiredElementsBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/RequiredElementsBuilder.java?rev=675332&r1=674910&r2=675332&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/RequiredElementsBuilder.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/RequiredElementsBuilder.java Wed Jul  9 13:11:45 2008
@@ -1,67 +1,99 @@
-/*
- * 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.secpolicy11.builders;
+package org.apache.cxf.ws.security.policy.builders;
 
-import java.util.Iterator;
+import java.util.Arrays;
+import java.util.List;
 
 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.SPConstants;
-import org.apache.ws.secpolicy.SP11Constants;
-import org.apache.ws.secpolicy.model.RequiredElements;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.ws.policy.AssertionBuilder;
+import org.apache.cxf.ws.policy.PolicyAssertion;
+import org.apache.cxf.ws.security.policy.SP11Constants;
+import org.apache.cxf.ws.security.policy.SP12Constants;
+import org.apache.cxf.ws.security.policy.SPConstants;
+import org.apache.cxf.ws.security.policy.model.RequiredElements;
 
-public class RequiredElementsBuilder implements AssertionBuilder {
 
+public class RequiredElementsBuilder implements AssertionBuilder {
+    private static final List<QName> KNOWN_ELEMENTS 
+        = Arrays.asList(SP11Constants.REQUIRED_ELEMENTS, SP12Constants.REQUIRED_ELEMENTS);
     
-    public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
-        
-        RequiredElements requiredElements = new RequiredElements(SPConstants.SP_V11);
-        OMAttribute attrXPathVersion = element.getAttribute(SP11Constants.ATTR_XPATH_VERSION);
-        
+    public List<QName> getKnownElements() {
+        return KNOWN_ELEMENTS;
+    }
+
+    public PolicyAssertion build(Element element)
+        throws IllegalArgumentException {
+
+        SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
+            ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
+
+        RequiredElements requiredElements = new RequiredElements(consts);
+        String attrXPathVersion = element.getAttributeNS(consts.getNamespace(), SPConstants.XPATH_VERSION);
+
         if (attrXPathVersion != null) {
-            requiredElements.setXPathVersion(attrXPathVersion.getAttributeValue());
+            requiredElements.setXPathVersion(attrXPathVersion);
         }
-        
-        for (Iterator iterator = element.getChildElements(); iterator.hasNext();) {
-            processElement((OMElement) iterator.next(),requiredElements);            
+
+
+        Node nd = element.getFirstChild();
+        while (nd != null) {
+            if (nd instanceof Element) {
+                processElement((Element)nd, requiredElements);                
+            }
+            nd = nd.getNextSibling();
         }
-        
         return requiredElements;
     }
-        
-    public QName[] getKnownElements() {
-        return new QName[] {SP11Constants.REQUIRED_ELEMENTS};
-    }
 
-    private void processElement(OMElement element, RequiredElements parent) {
-        QName name = element.getQName();
-        if (SP11Constants.XPATH.equals(name)) {
-            parent.addXPathExpression(element.getText());
-            Iterator namespaces = element.getAllDeclaredNamespaces();
-            while (namespaces.hasNext()) {
-                OMNamespace nm = (OMNamespace) namespaces.next();
-                parent.addDeclaredNamespaces(nm.getNamespaceURI(), nm.getPrefix());
+    private void processElement(Element element, RequiredElements parent) {
+        if (SPConstants.XPATH_EXPR.equals(element.getLocalName())) {
+            parent.addXPathExpression(DOMUtils.getRawContent(element));
+            addNamespaces(element, parent);
+        }
+    }
+    private void addNamespaces(Node element, RequiredElements parent) {
+        if (element.getParentNode() != null) {
+            addNamespaces(element.getParentNode(), parent);
+        }
+        if (element instanceof Element) {
+            Element el = (Element)element;
+            NamedNodeMap map = el.getAttributes();
+            for (int x = 0; x < map.getLength(); x++) {
+                Attr attr = (Attr)map.item(x);
+                if ("xmlns".equals(attr.getPrefix())) {
+                    parent.addDeclaredNamespaces(attr.getValue(), attr.getLocalName());
+                }
             }
         }
     }
-    
+
+    public PolicyAssertion buildCompatible(PolicyAssertion a, PolicyAssertion b) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
 }

Added: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/RequiredPartsBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/RequiredPartsBuilder.java?rev=675332&view=auto
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/RequiredPartsBuilder.java (added)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/RequiredPartsBuilder.java Wed Jul  9 13:11:45 2008
@@ -0,0 +1,76 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.ws.security.policy.builders;
+
+import java.util.Collections;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.apache.cxf.ws.policy.AssertionBuilder;
+import org.apache.cxf.ws.policy.PolicyAssertion;
+import org.apache.cxf.ws.security.policy.SP12Constants;
+import org.apache.cxf.ws.security.policy.SPConstants;
+import org.apache.cxf.ws.security.policy.model.Header;
+import org.apache.cxf.ws.security.policy.model.RequiredParts;
+
+public class RequiredPartsBuilder implements AssertionBuilder {
+        
+    public PolicyAssertion build(Element element) throws IllegalArgumentException {
+        RequiredParts requiredParts = new RequiredParts(SP12Constants.INSTANCE);
+        
+        Node nd = element.getFirstChild();
+        while (nd != null) {
+            if (nd instanceof Element) {
+                processElement((Element)nd, requiredParts);                
+            }
+            nd = nd.getNextSibling();
+        }
+
+        return requiredParts;
+    }
+       
+    public List<QName> getKnownElements() {
+        return Collections.singletonList(SP12Constants.REQUIRED_PARTS);
+    }
+
+    private void processElement(Element element, RequiredParts parent) {
+        if ("Header".equals(element.getLocalName())) {
+            Header header = new Header();
+
+            String nameAttribute = element.getAttribute(SPConstants.NAME);
+            if (nameAttribute != null) {
+                header.setName(nameAttribute);
+            }
+
+            String namespaceAttribute = element.getAttribute(SPConstants.NAMESPACE);
+            header.setNamespace(namespaceAttribute);
+
+            parent.addHeader(header);
+        }
+    }
+
+    public PolicyAssertion buildCompatible(PolicyAssertion a, PolicyAssertion b) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}

Propchange: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/RequiredPartsBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/RequiredPartsBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/RequiredPartsBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/SecureConversationTokenBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/SecureConversationTokenBuilder.java?rev=675332&r1=674910&r2=675332&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/SecureConversationTokenBuilder.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/SecureConversationTokenBuilder.java Wed Jul  9 13:11:45 2008
@@ -1,82 +1,119 @@
-/*
- * 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.secpolicy11.builders;
+package org.apache.cxf.ws.security.policy.builders;
+
+import java.util.Arrays;
+import java.util.List;
 
 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.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.ws.policy.AssertionBuilder;
+import org.apache.cxf.ws.policy.PolicyAssertion;
+import org.apache.cxf.ws.policy.PolicyBuilder;
+import org.apache.cxf.ws.security.policy.SP11Constants;
+import org.apache.cxf.ws.security.policy.SP12Constants;
+import org.apache.cxf.ws.security.policy.SPConstants;
+import org.apache.cxf.ws.security.policy.model.SecureConversationToken;
 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.SPConstants;
-import org.apache.ws.secpolicy.model.SecureConversationToken;
+
 
 public class SecureConversationTokenBuilder implements AssertionBuilder {
+    private static final List<QName> KNOWN_ELEMENTS 
+        = Arrays.asList(SP11Constants.SECURE_CONVERSATION_TOKEN, SP12Constants.SECURE_CONVERSATION_TOKEN);
+    
+    PolicyBuilder builder;
+    public SecureConversationTokenBuilder(PolicyBuilder b) {
+        builder = b;
+    }
+    public List<QName> getKnownElements() {
+        return KNOWN_ELEMENTS;
+    }
 
-    public Assertion build(OMElement element, AssertionBuilderFactory factory)
-            throws IllegalArgumentException {
-        SecureConversationToken conversationToken = new SecureConversationToken(SPConstants.SP_V11);
+    public PolicyAssertion build(Element element)
+        throws IllegalArgumentException {
+
+        SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
+            ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
+        
         
-        OMAttribute attribute = element.getAttribute(SP11Constants.INCLUDE_TOKEN);
+        SecureConversationToken conversationToken = new SecureConversationToken(consts);
+
+        String attribute = DOMUtils.getAttribute(element, consts.getIncludeToken());
         if (attribute == null) {
-            throw new IllegalArgumentException(
-                    "SecurityContextToken doesn't contain any sp:IncludeToken attribute");
+            throw new IllegalArgumentException("SecurityContextToken doesn't contain "
+                                               + "any sp:IncludeToken attribute");
         }
-        
-        String inclusionValue = attribute.getAttributeValue().trim();
-        
-        conversationToken.setInclusion(SP11Constants.getInclusionFromAttributeValue(inclusionValue));
-        
-        OMElement issuer = element.getFirstChildWithName(SP11Constants.ISSUER);
-        if ( issuer != null) {
-            conversationToken.setIssuerEpr(issuer.getFirstElement());
+
+        String inclusionValue = attribute.trim();
+
+        conversationToken.setInclusion(consts.getInclusionFromAttributeValue(inclusionValue));
+
+        Element issuer = DOMUtils.getFirstChildWithName(element, consts.getNamespace(), SPConstants.ISSUER);
+        if (issuer != null) {
+            conversationToken.setIssuerEpr(DOMUtils.getFirstElement(issuer));
         }
-        
-        element = element.getFirstChildWithName(SPConstants.POLICY);
+
+        element = DOMUtils.getFirstChildWithName(element, SPConstants.POLICY);
         if (element != null) {
-            if (element.getFirstChildWithName(SP11Constants.REQUIRE_DERIVED_KEYS) != null) {
+            if (DOMUtils.getFirstChildWithName(element, 
+                                               consts.getNamespace(),
+                                               SPConstants.REQUIRE_DERIVED_KEYS) != null) {
                 conversationToken.setDerivedKeys(true);
+            } else if (DOMUtils.getFirstChildWithName(element, 
+                                                      SP12Constants.REQUIRE_IMPLIED_DERIVED_KEYS) != null) {
+                conversationToken.setImpliedDerivedKeys(true);
+            } else if (DOMUtils.getFirstChildWithName(element, 
+                                                      SP12Constants.REQUIRE_EXPLICIT_DERIVED_KEYS) != null) {
+                conversationToken.setExplicitDerivedKeys(true);
             }
 
-            if (element
-                    .getFirstChildWithName(SP11Constants.REQUIRE_EXTERNAL_URI_REFERNCE) != null) {
+
+            if (DOMUtils.getFirstChildWithName(element,
+                                               consts.getNamespace(),
+                                               SPConstants.REQUIRE_EXTERNAL_URI_REFERNCE) != null) {
                 conversationToken.setRequireExternalUriRef(true);
             }
 
-            if (element
-                    .getFirstChildWithName(SP11Constants.SC10_SECURITY_CONTEXT_TOKEN) != null) {
+            if (DOMUtils.getFirstChildWithName(element, 
+                                               consts.getNamespace(),
+                                               SPConstants.SC10_SECURITY_CONTEXT_TOKEN) != null) {
                 conversationToken.setSc10SecurityContextToken(true);
             }
-            
-            OMElement bootstrapPolicyElement = element.getFirstChildWithName(SP11Constants.BOOTSTRAP_POLICY);
+
+            Element bootstrapPolicyElement = DOMUtils.getFirstChildWithName(element, 
+                                                                            consts.getNamespace(),
+                                                                            SPConstants.BOOTSTRAP_POLICY);
             if (bootstrapPolicyElement != null) {
-                Policy policy = PolicyEngine.getPolicy(bootstrapPolicyElement.getFirstElement());
+                Policy policy = builder.getPolicy(DOMUtils.getFirstElement(bootstrapPolicyElement));
                 conversationToken.setBootstrapPolicy(policy);
             }
         }
-        
+
         return conversationToken;
     }
 
-    public QName[] getKnownElements() {
-        return new QName[] {SP11Constants.SECURE_CONVERSATION_TOKEN};
+    public PolicyAssertion buildCompatible(PolicyAssertion a, PolicyAssertion b) {
+        // TODO Auto-generated method stub
+        return null;
     }
 
 }

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/SecurityContextTokenBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/SecurityContextTokenBuilder.java?rev=675332&r1=674910&r2=675332&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/SecurityContextTokenBuilder.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/SecurityContextTokenBuilder.java Wed Jul  9 13:11:45 2008
@@ -1,60 +1,80 @@
-/*
- * 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.secpolicy11.builders;
+package org.apache.cxf.ws.security.policy.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.builders.AssertionBuilder;
-import org.apache.ws.secpolicy.SP11Constants;
-import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.model.SecurityContextToken;
+import java.util.Arrays;
+import java.util.List;
 
 import javax.xml.namespace.QName;
 
+import org.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.ws.policy.AssertionBuilder;
+import org.apache.cxf.ws.policy.PolicyAssertion;
+import org.apache.cxf.ws.security.policy.SP11Constants;
+import org.apache.cxf.ws.security.policy.SP12Constants;
+import org.apache.cxf.ws.security.policy.SPConstants;
+import org.apache.cxf.ws.security.policy.model.SecurityContextToken;
+
+
 public class SecurityContextTokenBuilder implements AssertionBuilder {
+    private static final List<QName> KNOWN_ELEMENTS 
+        = Arrays.asList(SP11Constants.SECURITY_CONTEXT_TOKEN, SP12Constants.SECURITY_CONTEXT_TOKEN);
+    
+    public List<QName> getKnownElements() {
+        return KNOWN_ELEMENTS;
+    }
+    
+    public PolicyAssertion build(Element element)
+        throws IllegalArgumentException {
+
+        SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
+            ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
 
-    public Assertion build(OMElement element, AssertionBuilderFactory factory)
-            throws IllegalArgumentException {
+        SecurityContextToken contextToken = new SecurityContextToken(consts);
 
-        SecurityContextToken contextToken = new SecurityContextToken(SPConstants.SP_V11);
+        String includeAttr = DOMUtils.getAttribute(element, consts.getIncludeToken());
 
-        OMAttribute  includeAttr = element.getAttribute(SP11Constants.INCLUDE_TOKEN);
-        
-        if(includeAttr != null) {
-            int inclusion = SP11Constants.getInclusionFromAttributeValue(includeAttr.getAttributeValue());
-            contextToken.setInclusion(inclusion);
+        if (includeAttr != null) {
+            contextToken.setInclusion(consts.getInclusionFromAttributeValue(includeAttr));
         }
 
-        element = element.getFirstChildWithName(SPConstants.POLICY);
+        element = DOMUtils.getFirstChildWithName(element, SPConstants.POLICY);
 
         if (element != null) {
 
-            if (element.getFirstChildWithName(SP11Constants.REQUIRE_DERIVED_KEYS) != null) {
+            if (DOMUtils.getFirstChildWithName(element, 
+                                               consts.getNamespace(),
+                                               SPConstants.REQUIRE_DERIVED_KEYS) != null) {
                 contextToken.setDerivedKeys(true);
             }
 
-            if (element
-                    .getFirstChildWithName(SP11Constants.REQUIRE_EXTERNAL_URI_REFERNCE) != null) {
+            if (DOMUtils.getFirstChildWithName(element, 
+                                               consts.getNamespace(),
+                                               SPConstants.REQUIRE_EXTERNAL_URI_REFERNCE) != null) {
                 contextToken.setRequireExternalUriRef(true);
             }
 
-            if (element
-                    .getFirstChildWithName(SP11Constants.SC10_SECURITY_CONTEXT_TOKEN) != null) {
+            if (DOMUtils.getFirstChildWithName(element,
+                                               consts.getNamespace(),
+                                               SPConstants.SC10_SECURITY_CONTEXT_TOKEN) != null) {
                 contextToken.setSc10SecurityContextToken(true);
             }
         }
@@ -62,8 +82,10 @@
         return contextToken;
     }
 
-    public QName[] getKnownElements() {
-        return new QName[] {SP11Constants.SECURITY_CONTEXT_TOKEN};
+    public PolicyAssertion buildCompatible(PolicyAssertion a, PolicyAssertion b) {
+        // TODO Auto-generated method stub
+        return null;
     }
 
+
 }

Modified: cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/SignedElementsBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/SignedElementsBuilder.java?rev=675332&r1=674910&r2=675332&view=diff
==============================================================================
--- cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/SignedElementsBuilder.java (original)
+++ cxf/trunk/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/builders/SignedElementsBuilder.java Wed Jul  9 13:11:45 2008
@@ -1,66 +1,101 @@
-/*
- * 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.secpolicy11.builders;
+package org.apache.cxf.ws.security.policy.builders;
 
-import java.util.Iterator;
+import java.util.Arrays;
+import java.util.List;
 
 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.SPConstants;
-import org.apache.ws.secpolicy.model.SignedEncryptedElements;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.ws.policy.AssertionBuilder;
+import org.apache.cxf.ws.policy.PolicyAssertion;
+import org.apache.cxf.ws.security.policy.SP11Constants;
+import org.apache.cxf.ws.security.policy.SP12Constants;
+import org.apache.cxf.ws.security.policy.SPConstants;
+import org.apache.cxf.ws.security.policy.model.SignedEncryptedElements;
+
 
 public class SignedElementsBuilder implements AssertionBuilder {
+    private static final List<QName> KNOWN_ELEMENTS 
+        = Arrays.asList(SP11Constants.SIGNED_ELEMENTS, SP12Constants.SIGNED_ELEMENTS);
     
-    public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
-        
-        SignedEncryptedElements signedEncryptedElements = new SignedEncryptedElements(true, SPConstants.SP_V11);
-        OMAttribute attrXPathVersion = element.getAttribute(SP11Constants.ATTR_XPATH_VERSION);
+    public List<QName> getKnownElements() {
+        return KNOWN_ELEMENTS;
+    }
+     
+    public PolicyAssertion build(Element element)
+        throws IllegalArgumentException {
         
-        if (attrXPathVersion != null) {
-            signedEncryptedElements.setXPathVersion(attrXPathVersion.getAttributeValue());
+        SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
+            ? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
+    
+        SignedEncryptedElements signedEncryptedElements = new SignedEncryptedElements(true,
+                                                                                      consts);
+    
+        String attribute = element.getAttributeNS(consts.getNamespace(), SPConstants.XPATH_VERSION);
+        if (attribute != null) {
+            signedEncryptedElements.setXPathVersion(attribute);
         }
-        
-        for (Iterator iterator = element.getChildElements(); iterator.hasNext();) {
-            processElement((OMElement) iterator.next(), signedEncryptedElements);            
+    
+        Node nd = element.getFirstChild();
+        while (nd != null) {
+            if (nd instanceof Element) {
+                processElement((Element)nd, signedEncryptedElements);                
+            }
+            nd = nd.getNextSibling();
         }
-        
         return signedEncryptedElements;
     }
-        
-    public QName[] getKnownElements() {
-        return new QName[] {SP11Constants.SIGNED_ELEMENTS};
+    
+    
+    private void processElement(Element element, SignedEncryptedElements parent) {
+        if (SPConstants.XPATH_EXPR.equals(element.getLocalName())) {
+            parent.addXPathExpression(DOMUtils.getRawContent(element));
+            addNamespaces(element, parent);
+        }
     }
-
-    private void processElement(OMElement element, SignedEncryptedElements parent) {
-        QName name = element.getQName();
-        if (SP11Constants.XPATH.equals(name)) {
-            parent.addXPathExpression(element.getText());
-            Iterator namespaces = element.getAllDeclaredNamespaces();
-            while (namespaces.hasNext()) {
-                OMNamespace nm = (OMNamespace) namespaces.next();
-                parent.addDeclaredNamespaces(nm.getNamespaceURI(), nm.getPrefix());
+    private void addNamespaces(Node element, SignedEncryptedElements parent) {
+        if (element.getParentNode() != null) {
+            addNamespaces(element.getParentNode(), parent);
+        }
+        if (element instanceof Element) {
+            Element el = (Element)element;
+            NamedNodeMap map = el.getAttributes();
+            for (int x = 0; x < map.getLength(); x++) {
+                Attr attr = (Attr)map.item(x);
+                if ("xmlns".equals(attr.getPrefix())) {
+                    parent.addDeclaredNamespaces(attr.getValue(), attr.getLocalName());
+                }
             }
         }
     }
     
+    
+    public PolicyAssertion buildCompatible(PolicyAssertion a, PolicyAssertion b) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
 }



Mime
View raw message