You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by mf...@apache.org on 2012/12/11 03:45:03 UTC
svn commit: r1419978 - in /rave/trunk:
rave-portal-resources/src/main/webapp/WEB-INF/
rave-portal-resources/src/main/webapp/static/script/
rave-providers/rave-opensocial-provider/rave-opensocial-client/src/main/java/org/apache/rave/provider/opensocial/...
Author: mfranklin
Date: Tue Dec 11 02:45:01 2012
New Revision: 1419978
URL: http://svn.apache.org/viewvc?rev=1419978&view=rev
Log:
Committing patch from Robert O'Neill RAVE-851
Added:
rave/trunk/rave-providers/rave-opensocial-provider/rave-opensocial-client/src/main/java/org/apache/rave/provider/opensocial/controller/
rave/trunk/rave-providers/rave-opensocial-provider/rave-opensocial-client/src/main/java/org/apache/rave/provider/opensocial/controller/SecurityTokenController.java
Modified:
rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/dispatcher-servlet.xml
rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_opensocial.js
Modified: rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/dispatcher-servlet.xml
URL: http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/dispatcher-servlet.xml?rev=1419978&r1=1419977&r2=1419978&view=diff
==============================================================================
--- rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/dispatcher-servlet.xml (original)
+++ rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/dispatcher-servlet.xml Tue Dec 11 02:45:01 2012
@@ -35,6 +35,7 @@
-->
<context:component-scan base-package="org.apache.rave.portal.web.controller"/>
<context:component-scan base-package="org.apache.rave.portal.web.api"/>
+ <context:component-scan base-package="org.apache.rave.provider.opensocial.controller;"/>
<!-- Configures the @Controller programming model -->
<mvc:annotation-driven>
Modified: rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_opensocial.js
URL: http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_opensocial.js?rev=1419978&r1=1419977&r2=1419978&view=diff
==============================================================================
--- rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_opensocial.js (original)
+++ rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_opensocial.js Tue Dec 11 02:45:01 2012
@@ -94,9 +94,29 @@ rave.opensocial = rave.opensocial || (fu
container.views.createElementForEmbeddedExperience = function (rel, opt_gadgetInfo, opt_viewTarget, opt_coordinates, parentSite, opt_callback) {
- if (opt_viewTarget) {
- return rave.createPopup(opt_viewTarget);
- }
+ var widgetUrl = opt_gadgetInfo.url;
+
+ getSecurityToken({
+ "url": widgetUrl,
+ "pageid": rave.layout.getCurrentPageId(),
+ "successCallback": function(data) {
+ if (!data.error) {
+ var gadget = {
+ "widgetUrl": widgetUrl,
+ "securityToken": data.securityToken,
+ "metadata": opt_gadgetInfo
+ }
+
+ preloadMetadata(gadget);
+
+ if (opt_viewTarget) {
+ opt_callback(rave.createPopup(opt_viewTarget));
+ }
+ } else {
+ console.log(data.error.message);
+ }
+ }
+ })
};
container.views.createElementForUrl = function (rel, opt_viewTarget, opt_coordinates, parentSite, opt_callback) {
@@ -112,6 +132,19 @@ rave.opensocial = rave.opensocial || (fu
};
}
+
+ function getSecurityToken(args) {
+ $.ajax({
+ type: 'GET',
+ url: rave.getContext() + "api/rest/" + "st?url=" + args.url + "&pageid=" + args.pageid,
+ dataType: "json",
+ success: function (data) {
+ if (typeof args.successCallback == 'function') {
+ args.successCallback(data);
+ }
+ }
+ });
+ }
/**
* Validates a gadget's metadata and renders it on the page
@@ -121,30 +154,34 @@ rave.opensocial = rave.opensocial || (fu
function validateAndRenderGadget(gadget) {
var validationResult = validateMetadata(gadget.metadata);
if (validationResult.valid) {
- //Put our gadget metadata into the form that the common container is expecting
- var commonContainerMetadataWrapper = {};
- commonContainerMetadataWrapper[gadget.widgetUrl] = gadget.metadata;
-
- //Put our gadget security token data into the form that the common container is expecting
- var commonContainerTokenData = {};
- commonContainerTokenData[osapi.container.TokenResponse.TOKEN] = gadget.securityToken;
- commonContainerTokenData[osapi.container.MetadataResponse.RESPONSE_TIME_MS] = new Date().getTime();
- var commonContainerTokenWrapper = {};
- commonContainerTokenWrapper[gadget.widgetUrl] = commonContainerTokenData;
-
- //Setup the preloadConfig data with all our preload data
- var preloadConfig = {};
- preloadConfig[osapi.container.ContainerConfig.PRELOAD_METADATAS] = commonContainerMetadataWrapper;
- preloadConfig[osapi.container.ContainerConfig.PRELOAD_TOKENS] = commonContainerTokenWrapper;
- preloadConfig[osapi.container.ContainerConfig.PRELOAD_REF_TIME] = null;
-
- //Preload our data into the common container
- container.preloadCaches(preloadConfig);
+ preloadMetadata(gadget);
renderNewGadget(gadget);
} else {
rave.errorWidget(gadget.regionWidgetId, rave.getClientMessage("opensocial.render_error") + "<br /><br />" + validationResult.error);
}
}
+
+ function preloadMetadata(gadget) {
+ //Put our gadget metadata into the form that the common container is expecting
+ var commonContainerMetadataWrapper = {};
+ commonContainerMetadataWrapper[gadget.widgetUrl] = gadget.metadata;
+
+ //Put our gadget security token data into the form that the common container is expecting
+ var commonContainerTokenData = {};
+ commonContainerTokenData[osapi.container.TokenResponse.TOKEN] = gadget.securityToken;
+ commonContainerTokenData[osapi.container.MetadataResponse.RESPONSE_TIME_MS] = new Date().getTime();
+ var commonContainerTokenWrapper = {};
+ commonContainerTokenWrapper[gadget.widgetUrl] = commonContainerTokenData;
+
+ //Setup the preloadConfig data with all our preload data
+ var preloadConfig = {};
+ preloadConfig[osapi.container.ContainerConfig.PRELOAD_METADATAS] = commonContainerMetadataWrapper;
+ preloadConfig[osapi.container.ContainerConfig.PRELOAD_TOKENS] = commonContainerTokenWrapper;
+ preloadConfig[osapi.container.ContainerConfig.PRELOAD_REF_TIME] = null;
+
+ //Preload our data into the common container
+ container.preloadCaches(preloadConfig);
+ }
/**
* Renders a new gadget
Added: rave/trunk/rave-providers/rave-opensocial-provider/rave-opensocial-client/src/main/java/org/apache/rave/provider/opensocial/controller/SecurityTokenController.java
URL: http://svn.apache.org/viewvc/rave/trunk/rave-providers/rave-opensocial-provider/rave-opensocial-client/src/main/java/org/apache/rave/provider/opensocial/controller/SecurityTokenController.java?rev=1419978&view=auto
==============================================================================
--- rave/trunk/rave-providers/rave-opensocial-provider/rave-opensocial-client/src/main/java/org/apache/rave/provider/opensocial/controller/SecurityTokenController.java (added)
+++ rave/trunk/rave-providers/rave-opensocial-provider/rave-opensocial-client/src/main/java/org/apache/rave/provider/opensocial/controller/SecurityTokenController.java Tue Dec 11 02:45:01 2012
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.provider.opensocial.controller;
+
+import org.apache.rave.portal.model.Page;
+import org.apache.rave.portal.model.RegionWidget;
+import org.apache.rave.portal.model.Widget;
+import org.apache.rave.portal.model.WidgetStatus;
+import org.apache.rave.portal.model.impl.RegionImpl;
+import org.apache.rave.portal.model.impl.RegionWidgetImpl;
+import org.apache.rave.portal.service.PageService;
+import org.apache.rave.portal.service.WidgetService;
+import org.apache.rave.provider.opensocial.exception.SecurityTokenException;
+import org.apache.rave.provider.opensocial.service.impl.EncryptedBlobSecurityTokenService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Admin controller to manipulate Widget data
+ */
+@Controller
+public class SecurityTokenController{
+
+ @Autowired
+ private WidgetService widgetService;
+
+ @Autowired
+ private PageService pageService;
+
+ @Autowired
+ private EncryptedBlobSecurityTokenService securityTokenService;
+
+ @RequestMapping(value = "/api/rest/st", method = RequestMethod.GET, produces="application/json")
+ @ResponseBody
+ public Map<String, Object> getSecurityToken(@RequestParam("url") final String url, @RequestParam("pageid") final String pageId) {
+ Widget widget = widgetService.getWidgetByUrl(url);
+ Page page = pageService.getPage(pageId);
+
+ // Use a dummy RegionWidget to generate the security token
+ RegionWidget regionWidget = new RegionWidgetImpl(String.valueOf(System.currentTimeMillis()),"-1",
+ new RegionImpl("-1", page, -1));
+
+ Map<String, Object> jsonResponse = new HashMap<String, Object>();
+ Map<String, String> errorMessage = new HashMap<String, String>();
+
+ String securityToken = "";
+ if (widget != null && widget.getWidgetStatus() == WidgetStatus.PUBLISHED) {
+ try {
+ securityToken = securityTokenService.getEncryptedSecurityToken(regionWidget, widget);
+ } catch (SecurityTokenException e) {
+ errorMessage.put("message", "There was a problem creating the security token.");
+ }
+ } else if (widget != null && widget.getWidgetStatus() == WidgetStatus.PREVIEW) {
+ errorMessage.put("message", "The requested gadget exists in the gadget store but is not published.");
+ } else {
+ errorMessage.put("message", "The requested gadget does not exist in the gadget store.");
+ }
+
+ jsonResponse.put("securityToken", securityToken);
+ if (!errorMessage.isEmpty()) {
+ jsonResponse.put("error", errorMessage);
+ }
+
+ return jsonResponse;
+ }
+}