You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2015/08/12 13:33:05 UTC
[42/50] [abbrv] stratos git commit: Removing unnecessary features,
artifacts and restructuring distribution artifacts
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/esb-logo.gif
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/esb-logo.gif b/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/esb-logo.gif
new file mode 100755
index 0000000..95cb5b3
Binary files /dev/null and b/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/esb-logo.gif differ
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/gadget-logo.gif
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/gadget-logo.gif b/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/gadget-logo.gif
new file mode 100755
index 0000000..8e89ef5
Binary files /dev/null and b/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/gadget-logo.gif differ
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/governance-logo.gif
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/governance-logo.gif b/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/governance-logo.gif
new file mode 100755
index 0000000..af1ac45
Binary files /dev/null and b/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/governance-logo.gif differ
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/identity-logo.gif
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/identity-logo.gif b/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/identity-logo.gif
new file mode 100755
index 0000000..a2447bc
Binary files /dev/null and b/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/identity-logo.gif differ
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/mashup-logo.gif
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/mashup-logo.gif b/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/mashup-logo.gif
new file mode 100755
index 0000000..f8ed9be
Binary files /dev/null and b/products/stratos/modules/distribution/src/main/resources/powerded-by-logos/mashup-logo.gif differ
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/module.xml
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/module.xml b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/module.xml
new file mode 100644
index 0000000..2cb5634
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/module.xml
@@ -0,0 +1,69 @@
+<?xml version='1.0'?>
+<!--
+
+ 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.
+
+-->
+
+<module name="carbon" xmlns="http://wso2.org/projects/jaggery/module.xml">
+ <!-- scripts -->
+ <script>
+ <name>osgi</name>
+ <path>scripts/server/osgi.js</path>
+ </script>
+ <script>
+ <name>tenant</name>
+ <path>scripts/server/tenant.js</path>
+ </script>
+ <script>
+ <name>server</name>
+ <path>scripts/server/server.js</path>
+ </script>
+ <script>
+ <name>config</name>
+ <path>scripts/server/config.js</path>
+ </script>
+ <script>
+ <name>user</name>
+ <path>scripts/user/user.js</path>
+ </script>
+ <script>
+ <name>registry</name>
+ <path>scripts/registry/registry.js</path>
+ </script>
+ <script>
+ <name>registry-osgi</name>
+ <path>scripts/registry/registry-osgi.js</path>
+ </script>
+ <script>
+ <name>artifacts</name>
+ <path>scripts/registry/artifacts.js</path>
+ </script>
+ <script>
+ <name>space</name>
+ <path>scripts/user/space.js</path>
+ </script>
+ <script>
+ <name>registry-space</name>
+ <path>scripts/user/registry-space.js</path>
+ </script>
+ <script>
+ <name>user-manager</name>
+ <path>scripts/user/user-manager.js</path>
+ </script>
+</module>
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/artifacts.js
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/artifacts.js b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/artifacts.js
new file mode 100644
index 0000000..a05e567
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/artifacts.js
@@ -0,0 +1,595 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+(function (server, registry) {
+
+ var log = new Log();
+
+ var GenericArtifactManager = Packages.org.wso2.carbon.governance.api.generic.GenericArtifactManager;
+ var GenericArtifactFilter = Packages.org.wso2.carbon.governance.api.generic.GenericArtifactFilter;
+ var ByteArrayInputStream = Packages.java.io.ByteArrayInputStream;
+ var QName = Packages.javax.xml.namespace.QName;
+ var IOUtils = Packages.org.apache.commons.io.IOUtils;
+ var PrivilegedCarbonContext = Packages.org.wso2.carbon.context.PrivilegedCarbonContext; //Used regard tenant details
+ var CarbonContext = Packages.org.wso2.carbon.context.CarbonContext;
+ var MultitenantConstants = Packages.org.wso2.carbon.utils.multitenancy.MultitenantConstants;
+ var List = java.util.List;
+ var Map = java.util.Map;
+ var ArrayList = java.util.ArrayList;
+ var HashMap = java.util.HashMap;
+
+ var GovernanceUtils = Packages.org.wso2.carbon.governance.api.util.GovernanceUtils;//Used to obtain Asset Types
+ var DEFAULT_MEDIA_TYPE = 'application/vnd.wso2.registry-ext-type+xml';//Used to obtain Asset types
+ var PaginationContext = Packages.org.wso2.carbon.registry.core.pagination.PaginationContext;//Used for pagination on register
+
+ var REGISTRY_ABSOLUTE_PATH = "/_system/governance";
+
+ var HISTORY_PATH_SEPERATOR = '_';
+ var ASSET_PATH_SEPERATOR = '/';
+ var lcHistoryRegExpression = new RegExp(ASSET_PATH_SEPERATOR, 'g');
+ var HISTORY_PATH = '/_system/governance/_system/governance/repository/components/org.wso2.carbon.governance/lifecycles/history/';
+
+
+ var buildArtifact = function (manager, artifact) {
+ return {
+ id: String(artifact.id),
+ type: String(manager.type),
+ path: "/_system/governance" + String(artifact.getPath()),
+ lifecycle: artifact.getLifecycleName(),
+ lifecycleState: artifact.getLifecycleState(),
+ mediaType: String(artifact.getMediaType()),
+ attributes: (function () {
+ var i, name,
+ names = artifact.getAttributeKeys(),
+ length = names.length,
+ attributes = {};
+ for (i = 0; i < length; i++) {
+ name = names[i];
+
+ var data = artifact.getAttributes(name);
+
+ //Check if there is only one element
+ if (data.length == 1) {
+ attributes[name] = String(artifact.getAttribute(name));
+ }
+ else {
+ attributes[name] = data;
+ }
+ }
+ return attributes;
+ }()),
+ content: function () {
+ return new Stream(new ByteArrayInputStream(artifact.getContent()));
+ }
+ };
+ };
+
+ var createArtifact = function (manager, options) {
+ var name, attribute, i, length, lc,
+ artifact = manager.newGovernanceArtifact(new QName(options.name)),
+ attributes = options.attributes;
+ for (name in attributes) {
+ if (attributes.hasOwnProperty(name)) {
+ attribute = attributes[name];
+ if (attribute instanceof Array) {
+ /*length = attribute.length;
+ for (i = 0; i < length; i++) {
+ artifact.addAttribute(name, attribute[i]);
+ }*/
+ artifact.setAttributes(name, attribute);
+ } else {
+ artifact.setAttribute(name, attribute);
+ }
+ }
+ }
+ if (options.id) {
+ artifact.id = options.id;
+ }
+ if (options.content) {
+ if (options.content instanceof Stream) {
+ artifact.setContent(IOUtils.toByteArray(options.content.getStream()));
+ } else {
+ artifact.setContent(new java.lang.String(options.content).getBytes());
+ }
+ }
+ lc = options.lifecycles;
+ if (lc) {
+ length = lc.length;
+ for (i = 0; i < length; i++) {
+ artifact.attachLifeCycle(lc[i]);
+ }
+ }
+ return artifact;
+ };
+
+ var ArtifactManager = function (registry, type) {
+ this.registry = registry;
+ this.manager = new GenericArtifactManager(registry.registry.getChrootedRegistry("/_system/governance"), type);
+ this.type = type;
+ };
+ registry.ArtifactManager = ArtifactManager;
+
+ ArtifactManager.prototype.find = function (fn, paging) {
+ var i, length, artifacts,
+ artifactz = [];
+ artifacts = this.manager.findGenericArtifacts(new GenericArtifactFilter({
+ matches: function (artifact) {
+ return fn(buildArtifact(this, artifact));
+ }
+ }));
+ length = artifacts.length;
+ for (i = 0; i < length; i++) {
+ artifactz.push(buildArtifact(this, artifacts[i]));
+ }
+ return artifactz;
+ };
+
+
+ /*
+ * this funtion is used ArtifactManager find with map for query for solr basicly
+ * query - for maping attribute of resource
+ * pagin - pagination details
+ * return - list of artifacts under the seach request
+ *
+ */
+ ArtifactManager.prototype.search = function (query, paging) {
+
+ var list, map, key, artifacts, pagination, value, that,
+ artifactz = [];
+ pagination = generatePaginationForm(paging);
+ try {
+ PaginationContext.init(pagination.start, pagination.count, pagination.sortOrder,
+ pagination.sortBy, pagination.paginationLimit);
+ map = HashMap();
+ //case senstive search as it using greg with solr 1.4.1
+ if (!query) {
+ //listing for sorting
+ map = java.util.Collections.emptyMap();
+ } else if (query instanceof String || typeof query === 'string') {
+ list = new ArrayList();
+ list.add('*' + query + '*');
+ map.put('overview_name', list);
+ } else {
+ //support for only on name of attribut -
+ for (key in query) {
+ // if attribute is string values
+ if (query.hasOwnProperty(key)) {
+ value = query[key];
+ list = new ArrayList();
+ if (value instanceof Array) {
+ value.forEach(function (val) {
+ //solr config update need have '*' as first char in below line
+ //check life_cycle state
+ list.add(key == 'lcState' ? val : '*' + val + '*');
+ });
+ } else {
+ //solr config update need have '*' as first char in below line
+ list.add(key == 'lcState' ? value : '*' + value + '*');
+ }
+ map.put(key, list);
+ }
+ }//end of attribut looping (all attributes)
+ }
+ artifacts = this.manager.findGenericArtifacts(map);
+ that = this;
+ artifacts.forEach(function (artifact) {
+ artifactz.push(buildArtifact(that, artifact));
+ });
+ } finally {
+ PaginationContext.destroy();
+ }
+ return artifactz;
+ };
+
+ ArtifactManager.prototype.get = function (id) {
+ return buildArtifact(this, this.manager.getGenericArtifact(id))
+ };
+
+ ArtifactManager.prototype.count = function () {
+ return this.manager.getAllGenericArtifactIds().length;
+ };
+
+ /**
+ * @deprecated Please use search method instead
+ * @param paging
+ * @return {*}
+ */
+ ArtifactManager.prototype.list = function (paging) {
+ return this.search(null, paging);
+ };
+
+ /*
+ The function returns an array of asset types
+ @mediaType - The media type of the assets
+ @return An array of strings containing the asset paths
+ */
+ ArtifactManager.prototype.getAssetTypePaths = function (mediaType) {
+
+ //Use the default media type if one is not provided
+ if (!mediaType) {
+ mediaType = DEFAULT_MEDIA_TYPE;
+ }
+
+ //var assetArray=GovernanceUtils.findGovernanceArtifacts(mediaType,this.registry);
+ var result = Packages.org.wso2.carbon.governance.api.util.GovernanceUtils.findGovernanceArtifacts(mediaType, registry.registry);
+
+ return result;
+ //Create an empty array if no asset types are found
+ //return (!assetArray)?[]:assetArray;
+ };
+
+ /*
+ {
+ name: 'AndroidApp1',
+ attributes: {
+ overview_status: "CREATED",
+ overview_name: 'AndroidApp1',
+ overview_version: '1.0.0',
+ overview_url: 'http://overview.com',
+ overview_provider: 'admin',
+ images_thumbnail: 'http://localhost:9763/portal/gadgets/co2-emission/thumbnail.jpg',
+ images_banner: 'http://localhost:9763/portal/gadgets/electric-power/banner.jpg'
+ },
+ lifecycles : ['lc1', 'lc2'],
+ content : '<?xml ....>'
+ }
+ */
+ ArtifactManager.prototype.add = function (options) {
+ this.manager.addGenericArtifact(createArtifact(this.manager, options));
+ };
+
+ ArtifactManager.prototype.update = function (options) {
+ this.manager.updateGenericArtifact(createArtifact(this.manager, options));
+ };
+
+ ArtifactManager.prototype.remove = function (id) {
+ this.manager.removeGenericArtifact(id);
+ };
+
+ /*
+ Attaches the provided lifecycle name to the artifact
+ @lifecycleName: The name of a valid lifecycle.The lifecycle should be visible to the
+ registry.
+ @options: The artifact to which the life cycle must be attached.
+ */
+ ArtifactManager.prototype.attachLifecycle = function (lifecycleName, options) {
+ var artifact = getArtifactFromImage(this.manager, options);
+ if (!artifact) {
+ throw new Error('Specified artifact cannot be found : ' + JSON.stringify(options));
+ }
+ artifact.attachLifecycle(lifecycleName);
+ };
+
+ /*
+ Removes the attached lifecycle from the artifact
+ @options: The artifact from which the life cycle must be removed
+ */
+ ArtifactManager.prototype.detachLifecycle = function (options) {
+ var artifact = getArtifactFromImage(this.manager, options);
+ if (!artifact) {
+ throw new Error('Specified artifact cannot be found : ' + JSON.stringify(options));
+ }
+ artifact.detachLifecycle();
+ };
+
+ /*
+ Promotes the artifact to the next stage in its life cycle
+ @options: An artifact image (Not a real artifact)
+ */
+ ArtifactManager.prototype.promoteLifecycleState = function (state, options) {
+ var checkListItems,
+ artifact = getArtifactFromImage(this.manager, options);
+ if (!artifact) {
+ throw new Error('Specified artifact cannot be found : ' + JSON.stringify(options));
+ }
+ //checkListItems = artifact.getAllCheckListItemNames();
+ artifact.invokeAction(state);
+ };
+
+ /*
+ Gets the current lifecycle state
+ @options: An artifact object
+ @returns: The life cycle state
+ */
+ ArtifactManager.prototype.getLifecycleState = function (options) {
+ var artifact = getArtifactFromImage(this.manager, options);
+ if (!artifact) {
+ throw new Error('Specified artifact cannot be found : ' + JSON.stringify(options));
+ }
+ return artifact.getLifecycleState();
+ };
+
+ /*
+ The function returns the list of check list items for a given state
+ @options: The artifact
+ @returns: A String array containing the check list items.(Can be empty if no check list items are present)
+ */
+ ArtifactManager.prototype.getCheckListItemNames = function (options) {
+ var artifact = getArtifactFromImage(this.manager, options);
+
+ var checkListItems = artifact.getAllCheckListItemNames() || [];
+
+ var checkListItemArray = [];
+
+ //Go through each check list item
+ for (var index in checkListItems) {
+ //Get whether the check list item is checked
+ var state = artifact.isLCItemChecked(index);
+ checkListItemArray.push({ 'name': checkListItems[index], 'checked': state });
+ }
+
+ return checkListItemArray;
+ };
+
+ /*
+ The function checks whether a given check list item at the provided index is checked for the current state
+ @index: The index of the check list item.This must be a value between 0 and the maximum check list item
+ that appears in the lifecycle definition
+ @options: An artifact object
+ @throws Exception: If the index is not within 0 and the max check list item or if there is an issue ticking the item
+ */
+ ArtifactManager.prototype.isItemChecked = function (index, options) {
+
+ var artifact = getArtifactFromImage(this.manager, options);
+
+ var checkListItems = artifact.getAllCheckListItemNames();
+
+ var checkListLength = checkListItems.length;
+
+ if ((index < 0) || (index > checkListLength)) {
+ throw "The index value: " + index + " must be between 0 and " + checkListLength + ".Please refer to the lifecycle definition in the registry.xml for the number of check list items.";
+ }
+
+ var result = artifact.isLCItemChecked(index);
+
+ return result;
+ };
+
+ /*
+ The method enables the check list item and the given index
+ @index: The index of the check list item.This must be a value between 0 and the maximum check list item
+ that appears in the lifecycle definition.
+ @options: An artifact object
+ @throws Exception: If the index is not within 0 and max check list item or if there is an issue ticking the item.
+ */
+ ArtifactManager.prototype.checkItem = function (index, options) {
+
+ var artifact = getArtifactFromImage(this.manager, options);
+
+ var checkListItems = artifact.getAllCheckListItemNames();
+
+ var checkListLength = checkListItems.length;
+
+ if ((index < 0) || (index > checkListLength)) {
+ throw "The index value: " + index + " must be between 0 and " + checkListLength + ".Please refer to the lifecycle definition in the registry.xml for the number of check list items.";
+ }
+
+ artifact.checkLCItem(index);
+ };
+
+ /*
+ The method disables the check list item at the given index
+ @index: The index of the check list item.This must be a value between 0 and the maximum check list item
+ that appears in the lifecycle definition
+ @options: An artifact object
+ @throws Exception: If the index is not within 0 and max check list item or if there is an issue ticking the item
+ */
+ ArtifactManager.prototype.uncheckItem = function (index, options) {
+
+ var artifact = getArtifactFromImage(this.manager, options);
+
+ var checkListItems = artifact.getAllCheckListItemNames();
+
+ var checkListLength = checkListItems.length;
+
+ if ((index < 0) || (index > checkListLength)) {
+ throw "The index value: " + index + " must be between 0 and " + checkListLength + ".Please refer to the lifecycle definition in the registry.xml for the number of check list items.";
+ }
+
+ artifact.uncheckLCItem(index);
+ };
+
+ /*
+ The method obtains the list of all available actions for the current state of the asset
+ @options: An artifact object
+ @returns: The list of available actions for the current state,else false
+ */
+ ArtifactManager.prototype.availableActions = function (options) {
+ var artifact = getArtifactFromImage(this.manager, options);
+ if (!artifact) {
+ throw new Error('Specified artifact cannot be found : ' + JSON.stringify(options));
+ }
+ return artifact.getAllLifecycleActions() || [];
+ };
+
+ /*
+ The function returns the life-cycle history path using
+ the provided asset.
+ @options: An asset.
+ @return: A string path of the life-cycle history.
+ */
+ ArtifactManager.prototype.getLifecycleHistoryPath = function (options) {
+
+ return getHistoryPath(options.path);
+ };
+
+ /*
+ The function obtains the lifecycle history for the provided asset
+ @options: An asset with a valid path.(A path which exists in the registry
+ @return: A resource object containing the history as an xml
+ */
+ ArtifactManager.prototype.getLifecycleHistory=function(options){
+ var historyPath=getHistoryPath(options.path);
+ return this.registry.get(historyPath);
+ };
+
+ /*
+ The function returns the life-cycle attached to the provided artifact
+ @options: An asset as returned by the ArtifactManager get method
+ @return: A string indicating the lifecycle name.If the artifact does not
+ have a life-cycle then an empty string is returned.
+ */
+ ArtifactManager.prototype.getLifeCycleName = function (options) {
+
+ var artifact = getArtifactFromImage(this.manager, options);
+
+ var lifecycleName = '';
+
+ if (artifact != null) {
+ lifecycleName = artifact.getLifecycleName();
+ }
+
+ return lifecycleName;
+ };
+
+ /*
+ The function returns all versions of the provided artifact
+ @options: The artifact to be checked
+ @return: A list of all the different versions of the provided asset
+ */
+ ArtifactManager.prototype.getAllAssetVersions = function (assetName) {
+
+ var matchingArtifacts = [];
+
+ var pred = {
+ overview_name: assetName || ''
+ };
+
+ this.find(function (artifact) {
+
+ //Add to the matches if the artifact exists
+ if (assert(artifact.attributes, pred)) {
+
+ //We only need the id and version
+ matchingArtifacts.push({id: artifact.id, version: artifact.attributes.overview_version});
+ }
+ });
+
+ return matchingArtifacts;
+ };
+
+ /*
+ The function checks if the two objects a and b are equal.If a property in b is not
+ in a, then both objects are assumed to be different.
+ @a: The object to be compared
+ @b: The object containing properties that must match in a
+ @return: True if the objects are equal,else false.
+ */
+ var assert = function (a, b) {
+
+ //Assume the objects will be same
+ var equal = true;
+
+ for (var key in b) {
+
+
+ if (a.hasOwnProperty(key)) {
+
+ //If the two keys are not equal
+ if (a[key] != b[key]) {
+ return false;
+ }
+ }
+ else {
+ return false;
+ }
+ }
+
+ return equal;
+ };
+
+ /*
+ The function generates the history path of a given asset
+ using its path
+ @assetPath:The path of the asset to be retrieved.
+ @return: The path of lifecycle history information
+ */
+ var getHistoryPath = function (assetPath) {
+
+ //Replace the / in the assetPath
+ var partialHistoryPath = assetPath.replace(lcHistoryRegExpression, HISTORY_PATH_SEPERATOR);
+
+ var fullPath = HISTORY_PATH + partialHistoryPath;
+
+ return fullPath;
+ };
+
+ /*
+ generatePaginationForm will genrate json for registry pagination context, (pagination consistent handling)
+ @pagin:The pagination details from UI
+ @
+ */
+ var generatePaginationForm = function (pagin) {
+
+ //pagination context for default
+ var paginationLimit = 300;
+ var paginationForm = {
+ 'start': 0,
+ 'count': 12,
+ 'sortOrder': 'ASC',
+ 'sortBy': 'overview_name',
+ 'paginationLimit': 2147483647
+ };
+
+ if (!pagin) {
+ return paginationForm;
+ }
+
+ if (pagin.count != null) {
+ paginationForm.count = pagin.count;
+ }
+ if (pagin.start != null) {
+ paginationForm.start = pagin.start;
+ }
+ if (pagin.paginationLimit != null) {
+ paginationForm.paginationLimit = pagin.paginationLimit;
+ }
+ if (pagin.sortBy != null) {
+ paginationForm.sortBy = pagin.sortBy;
+ }
+ if (paginationForm.sortOrder != null) {
+ paginationForm.sortOrder = pagin.sortOrder;
+ }
+ return paginationForm;
+
+ };
+
+ /*
+ Helper function to create an artifact instance from a set of options (an image).
+ */
+ var getArtifactFromImage = function (manager, options) {
+
+ var path = options.path || '';
+ var lcName = options.lifecycle || '';
+ var artifact = createArtifact(manager, {
+ id: options.id,
+ attributes: options.attributes
+ });
+
+ path = path.replace(REGISTRY_ABSOLUTE_PATH, '');
+
+ artifact.setArtifactPath(path);
+ artifact.setLcName(lcName);
+
+ return artifact;
+ };
+
+}(server, registry));
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/registry-osgi.js
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/registry-osgi.js b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/registry-osgi.js
new file mode 100644
index 0000000..eefbaad
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/registry-osgi.js
@@ -0,0 +1,466 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+var registry = registry || {};
+
+(function (server, registry) {
+ var log = new Log();
+
+ var Resource = Packages.org.wso2.carbon.registry.core.Resource;
+
+ var Collection = Packages.org.wso2.carbon.registry.core.Collection;
+
+ var Comment = Packages.org.wso2.carbon.registry.core.Comment;
+
+ var StaticConfiguration = Packages.org.wso2.carbon.registry.core.config.StaticConfiguration;
+
+ var queryPath = '/_system/config/repository/components/org.wso2.carbon.registry/queries/';
+
+ var content = function (registry, resource, paging) {
+ if (resource instanceof Collection) {
+ // #1 : this always sort children by name, so sorting cannot be done for the chunk
+ return children(registry, resource, paging);
+ }
+ if (resource instanceof Comment) {
+ return String(resource.getText());
+ }
+ var stream = resource.getContentStream();
+ if (stream) {
+ return new Stream(stream);
+ }
+ return String(resource.content);
+ };
+
+ var resourceSorter = function (key) {
+ var nameAsc = function (l, r) {
+ var lname, rname;
+ if (l instanceof Collection) {
+ lname = l.getName();
+ lname = lname.substring(lname.lastIndexOf('/') + 1);
+ } else {
+ lname = l.name;
+ }
+ if (r instanceof Collection) {
+ rname = r.getName();
+ rname = rname.substring(rname.lastIndexOf('/') + 1);
+ } else {
+ rname = r.name;
+ }
+ return lname === rname ? 0 : (lname > rname ? 1 : -1);
+ };
+ switch (key) {
+ case 'time-created-asc' :
+ return function (l, r) {
+ return l.getCreatedTime().getTime() - r.getCreatedTime().getTime();
+ };
+ case 'time-created-des' :
+ return function (l, r) {
+ return r.getCreatedTime().getTime() - l.getCreatedTime().getTime();
+ };
+ case 'name-asc' :
+ return nameAsc;
+ case 'name-des' :
+ return function (l, r) {
+ return -nameAsc(l, r);
+ };
+ default:
+ return resourceSorter('time-created-des');
+ }
+ };
+
+ var children = function (registry, resource, paging) {
+ var resources = resource.getChildren();
+ //we have to manually sort this due to the bug in registry.getChildren() (#1 above)
+ //resources.sort(resourceSorter(paging.sort));
+ return resources.slice(paging.start, paging.start + paging.count);
+ };
+
+ var resource = function (registry, resource) {
+ var path = String(resource.path),
+ o = {
+ created: {
+ author: String(resource.authorUserName),
+ time: resource.createdTime.time
+ },
+ content: content(registry, resource, {
+ start: 0,
+ count: 10
+ }),
+ id: String(resource.id),
+ version: resource.versionNumber
+ };
+ if (resource instanceof Comment) {
+ return o;
+ }
+ if (resource instanceof Collection) {
+ o.collection = (resource instanceof Collection);
+ }
+ o.uuid = String(resource.UUID);
+ o.path = String(path);
+ o.name = String(resource.name) || resolveName(path);
+ o.description = String(resource.description);
+ o.updated = {
+ author: String(resource.lastUpdaterUserName),
+ time: resource.lastModified.time
+ };
+ o.mediaType = String(resource.mediaType);
+ o.properties = function () {
+ return properties(resource);
+ };
+ o.aspects = function () {
+ return aspects(resource);
+ };
+ return o;
+ };
+
+ var properties = function (resource) {
+ var prop,
+ properties = resource.properties,
+ props = properties.keySet().toArray(),
+ length = props.length,
+ o = {};
+ for (var i = 0; i < length; i++) {
+ prop = props[i];
+ o[prop] = resource.getPropertyValues(prop).toArray();
+ }
+ return o;
+ };
+
+ var aspects = function (resource) {
+ var aspects = resource.getAspects();
+ return aspects ? aspects.toArray() : [];
+ };
+
+ var resolveName = function (path) {
+ path = path.charAt(path.length - 1) === '/' ? path.substring(0, path.length - 1) : path;
+ return path.substring(path.lastIndexOf('/') + 1);
+ };
+
+ var merge = function (def, options) {
+ if (options) {
+ for (var op in def) {
+ if (def.hasOwnProperty(op)) {
+ def[op] = options[op] || def[op];
+ }
+ }
+ }
+ return def;
+ };
+
+ var Registry = function (serv, options) {
+ var registryService = server.osgiService('org.wso2.carbon.registry.core.service.RegistryService'),
+ carbon = require('carbon');
+ if (options) {
+ this.server = serv;
+ } else {
+ this.server = new server.Server();
+ options = serv || {};
+ }
+
+ if (options.tenantId) {
+ this.tenantId = options.tenantId;
+ } else if (options.username || options.domain) {
+ this.tenantId = server.tenantId({
+ domain: options.domain,
+ username: options.username
+ });
+ } else {
+ this.tenantId = server.tenantId();
+ }
+
+ if (options.username) {
+ this.username = options.username;
+ } else if (options.system) {
+ this.username = carbon.user.systemUser;
+ } else {
+ this.username = carbon.user.anonUser;
+ }
+
+ this.registry = registryService.getRegistry(this.username, this.tenantId);
+ this.versioning = {
+ comments: StaticConfiguration.isVersioningComments()
+ };
+ };
+
+ registry.Registry = Registry;
+
+ Registry.prototype.put = function (path, resource) {
+ var res;
+ if (resource.collection) {
+ res = this.registry.newCollection();
+ } else {
+ res = this.registry.newResource();
+ if (resource.content instanceof Stream) {
+ res.contentStream = resource.content.getStream();
+ } else {
+ res.content = resource.content || null;
+ }
+ res.mediaType = resource.mediaType || null;
+ }
+ res.name = resource.name;
+ res.description = resource.description || null;
+ res.UUID = resource.uuid || null;
+
+ var values, length, i, ArrayList,
+ properties = resource.properties;
+ if (properties) {
+ ArrayList = java.util.ArrayList;
+ for (var name in properties) {
+ var list = new ArrayList();
+ if (properties.hasOwnProperty(name)) {
+ values = properties[name];
+ values = values instanceof Array ? values : [values];
+ length = values.length;
+ for (i = 0; i < length; i++) {
+ list.add(values[i]);
+ }
+ res.setProperty(name, list);
+ }
+ }
+ }
+
+ var aspects = resource.aspects;
+ if (aspects) {
+ length = aspects.length;
+ for (i = 0; i < length; i++) {
+ res.addAspect(aspects[i]);
+ }
+ }
+
+ this.registry.put(path, res);
+ };
+
+ Registry.prototype.remove = function (path) {
+ this.registry.delete(path);
+ };
+
+ Registry.prototype.move = function (src, dest) {
+ this.registry.move(src, dest);
+ };
+
+ Registry.prototype.rename = function (current, newer) {
+ this.registry.rename(current, newer);
+ };
+
+ Registry.prototype.copy = function (src, dest) {
+ this.registry.copy(src, dest);
+ };
+
+ Registry.prototype.restore = function (path) {
+ this.registry.restoreVersion(path);
+ };
+
+ Registry.prototype.get = function (path) {
+ if (!this.exists(path)) {
+ return null;
+ }
+ var res = this.registry.get(path);
+ return resource(this, res);
+ };
+
+ Registry.prototype.exists = function (path) {
+ return this.registry.resourceExists(path);
+ };
+
+ Registry.prototype.content = function (path, paging) {
+ if (!this.exists(path)) {
+ return null;
+ }
+ var resource = this.registry.get(path);
+ paging = merge({
+ start: 0,
+ count: 10,
+ sort: 'recent'
+ }, paging);
+ return content(this, resource, paging);
+ };
+
+ Registry.prototype.tags = function (path) {
+ var tags, i, length,
+ tagz = [];
+ tags = this.registry.getTags(path);
+ length = tags.length;
+ for (i = 0; i < length; i++) {
+ tagz.push(String(tags[i].tagName));
+ }
+ return tagz;
+ };
+
+ Registry.prototype.tag = function (path, tags) {
+ var i, length;
+ tags = tags instanceof Array ? tags : [tags];
+ length = tags.length;
+ for (i = 0; i < length; i++) {
+ this.registry.applyTag(path, tags[i]);
+ }
+ };
+
+ Registry.prototype.untag = function (path, tags) {
+ var i, length;
+ tags = tags instanceof Array ? tags : [tags];
+ length = tags.length;
+ for (i = 0; i < length; i++) {
+ this.registry.removeTag(path, tags[i]);
+ }
+ };
+
+ Registry.prototype.associate = function (src, dest, type) {
+ this.registry.addAssociation(src, dest, type);
+ };
+
+ Registry.prototype.dissociate = function (src, dest, type) {
+ this.registry.removeAssociation(src, dest, type);
+ };
+
+ Registry.prototype.associations = function (path, type) {
+ var i, asso,
+ assos = type ? this.registry.getAssociations(path, type) : this.registry.getAllAssociations(path),
+ length = assos.length,
+ associations = [];
+ for (i = 0; i < length; i++) {
+ asso = assos[i];
+ associations.push({
+ type: String(asso.associationType),
+ src: String(asso.sourcePath),
+ dest: String(asso.destinationPath)
+ });
+ }
+ return associations;
+ };
+
+ Registry.prototype.addProperty = function (path, name, value) {
+ var resource = this.registry.get(path);
+ resource.addProperty(name, value);
+ };
+
+ Registry.prototype.removeProperty = function (path, name, value) {
+ var resource = this.registry.get(path);
+ (value ? resource.removePropertyValue(name, value) : resource.removeProperty(name));
+ };
+
+ Registry.prototype.properties = function (path) {
+ var resource = this.registry.get(path);
+ return properties(resource);
+ };
+
+ Registry.prototype.version = function (path) {
+ this.registry.createVersion(path);
+ };
+
+ Registry.prototype.versions = function (path) {
+ return this.registry.getVersions(path);
+ };
+
+ Registry.prototype.unversion = function (path, snapshot) {
+ this.registry.removeVersionHistory(path, snapshot);
+ };
+
+ Registry.prototype.comment = function (path, comment) {
+ this.registry.addComment(path, new Comment(comment));
+ };
+
+ Registry.prototype.comments = function (path, paging) {
+ var i, length, comments, comment, key,
+ commentz = [];
+ paging = merge({
+ start: 0,
+ count: 25,
+ sort: 'recent'
+ }, paging);
+
+ comments = this.registry.getComments(path);
+ //we have to manually sort this due to the bug in registry.getChildren() (#1 above)
+ key = paging.sort;
+ key = (key === 'time-created-des' || key === 'time-created-asc') ? key : 'time-created-des';
+ comments = comments.sort(resourceSorter(key));
+ comments = comments.slice(paging.start, paging.start + paging.count);
+ length = comments.length;
+ for (i = 0; i < length; i++) {
+ comment = comments[i];
+ commentz.push({
+ content: comment.getText(),
+ created: {
+ author: comment.getUser(),
+ time: comment.getCreatedTime().getTime()
+ },
+ path: comment.getCommentPath()
+ });
+ }
+ return commentz;
+ };
+
+ Registry.prototype.commentCount = function (path) {
+ return this.registry.getComments(path).length;
+ };
+
+ Registry.prototype.uncomment = function (path) {
+ this.registry.removeComment(path);
+ };
+
+ Registry.prototype.rate = function (path, rating) {
+ this.registry.rateResource(path, rating);
+ };
+
+ Registry.prototype.unrate = function (path) {
+ this.registry.rateResource(path, 0);
+ };
+
+ Registry.prototype.rating = function (path, username) {
+ var rating = {
+ average: this.registry.getAverageRating(path)
+ };
+ if (username) {
+ rating.user = this.registry.getRating(path, username);
+ }
+ return rating;
+ };
+
+ Registry.prototype.link = function (path, target) {
+ return this.registry.createLink(path, target);
+ };
+
+ Registry.prototype.unlink = function (path) {
+ return this.registry.removeLink(path);
+ };
+
+ Registry.prototype.search = function (query, paging) {
+ var res = this.registry.searchContent(query);
+ paging = merge({
+ start: 0,
+ count: 10,
+ sort: 'recent'
+ }, paging);
+ return res ? content(this, res, paging) : [];
+ };
+
+ Registry.prototype.query = function (path, params) {
+ var res, name,
+ map = new java.util.HashMap();
+ for (name in params) {
+ if (params.hasOwnProperty(name)) {
+ map.put(name, params[name]);
+ }
+ }
+ res = this.registry.executeQuery(path, map);
+ return res.getChildren();
+ };
+
+}(server, registry));
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/registry-ws.js
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/registry-ws.js b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/registry-ws.js
new file mode 100644
index 0000000..014a75c
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/registry-ws.js
@@ -0,0 +1,77 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+var log = new Log();
+
+var Registry = function (server) {
+ this.server = server;
+};
+
+var Resource = function (name) {
+
+};
+
+var Collection = function (name) {
+
+};
+
+Registry.prototype.invoke = function (action, payload) {
+ var options,
+ ws = require('ws'),
+ client = new ws.WSRequest(),
+ server = this.server;
+
+ options = {
+ useSOAP: 1.2,
+ useWSA: 1.0,
+ action: action,
+ HTTPHeaders: [
+ { name: 'Cookie', value: server.cookie }
+ ]
+ };
+
+ try {
+ client.open(options, server.url + '/services/WSRegistryService', false);
+ client.send(payload);
+ return client.responseXML;
+ } catch (e) {
+ log.error(e.toString());
+ throw new Error('Error while invoking action in WSRegistryService : ' +
+ action + ', user : ' + server.user.username);
+ }
+};
+
+Registry.prototype.putResource = function (path, resource) {
+
+};
+
+Registry.prototype.getResource = function (path) {
+ var res, payload,
+ base64 = require('/modules/base64.js');
+
+ payload =
+ <api:getContent xmlns:api="http://api.ws.registry.carbon.wso2.org">
+ <api:path>{path}</api:path>
+ </api:getContent>;
+
+ res = this.invoke('urn:getContent', payload);
+ return base64.decode(String(res.*::['return'].text()));
+};
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/registry.js
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/registry.js b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/registry.js
new file mode 100644
index 0000000..43467bc
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/registry/registry.js
@@ -0,0 +1,45 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+var registry = {};
+
+(function (registry) {
+ var ActionConstants = Packages.org.wso2.carbon.registry.core.ActionConstants,
+ AccessControlConstants = Packages.org.wso2.carbon.registry.core.utils.AccessControlConstants;
+
+ registry.Registry = function (server, auth) {
+ var osgi = require('registry-osgi.js').registry,
+ o = new osgi.Registry(server, auth);
+ o.prototype = this;
+ return o;
+ };
+
+ registry.actions = {};
+
+ registry.actions.GET = ActionConstants.GET;
+
+ registry.actions.PUT = ActionConstants.PUT;
+
+ registry.actions.DELETE = ActionConstants.DELETE;
+
+ registry.actions.AUTHORIZE = AccessControlConstants.AUTHORIZE;
+
+}(registry));
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/config.js
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/config.js b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/config.js
new file mode 100644
index 0000000..fe5078f
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/config.js
@@ -0,0 +1,53 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+(function (server) {
+ var process = require('process'),
+ configDir = 'file:///' + process.getProperty('carbon.config.dir.path').replace(/[\\]/g, '/').replace(/^[\/]/g, '') + '/';
+ server.loadConfig = function (path) {
+ var content,
+ index = path.lastIndexOf('.'),
+ ext = (index !== -1 && index < path.length) ? path.substring(index + 1) : '',
+ file = new File(configDir + path);
+ if (!file.isExists()) {
+ throw new Error('Specified config file does not exists : ' + path);
+ }
+ if (file.isDirectory()) {
+ throw new Error('Specified config file is a directory : ' + path);
+ }
+ file.open('r');
+ content = file.readAll();
+ file.close();
+ switch (ext) {
+ case 'xml' :
+ return new XML(content);
+ case 'json' :
+ return parse(content);
+ case 'properties' :
+ default :
+ return content;
+
+ }
+ };
+
+ server.home = 'file:///' + require('process').getProperty('carbon.home').replace(/[\\]/g, '/').replace(/^[\/]/g, '');
+
+}(server));
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/osgi.js
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/osgi.js b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/osgi.js
new file mode 100644
index 0000000..2175c23
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/osgi.js
@@ -0,0 +1,31 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+var server = {};
+
+(function (server) {
+ var PrivilegedCarbonContext = Packages.org.wso2.carbon.context.PrivilegedCarbonContext,
+ Class = java.lang.Class;
+
+ server.osgiService = function (clazz) {
+ return PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(Class.forName(clazz));
+ };
+}(server));
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/server.js
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/server.js b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/server.js
new file mode 100644
index 0000000..ba6300d
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/server.js
@@ -0,0 +1,115 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+(function (server) {
+ var log = new Log();
+
+ var login = function (url, username, password) {
+ var res, options, payload,
+ ws = require('ws'),
+ client = new ws.WSRequest(),
+ host = url.match(/.*:\/\/([^:\/]*)/)[1];
+
+ options = {
+ useSOAP: 1.2,
+ useWSA: 1.0,
+ action: 'urn:login'
+ };
+
+ payload =
+ <aut:login xmlns:aut="http://authentication.services.core.carbon.wso2.org">
+ <aut:username>{username}</aut:username>
+ <aut:password>{password}</aut:password>
+ <aut:remoteAddress>{host}</aut:remoteAddress>
+ </aut:login>;
+
+ try {
+ client.open(options, url + '/services/AuthenticationAdmin', false);
+ client.send(payload);
+ res = client.responseXML;
+ if (res.*::["return"].text() != 'true') {
+ return false;
+ }
+ return client.getResponseHeader('Set-Cookie');
+ } catch (e) {
+ log.error(e.toString());
+ throw new Error('Error while login to the server : ' + url + ', user : ' + username);
+ }
+ };
+
+ var logout = function (url, cookie) {
+ var options,
+ ws = require('ws'),
+ client = new ws.WSRequest();
+
+ options = {
+ useSOAP: 1.2,
+ useWSA: 1.0,
+ action: 'urn:logout',
+ mep: 'in-only',
+ HTTPHeaders: [
+ { name: 'Cookie', value: cookie }
+ ]
+ };
+
+ try {
+ client.open(options, url + '/services/AuthenticationAdmin', false);
+ client.send(null);
+ return true;
+ } catch (e) {
+ log.error(e.toString());
+ throw new Error('Error while logging out in server : ' + url + ', cookie : ' + cookie);
+ }
+ };
+
+ var Cookie = function (cookie) {
+ this.cookie = cookie;
+ };
+
+ server.Cookie = Cookie;
+
+ var Server = function (options) {
+ this.url = (options && options.url) ? options.url : 'local:/';
+ };
+ server.Server = Server;
+
+ Server.prototype.authenticate = function (username, password) {
+ var realm, user,
+ carbon = require('carbon'),
+ realmService = server.osgiService('org.wso2.carbon.user.core.service.RealmService');
+ user = carbon.server.tenantUser(username);
+ realm = realmService.getTenantUserRealm(user.tenantId);
+ if(realm == null){
+ throw new Error("Invalid domain or unactivated tenant login");
+ }else{
+ return realm.getUserStoreManager().authenticate(user.username, password);
+ }
+ };
+
+ Server.prototype.login = function (username, password) {
+ var cookie = login(this.url, username, password);
+ return new Cookie(cookie);
+ };
+
+ Server.prototype.logout = function (cookie) {
+ return logout(this.url, cookie.cookie);
+ };
+}(server));
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/tenant.js
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/tenant.js b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/tenant.js
new file mode 100644
index 0000000..255e7d7
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/server/tenant.js
@@ -0,0 +1,70 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+(function (server) {
+ var PrivilegedCarbonContext = Packages.org.wso2.carbon.context.PrivilegedCarbonContext,
+ MultitenantConstants = Packages.org.wso2.carbon.utils.multitenancy.MultitenantConstants,
+ MultitenantUtils = Packages.org.wso2.carbon.utils.multitenancy.MultitenantUtils,
+ realmService = server.osgiService('org.wso2.carbon.user.core.service.RealmService'),
+ tenantManager = realmService.getTenantManager();
+
+ server.tenantDomain = function (options) {
+ if (!options) {
+ return PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
+ }
+ if(options.tenantId) {
+ return tenantManager.getDomain(options.tenantId);
+ }
+ if (options.username) {
+ return MultitenantUtils.getTenantDomain(options.username);
+ }
+ if (options.url) {
+ return MultitenantUtils.getTenantDomainFromRequestURL(options.url);
+ }
+ return null;
+ };
+
+ server.tenantId = function (options) {
+ var domain = options ? (options.domain || server.tenantDomain(options)) : server.tenantDomain();
+ return domain ? tenantManager.getTenantId(domain) : null;
+ };
+
+ server.tenantUser = function (username) {
+ var domain = server.tenantDomain({
+ username: username
+ }),
+ id = server.tenantId({
+ domain: domain
+ });
+ username = MultitenantUtils.getTenantAwareUsername(username);
+ return {
+ domain: domain,
+ username: username,
+ tenantId: id
+ };
+ };
+
+ server.superTenant = {
+ tenantId: MultitenantConstants.SUPER_TENANT_ID,
+ domain: MultitenantConstants.SUPER_TENANT_DOMAIN_NAME
+ };
+
+}(server));
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/registry-space.js
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/registry-space.js b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/registry-space.js
new file mode 100644
index 0000000..9536fb4
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/registry-space.js
@@ -0,0 +1,60 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+(function (server, registry, user) {
+
+ var Space = function (user, space, options) {
+ var serv = new server.Server(options.serverUrl);
+ this.registry = new registry.Registry(serv, {
+ username: options.username || user,
+ domain: options.domain || server.tenantDomain()
+ });
+ this.prefix = options.path + '/' + user + '/' + space;
+ if (!this.registry.exists(this.prefix)) {
+ this.registry.put(this.prefix, {
+ collection: true
+ });
+ }
+ };
+ user.Space = Space;
+
+ Space.prototype.put = function (key, value) {
+ value = (!(value instanceof String) && typeof value !== "string") ? stringify(value) : value;
+ this.registry.put(this.prefix + '/' + key, {
+ content: value
+ });
+ };
+
+ Space.prototype.get = function (key) {
+ var o = this.registry.content(this.prefix + '/' + key);
+ return o ? o.toString() : null;
+ };
+
+ Space.prototype.remove = function (key) {
+ this.registry.remove(this.prefix + '/' + key);
+ };
+
+ Space.prototype.find = function (filter) {
+
+ };
+
+
+}(server, registry, user));
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/space.js
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/space.js b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/space.js
new file mode 100644
index 0000000..c895cc1
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/space.js
@@ -0,0 +1,31 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+(function (server, user) {
+
+ user.Space = function (user, space, options) {
+ var reg = require('registry-space.js').user,
+ o = new reg.Space(user, space, options);
+ o.prototype = this;
+ return o;
+ };
+
+}(server, user));
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/user-manager.js
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/user-manager.js b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/user-manager.js
new file mode 100644
index 0000000..56833b9
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/user-manager.js
@@ -0,0 +1,179 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+(function (server, user) {
+
+ var log = new Log();
+
+ var processPerms = function (perms, fn) {
+ var perm, actions, i, length;
+ for (perm in perms) {
+ if (perms.hasOwnProperty(perm)) {
+ actions = perms[perm];
+ length = actions.length;
+ for (i = 0; i < length; i++) {
+ fn(perm, actions[i]);
+ }
+ }
+ }
+ };
+
+ var UserManager = function (serv, tenantId) {
+ this.server = serv;
+ this.tenantId = tenantId || server.superTenant.tenantId;
+ var realmService = server.osgiService('org.wso2.carbon.user.core.service.RealmService'),
+ realm = realmService.getTenantUserRealm(this.tenantId);
+ this.manager = realm.getUserStoreManager();
+ this.authorizer = realm.getAuthorizationManager();
+ };
+ user.UserManager = UserManager;
+
+ UserManager.prototype.getUser = function (username) {
+ if (!this.manager.isExistingUser(username)) {
+ return null;
+ }
+ return new user.User(this, username);
+ };
+ UserManager.prototype.getRoleListOfUser = function (username) {
+ return this.manager.getRoleListOfUser(username);
+ };
+ UserManager.prototype.addUser = function (username, password, roles, claims, profile) {
+ this.manager.addUser(username, password, roles || [], claims || null, profile);
+ };
+
+ UserManager.prototype.removeUser = function (username) {
+ this.manager.deleteUser(username);
+ };
+
+ UserManager.prototype.userExists = function (username) {
+ return this.manager.isExistingUser(username);
+ };
+
+ UserManager.prototype.roleExists = function (role) {
+ return this.manager.isExistingRole(role);
+ };
+ UserManager.prototype.updateRole = function (previousRoleName, newRoleName) {
+ return this.manager.updateRoleName(previousRoleName, newRoleName);
+ };
+ UserManager.prototype.getClaims = function (username, profile) {
+ return this.manager.getUserClaimValues(username, profile);
+ };
+ UserManager.prototype.getClaimsForSet = function (username,claims, profile) {
+ return this.manager.getUserClaimValues(username,claims, profile);
+ };
+ UserManager.prototype.getClaim = function (username, claim, profile) {
+ return this.manager.getUserClaimValue(username, claim, profile);
+ };
+
+ UserManager.prototype.setClaims = function (username, claims, profile) {
+ return this.manager.setUserClaimValues(username, claims, profile);
+ };
+
+ UserManager.prototype.setClaim = function (username, claim, value, profile) {
+ return this.manager.setUserClaimValue(username, claim, value, profile);
+ };
+
+ UserManager.prototype.isAuthorized = function (role, permission, action) {
+ return this.authorizer.isRoleAuthorized(role, permission, action);
+ };
+ UserManager.prototype.updateRoleListOfUser = function(name, deletedRoles, newRoles){
+ return this.manager.updateRoleListOfUser(name, deletedRoles, newRoles);
+ };
+ UserManager.prototype.updateUserListOfRole = function(name, deletedUsers, newUsers){
+ return this.manager.updateUserListOfRole(name, deletedUsers, newUsers);
+ };
+ UserManager.prototype.listUsers = function () {
+ return this.manager.listUsers("*", -1);
+ };
+ UserManager.prototype.addRole = function (role, users, permissions) {
+ var perms = [],
+ Permission = Packages.org.wso2.carbon.user.api.Permission;
+ processPerms(permissions, function (id, action) {
+ perms.push(new Permission(id, action));
+ });
+ this.manager['addRole(java.lang.String,java.lang.String[],org.wso2.carbon.user.api.Permission[])']
+ (role, users, perms);
+ };
+
+ UserManager.prototype.removeRole = function (role) {
+ this.manager.deleteRole(role);
+ };
+
+ UserManager.prototype.allRoles = function () {
+ return this.manager.getRoleNames();
+ };
+ UserManager.prototype.getUserListOfRole = function (role) {
+ return this.manager.getUserListOfRole(role);
+ };
+ /**
+ * um.authorizeRole('store-admin', '/permissions/mypermission', 'ui-execute');
+ *
+ * um.authorizeRole('store-admin', {
+ * '/permissions/myperm1' : ['read', 'write'],
+ * '/permissions/myperm2' : ['read', 'write']
+ * });
+ *
+ * @param role
+ * @param permission
+ * @param action
+ */
+ UserManager.prototype.authorizeRole = function (role, permission, action) {
+ var that = this;
+ if (permission instanceof String || typeof permission === 'string') {
+ if (!that.isAuthorized(role, permission, action)) {
+ that.authorizer.authorizeRole(role, permission, action);
+ }
+ } else {
+ processPerms(permission, function (id, action) {
+ if (!that.isAuthorized(role, id, action)) {
+ that.authorizer.authorizeRole(role, id, action);
+ if (log.isDebugEnabled()) {
+ log.debug('permission added(role:permission:action) - ' + role + ':' + id + ':' + action);
+ }
+ }
+ });
+ }
+ };
+
+ /**
+ * um.denyRole('store-admin', '/permissions/mypermission', 'ui-execute');
+ *
+ * um.denyRole('store-admin', {
+ * '/permissions/myperm1' : ['read', 'write'],
+ * '/permissions/myperm2' : ['read', 'write']
+ * });
+ *
+ * @param role
+ * @param permission
+ * @param action
+ */
+ UserManager.prototype.denyRole = function (role, permission, action) {
+ var deny = this.authorizer.denyRole;
+ if (permission instanceof String || typeof permission === 'string') {
+ deny(role, permission, action);
+ } else {
+ processPerms(permission, function (id, action) {
+ deny(role, id, action);
+ });
+ }
+ };
+
+}(server, user));
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/user.js
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/user.js b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/user.js
new file mode 100644
index 0000000..66b253d
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/temp-artifacts/carbon/scripts/user/user.js
@@ -0,0 +1,99 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+var user = {};
+
+(function (user) {
+
+ var CarbonConstants = Packages.org.wso2.carbon.CarbonConstants;
+
+ user.systemUser = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
+
+ user.anonUser = CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME;
+
+ user.anonRole = CarbonConstants.REGISTRY_ANONNYMOUS_ROLE_NAME;
+
+ var User = function (manager, username) {
+ this.um = manager;
+ this.tenantId = manager.tenantId;
+ this.username = username;
+ };
+ user.User = User;
+
+ User.prototype.getClaims = function (profile) {
+ return this.um.getClaims(this.username, profile);
+ };
+ User.prototype.getClaimsForSet = function (claims,profile) {
+ return this.um.getClaimsForSet(this.username, claims, profile);
+ };
+
+ User.prototype.setClaims = function (claims, profile) {
+ this.um.setClaims(this.username, claims, profile);
+ };
+
+ User.prototype.getRoles = function () {
+ return this.um.manager.getRoleListOfUser(this.username);
+ };
+
+ User.prototype.hasRoles = function (roles) {
+ var i, j, role,
+ rs = this.getRoles(),
+ length1 = roles.length,
+ length2 = rs.length;
+ L1:
+ for (i = 0; i < length1; i++) {
+ //Array.indexOf() fails due to Java String vs JS String difference
+ role = roles[i];
+ for (j = 0; j < length2; j++) {
+ if (role == rs[j]) {
+ continue L1;
+ }
+ }
+ return false;
+ }
+ return true;
+ };
+
+ User.prototype.addRoles = function (roles) {
+ return this.um.manager.updateRoleListOfUser(this.username, [], roles);
+ };
+
+ User.prototype.removeRoles = function (roles) {
+ return this.um.manager.updateRoleListOfUser(this.username, roles, []);
+ };
+
+ User.prototype.updateRoles = function (remove, add) {
+ return this.um.manager.updateRoleListOfUser(this.username, remove, add);
+ };
+
+ User.prototype.isAuthorized = function (permission, action) {
+ var i,
+ roles = this.getRoles(),
+ length = roles.length;
+ for (i = 0; i < length; i++) {
+ if (this.um.authorizer.isRoleAuthorized(roles[i], permission, action)) {
+ return true;
+ }
+ }
+ return false;
+ };
+
+}(user));
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/org.jaggeryjs.hostobjects.xhr_0.9.0.ALPHA4_wso2v1.jar
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/org.jaggeryjs.hostobjects.xhr_0.9.0.ALPHA4_wso2v1.jar b/products/stratos/modules/distribution/src/main/temp-artifacts/org.jaggeryjs.hostobjects.xhr_0.9.0.ALPHA4_wso2v1.jar
new file mode 100644
index 0000000..60f6f07
Binary files /dev/null and b/products/stratos/modules/distribution/src/main/temp-artifacts/org.jaggeryjs.hostobjects.xhr_0.9.0.ALPHA4_wso2v1.jar differ
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/org.wso2.store.sso.common_1.0.0.jar
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/org.wso2.store.sso.common_1.0.0.jar b/products/stratos/modules/distribution/src/main/temp-artifacts/org.wso2.store.sso.common_1.0.0.jar
new file mode 100644
index 0000000..4a74e5b
Binary files /dev/null and b/products/stratos/modules/distribution/src/main/temp-artifacts/org.wso2.store.sso.common_1.0.0.jar differ
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/org.wso2.stratos.identity.saml2.sso.mgt_2.2.0.jar
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/org.wso2.stratos.identity.saml2.sso.mgt_2.2.0.jar b/products/stratos/modules/distribution/src/main/temp-artifacts/org.wso2.stratos.identity.saml2.sso.mgt_2.2.0.jar
new file mode 100644
index 0000000..29a9fb7
Binary files /dev/null and b/products/stratos/modules/distribution/src/main/temp-artifacts/org.wso2.stratos.identity.saml2.sso.mgt_2.2.0.jar differ
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/sso/module.xml
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/sso/module.xml b/products/stratos/modules/distribution/src/main/temp-artifacts/sso/module.xml
new file mode 100644
index 0000000..159203b
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/temp-artifacts/sso/module.xml
@@ -0,0 +1,28 @@
+<?xml version='1.0'?>
+<!--
+
+ 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.
+
+-->
+
+<module name="sso" xmlns="http://wso2.org/projects/jaggery/module.xml">
+ <script>
+ <name>client</name>
+ <path>scripts/sso.client.js</path>
+ </script>
+</module>
http://git-wip-us.apache.org/repos/asf/stratos/blob/8d321a26/products/stratos/modules/distribution/src/main/temp-artifacts/sso/scripts/sso.client.js
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/temp-artifacts/sso/scripts/sso.client.js b/products/stratos/modules/distribution/src/main/temp-artifacts/sso/scripts/sso.client.js
new file mode 100644
index 0000000..9553220
--- /dev/null
+++ b/products/stratos/modules/distribution/src/main/temp-artifacts/sso/scripts/sso.client.js
@@ -0,0 +1,193 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+/**
+ * Following module act as a client to create a saml request and also to
+ * unwrap and return attributes of a returning saml response
+ * @type {{}}
+ */
+
+var client = {};
+
+(function (client) {
+
+ var Util = Packages.org.wso2.store.sso.common.util.Util,
+ carbon = require('carbon'),
+ log = new Log();
+
+ /**
+ * obtains an encoded saml response and return a decoded/unmarshalled saml obj
+ * @param samlResp
+ * @return {*}
+ */
+ client.getSamlObject = function (samlResp) {
+ var decodedResp = Util.decode(samlResp);
+ return Util.unmarshall(decodedResp);
+ };
+
+ /**
+ * validating the signature of the response saml object
+ */
+ client.validateSignature = function (samlObj, config) {
+ var tDomain = Util.getDomainName(samlObj);
+ var tId = carbon.server.tenantId({domain: tDomain});
+
+ return Util.validateSignature(samlObj,
+ config.KEY_STORE_NAME, config.KEY_STORE_PASSWORD, config.IDP_ALIAS, tId, tDomain);
+ };
+
+ /**
+ * Checking if the request is a logout call
+ */
+ client.isLogoutRequest = function (samlObj) {
+ return samlObj instanceof Packages.org.opensaml.saml2.core.LogoutRequest;
+ };
+
+ /**
+ * Checking if the request is a logout call
+ */
+ client.isLogoutResponse = function (samlObj) {
+ return samlObj instanceof Packages.org.opensaml.saml2.core.LogoutResponse;
+ };
+
+ /**
+ * getting url encoded saml authentication request
+ * @param issuerId
+ */
+ client.getEncodedSAMLAuthRequest = function (issuerId) {
+ return Util.encode(
+ Util.marshall(
+ new Packages.org.wso2.store.sso.common.builders.AuthReqBuilder().buildAuthenticationRequest(issuerId)
+ ));
+ };
+
+ /**
+ * get url encoded saml logout request
+ */
+ client.getEncodedSAMLLogoutRequest = function (user, sessionIndex, issuerId) {
+ return Util.encode(
+ Util.marshall(
+ new Packages.org.wso2.store.sso.common.builders.LogoutRequestBuilder().buildLogoutRequest(user, sessionIndex,
+ Packages.org.wso2.store.sso.common.constants.SSOConstants.LOGOUT_USER,
+ issuerId)));
+ };
+
+ /**
+ * Reads the returning SAML login response and populates a session info object
+ */
+ client.decodeSAMLLoginResponse = function (samlObj, samlResp, sessionId) {
+ var samlSessionObj = {
+ // sessionId, loggedInUser, sessionIndex, samlToken
+ };
+
+ if (samlObj instanceof Packages.org.opensaml.saml2.core.Response) {
+
+ var assertions = samlObj.getAssertions();
+
+ // extract the session index
+ if (assertions != null && assertions.size() > 0) {
+ var authenticationStatements = assertions.get(0).getAuthnStatements();
+ var authnStatement = authenticationStatements.get(0);
+ if (authnStatement != null) {
+ if (authnStatement.getSessionIndex() != null) {
+ samlSessionObj.sessionIndex = authnStatement.getSessionIndex();
+ }
+ }
+ }
+
+ // extract the username
+ if (assertions != null && assertions.size() > 0) {
+ var subject = assertions.get(0).getSubject();
+ var samlAssertion = assertions.get(0);
+ if (subject != null) {
+ if (subject.getNameID() != null) {
+ samlSessionObj.loggedInUser = subject.getNameID().getValue();
+ }
+ }
+ }
+ samlSessionObj.sessionId = sessionId;
+ samlSessionObj.samlToken = samlResp;
+ }
+
+ return samlSessionObj;
+ };
+
+ client.getURLencodedB64EncodedSAML2Token = function(samlObj){
+ var saml2Token = {
+ // URLEncodedB64
+ };
+ if (samlObj instanceof Packages.org.opensaml.saml2.core.Response) {
+ saml2Token.URLEncodedB64 = Util.getURLEncodedB64SAML2Token(samlObj);
+ }
+ return saml2Token;
+ };
+
+ client.getB64EncodedtSAMLAssertion = function(samlObj){
+ var saml2Token = {
+ // URLEncodedB64
+ };
+ if (samlObj instanceof Packages.org.opensaml.saml2.core.Response) {
+ saml2Token.b64Encoded = Util.getB64EncodedtSAMLAssertion(samlObj);
+ }
+ return saml2Token;
+ };
+
+
+ client.b64encode = function(str){
+ return Util.encode(str);
+ };
+
+ /**
+ * This method is to get the session index when a single logout happens
+ * The IDP sends a logout request to the ACS with the session index, so that
+ * the app can invalidate the associated HTTP Session
+ */
+ client.decodeSAMLLogoutRequest = function (samlObj) {
+ var sessionIndex = null;
+
+ if (samlObj instanceof org.opensaml.saml2.core.LogoutRequest) {
+ var sessionIndexes = samlObj.getSessionIndexes();
+ if (sessionIndexes != null && sessionIndexes.size() > 0) {
+ sessionIndex = sessionIndexes.get(0).getSessionIndex();
+ }
+ }
+
+ return sessionIndex;
+
+ };
+
+ client.getTenantDomain = function (samlObj) {
+ var tDomain = Util.getDomainName(samlObj);
+ return tDomain;
+ };
+
+ client.getRoleList = function(samlObj) {
+ var roleObj = [];
+ var roleString = Util.getRoles(samlObj);
+ log.info("role string : " + roleString);
+ var roleSplit = roleString.split(",");
+ for(var i=0; i < roleSplit.length;i++){
+ roleObj.push(roleSplit[i].trim());
+ }
+ return roleObj;
+ };
+
+}(client));