You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by sa...@apache.org on 2006/08/05 12:33:07 UTC
svn commit: r428981 - in /webservices/commons/trunk/modules/neethi:
examples/wsse/src/org/ examples/wsse/src/org/apache/
examples/wsse/src/org/apache/ws/ examples/wsse/src/org/apache/ws/security/
examples/wsse/src/org/apache/ws/security/policy/ example...
Author: sanka
Date: Sat Aug 5 03:33:05 2006
New Revision: 428981
URL: http://svn.apache.org/viewvc?rev=428981&view=rev
Log:
Adding a sample code for processing WSSecurity Policy Assertions
Added:
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/AlgorithmSuiteBuilder.java
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/AsymmetricBindingBuilder.java
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/EncryptedElementsBuilder.java
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/EncryptedPartsBuilders.java
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/LayoutBuilder.java
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/ProtectionTokenBuilder.java
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SecurityAssertionBuilder.java
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SignedElementsBuilder.java
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SignedPartsBuilder.java
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SupportingTokensBuilder.java
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/Test.java
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/TransportBindingBuilder.java
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/TransportTokenBuilder.java
webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/UsernameTokenBuilder.java
webservices/commons/trunk/modules/neethi/src/org/apache/neethi/builders/XMLPrimitiveAssertionBuilder.java
Modified:
webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java
webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AssertionBuilderFactory.java
webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyEngine.java
webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java
Added: webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/AlgorithmSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/AlgorithmSuiteBuilder.java?rev=428981&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/AlgorithmSuiteBuilder.java (added)
+++ webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/AlgorithmSuiteBuilder.java Sat Aug 5 03:33:05 2006
@@ -0,0 +1,131 @@
+/*
+ * 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.
+ */
+package org.apache.ws.security.policy.builders;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyEngine;
+import org.apache.neethi.XmlPrimtiveAssertion;
+import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.security.policy.Constants;
+import org.apache.ws.security.policy.model.AlgorithmSuite;
+
+public class AlgorithmSuiteBuilder implements AssertionBuilder {
+
+ public static final String INCLUSIVE_C14N = "InclusiveC14N";
+ public static final String SOAP_NORMALIZATION_10 = "SoapNormalization10";
+ public static final String STR_TRANSFORM_10 = "STRTransform10";
+ public static final String XPATH10 = "XPath10";
+ public static final String XPATH_FILTER20 = "XPathFilter20";
+
+
+ public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+ AlgorithmSuite algorithmSuite = new AlgorithmSuite();
+
+ Policy policy = PolicyEngine.getPolicy(element.getFirstElement());
+ policy = (Policy) policy.normalize(false);
+
+ for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
+ processAlternative((List) iterator.next(), algorithmSuite);
+ }
+ return algorithmSuite;
+ }
+
+ private void processAlternative(List assertionList, AlgorithmSuite target) {
+ AlgorithmSuite algorithmSuite = new AlgorithmSuite();
+
+ XmlPrimtiveAssertion primtiveAssertion;
+
+ for (Iterator iterator = assertionList.iterator(); iterator.hasNext();) {
+ primtiveAssertion = (XmlPrimtiveAssertion) iterator.next();
+ QName qname = primtiveAssertion.getName();
+ String localName = qname.getLocalPart();
+
+ if (localName.equals(INCLUSIVE_C14N)) {
+ algorithmSuite.setC14n(Constants.C14N);
+
+ } else if (localName.equals(SOAP_NORMALIZATION_10)) {
+ algorithmSuite.setSoapNormalization(Constants.SNT);
+
+ } else if (localName.equals(STR_TRANSFORM_10)) {
+ algorithmSuite.setStrTransform(Constants.STRT10);
+
+ } else if (localName.equals(XPATH10)) {
+ algorithmSuite.setXPath(Constants.XPATH);
+
+ } else if (localName.equals(XPATH_FILTER20)) {
+ algorithmSuite.setXPath(Constants.XPATH20);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_BASIC128)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_BASIC128);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_BASIC128_RSA15)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_BASIC128_RSA15);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_BASIC128_SHA256)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_BASIC128_SHA256);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_BASIC128_SHA256_RSA15)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_BASIC128_SHA256_RSA15);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_BASIC192)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_BASIC192);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_BASIC192_RSA15)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_BASIC192_RSA15);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_BASIC192_SHA256)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_BASIC192_SHA256);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_BASIC192_SHA256_RSA15)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_BASIC192_SHA256_RSA15);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_BASIC256)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_BASIC256);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_BASIC256_RSA15)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_BASIC256_RSA15);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_BASIC256_SHA256)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_BASIC256_SHA256);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_BASIC256_SHA256_RSA15)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_BASIC256_SHA256_RSA15);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_TRIPLE_DES)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_TRIPLE_DES);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_TRIPLE_DES_RSA15)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_TRIPLE_DES_RSA15);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_TRIPLE_DES_SHA256)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_TRIPLE_DES_SHA256);
+
+ } else if (localName.equals(Constants.ALGO_SUITE_TRIPLE_DES_SHA256_RSA15)) {
+ algorithmSuite.setAlgorithmSuite(Constants.ALGO_SUITE_TRIPLE_DES_SHA256_RSA15);
+ }
+ }
+
+ target.addOption(algorithmSuite);
+ }
+}
Added: webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/AsymmetricBindingBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/AsymmetricBindingBuilder.java?rev=428981&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/AsymmetricBindingBuilder.java (added)
+++ webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/AsymmetricBindingBuilder.java Sat Aug 5 03:33:05 2006
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+package org.apache.ws.security.policy.builders;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.builders.AssertionBuilder;
+
+public class AsymmetricBindingBuilder implements AssertionBuilder {
+
+ public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+
+ }
+
+}
Added: webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/EncryptedElementsBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/EncryptedElementsBuilder.java?rev=428981&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/EncryptedElementsBuilder.java (added)
+++ webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/EncryptedElementsBuilder.java Sat Aug 5 03:33:05 2006
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+package org.apache.ws.security.policy.builders;
+
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.security.policy.Constants;
+import org.apache.ws.security.policy.model.SignedEncryptedElements;
+
+public class EncryptedElementsBuilder implements AssertionBuilder {
+
+ public static final QName ATTR_XPATH_VERSION = new QName(Constants.SP_NS, "XPathVersion");
+ public static final QName XPATH = new QName(Constants.SP_NS, "XPath");
+
+ public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+ SignedEncryptedElements signedEncryptedElements = new SignedEncryptedElements(false);
+
+ OMAttribute attribute = element.getAttribute(ATTR_XPATH_VERSION);
+ if (attribute != null) {
+ signedEncryptedElements.setXPathVersion(attribute.getAttributeValue());
+ }
+
+ for (Iterator iterator = element.getChildElements(); iterator.hasNext();) {
+ processElement((OMElement) iterator.next(), signedEncryptedElements);
+ }
+
+ return signedEncryptedElements;
+ }
+
+ private void processElement(OMElement element, SignedEncryptedElements parent) {
+ if (XPATH.equals(element.getQName())) {
+ parent.setXPathVersion(element.getText());
+ }
+ }
+}
Added: webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/EncryptedPartsBuilders.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/EncryptedPartsBuilders.java?rev=428981&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/EncryptedPartsBuilders.java (added)
+++ webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/EncryptedPartsBuilders.java Sat Aug 5 03:33:05 2006
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+package org.apache.ws.security.policy.builders;
+
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.security.policy.Constants;
+import org.apache.ws.security.policy.model.Header;
+import org.apache.ws.security.policy.model.SignedEncryptedParts;
+
+public class EncryptedPartsBuilders implements AssertionBuilder {
+
+ public static final QName HEADER = new QName(Constants.SP_NS, "Header");
+ public static final QName NAME = new QName(Constants.SP_NS, "Name");
+ public static final QName NAMESPACE = new QName(Constants.SP_NS, "Namespace");
+ public static final QName BODY = new QName(Constants.SP_NS, "Body");
+
+ public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+
+ SignedEncryptedParts signedEncryptedParts = new SignedEncryptedParts(false);
+
+ for (Iterator iterator = element.getChildElements(); iterator.hasNext();) {
+ processElement((OMElement) iterator.next(), signedEncryptedParts);
+ }
+
+ return signedEncryptedParts;
+ }
+
+ private void processElement(OMElement element, SignedEncryptedParts parent) {
+
+ QName name = element.getQName();
+
+ if (HEADER.equals(name)) {
+ Header header = new Header();
+
+ OMAttribute nameAttribute = element.getAttribute(NAME);
+ header.setName(nameAttribute.getAttributeValue());
+
+ OMAttribute namespaceAttribute = element.getAttribute(NAMESPACE);
+ header.setNamespace(namespaceAttribute.getAttributeValue());
+
+ } else if (BODY.equals(name)) {
+ parent.setBody(true);
+ }
+ }
+}
Added: webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/LayoutBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/LayoutBuilder.java?rev=428981&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/LayoutBuilder.java (added)
+++ webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/LayoutBuilder.java Sat Aug 5 03:33:05 2006
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+package org.apache.ws.security.policy.builders;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyEngine;
+import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.security.policy.Constants;
+import org.apache.ws.security.policy.model.Layout;
+
+public class LayoutBuilder implements AssertionBuilder {
+
+ private static final QName STRICT = new QName(Constants.SP_NS, "Strict");
+ private static final QName LAX = new QName(Constants.SP_NS, "Lax");
+ private static final QName LAXTSFIRST = new QName(Constants.SP_NS, "LaxTsFirst");
+ private static final QName LAXTSLAST = new QName(Constants.SP_NS,"LaxTsLast");
+
+ public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+ Layout layout = new Layout();
+
+ Policy policy = PolicyEngine.getPolicy(element);
+ policy = (Policy) policy.normalize(false);
+
+ for (Iterator iterator = policy.getAlternatives(); iterator.hasNext(); ) {
+ processAlternative((List) iterator.next(), layout);
+ }
+
+ return layout;
+ }
+
+ public void processAlternative(List assertions, Layout parent) {
+ Layout layout = new Layout();
+
+ for (Iterator iterator = assertions.iterator(); iterator.hasNext();) {
+ Assertion assertion = (Assertion) iterator.next();
+ QName qname = assertion.getName();
+
+ if (STRICT.equals(qname)) {
+ layout.setValue(Constants.LAYOUT_STRICT);
+ } else if (LAX.equals(qname)) {
+ layout.setValue(Constants.LAYOUT_LAX);
+ } else if (LAXTSFIRST.equals(qname)) {
+ layout.setValue(Constants.LAYOUT_LAX_TIMESTAMP_FIRST);
+ } else if (LAXTSLAST.equals(qname)) {
+ layout.setValue(Constants.LAYOUT_LAX_TIMESTAMP_LAST);
+ }
+
+ }
+ parent.addOption(layout);
+ }
+
+}
Added: webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/ProtectionTokenBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/ProtectionTokenBuilder.java?rev=428981&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/ProtectionTokenBuilder.java (added)
+++ webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/ProtectionTokenBuilder.java Sat Aug 5 03:33:05 2006
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+package org.apache.ws.security.policy.builders;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyEngine;
+import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.security.policy.model.ProtectionToken;
+import org.apache.ws.security.policy.model.Token;
+
+public class ProtectionTokenBuilder implements AssertionBuilder {
+
+ public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+ ProtectionToken protectionToken = new ProtectionToken();
+
+ Policy policy = PolicyEngine.getPolicy(element);
+ policy = (Policy) policy.normalize(false);
+
+ for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
+ processAlternative((List) iterator.next(), protectionToken);
+ }
+
+ return protectionToken;
+ }
+
+ private void processAlternative(List assertions, ProtectionToken parent) {
+ ProtectionToken protectionToken = new ProtectionToken();
+
+ Token token = (Token) assertions.get(0);
+ protectionToken.setToken(token);
+
+ parent.addOption(protectionToken);
+ }
+}
Added: webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SecurityAssertionBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SecurityAssertionBuilder.java?rev=428981&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SecurityAssertionBuilder.java (added)
+++ webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SecurityAssertionBuilder.java Sat Aug 5 03:33:05 2006
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+package org.apache.ws.security.policy.builders;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.builders.AssertionBuilder;
+
+public class SecurityAssertionBuilder implements AssertionBuilder {
+
+ private static final String TRANSPORT_BINDING = "TransportBinding";
+ private static final String SYMMETRIC_BINDING = "SymmetricBinding";
+ private static final String ASYMMETRIC_BINDING = "AsymmetricBinding";
+
+ public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+
+ QName qname = element.getQName();
+
+ if (TRANSPORT_BINDING.equals(qname.getLocalPart())) {
+
+ } else if (SYMMETRIC_BINDING.equals(qname.getLocalPart())) {
+
+ } else if (ASYMMETRIC_BINDING.equals(qname.getLocalPart())) {
+
+ }
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+}
Added: webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SignedElementsBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SignedElementsBuilder.java?rev=428981&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SignedElementsBuilder.java (added)
+++ webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SignedElementsBuilder.java Sat Aug 5 03:33:05 2006
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.security.policy.builders;
+
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.security.policy.Constants;
+import org.apache.ws.security.policy.model.SignedEncryptedElements;
+
+public class SignedElementsBuilder implements AssertionBuilder {
+
+ public static final QName ATTR_XPATH_VERSION = new QName(Constants.SP_NS, "XPathVersion");
+ public static final QName XPATH = new QName(Constants.SP_NS, "XPath");
+
+ public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+
+ SignedEncryptedElements signedEncryptedElements = new SignedEncryptedElements(true);
+ OMAttribute attrXPathVersion = element.getAttribute(ATTR_XPATH_VERSION);
+
+ if (attrXPathVersion != null) {
+ signedEncryptedElements.setXPathVersion(attrXPathVersion.getAttributeValue());
+ }
+
+ for (Iterator iterator = element.getChildElements(); iterator.hasNext();) {
+ processElement((OMElement) iterator.next(), signedEncryptedElements);
+ }
+
+ return signedEncryptedElements;
+ }
+
+ private void processElement(OMElement element, SignedEncryptedElements parent) {
+ QName name = element.getQName();
+ if (XPATH.equals(name)) {
+ parent.addXPathExpression(element.getText());
+ }
+ }
+}
Added: webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SignedPartsBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SignedPartsBuilder.java?rev=428981&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SignedPartsBuilder.java (added)
+++ webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SignedPartsBuilder.java Sat Aug 5 03:33:05 2006
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+package org.apache.ws.security.policy.builders;
+
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.security.policy.Constants;
+import org.apache.ws.security.policy.model.Header;
+import org.apache.ws.security.policy.model.SignedEncryptedParts;
+
+public class SignedPartsBuilder implements AssertionBuilder {
+ public static final QName HEADER = new QName(Constants.SP_NS, "Header");
+ public static final QName NAME = new QName(Constants.SP_NS, "Name");
+ public static final QName NAMESPACE = new QName(Constants.SP_NS, "Namespace");
+ public static final QName BODY = new QName(Constants.SP_NS, "Body");
+
+ public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+ SignedEncryptedParts signedEncryptedParts = new SignedEncryptedParts(true);
+
+ for (Iterator iterator = element.getChildElements(); iterator.hasNext();) {
+ processElement((OMElement) iterator.next(), signedEncryptedParts);
+ }
+
+ return signedEncryptedParts;
+ }
+
+ private void processElement(OMElement element, SignedEncryptedParts parent) {
+
+ QName name = element.getQName();
+
+ if (HEADER.equals(name)) {
+ Header header = new Header();
+
+ OMAttribute nameAttribute = element.getAttribute(NAME);
+ header.setName(nameAttribute.getAttributeValue());
+
+ OMAttribute namespaceAttribute = element.getAttribute(NAMESPACE);
+ header.setNamespace(namespaceAttribute.getAttributeValue());
+
+ } else if (BODY.equals(name)) {
+ parent.setBody(true);
+ }
+ }
+}
Added: webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SupportingTokensBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SupportingTokensBuilder.java?rev=428981&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SupportingTokensBuilder.java (added)
+++ webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/SupportingTokensBuilder.java Sat Aug 5 03:33:05 2006
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+package org.apache.ws.security.policy.builders;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyEngine;
+import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.security.policy.Constants;
+import org.apache.ws.security.policy.model.AlgorithmSuite;
+import org.apache.ws.security.policy.model.SignedEncryptedElements;
+import org.apache.ws.security.policy.model.SignedEncryptedParts;
+import org.apache.ws.security.policy.model.SupportingToken;
+import org.apache.ws.security.policy.model.Token;
+
+public class SupportingTokensBuilder implements AssertionBuilder {
+
+ public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+ QName name = element.getQName();
+ SupportingToken supportingToken = null;
+
+ if (Constants.SUPPORIING_TOKENS.equals(name)) {
+ supportingToken = new SupportingToken(Constants.SUPPORTING_TOKEN_SUPPORTING);
+ } else if (Constants.SIGNED_SUPPORTING_TOKENS.equals(name)) {
+ supportingToken = new SupportingToken(Constants.SUPPORTING_TOKEN_SIGNED);
+ } else if (Constants.ENDORSING_SUPPORTING_TOKENS.equals(name)) {
+ supportingToken = new SupportingToken(Constants.SUPPORTING_TOKEN_ENDORSING);
+ } else if (Constants.SIGNED_ENDORSING_SUPPORTING_TOKENS.equals(name)) {
+ supportingToken = new SupportingToken(Constants.SUPPORTING_TOKEN_SIGNED_ENDORSING);
+ }
+
+ Policy policy = (Policy) PolicyEngine.getPolicy(element);
+ policy = (Policy) policy.normalize(false);
+
+ for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
+ processAlternative((List) iterator.next(), supportingToken);
+ }
+
+ return supportingToken;
+ }
+
+ private void processAlternative(List assertions, SupportingToken parent) {
+ SupportingToken supportingToken = new SupportingToken(parent.getTokenType());
+
+ for (Iterator iterator = assertions.iterator(); iterator.hasNext();) {
+
+ Assertion primitive = (Assertion) iterator.next();
+ QName qname = primitive.getName();
+
+ if (Constants.ALGORITHM_SUITE.equals(qname)) {
+ supportingToken.setAlgorithmSuite((AlgorithmSuite) primitive);
+
+ } else if (Constants.SIGNED_PARTS.equals(qname)) {
+ supportingToken.setSignedParts((SignedEncryptedParts) primitive);
+
+ } else if (Constants.SIGNED_ELEMENTS.equals(qname)) {
+ supportingToken.setSignedElements((SignedEncryptedElements) primitive);
+
+ } else if (Constants.ENCRYPTED_PARTS.equals(qname)) {
+ supportingToken.setEncryptedParts((SignedEncryptedParts) primitive);
+
+ } else if (Constants.ENCRYPTED_ELEMENTS.equals(qname)) {
+ supportingToken.setEncryptedElements((SignedEncryptedElements) primitive);
+
+ } else if (primitive instanceof Token) {
+ supportingToken.addToken((Token) primitive);
+ }
+ }
+
+ parent.addOption(supportingToken);
+ }
+
+
+}
Added: webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/Test.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/Test.java?rev=428981&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/Test.java (added)
+++ webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/Test.java Sat Aug 5 03:33:05 2006
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+package org.apache.ws.security.policy.builders;
+
+import java.io.FileInputStream;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
+import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyEngine;
+import org.apache.ws.security.policy.Constants;
+
+
+public class Test {
+
+ public static void main(String[] args) throws Exception {
+
+ OMElement element = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getOMFactory(),
+ XMLInputFactory.newInstance().createXMLStreamReader(new FileInputStream("/home/sanka/testpolicy.xml"))).getDocumentElement();
+
+ AssertionBuilderFactory factory = new AssertionBuilderFactory();
+ AssertionBuilder builder;
+
+ builder = new TransportBindingBuilder();
+ PolicyEngine.registerBuilder(new QName(Constants.SP_NS, "TransportBinding"), builder);
+
+ builder = new AlgorithmSuiteBuilder();
+ PolicyEngine.registerBuilder(new QName(Constants.SP_NS,"AlgorithmSuite"),builder);
+
+ builder = new TransportTokenBuilder();
+ PolicyEngine.registerBuilder(new QName(Constants.SP_NS, "TransportToken"), builder);
+
+ builder = new LayoutBuilder();
+ PolicyEngine.registerBuilder(new QName(Constants.SP_NS, "Layout"), builder);
+
+ builder = new SignedElementsBuilder();
+ PolicyEngine.registerBuilder(new QName(Constants.SP_NS, "SignedElements"), builder);
+
+ builder = new SignedPartsBuilder();
+ PolicyEngine.registerBuilder(new QName(Constants.SP_NS, "SignedParts"), builder);
+
+ builder = new SupportingTokensBuilder();
+ PolicyEngine.registerBuilder(new QName(Constants.SP_NS, "SupportingTokens"), builder);
+ PolicyEngine.registerBuilder(new QName(Constants.SP_NS, "SignedSupportingTokens"), builder);
+ PolicyEngine.registerBuilder(new QName(Constants.SP_NS, "EndorsingSupportingTokens"), builder);
+ PolicyEngine.registerBuilder(new QName(Constants.SP_NS, "SignedEndorsingSupportingTokens"), builder);
+
+
+ builder = new UsernameTokenBuilder();
+ PolicyEngine.registerBuilder(new QName(Constants.SP_NS, "UsernameToken"), builder);
+
+ Policy p = PolicyEngine.getPolicy(element);
+ System.out.println(p + "done");
+
+ }
+}
Added: webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/TransportBindingBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/TransportBindingBuilder.java?rev=428981&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/TransportBindingBuilder.java (added)
+++ webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/TransportBindingBuilder.java Sat Aug 5 03:33:05 2006
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+package org.apache.ws.security.policy.builders;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyEngine;
+import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.security.policy.Constants;
+import org.apache.ws.security.policy.model.AlgorithmSuite;
+import org.apache.ws.security.policy.model.Layout;
+import org.apache.ws.security.policy.model.SupportingToken;
+import org.apache.ws.security.policy.model.TransportBinding;
+import org.apache.ws.security.policy.model.TransportToken;
+
+public class TransportBindingBuilder implements AssertionBuilder {
+
+ public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+ TransportBinding transportBinding = new TransportBinding();
+ OMElement policyElement = element.getFirstElement();
+
+ Policy policy = PolicyEngine.getPolicy(policyElement);
+ policy = (Policy) policy.normalize(false);
+
+ for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
+ processAlternative((List) iterator.next(), transportBinding, factory);
+ }
+
+
+ return transportBinding;
+ }
+
+ private void processAlternative(List assertionList, TransportBinding parent, AssertionBuilderFactory factory) {
+ TransportBinding transportBinding = new TransportBinding();
+
+ for (Iterator iterator = assertionList.iterator(); iterator.hasNext(); ) {
+
+ Assertion primitive = (Assertion) iterator.next();
+ QName name = primitive.getName();
+
+ if (name.equals(Constants.ALGORITHM_SUITE)) {
+ transportBinding.setAlgorithmSuite((AlgorithmSuite) primitive);
+
+ } else if (name.equals(Constants.TRANSPORT_TOKEN)) {
+ transportBinding.setTransportToken(((TransportToken) primitive));
+
+ } else if (name.equals(Constants.INCLUDE_TIMESTAMP)) {
+ transportBinding.setIncludeTimestamp(true);
+
+ } else if (name.equals(Constants.LAYOUT)) {
+ transportBinding.setLayout((Layout) primitive);
+
+ } else if (name.equals(Constants.SIGNED_SUPPORTING_TOKENS)) {
+ transportBinding.setSignedSupportingToken((SupportingToken) primitive);
+
+ } else if (name.equals(Constants.SIGNED_ENDORSING_SUPPORTING_TOKENS)) {
+ transportBinding.setSignedEndorsingSupportingTokens((SupportingToken) primitive);
+ }
+ }
+ parent.addOption(transportBinding);
+ }
+}
Added: webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/TransportTokenBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/TransportTokenBuilder.java?rev=428981&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/TransportTokenBuilder.java (added)
+++ webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/TransportTokenBuilder.java Sat Aug 5 03:33:05 2006
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+package org.apache.ws.security.policy.builders;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyEngine;
+import org.apache.neethi.XmlPrimtiveAssertion;
+import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.security.policy.Constants;
+import org.apache.ws.security.policy.model.HttpsToken;
+import org.apache.ws.security.policy.model.TransportToken;
+
+public class TransportTokenBuilder implements AssertionBuilder {
+
+
+
+ public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+ TransportToken transportToken = new TransportToken();
+
+ Policy policy = PolicyEngine.getPolicy(element.getFirstElement());
+ policy = (Policy) policy.normalize(false);
+
+ for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
+ processAlternative((List) iterator.next(), transportToken);
+ }
+
+ return transportToken;
+ }
+
+
+ private void processAlternative(List assertions, TransportToken parent) {
+ TransportToken transportToken = new TransportToken();
+
+ for (Iterator iterator = assertions.iterator(); iterator.hasNext();) {
+ XmlPrimtiveAssertion primtive = (XmlPrimtiveAssertion) iterator.next();
+ QName qname = primtive.getName();
+
+ if (Constants.HTTPS_TOKEN.equals(qname)) {
+ HttpsToken httpsToken = new HttpsToken();
+ transportToken.setTransportToken(httpsToken);
+ }
+ }
+
+ parent.addOption(transportToken);
+ }
+}
Added: webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/UsernameTokenBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/UsernameTokenBuilder.java?rev=428981&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/UsernameTokenBuilder.java (added)
+++ webservices/commons/trunk/modules/neethi/examples/wsse/src/org/apache/ws/security/policy/builders/UsernameTokenBuilder.java Sat Aug 5 03:33:05 2006
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+package org.apache.ws.security.policy.builders;
+
+import java.util.Iterator;
+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.Policy;
+import org.apache.neethi.PolicyEngine;
+import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.ws.security.policy.Constants;
+import org.apache.ws.security.policy.model.UsernameToken;
+
+public class UsernameTokenBuilder implements AssertionBuilder {
+
+
+ public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+ UsernameToken usernameToken = new UsernameToken();
+
+ OMAttribute attribute = element.getAttribute(Constants.INCLUDE_TOKEN);
+ String inclusionValue = attribute.getAttributeValue();
+
+ if (inclusionValue.endsWith(Constants.INCLUDE_NEVER)) {
+ usernameToken.setInclusion(Constants.INCLUDE_NEVER);
+
+ } else if (inclusionValue.endsWith(Constants.INCLUDE_ONCE)) {
+ usernameToken.setInclusion(Constants.INCLUDE_ONCE);
+
+ } else if (inclusionValue.endsWith(Constants.INCLUDE_ALWAYS_TO_RECIPIENT)) {
+ usernameToken.setInclusion(Constants.INCLUDE_ALWAYS_TO_RECIPIENT);
+
+ } else if (inclusionValue.endsWith(Constants.INCLUDE_ALWAYS)) {
+ usernameToken.setInclusion(Constants.INCLUDE_ALWAYS);
+ }
+
+ Policy policy = PolicyEngine.getPolicy(element);
+ policy = (Policy) policy.normalize(false);
+
+ for (Iterator iterator = policy.getAlternatives(); iterator.hasNext();) {
+ processAlternative((List) iterator.next(), usernameToken);
+ }
+
+ return usernameToken;
+ }
+
+ private void processAlternative(List assertions, UsernameToken parent) {
+ UsernameToken usernameToken = new UsernameToken();
+ usernameToken.setInclusion(parent.getInclusion());
+
+ for (Iterator iterator = assertions.iterator(); iterator.hasNext();) {
+ Assertion assertion = (Assertion) iterator.next();
+ QName qname = assertion.getName();
+
+ if (Constants.WSS_USERNAME_TOKEN10.equals(qname)) {
+ usernameToken.setUseUTProfile11(false)
+ ;
+ } else if (Constants.WSS_USERNAME_TOKEN11.equals(qname)) {
+ usernameToken.setUseUTProfile11(true);
+ }
+ }
+ parent.addOption(usernameToken);
+ }
+}
Modified: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java?rev=428981&r1=428980&r2=428981&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java Sat Aug 5 03:33:05 2006
@@ -16,7 +16,6 @@
package org.apache.neethi;
import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamWriter;
public interface Assertion extends PolicyComponent {
@@ -25,7 +24,4 @@
public boolean isOptional();
public PolicyComponent normalize();
-
- public void serialize(XMLStreamWriter writer);
-
}
Modified: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AssertionBuilderFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AssertionBuilderFactory.java?rev=428981&r1=428980&r2=428981&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AssertionBuilderFactory.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AssertionBuilderFactory.java Sat Aug 5 03:33:05 2006
@@ -76,8 +76,8 @@
return builder.build(element, this);
}
- public AssertionBuilder getBuilder(String namespace) {
- return (AssertionBuilder) registeredBuilders.get(namespace);
+ public AssertionBuilder getBuilder(QName qname) {
+ return (AssertionBuilder) registeredBuilders.get(qname);
}
Modified: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyEngine.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyEngine.java?rev=428981&r1=428980&r2=428981&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyEngine.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyEngine.java Sat Aug 5 03:33:05 2006
@@ -44,6 +44,10 @@
public static final String ALL = "All";
private static AssertionBuilderFactory factory = new AssertionBuilderFactory();
+
+ static {
+// factory.registerBuilder(, builder)
+ }
/**
* Registers an AssertionBuilder instances and associates it with a QName.
@@ -127,8 +131,9 @@
}
} else {
- AssertionBuilder builder = factory.getBuilder(childElement
- .getNamespace().getName());
+
+ AssertionBuilder builder = factory.getBuilder(childElement.getQName());
+
if (builder == null) {
XmlPrimtiveAssertion xmlPrimtiveAssertion = new XmlPrimtiveAssertion(
Modified: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java?rev=428981&r1=428980&r2=428981&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java Sat Aug 5 03:33:05 2006
@@ -35,6 +35,8 @@
}
public QName getName() {
+ System.out.println(element.getQName());
+
return (element != null) ? element.getQName() : null;
}
Added: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/builders/XMLPrimitiveAssertionBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/builders/XMLPrimitiveAssertionBuilder.java?rev=428981&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/builders/XMLPrimitiveAssertionBuilder.java (added)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/builders/XMLPrimitiveAssertionBuilder.java Sat Aug 5 03:33:05 2006
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+package org.apache.neethi.builders;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.XmlPrimtiveAssertion;
+
+public class XMLPrimitiveAssertionBuilder implements AssertionBuilder {
+
+ public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+ return new XmlPrimtiveAssertion(element);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org