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 [8/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...

Copied: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/KeyValueToken.java (from r1197660, axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/HttpsToken.java)
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/KeyValueToken.java?p2=webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/KeyValueToken.java&p1=axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/HttpsToken.java&r1=1197660&r2=1210203&rev=1210203&view=diff
==============================================================================
--- axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/HttpsToken.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/KeyValueToken.java Sun Dec  4 20:33:05 2011
@@ -1,144 +1,83 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+/**
+ * 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
+ * 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.
+ * 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.secpolicy.model;
 
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.neethi.PolicyComponent;
-import org.apache.ws.secpolicy.SP11Constants;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
 import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.SP12Constants;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+import java.util.List;
 
 /**
- * 
- * @author Ruchith Fernando (ruchith.fernando@gmail.com)
+ * @author $Author$
+ * @version $Revision$ $Date$
  */
-public class HttpsToken extends Token {
+public class KeyValueToken extends AbstractToken {
 
-    public HttpsToken(int version){
-        setVersion(version);
-    }
-    
-    private boolean requireClientCertificate = false;
-    private boolean httpBasicAuthentication = false;
-    private boolean httpDigestAuthentication = false;
-
-    public boolean isRequireClientCertificate() {
-        return requireClientCertificate;
-    }
-
-    public void setRequireClientCertificate(boolean requireClientCertificate) {
-        this.requireClientCertificate = requireClientCertificate;
-    }
-    
-    /**
-     * @return the httpBasicAuthentication
-     */
-    public boolean isHttpBasicAuthentication()
-    {
-        return httpBasicAuthentication;
-    }
-
-    /**
-     * @param httpBasicAuthentication the httpBasicAuthentication to set
-     */
-    public void setHttpBasicAuthentication(boolean httpBasicAuthentication)
-    {
-        this.httpBasicAuthentication = httpBasicAuthentication;
-    }
-
-    /**
-     * @return the httpDigestAuthentication
-     */
-    public boolean isHttpDigestAuthentication()
-    {
-        return httpDigestAuthentication;
-    }
-
-    /**
-     * @param httpDigestAuthentication the httpDigestAuthentication to set
-     */
-    public void setHttpDigestAuthentication(boolean httpDigestAuthentication)
-    {
-        this.httpDigestAuthentication = httpDigestAuthentication;
-    }
+    private boolean rsaKeyValue;
 
-    public QName getName() {
-        if (version == SPConstants.SP_V12) {
-            return SP12Constants.HTTPS_TOKEN;
-        } else {
-            return SP11Constants.HTTPS_TOKEN;
-        }
-    }
+    public KeyValueToken(SPConstants.SPVersion version, SPConstants.IncludeTokenType includeTokenType, Policy nestedPolicy) {
+        super(version, includeTokenType, null, null, null, nestedPolicy);
+        setIncludeTokenType(includeTokenType);
 
-    public PolicyComponent normalize() {
-        throw new UnsupportedOperationException();
+        parseNestedPolicy(nestedPolicy, this);
     }
 
-    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
-
-        String localname = getName().getLocalPart();
-        String namespaceURI = getName().getNamespaceURI();
-
-        String prefix = writer.getPrefix(namespaceURI);
-        if (prefix == null) {
-            prefix = getName().getPrefix();
-            writer.setPrefix(prefix, namespaceURI);
-        }
-
-        // <sp:HttpsToken
-        writer.writeStartElement(prefix, localname, namespaceURI);
-
+    public QName getName() {
+        return getVersion().getSPConstants().getKeyValueToken();
+    }
 
-        if (version == SPConstants.SP_V12) {
-            
-            if (isRequireClientCertificate() ||
-                isHttpBasicAuthentication() ||
-                isHttpDigestAuthentication()) {
-                // <wsp:Policy>
-                writer.writeStartElement(SPConstants.POLICY.getPrefix(), SPConstants.POLICY.getLocalPart(), SPConstants.POLICY.getNamespaceURI());
-                
-                /*
-                 *  The ws policy 1.2 specification states that only one of those should be present, although
-                 * a web server (say tomcat) could be normally configured to require both a client certificate and 
-                 * a http user/pwd authentication. Nevertheless stick to the specification.
-                 */
-                if(isHttpBasicAuthentication()) {
-                    writer.writeStartElement(prefix, SPConstants.HTTP_BASIC_AUTHENTICATION.getLocalPart(), namespaceURI);
-                    writer.writeEndElement();
-                } else if(isHttpDigestAuthentication()) {
-                    writer.writeStartElement(prefix, SPConstants.HTTP_DIGEST_AUTHENTICATION.getLocalPart(), namespaceURI);
-                    writer.writeEndElement();
-                } else if(isRequireClientCertificate()) {
-                    writer.writeStartElement(prefix, SPConstants.REQUIRE_CLIENT_CERTIFICATE.getLocalPart(), namespaceURI);
-                    writer.writeEndElement();
+    @Override
+    protected AbstractSecurityAssertion cloneAssertion(Policy nestedPolicy) {
+        return new KeyValueToken(getVersion(), getIncludeTokenType(), nestedPolicy);
+    }
+
+    protected void parseNestedPolicy(Policy nestedPolicy, KeyValueToken keyValueToken) {
+        Iterator<List<Assertion>> alternatives = nestedPolicy.getAlternatives();
+        //we just process the first alternative
+        //this means that if we have a compact policy only the first alternative is visible
+        //in contrary to a normalized policy where just one alternative exists
+        if (alternatives.hasNext()) {
+            List<Assertion> assertions = alternatives.next();
+            for (int i = 0; i < assertions.size(); i++) {
+                Assertion assertion = assertions.get(i);
+                String assertionName = assertion.getName().getLocalPart();
+                String assertionNamespace = assertion.getName().getNamespaceURI();
+                if (getVersion().getSPConstants().getRsaKeyValue().getLocalPart().equals(assertionName)
+                        && getVersion().getSPConstants().getRsaKeyValue().getNamespaceURI().equals(assertionNamespace)) {
+                    if (keyValueToken.isRsaKeyValue()) {
+                        throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+                    }
+                    keyValueToken.setRsaKeyValue(true);
+                    continue;
                 }
-                // </wsp:Policy>
-                writer.writeEndElement();
             }
-        } else {
-            // RequireClientCertificate=".."
-            writer.writeAttribute(SPConstants.REQUIRE_CLIENT_CERTIFICATE.getLocalPart(), Boolean
-                            .toString(isRequireClientCertificate()));
         }
+    }
+
+    public boolean isRsaKeyValue() {
+        return rsaKeyValue;
+    }
 
-        writer.writeEndElement();
-        // </sp:HttpsToken>
+    protected void setRsaKeyValue(boolean rsaKeyValue) {
+        this.rsaKeyValue = rsaKeyValue;
     }
 }

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

Modified: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/Layout.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/Layout.java?rev=1210203&r1=1210202&r2=1210203&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/Layout.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/Layout.java Sun Dec  4 20:33:05 2011
@@ -1,112 +1,113 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
+/**
+ * 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
  *
- * 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
  *
- *      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.
+ * 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.secpolicy.model;
 
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyComponent;
+import org.apache.neethi.PolicyContainingAssertion;
+import org.apache.ws.secpolicy.SPConstants;
+
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
+import java.util.*;
 
-import org.apache.neethi.PolicyComponent;
-import org.apache.ws.secpolicy.SP11Constants;
-import org.apache.ws.secpolicy.SP12Constants;
-import org.apache.ws.secpolicy.SPConstants;
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class Layout extends AbstractSecurityAssertion implements PolicyContainingAssertion {
 
-public class Layout extends AbstractSecurityAssertion {
+    public enum LayoutType {
+        Strict,
+        Lax,
+        LaxTsFirst,
+        LaxTsLast;
+
+        private static final Map<String, LayoutType> lookup = new HashMap<String, LayoutType>();
+
+        static {
+            for (LayoutType u : EnumSet.allOf(LayoutType.class))
+                lookup.put(u.name(), u);
+        }
 
-    private String value = SPConstants.LAYOUT_LAX;
-    
-    public Layout(int version) {
-        setVersion(version);
-    }
-
-    /**
-     * @return Returns the value.
-     */
-    public String getValue() {
-        return value;
-    }
-
-    /**
-     * @param value
-     *            The value to set.
-     */
-    public void setValue(String value) {
-        if (SPConstants.LAYOUT_LAX.equals(value)
-                || SPConstants.LAYOUT_STRICT.equals(value)
-                || SPConstants.LAYOUT_LAX_TIMESTAMP_FIRST.equals(value)
-                || SPConstants.LAYOUT_LAX_TIMESTAMP_LAST.equals(value)) {
-            this.value = value;
-        } else {
-            // throw new WSSPolicyException("Incorrect layout value : " +
-            // value);
+        public static LayoutType lookUp(String name) {
+            return lookup.get(name);
         }
     }
 
+    private Policy nestedPolicy;
+    private LayoutType layoutType = LayoutType.Lax;
+
+    public Layout(SPConstants.SPVersion version, Policy nestedPolicy) {
+        super(version);
+        this.nestedPolicy = nestedPolicy;
+
+        parseNestedPolicy(nestedPolicy, this);
+    }
+
+    public Policy getPolicy() {
+        return nestedPolicy;
+    }
+
     public QName getName() {
-        if ( version == SPConstants.SP_V12 ) {
-            return SP12Constants.LAYOUT;
-        } else {
-            return SP11Constants.LAYOUT; 
-        }  
+        return getVersion().getSPConstants().getLayout();
     }
 
     public PolicyComponent normalize() {
-        throw new UnsupportedOperationException();
+        return super.normalize(getPolicy());
     }
 
     public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+        super.serialize(writer, getPolicy());
+    }
 
-        String localName = getName().getLocalPart();
-        String namespaceURI = getName().getNamespaceURI();
-
-        String prefix = writer.getPrefix(namespaceURI);
-
-        if (prefix == null) {
-            prefix = getName().getPrefix();
-            writer.setPrefix(prefix, namespaceURI);
+    @Override
+    protected AbstractSecurityAssertion cloneAssertion(Policy nestedPolicy) {
+        return new Layout(getVersion(), nestedPolicy);
+    }
+
+    protected void parseNestedPolicy(Policy nestedPolicy, Layout layout) {
+        Iterator<List<Assertion>> alternatives = nestedPolicy.getAlternatives();
+        //we just process the first alternative
+        //this means that if we have a compact policy only the first alternative is visible
+        //in contrary to a normalized policy where just one alternative exists
+        if (alternatives.hasNext()) {
+            List<Assertion> assertions = alternatives.next();
+            for (int i = 0; i < assertions.size(); i++) {
+                Assertion assertion = assertions.get(i);
+                String assertionName = assertion.getName().getLocalPart();
+                LayoutType layoutType = LayoutType.lookUp(assertionName);
+                if (layoutType != null) {
+                    layout.setLayoutType(layoutType);
+                    continue;
+                }
+            }
         }
+    }
 
-        // <sp:Layout>
-        writer.writeStartElement(prefix, localName, namespaceURI);
+    public LayoutType getLayoutType() {
+        return layoutType;
+    }
 
-        // <wsp:Policy>
-        writer.writeStartElement(SPConstants.POLICY.getPrefix(), SPConstants.POLICY
-                .getLocalPart(), SPConstants.POLICY.getNamespaceURI());
-
-        // .. <sp:Strict /> | <sp:Lax /> | <sp:LaxTsFirst /> | <sp:LaxTsLast /> ..
-        if (SPConstants.LAYOUT_STRICT.equals(value)) {
-            writer.writeStartElement(prefix, SPConstants.LAYOUT_STRICT, namespaceURI);
-            
-        } else if (SPConstants.LAYOUT_LAX.equals(value)) {
-            writer.writeStartElement(prefix, SPConstants.LAYOUT_LAX, namespaceURI);
-            
-        } else if (SPConstants.LAYOUT_LAX_TIMESTAMP_FIRST.equals(value)) {
-            writer.writeStartElement(prefix, SPConstants.LAYOUT_LAX_TIMESTAMP_FIRST, namespaceURI);
-            
-        } else if (SPConstants.LAYOUT_LAX_TIMESTAMP_LAST.equals(value)) {
-            writer.writeStartElement(prefix, SPConstants.LAYOUT_LAX_TIMESTAMP_LAST, namespaceURI);
-        }
-        
-        writer.writeEndElement();
-        
-        // </wsp:Policy>
-        writer.writeEndElement();
-        
-        // </sp:Layout>
-        writer.writeEndElement();
+    protected void setLayoutType(LayoutType layoutType) {
+        this.layoutType = layoutType;
     }
 }

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

Modified: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/ProtectionToken.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/ProtectionToken.java?rev=1210203&r1=1210202&r2=1210203&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/ProtectionToken.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/ProtectionToken.java Sun Dec  4 20:33:05 2011
@@ -1,127 +1,44 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
+/**
+ * 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
  *
- * 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
  *
- *      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.
+ * 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.secpolicy.model;
 
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.neethi.PolicyComponent;
-import org.apache.ws.secpolicy.SP11Constants;
-import org.apache.ws.secpolicy.SP12Constants;
+import org.apache.neethi.Policy;
 import org.apache.ws.secpolicy.SPConstants;
 
-public class ProtectionToken extends AbstractSecurityAssertion implements TokenWrapper {
-    
-    private Token protectionToken;
-    
-    public ProtectionToken(int version) {
-        setVersion(version);
-    }
+import javax.xml.namespace.QName;
 
-    /**
-     * @return Returns the protectionToken.
-     */
-    public Token getProtectionToken() {
-        return protectionToken;
-    }
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class ProtectionToken extends AbstractTokenWrapper {
 
-    /**
-     * @param protectionToken The protectionToken to set.
-     */
-    public void setProtectionToken(Token protectionToken) {
-        this.protectionToken = protectionToken;
+    public ProtectionToken(SPConstants.SPVersion version, Policy nestedPolicy) {
+        super(version, nestedPolicy);
     }
 
-    public void setToken(Token tok) {
-        this.setProtectionToken(tok);
-    }
-    
     public QName getName() {
-        if ( version == SPConstants.SP_V12) {
-            return SP12Constants.PROTECTION_TOKEN;
-        } else {
-            return SP11Constants.PROTECTION_TOKEN;
-        }     
+        return getVersion().getSPConstants().getProtectionToken();
     }
 
-    public PolicyComponent normalize() {
-        /*
-         *  ProtectionToken can not contain multiple values. Hence we consider it
-         *  to always be in the normalized format.
-         */
-        return this;
+    @Override
+    protected AbstractSecurityAssertion cloneAssertion(Policy nestedPolicy) {
+        return new ProtectionToken(getVersion(), nestedPolicy);
     }
-
-    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
-        String localname = getName().getLocalPart();
-        String namespaceURI = getName().getNamespaceURI();
-        
-        String prefix;
-        
-        String writerPrefix = writer.getPrefix(namespaceURI);
-        if (writerPrefix == null) {
-            prefix = getName().getPrefix();
-            writer.setPrefix(prefix, namespaceURI);
-            
-        } else {
-            prefix = writerPrefix;
-        }
-        
-        // <sp:ProtectionToken>
-        writer.writeStartElement(prefix, localname, namespaceURI);
-        
-        if (writerPrefix == null) {
-            // xmlns:sp=".."
-            writer.writeNamespace(prefix, namespaceURI);
-        }
-        
-        String policyLocalName = SPConstants.POLICY.getLocalPart();
-        String policyNamespaceURI = SPConstants.POLICY.getNamespaceURI();
-        
-        String wspPrefix;
-        
-        String wspWriterPrefix = writer.getPrefix(policyNamespaceURI);
-        
-        if (wspWriterPrefix == null) {
-            wspPrefix = SPConstants.POLICY.getPrefix();
-            writer.setPrefix(wspPrefix, policyNamespaceURI);
-        } else {
-            wspPrefix = wspWriterPrefix;
-        }
-        
-        // <wsp:Policy>
-        writer.writeStartElement(wspPrefix, policyLocalName, policyNamespaceURI);
-        
-        if (wspWriterPrefix == null) {
-            // xmlns:wsp=".."
-            writer.writeNamespace(wspPrefix, policyNamespaceURI);
-        }
-        
-        if (protectionToken == null) {
-            throw new RuntimeException("ProtectionToken is not set");
-        }
-        
-        protectionToken.serialize(writer);
-        
-        // </wsp:Policy>
-        writer.writeEndElement();
-
-        // </sp:ProtectionToken>
-        writer.writeEndElement();
-    }    
 }

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

Copied: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientEncryptionToken.java (from r1197660, axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientToken.java)
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientEncryptionToken.java?p2=webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientEncryptionToken.java&p1=axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientToken.java&r1=1197660&r2=1210203&rev=1210203&view=diff
==============================================================================
--- axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientToken.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientEncryptionToken.java Sun Dec  4 20:33:05 2011
@@ -1,104 +1,44 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
+/**
+ * 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
  *
- * 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
  *
- *      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.
+ * 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.secpolicy.model;
 
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.neethi.PolicyComponent;
-import org.apache.ws.secpolicy.SP11Constants;
-import org.apache.ws.secpolicy.SP12Constants;
+import org.apache.neethi.Policy;
 import org.apache.ws.secpolicy.SPConstants;
 
-public class RecipientToken extends AbstractSecurityAssertion implements TokenWrapper {
-    
-    private Token receipientToken;
-    
-    public RecipientToken(int version) {
-        setVersion(version);
-    }
-   
-    /**
-     * @return Returns the receipientToken.
-     */
-    public Token getReceipientToken() {
-        return receipientToken;
-    }
+import javax.xml.namespace.QName;
 
-    /**
-     * @param receipientToken The receipientToken to set.
-     */
-    public void setReceipientToken(Token receipientToken) {
-        this.receipientToken = receipientToken;
-    }
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class RecipientEncryptionToken extends AbstractTokenWrapper {
 
-    /* (non-Javadoc)
-     * @see org.apache.ws.security.policy.TokenWrapper#setToken(org.apache.ws.security.policy.Token)
-     */
-    public void setToken(Token tok) {
-        this.setReceipientToken(tok);
+    public RecipientEncryptionToken(SPConstants.SPVersion version, Policy nestedPolicy) {
+        super(version, nestedPolicy);
     }
 
     public QName getName() {
-        if ( version == SPConstants.SP_V12) {
-            return SP12Constants.RECIPIENT_TOKEN;
-        } else {
-            return SP11Constants.RECIPIENT_TOKEN;
-        }     
+        return getVersion().getSPConstants().getRecipientEncryptionToken();
     }
 
-    public PolicyComponent normalize() {
-        throw new UnsupportedOperationException();
+    @Override
+    protected AbstractSecurityAssertion cloneAssertion(Policy nestedPolicy) {
+        return new RecipientEncryptionToken(getVersion(), nestedPolicy);
     }
-
-    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
-        String localName = getName().getLocalPart();
-        String namespaceURI = getName().getNamespaceURI();
-
-        String prefix = writer.getPrefix(namespaceURI);
-
-        if (prefix == null) {
-            prefix = getName().getPrefix();
-            writer.setPrefix(prefix, namespaceURI);
-        }
-        
-        // <sp:RecipientToken>
-        writer.writeStartElement(prefix, localName, namespaceURI);
-        
-        String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
-        if (pPrefix == null) {
-            pPrefix = SPConstants.POLICY.getPrefix();
-            writer.setPrefix(pPrefix, SPConstants.POLICY.getNamespaceURI());
-        }
-        
-        // <wsp:Policy>
-        writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY.getNamespaceURI());
-
-        Token token = getReceipientToken();
-        if (token == null) {
-            throw new RuntimeException("RecipientToken doesn't contain any token assertions");
-        }
-        token.serialize(writer);
-        
-        // </wsp:Policy>
-        writer.writeEndElement();
-        
-        // </sp:RecipientToken>
-        writer.writeEndElement();
-    }    
 }

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

Copied: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientSignatureToken.java (from r1197660, axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientToken.java)
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientSignatureToken.java?p2=webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientSignatureToken.java&p1=axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientToken.java&r1=1197660&r2=1210203&rev=1210203&view=diff
==============================================================================
--- axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientToken.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientSignatureToken.java Sun Dec  4 20:33:05 2011
@@ -1,104 +1,44 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
+/**
+ * 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
  *
- * 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
  *
- *      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.
+ * 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.secpolicy.model;
 
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.neethi.PolicyComponent;
-import org.apache.ws.secpolicy.SP11Constants;
-import org.apache.ws.secpolicy.SP12Constants;
+import org.apache.neethi.Policy;
 import org.apache.ws.secpolicy.SPConstants;
 
-public class RecipientToken extends AbstractSecurityAssertion implements TokenWrapper {
-    
-    private Token receipientToken;
-    
-    public RecipientToken(int version) {
-        setVersion(version);
-    }
-   
-    /**
-     * @return Returns the receipientToken.
-     */
-    public Token getReceipientToken() {
-        return receipientToken;
-    }
+import javax.xml.namespace.QName;
 
-    /**
-     * @param receipientToken The receipientToken to set.
-     */
-    public void setReceipientToken(Token receipientToken) {
-        this.receipientToken = receipientToken;
-    }
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class RecipientSignatureToken extends AbstractTokenWrapper {
 
-    /* (non-Javadoc)
-     * @see org.apache.ws.security.policy.TokenWrapper#setToken(org.apache.ws.security.policy.Token)
-     */
-    public void setToken(Token tok) {
-        this.setReceipientToken(tok);
+    public RecipientSignatureToken(SPConstants.SPVersion version, Policy nestedPolicy) {
+        super(version, nestedPolicy);
     }
 
     public QName getName() {
-        if ( version == SPConstants.SP_V12) {
-            return SP12Constants.RECIPIENT_TOKEN;
-        } else {
-            return SP11Constants.RECIPIENT_TOKEN;
-        }     
+        return getVersion().getSPConstants().getRecipientSignatureToken();
     }
 
-    public PolicyComponent normalize() {
-        throw new UnsupportedOperationException();
+    @Override
+    protected AbstractSecurityAssertion cloneAssertion(Policy nestedPolicy) {
+        return new RecipientSignatureToken(getVersion(), nestedPolicy);
     }
-
-    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
-        String localName = getName().getLocalPart();
-        String namespaceURI = getName().getNamespaceURI();
-
-        String prefix = writer.getPrefix(namespaceURI);
-
-        if (prefix == null) {
-            prefix = getName().getPrefix();
-            writer.setPrefix(prefix, namespaceURI);
-        }
-        
-        // <sp:RecipientToken>
-        writer.writeStartElement(prefix, localName, namespaceURI);
-        
-        String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
-        if (pPrefix == null) {
-            pPrefix = SPConstants.POLICY.getPrefix();
-            writer.setPrefix(pPrefix, SPConstants.POLICY.getNamespaceURI());
-        }
-        
-        // <wsp:Policy>
-        writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY.getNamespaceURI());
-
-        Token token = getReceipientToken();
-        if (token == null) {
-            throw new RuntimeException("RecipientToken doesn't contain any token assertions");
-        }
-        token.serialize(writer);
-        
-        // </wsp:Policy>
-        writer.writeEndElement();
-        
-        // </sp:RecipientToken>
-        writer.writeEndElement();
-    }    
 }

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

Modified: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientToken.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientToken.java?rev=1210203&r1=1210202&r2=1210203&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientToken.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RecipientToken.java Sun Dec  4 20:33:05 2011
@@ -1,104 +1,44 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
+/**
+ * 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
  *
- * 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
  *
- *      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.
+ * 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.secpolicy.model;
 
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.neethi.PolicyComponent;
-import org.apache.ws.secpolicy.SP11Constants;
-import org.apache.ws.secpolicy.SP12Constants;
+import org.apache.neethi.Policy;
 import org.apache.ws.secpolicy.SPConstants;
 
-public class RecipientToken extends AbstractSecurityAssertion implements TokenWrapper {
-    
-    private Token receipientToken;
-    
-    public RecipientToken(int version) {
-        setVersion(version);
-    }
-   
-    /**
-     * @return Returns the receipientToken.
-     */
-    public Token getReceipientToken() {
-        return receipientToken;
-    }
+import javax.xml.namespace.QName;
 
-    /**
-     * @param receipientToken The receipientToken to set.
-     */
-    public void setReceipientToken(Token receipientToken) {
-        this.receipientToken = receipientToken;
-    }
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class RecipientToken extends AbstractTokenWrapper {
 
-    /* (non-Javadoc)
-     * @see org.apache.ws.security.policy.TokenWrapper#setToken(org.apache.ws.security.policy.Token)
-     */
-    public void setToken(Token tok) {
-        this.setReceipientToken(tok);
+    public RecipientToken(SPConstants.SPVersion version, Policy nestedPolicy) {
+        super(version, nestedPolicy);
     }
 
     public QName getName() {
-        if ( version == SPConstants.SP_V12) {
-            return SP12Constants.RECIPIENT_TOKEN;
-        } else {
-            return SP11Constants.RECIPIENT_TOKEN;
-        }     
+        return getVersion().getSPConstants().getRecipientToken();
     }
 
-    public PolicyComponent normalize() {
-        throw new UnsupportedOperationException();
+    @Override
+    protected AbstractSecurityAssertion cloneAssertion(Policy nestedPolicy) {
+        return new RecipientToken(getVersion(), nestedPolicy);
     }
-
-    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
-        String localName = getName().getLocalPart();
-        String namespaceURI = getName().getNamespaceURI();
-
-        String prefix = writer.getPrefix(namespaceURI);
-
-        if (prefix == null) {
-            prefix = getName().getPrefix();
-            writer.setPrefix(prefix, namespaceURI);
-        }
-        
-        // <sp:RecipientToken>
-        writer.writeStartElement(prefix, localName, namespaceURI);
-        
-        String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
-        if (pPrefix == null) {
-            pPrefix = SPConstants.POLICY.getPrefix();
-            writer.setPrefix(pPrefix, SPConstants.POLICY.getNamespaceURI());
-        }
-        
-        // <wsp:Policy>
-        writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY.getNamespaceURI());
-
-        Token token = getReceipientToken();
-        if (token == null) {
-            throw new RuntimeException("RecipientToken doesn't contain any token assertions");
-        }
-        token.serialize(writer);
-        
-        // </wsp:Policy>
-        writer.writeEndElement();
-        
-        // </sp:RecipientToken>
-        writer.writeEndElement();
-    }    
 }

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

Added: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RelToken.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RelToken.java?rev=1210203&view=auto
==============================================================================
--- webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RelToken.java (added)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RelToken.java Sun Dec  4 20:33:05 2011
@@ -0,0 +1,126 @@
+/**
+ * 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.secpolicy.model;
+
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
+import org.apache.ws.secpolicy.SPConstants;
+import org.w3c.dom.Element;
+
+import javax.xml.namespace.QName;
+import java.util.*;
+
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class RelToken extends AbstractToken {
+
+    public enum RelTokenType {
+        WssRelV10Token10,
+        WssRelV20Token10,
+        WssRelV10Token11,
+        WssRelV20Token11;
+
+        private static final Map<String, RelTokenType> lookup = new HashMap<String, RelTokenType>();
+
+        static {
+            for (RelTokenType u : EnumSet.allOf(RelTokenType.class))
+                lookup.put(u.name(), u);
+        }
+
+        public static RelTokenType lookUp(String name) {
+            return lookup.get(name);
+        }
+    }
+
+    private boolean requireKeyIdentifierReference;
+    private RelTokenType relTokenType;
+
+    public RelToken(SPConstants.SPVersion version, SPConstants.IncludeTokenType includeTokenType,
+                    Element issuer, String issuerName, Element claims, Policy nestedPolicy) {
+        super(version, includeTokenType, issuer, issuerName, claims, nestedPolicy);
+
+        parseNestedPolicy(nestedPolicy, this);
+    }
+
+    public QName getName() {
+        return getVersion().getSPConstants().getRelToken();
+    }
+
+    @Override
+    protected AbstractSecurityAssertion cloneAssertion(Policy nestedPolicy) {
+        return new RelToken(getVersion(), getIncludeTokenType(), getIssuer(), getIssuerName(), getClaims(), nestedPolicy);
+    }
+
+    protected void parseNestedPolicy(Policy nestedPolicy, RelToken relToken) {
+        Iterator<List<Assertion>> alternatives = nestedPolicy.getAlternatives();
+        //we just process the first alternative
+        //this means that if we have a compact policy only the first alternative is visible
+        //in contrary to a normalized policy where just one alternative exists
+        if (alternatives.hasNext()) {
+            List<Assertion> assertions = alternatives.next();
+            for (int i = 0; i < assertions.size(); i++) {
+                Assertion assertion = assertions.get(i);
+                String assertionName = assertion.getName().getLocalPart();
+                String assertionNamespace = assertion.getName().getNamespaceURI();
+                DerivedKeys derivedKeys = DerivedKeys.lookUp(assertionName);
+                if (derivedKeys != null) {
+                    if (relToken.getDerivedKeys() != null) {
+                        throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+                    }
+                    relToken.setDerivedKeys(derivedKeys);
+                    continue;
+                }
+                if (getVersion().getSPConstants().getRequireKeyIdentifierReference().getLocalPart().equals(assertionName)
+                        && getVersion().getSPConstants().getRequireKeyIdentifierReference().getNamespaceURI().equals(assertionNamespace)) {
+                    if (relToken.isRequireKeyIdentifierReference()) {
+                        throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+                    }
+                    relToken.setRequireKeyIdentifierReference(true);
+                    continue;
+                }
+                RelTokenType samlTokenType = RelTokenType.lookUp(assertionName);
+                if (samlTokenType != null) {
+                    if (relToken.getRelTokenType() != null) {
+                        throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+                    }
+                    relToken.setRelTokenType(samlTokenType);
+                    continue;
+                }
+            }
+        }
+    }
+
+    public boolean isRequireKeyIdentifierReference() {
+        return requireKeyIdentifierReference;
+    }
+
+    public void setRequireKeyIdentifierReference(boolean requireKeyIdentifierReference) {
+        this.requireKeyIdentifierReference = requireKeyIdentifierReference;
+    }
+
+    public RelTokenType getRelTokenType() {
+        return relTokenType;
+    }
+
+    protected void setRelTokenType(RelTokenType relTokenType) {
+        this.relTokenType = relTokenType;
+    }
+}

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

Modified: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RequiredElements.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RequiredElements.java?rev=1210203&r1=1210202&r2=1210203&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RequiredElements.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RequiredElements.java Sun Dec  4 20:33:05 2011
@@ -1,134 +1,109 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
+/**
+ * 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
  *
- * 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
  *
- *      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.
+ * 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.secpolicy.model;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.HashMap;
+import org.apache.neethi.Constants;
+import org.apache.neethi.Policy;
+import org.apache.ws.secpolicy.SPConstants;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
-import org.apache.neethi.PolicyComponent;
-import org.apache.ws.secpolicy.SP11Constants;
-import org.apache.ws.secpolicy.SP12Constants;
-import org.apache.ws.secpolicy.SPConstants;
-
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
 public class RequiredElements extends AbstractSecurityAssertion {
 
-    private ArrayList xPathExpressions = new ArrayList();
-    
-    private HashMap declaredNamespaces = new HashMap();
-
     private String xPathVersion;
+    private List<XPath> xPaths = new ArrayList<XPath>();
 
-    public RequiredElements(int version) {
-        setVersion(version);
-    }
+    public RequiredElements(SPConstants.SPVersion version, String xPathVersion, List<XPath> xPaths) {
+        super(version);
 
-    /**
-     * @return Returns the xPathExpressions.
-     */
-    public ArrayList getXPathExpressions() {
-        return xPathExpressions;
+        this.xPathVersion = xPathVersion;
+        this.xPaths.addAll(xPaths);
     }
 
-    public void addXPathExpression(String expr) {
-        this.xPathExpressions.add(expr);
+    public QName getName() {
+        return getVersion().getSPConstants().getRequiredElements();
     }
 
-    /**
-     * @return Returns the xPathVersion.
-     */
-    public String getXPathVersion() {
-        return xPathVersion;
+    @Override
+    protected AbstractSecurityAssertion cloneAssertion(Policy nestedPolicy) {
+        return new RequiredElements(getVersion(), getXPathVersion(), getXPaths());
     }
 
-    /**
-     * @param pathVersion
-     *            The xPathVersion to set.
-     */
-    public void setXPathVersion(String pathVersion) {
-        xPathVersion = pathVersion;
-    }
-    
-    public HashMap getDeclaredNamespaces () {
-        return declaredNamespaces;
-    }
-    
-    public void addDeclaredNamespaces(String uri, String prefix ) {
-        declaredNamespaces.put(prefix, uri);
-    }
-        
     public void serialize(XMLStreamWriter writer) throws XMLStreamException {
-
-        String localName = getName().getLocalPart();
-        String namespaceURI = getName().getNamespaceURI();
-
-        String prefix;
-        String writerPrefix = writer.getPrefix(namespaceURI);
-
-        if (writerPrefix == null) {
-            prefix = getName().getPrefix();
-            writer.setPrefix(prefix, namespaceURI);
-        } else {
-            prefix = writerPrefix;
+        writer.writeStartElement(getName().getPrefix(), getName().getLocalPart(), getName().getNamespaceURI());
+        writer.writeNamespace(getName().getPrefix(), getName().getNamespaceURI());
+        if (!isNormalized() && isOptional()) {
+            writer.writeAttribute(Constants.ATTR_WSP, writer.getNamespaceContext().getNamespaceURI(Constants.ATTR_WSP), Constants.ATTR_OPTIONAL, "true");
         }
-
-        //  <sp:RequiredElements>
-        writer.writeStartElement(prefix, localName, namespaceURI);
-        
-        // xmlns:sp=".."
-        writer.writeNamespace(prefix, namespaceURI);
-
-        if (writerPrefix == null) {
-            // xmlns:sp=".."
-            writer.writeNamespace(prefix, namespaceURI);
+        if (getXPathVersion() != null) {
+            writer.writeAttribute(SPConstants.XPATH_VERSION, getXPathVersion());
         }
-
-        if (xPathVersion != null) {
-            writer.writeAttribute(prefix, namespaceURI, SPConstants.XPATH_VERSION, xPathVersion);
+        if (isIgnorable()) {
+            writer.writeAttribute(Constants.ATTR_WSP, writer.getNamespaceContext().getNamespaceURI(Constants.ATTR_WSP), Constants.ATTR_IGNORABLE, "true");
         }
-
-        String xpathExpression;
-
-        for (Iterator iterator = xPathExpressions.iterator(); iterator
-                .hasNext();) {
-            xpathExpression = (String) iterator.next();
-            // <sp:XPath ..>
-            writer.writeStartElement(prefix, SPConstants.XPATH_EXPR, namespaceURI);
-            writer.writeCharacters(xpathExpression);
+        for (int i = 0; i < xPaths.size(); i++) {
+            XPath xPath = xPaths.get(i);
+            if (XPath.Version.V1 == xPath.getVersion()) {
+                writer.writeStartElement(
+                        getVersion().getSPConstants().getXPathExpression().getPrefix(),
+                        getVersion().getSPConstants().getXPathExpression().getLocalPart(),
+                        getVersion().getSPConstants().getXPathExpression().getNamespaceURI());
+            } else if (XPath.Version.V2 == xPath.getVersion()) {
+                writer.writeStartElement(
+                        getVersion().getSPConstants().getXPath2Expression().getPrefix(),
+                        getVersion().getSPConstants().getXPath2Expression().getLocalPart(),
+                        getVersion().getSPConstants().getXPath2Expression().getNamespaceURI());
+                writer.writeNamespace(
+                        getVersion().getSPConstants().getXPath2Expression().getPrefix(),
+                        getVersion().getSPConstants().getXPath2Expression().getNamespaceURI());
+                writer.writeAttribute(SPConstants.FILTER, xPath.getFilter());
+            }
+            Iterator<Map.Entry<String, String>> namespaceIterator = xPath.getPrefixNamespaceMap().entrySet().iterator();
+            while (namespaceIterator.hasNext()) {
+                Map.Entry<String, String> namespaceEntry = namespaceIterator.next();
+                writer.writeNamespace(namespaceEntry.getKey(), namespaceEntry.getValue());
+            }
+            writer.writeCharacters(xPath.getXPath());
             writer.writeEndElement();
         }
-
-        //</sp:RequiredElements>
         writer.writeEndElement();
     }
 
-    public QName getName() {
-        if (version == SPConstants.SP_V12) {
-            return SP12Constants.REQUIRED_ELEMENTS;
-        } else {
-            return SP11Constants.REQUIRED_ELEMENTS;
-        }      
+    public List<XPath> getXPaths() {
+        return xPaths;
+    }
+
+    public String getXPathVersion() {
+        return xPathVersion;
     }
 
-    public PolicyComponent normalize() {
-        return this;
+    protected void setXPathVersion(String xPathVersion) {
+        this.xPathVersion = xPathVersion;
     }
 }

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

Modified: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RequiredParts.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RequiredParts.java?rev=1210203&r1=1210202&r2=1210203&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RequiredParts.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/RequiredParts.java Sun Dec  4 20:33:05 2011
@@ -1,98 +1,81 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
+/**
+ * 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
  *
- * 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
  *
- *      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.
+ * 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.secpolicy.model;
 
-import java.util.ArrayList;
-import java.util.Iterator;
+import org.apache.neethi.Constants;
+import org.apache.neethi.Policy;
+import org.apache.ws.secpolicy.SPConstants;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
+import java.util.ArrayList;
+import java.util.List;
 
-import org.apache.neethi.PolicyComponent;
-import org.apache.ws.secpolicy.SP11Constants;
-import org.apache.ws.secpolicy.SP12Constants;
-import org.apache.ws.secpolicy.SPConstants;
-
+/**
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
 public class RequiredParts extends AbstractSecurityAssertion {
-    
-    private ArrayList headers = new ArrayList();
-    
-    public RequiredParts(int version) {
-        setVersion(version);
-    }
 
-    /**
-     * @return Returns the headers.
-     */
-    public ArrayList getHeaders() {
-        return this.headers;
-    }
+    private List<Header> headers = new ArrayList<Header>();
 
-    /**
-     * @param headers The headers to set.
-     */
-    public void addHeader(Header header) {
-        this.headers.add(header);
+    public RequiredParts(SPConstants.SPVersion version, List<Header> headers) {
+        super(version);
+        this.headers.addAll(headers);
     }
 
-
     public QName getName() {
-         return SP12Constants.REQUIRED_PARTS;         
-    }
-
-    public PolicyComponent normalize() {
-        return this;
+        return getVersion().getSPConstants().getRequiredParts();
     }
 
     public void serialize(XMLStreamWriter writer) throws XMLStreamException {
-        String localName = getName().getLocalPart();
-        String namespaceURI = getName().getNamespaceURI();
-
-        String prefix = writer.getPrefix(namespaceURI);
-
-        if (prefix == null) {
-            prefix = getName().getPrefix();
-            writer.setPrefix(prefix, namespaceURI);
+        writer.writeStartElement(getName().getPrefix(), getName().getLocalPart(), getName().getNamespaceURI());
+        writer.writeNamespace(getName().getPrefix(), getName().getNamespaceURI());
+        if (!isNormalized() && isOptional()) {
+            writer.writeAttribute(Constants.ATTR_WSP, writer.getNamespaceContext().getNamespaceURI(Constants.ATTR_WSP), Constants.ATTR_OPTIONAL, "true");
+        }
+        if (isIgnorable()) {
+            writer.writeAttribute(Constants.ATTR_WSP, writer.getNamespaceContext().getNamespaceURI(Constants.ATTR_WSP), Constants.ATTR_IGNORABLE, "true");
         }
-            
-        // <sp:RequiredParts> 
-        writer.writeStartElement(prefix, localName, namespaceURI);
-        
-        // xmlns:sp=".."
-        writer.writeNamespace(prefix, namespaceURI);
-        
-        Header header;        
-        for (Iterator iterator = headers.iterator(); iterator.hasNext();) {
-            header = (Header) iterator.next();
-            // <sp:Header Name=".." Namespace=".." />
-            writer.writeStartElement(prefix, SPConstants.HEADER, namespaceURI);
-            // Name attribute is optional
+        for (int i = 0; i < getHeaders().size(); i++) {
+            Header header = getHeaders().get(i);
+            final QName headerName = getVersion().getSPConstants().getHeader();
+            writer.writeEmptyElement(headerName.getPrefix(), headerName.getLocalPart(), headerName.getNamespaceURI());
             if (header.getName() != null) {
-                writer.writeAttribute("Name", header.getName());
+                writer.writeAttribute(SPConstants.NAME, header.getName());
             }
-            writer.writeAttribute("Namespace", header.getNamespace());
-            
-            writer.writeEndElement();
+            writer.writeAttribute(SPConstants.NAMESPACE, header.getNamespace());
         }
-        
-        // </sp:RequiredParts>
         writer.writeEndElement();
-    }    
-    
-    
+    }
+
+    @Override
+    protected AbstractSecurityAssertion cloneAssertion(Policy nestedPolicy) {
+        return new RequiredParts(getVersion(), getHeaders());
+    }
+
+    public List<Header> getHeaders() {
+        return this.headers;
+    }
+
+    protected void addHeader(Header header) {
+        this.headers.add(header);
+    }
 }

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

Copied: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/SamlToken.java (from r1197660, axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/HttpsToken.java)
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/SamlToken.java?p2=webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/SamlToken.java&p1=axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/HttpsToken.java&r1=1197660&r2=1210203&rev=1210203&view=diff
==============================================================================
--- axis/axis2/java/rampart/trunk/modules/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/HttpsToken.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/SamlToken.java Sun Dec  4 20:33:05 2011
@@ -1,144 +1,127 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+/**
+ * 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
+ * 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.
+ * 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.secpolicy.model;
 
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.neethi.PolicyComponent;
-import org.apache.ws.secpolicy.SP11Constants;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
 import org.apache.ws.secpolicy.SPConstants;
-import org.apache.ws.secpolicy.SP12Constants;
+import org.w3c.dom.Element;
+
+import javax.xml.namespace.QName;
+import java.util.*;
 
 /**
- * 
- * @author Ruchith Fernando (ruchith.fernando@gmail.com)
+ * @author $Author$
+ * @version $Revision$ $Date$
  */
-public class HttpsToken extends Token {
+public class SamlToken extends AbstractToken {
 
-    public HttpsToken(int version){
-        setVersion(version);
-    }
-    
-    private boolean requireClientCertificate = false;
-    private boolean httpBasicAuthentication = false;
-    private boolean httpDigestAuthentication = false;
-
-    public boolean isRequireClientCertificate() {
-        return requireClientCertificate;
-    }
-
-    public void setRequireClientCertificate(boolean requireClientCertificate) {
-        this.requireClientCertificate = requireClientCertificate;
-    }
-    
-    /**
-     * @return the httpBasicAuthentication
-     */
-    public boolean isHttpBasicAuthentication()
-    {
-        return httpBasicAuthentication;
-    }
-
-    /**
-     * @param httpBasicAuthentication the httpBasicAuthentication to set
-     */
-    public void setHttpBasicAuthentication(boolean httpBasicAuthentication)
-    {
-        this.httpBasicAuthentication = httpBasicAuthentication;
-    }
-
-    /**
-     * @return the httpDigestAuthentication
-     */
-    public boolean isHttpDigestAuthentication()
-    {
-        return httpDigestAuthentication;
-    }
-
-    /**
-     * @param httpDigestAuthentication the httpDigestAuthentication to set
-     */
-    public void setHttpDigestAuthentication(boolean httpDigestAuthentication)
-    {
-        this.httpDigestAuthentication = httpDigestAuthentication;
-    }
-
-    public QName getName() {
-        if (version == SPConstants.SP_V12) {
-            return SP12Constants.HTTPS_TOKEN;
-        } else {
-            return SP11Constants.HTTPS_TOKEN;
+    public enum SamlTokenType {
+        WssSamlV10Token10,
+        WssSamlV11Token10,
+        WssSamlV10Token11,
+        WssSamlV11Token11,
+        WssSamlV20Token11;
+
+        private static final Map<String, SamlTokenType> lookup = new HashMap<String, SamlTokenType>();
+
+        static {
+            for (SamlTokenType u : EnumSet.allOf(SamlTokenType.class))
+                lookup.put(u.name(), u);
         }
-    }
 
-    public PolicyComponent normalize() {
-        throw new UnsupportedOperationException();
+        public static SamlTokenType lookUp(String name) {
+            return lookup.get(name);
+        }
     }
 
-    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+    private boolean requireKeyIdentifierReference;
+    private SamlTokenType samlTokenType;
 
-        String localname = getName().getLocalPart();
-        String namespaceURI = getName().getNamespaceURI();
+    public SamlToken(SPConstants.SPVersion version, SPConstants.IncludeTokenType includeTokenType,
+                     Element issuer, String issuerName, Element claims, Policy nestedPolicy) {
+        super(version, includeTokenType, issuer, issuerName, claims, nestedPolicy);
 
-        String prefix = writer.getPrefix(namespaceURI);
-        if (prefix == null) {
-            prefix = getName().getPrefix();
-            writer.setPrefix(prefix, namespaceURI);
-        }
-
-        // <sp:HttpsToken
-        writer.writeStartElement(prefix, localname, namespaceURI);
+        parseNestedPolicy(nestedPolicy, this);
+    }
 
+    public QName getName() {
+        return getVersion().getSPConstants().getSamlToken();
+    }
 
-        if (version == SPConstants.SP_V12) {
-            
-            if (isRequireClientCertificate() ||
-                isHttpBasicAuthentication() ||
-                isHttpDigestAuthentication()) {
-                // <wsp:Policy>
-                writer.writeStartElement(SPConstants.POLICY.getPrefix(), SPConstants.POLICY.getLocalPart(), SPConstants.POLICY.getNamespaceURI());
-                
-                /*
-                 *  The ws policy 1.2 specification states that only one of those should be present, although
-                 * a web server (say tomcat) could be normally configured to require both a client certificate and 
-                 * a http user/pwd authentication. Nevertheless stick to the specification.
-                 */
-                if(isHttpBasicAuthentication()) {
-                    writer.writeStartElement(prefix, SPConstants.HTTP_BASIC_AUTHENTICATION.getLocalPart(), namespaceURI);
-                    writer.writeEndElement();
-                } else if(isHttpDigestAuthentication()) {
-                    writer.writeStartElement(prefix, SPConstants.HTTP_DIGEST_AUTHENTICATION.getLocalPart(), namespaceURI);
-                    writer.writeEndElement();
-                } else if(isRequireClientCertificate()) {
-                    writer.writeStartElement(prefix, SPConstants.REQUIRE_CLIENT_CERTIFICATE.getLocalPart(), namespaceURI);
-                    writer.writeEndElement();
+    @Override
+    protected AbstractSecurityAssertion cloneAssertion(Policy nestedPolicy) {
+        return new SamlToken(getVersion(), getIncludeTokenType(), getIssuer(), getIssuerName(), getClaims(), nestedPolicy);
+    }
+
+    protected void parseNestedPolicy(Policy nestedPolicy, SamlToken samlToken) {
+        Iterator<List<Assertion>> alternatives = nestedPolicy.getAlternatives();
+        //we just process the first alternative
+        //this means that if we have a compact policy only the first alternative is visible
+        //in contrary to a normalized policy where just one alternative exists
+        if (alternatives.hasNext()) {
+            List<Assertion> assertions = alternatives.next();
+            for (int i = 0; i < assertions.size(); i++) {
+                Assertion assertion = assertions.get(i);
+                String assertionName = assertion.getName().getLocalPart();
+                String assertionNamespace = assertion.getName().getNamespaceURI();
+                DerivedKeys derivedKeys = DerivedKeys.lookUp(assertionName);
+                if (derivedKeys != null) {
+                    if (samlToken.getDerivedKeys() != null) {
+                        throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+                    }
+                    samlToken.setDerivedKeys(derivedKeys);
+                    continue;
+                }
+                if (getVersion().getSPConstants().getRequireKeyIdentifierReference().getLocalPart().equals(assertionName)
+                        && getVersion().getSPConstants().getRequireKeyIdentifierReference().getNamespaceURI().equals(assertionNamespace)) {
+                    if (samlToken.isRequireKeyIdentifierReference()) {
+                        throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+                    }
+                    samlToken.setRequireKeyIdentifierReference(true);
+                    continue;
+                }
+                SamlTokenType samlTokenType = SamlTokenType.lookUp(assertionName);
+                if (samlTokenType != null) {
+                    if (samlToken.getSamlTokenType() != null) {
+                        throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+                    }
+                    samlToken.setSamlTokenType(samlTokenType);
+                    continue;
                 }
-                // </wsp:Policy>
-                writer.writeEndElement();
             }
-        } else {
-            // RequireClientCertificate=".."
-            writer.writeAttribute(SPConstants.REQUIRE_CLIENT_CERTIFICATE.getLocalPart(), Boolean
-                            .toString(isRequireClientCertificate()));
         }
+    }
+
+    public boolean isRequireKeyIdentifierReference() {
+        return requireKeyIdentifierReference;
+    }
+
+    public void setRequireKeyIdentifierReference(boolean requireKeyIdentifierReference) {
+        this.requireKeyIdentifierReference = requireKeyIdentifierReference;
+    }
+
+    public SamlTokenType getSamlTokenType() {
+        return samlTokenType;
+    }
 
-        writer.writeEndElement();
-        // </sp:HttpsToken>
+    protected void setSamlTokenType(SamlTokenType samlTokenType) {
+        this.samlTokenType = samlTokenType;
     }
 }

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

Modified: webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/SecureConversationToken.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/SecureConversationToken.java?rev=1210203&r1=1210202&r2=1210203&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/SecureConversationToken.java (original)
+++ webservices/wss4j/branches/swssf/rampart-policy/src/main/java/org/apache/ws/secpolicy/model/SecureConversationToken.java Sun Dec  4 20:33:05 2011
@@ -1,185 +1,138 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+/**
+ * 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
+ * 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.
+ * 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.secpolicy.model;
 
-import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
 import org.apache.neethi.Policy;
-import org.apache.ws.secpolicy.SP11Constants;
-import org.apache.ws.secpolicy.SP12Constants;
+import org.apache.neethi.builders.PolicyContainingPrimitiveAssertion;
 import org.apache.ws.secpolicy.SPConstants;
+import org.w3c.dom.Element;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
+import java.util.Iterator;
+import java.util.List;
 
 /**
- * Model class of SecureConversationToken assertion
+ * @author $Author$
+ * @version $Revision$ $Date$
  */
 public class SecureConversationToken extends SecurityContextToken {
 
     private Policy bootstrapPolicy;
 
-    private OMElement issuerEpr;
-    
-    public SecureConversationToken(int version) {
-        super(version);
-    }
+    private boolean mustNotSendCancel;
+    private boolean mustNotSendAmend;
+    private boolean mustNotSendRenew;
+
+    public SecureConversationToken(SPConstants.SPVersion version, SPConstants.IncludeTokenType includeTokenType,
+                                   Element issuer, String issuerName, Element claims, Policy nestedPolicy) {
+        super(version, includeTokenType, issuer, issuerName, claims, nestedPolicy);
 
-    /**
-     * @return Returns the bootstrapPolicy.
-     */
-    public Policy getBootstrapPolicy() {
-        return bootstrapPolicy;
+        parseNestedPolicy(nestedPolicy, this);
     }
 
-    /**
-     * @param bootstrapPolicy
-     *            The bootstrapPolicy to set.
-     */
-    public void setBootstrapPolicy(Policy bootstrapPolicy) {
-        this.bootstrapPolicy = bootstrapPolicy;
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.neethi.Assertion#getName()
-     */
     public QName getName() {
-        if ( version == SPConstants.SP_V12) {
-            return SP12Constants.SECURE_CONVERSATION_TOKEN;
-        } else {
-            return SP11Constants.SECURE_CONVERSATION_TOKEN; 
-        }      
-    }
-
-    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
-
-        String localname = getName().getLocalPart();
-        String namespaceURI = getName().getNamespaceURI();
-        String prefix;
-
-        String writerPrefix = writer.getPrefix(namespaceURI);
-
-        if (writerPrefix == null) {
-            prefix = getName().getPrefix();
-            writer.setPrefix(prefix, namespaceURI);
-        } else {
-            prefix = writerPrefix;
-        }
-
-        // <sp:SecureConversationToken>
-        writer.writeStartElement(prefix, localname, namespaceURI);
-
-        if (writerPrefix == null) {
-            // xmlns:sp=".."
-            writer.writeNamespace(prefix, namespaceURI);
-        }
-
-        String inclusion;
-        
-        if (version == SPConstants.SP_V12) {
-            inclusion = SP12Constants.getAttributeValueFromInclusion(getInclusion());
-        } else {
-            inclusion = SP11Constants.getAttributeValueFromInclusion(getInclusion()); 
-        }
-
-        if (inclusion != null) {
-            writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
-        }
-
-        if (issuerEpr != null) {
-            // <sp:Issuer>
-            writer.writeStartElement(prefix, SPConstants.ISSUER , namespaceURI);
-
-            issuerEpr.serialize(writer);
-
-            writer.writeEndElement();
-        }
-
-        if (isDerivedKeys() || isRequireExternalUriRef()
-                || isSc10SecurityContextToken() || (bootstrapPolicy != null)) {
-
-            String wspNamespaceURI = SPConstants.POLICY.getNamespaceURI();
-
-            String wspPrefix;
-
-            String wspWriterPrefix = writer.getPrefix(wspNamespaceURI);
-
-            if (wspWriterPrefix == null) {
-                wspPrefix = SPConstants.POLICY.getPrefix();
-                writer.setPrefix(wspPrefix, wspNamespaceURI);
-
-            } else {
-                wspPrefix = wspWriterPrefix;
-            }
+        return getVersion().getSPConstants().getSecureConversationToken();
+    }
 
-            // <wsp:Policy>
-            writer.writeStartElement(wspPrefix,
-                    SPConstants.POLICY.getLocalPart(), wspNamespaceURI);
-
-            if (wspWriterPrefix == null) {
-                // xmlns:wsp=".."
-                writer.writeNamespace(wspPrefix, wspNamespaceURI);
-            }
-            
-            if (isDerivedKeys()) {
-                // <sp:RequireDerivedKeys />
-                writer.writeEmptyElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI);
-            }
-            
-            if (isRequireExternalUriRef()) {
-                // <sp:RequireExternalUriReference />
-                writer.writeEmptyElement(prefix, SPConstants.REQUIRE_EXTERNAL_URI_REFERNCE, namespaceURI);
-            }
-            
-            if (isSc10SecurityContextToken()) {
-                // <sp:SC10SecurityContextToken />
-                writer.writeEmptyElement(prefix, SPConstants.SC10_SECURITY_CONTEXT_TOKEN, namespaceURI);
-            }
-            
-            if (bootstrapPolicy != null) {
-                // <sp:BootstrapPolicy ..>
-                writer.writeStartElement(prefix, SPConstants.BOOTSTRAP_POLICY, namespaceURI);
-                bootstrapPolicy.serialize(writer);
-                writer.writeEndElement();
-            }
+    @Override
+    protected AbstractSecurityAssertion cloneAssertion(Policy nestedPolicy) {
+        return new SecureConversationToken(getVersion(), getIncludeTokenType(), getIssuer(), getIssuerName(), getClaims(), nestedPolicy);
+    }
+
+    protected void parseNestedPolicy(Policy nestedPolicy, SecureConversationToken secureConversationToken) {
+        Iterator<List<Assertion>> alternatives = nestedPolicy.getAlternatives();
+        //we just process the first alternative
+        //this means that if we have a compact policy only the first alternative is visible
+        //in contrary to a normalized policy where just one alternative exists
+        if (alternatives.hasNext()) {
+            List<Assertion> assertions = alternatives.next();
+            for (int i = 0; i < assertions.size(); i++) {
+                Assertion assertion = assertions.get(i);
+                String assertionName = assertion.getName().getLocalPart();
+                String assertionNamespace = assertion.getName().getNamespaceURI();
+                if (getVersion().getSPConstants().getMustNotSendCancel().getLocalPart().equals(assertionName)
+                        && getVersion().getSPConstants().getMustNotSendCancel().getNamespaceURI().equals(assertionNamespace)) {
+                    if (secureConversationToken.isMustNotSendCancel()) {
+                        throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+                    }
+                    secureConversationToken.setMustNotSendCancel(true);
+                    continue;
+                }
+                if (getVersion().getSPConstants().getMustNotSendAmend().getLocalPart().equals(assertionName)
+                        && getVersion().getSPConstants().getMustNotSendAmend().getNamespaceURI().equals(assertionNamespace)) {
+                    if (secureConversationToken.isMustNotSendAmend()) {
+                        throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+                    }
+                    secureConversationToken.setMustNotSendAmend(true);
+                    continue;
+                }
+                if (getVersion().getSPConstants().getMustNotSendRenew().getLocalPart().equals(assertionName)
+                        && getVersion().getSPConstants().getMustNotSendRenew().getNamespaceURI().equals(assertionNamespace)) {
+                    if (secureConversationToken.isMustNotSendRenew()) {
+                        throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+                    }
+                    secureConversationToken.setMustNotSendRenew(true);
+                    continue;
+                }
+                if (getVersion().getSPConstants().getBootstrapPolicy().getLocalPart().equals(assertionName)
+                        && getVersion().getSPConstants().getBootstrapPolicy().getNamespaceURI().equals(assertionNamespace)) {
+                    if (secureConversationToken.getBootstrapPolicy() != null) {
+                        throw new IllegalArgumentException(SPConstants.ERR_INVALID_POLICY);
+                    }
+                    PolicyContainingPrimitiveAssertion policyContainingPrimitiveAssertion = (PolicyContainingPrimitiveAssertion) assertion;
+                    secureConversationToken.setBootstrapPolicy(policyContainingPrimitiveAssertion.getPolicy());
+                    continue;
+                }
+            }
+        }
+    }
+
+    public boolean isMustNotSendCancel() {
+        return mustNotSendCancel;
+    }
+
+    protected void setMustNotSendCancel(boolean mustNotSendCancel) {
+        this.mustNotSendCancel = mustNotSendCancel;
+    }
+
+    public boolean isMustNotSendAmend() {
+        return mustNotSendAmend;
+    }
+
+    protected void setMustNotSendAmend(boolean mustNotSendAmend) {
+        this.mustNotSendAmend = mustNotSendAmend;
+    }
 
-            // </wsp:Policy>
-            writer.writeEndElement();
-        }
+    public boolean isMustNotSendRenew() {
+        return mustNotSendRenew;
+    }
 
-        // </sp:SecureConversationToken>
-        writer.writeEndElement();
+    protected void setMustNotSendRenew(boolean mustNotSendRenew) {
+        this.mustNotSendRenew = mustNotSendRenew;
     }
 
-    /**
-     * @return Returns the issuerEpr.
-     */
-    public OMElement getIssuerEpr() {
-        return issuerEpr;
-    }
-
-    /**
-     * @param issuerEpr
-     *            The issuerEpr to set.
-     */
-    public void setIssuerEpr(OMElement issuerEpr) {
-        this.issuerEpr = issuerEpr;
+    public Policy getBootstrapPolicy() {
+        return bootstrapPolicy;
     }
 
+    protected void setBootstrapPolicy(Policy bootstrapPolicy) {
+        this.bootstrapPolicy = bootstrapPolicy;
+    }
 }

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