diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-02-26 04:25:11 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-02-26 04:25:11 +0000 |
commit | 313e83d4f0dc58220e31c035e5350beb19139522 (patch) | |
tree | 2e791782f071381bf2108570dacc90bfab9b5ef2 /branches/sca-java-1.x/samples/store-secure/src/main/resources | |
parent | 176f6afc0662e66b14e56e7569da47ff3efa843f (diff) |
Adding new store-secure sample to exercise security policy in web 2.0 extensions
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@748005 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
3 files changed, 279 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/samples/store-secure/src/main/resources/definitions.xml b/branches/sca-java-1.x/samples/store-secure/src/main/resources/definitions.xml new file mode 100644 index 0000000000..58db5df865 --- /dev/null +++ b/branches/sca-java-1.x/samples/store-secure/src/main/resources/definitions.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + * 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. +--> +<sca:definitions xmlns="http://www.osoa.org/xmlns/sca/1.0" + targetNamespace="http://www.osoa.org/xmlns/sca/1.0" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" + xmlns:store="http://store"> + + + <!-- WS Security POLICY SETS --> + <sca:policySet name="widgetBindingAuthenticationPolicySet" + provides="sca:authentication" + appliesTo="tuscany:binding.http"> + <tuscany:basicAuthentication> + <tuscany:authorizedUsers> + <tuscany:user name="user1" password="pwd1" role="admin"/> + <tuscany:user name="user2" password="pwd2" role="user"/> + <tuscany:user name="user3" password="pwd3" role="user"/> + </tuscany:authorizedUsers> + </tuscany:basicAuthentication> + </sca:policySet> + + <!-- WS Security POLICY SETS --> + <sca:policySet name="widgetServiceAuthenticationPolicySet" + provides="sca:authentication" + appliesTo="sca:service"> + <tuscany:basicAuthentication> + <tuscany:authorizedUsers> + <tuscany:user name="user1" password="pwd1" role="admin"/> + <tuscany:user name="user2" password="pwd2" role="user"/> + <tuscany:user name="user3" password="pwd3" role="user"/> + </tuscany:authorizedUsers> + </tuscany:basicAuthentication> + </sca:policySet> + + </sca:definitions> diff --git a/branches/sca-java-1.x/samples/store-secure/src/main/resources/store.composite b/branches/sca-java-1.x/samples/store-secure/src/main/resources/store.composite new file mode 100644 index 0000000000..8aef45c53c --- /dev/null +++ b/branches/sca-java-1.x/samples/store-secure/src/main/resources/store.composite @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0" + targetNamespace="http://store" + name="store"> + + <component name="Store"> + <t:implementation.widget location="uiservices/store.html"/> + <service name="Widget" requires="authentication"> + <t:binding.http uri="/store"/> + </service> + <reference name="catalog" target="Catalog"> + <t:binding.jsonrpc/> + </reference> + <reference name="shoppingCart" target="ShoppingCart/Cart"> + <t:binding.atom/> + </reference> + <reference name="shoppingTotal" target="ShoppingCart/Total"> + <t:binding.jsonrpc/> + </reference> + </component> + + <component name="Catalog"> + <implementation.java class="services.FruitsCatalogImpl"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <t:binding.jsonrpc/> + </service> + <reference name="currencyConverter" target="CurrencyConverter"/> + </component> + + <component name="ShoppingCart"> + <implementation.java class="services.ShoppingCartImpl"/> + <service name="Cart"> + <t:binding.atom uri="/ShoppingCart/Cart"/> + </service> + <service name="Total"> + <t:binding.jsonrpc/> + </service> + </component> + + <component name="CurrencyConverter"> + <implementation.java class="services.CurrencyConverterImpl"/> + </component> + +</composite> diff --git a/branches/sca-java-1.x/samples/store-secure/src/main/resources/uiservices/store.html b/branches/sca-java-1.x/samples/store-secure/src/main/resources/uiservices/store.html new file mode 100644 index 0000000000..45604463d1 --- /dev/null +++ b/branches/sca-java-1.x/samples/store-secure/src/main/resources/uiservices/store.html @@ -0,0 +1,162 @@ +<!-- + * 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. +--> +<html> +<head> +<title>Store</title> + +<script type="text/javascript" src="store.js"></script> + +<script language="JavaScript"> + + //@Reference + var catalog = new Reference("catalog"); + + //@Reference + var shoppingCart = new Reference("shoppingCart"); + + //@Reference + var shoppingTotal = new Reference("shoppingTotal"); + + var catalogItems; + + function catalog_getResponse(items,exception) { + if(exception){ + alert(exception.message); + return; + } + var catalog = ""; + + for (var i=0; i<items.length; i++) { + var item = items[i].name + ' - ' + items[i].price; + catalog += '<input name="items" type="checkbox" value="' + + item + '">' + item + ' <br>'; + } + document.getElementById('catalog').innerHTML=catalog; + catalogItems = items; + } + + function shoppingCart_getResponse(feed) { + if (feed != null) { + var entries = feed.getElementsByTagName("entry"); + var list = ""; + for (var i=0; i<entries.length; i++) { + var content = entries[i].getElementsByTagName("content")[0]; + var name = content.getElementsByTagName("name")[0].firstChild.nodeValue; + var price = content.getElementsByTagName("price")[0].firstChild.nodeValue; + list += name + ' - ' + price + ' <br>'; + } + document.getElementById("shoppingCart").innerHTML = list; + + if (entries.length != 0) { + try { + shoppingTotal.getTotal(shoppingTotal_getTotalResponse); + } + catch(e){ + alert(e); + } + } + } + } + + function shoppingTotal_getTotalResponse(total,exception) { + if(exception) { + alert(exception.message); + return; + } + document.getElementById('total').innerHTML = total; + } + + function shoppingCart_postResponse(entry) { + shoppingCart.get("", shoppingCart_getResponse); + } + + function addToCart() { + var items = document.catalogForm.items; + var j = 0; + for (var i=0; i<items.length; i++) + if (items[i].checked) { + + var entry = '<entry xmlns="http://www.w3.org/2005/Atom"><title>item</title><content type="text/xml">' + + '<Item xmlns="http://services/">' + + '<name xmlns="">' + catalogItems[i].name + '</name>' + '<price xmlns="">' + catalogItems[i].price + '</price>' + + '</Item>' + '</content></entry>'; + shoppingCart.post(entry, shoppingCart_postResponse); + items[i].checked = false; + } + } + function checkoutCart() { + document.getElementById('store').innerHTML='<h2>' + + 'Thanks for Shopping With Us!</h2>'+ + '<h2>Your Order</h2>'+ + '<form name="orderForm">'+ + document.getElementById('shoppingCart').innerHTML+ + '<br>'+ + document.getElementById('total').innerHTML+ + '<br>'+ + '<br>'+ + '<input type="submit" value="Continue Shopping">'+ + '</form>'; + shoppingCart.del("", null); + } + function deleteCart() { + shoppingCart.del("", null); + document.getElementById('shoppingCart').innerHTML = ""; + document.getElementById('total').innerHTML = ""; + } + + function init() { + + try { + catalog.get(catalog_getResponse); + shoppingCart.get("", shoppingCart_getResponse); + } + catch(e){ + alert(e); + } + } + +</script> + +</head> + +<body onload="init()"> +<h1>Store</h1> + <div id="store"> + <h2>Catalog</h2> + <form name="catalogForm"> + <div id="catalog" ></div> + <br> + <input type="button" onClick="addToCart()" value="Add to Cart"> + </form> + + <br> + + <h2>Your Shopping Cart</h2> + <form name="shoppingCartForm"> + <div id="shoppingCart"></div> + <br> + <div id="total"></div> + <br> + <input type="button" onClick="checkoutCart()" value="Checkout"> + <input type="button" onClick="deleteCart()" value="Empty"> + <a href="../ShoppingCart/Cart/">(feed)</a> + </form> + </div> +</body> +</html> |