Author: ivol37 at gmail.com
Date: Tue Dec 7 11:39:18 2010
New Revision: 480
Log:
[AMDATU-205] Removed oAuth support (server-side) from the Shindig bundle
Removed:
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/oauth/AmdatuOAuthServlet.java
trunk/amdatu-opensocial/shindig/src/main/resources/conf/oauth.json
Modified:
trunk/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/service/OAuthTokenProviderImpl.java
trunk/amdatu-example/course-gadget/pom.xml
trunk/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/osgi/Activator.java
trunk/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/service/CourseGadgetServiceImpl.java
trunk/amdatu-example/course-gadget/src/main/resources/jsp/CourseGadget.jsp
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/module/SocialApiModuleImpl.java
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
trunk/amdatu-opensocial/shindig/src/main/resources/conf/canonicaldb.json
Modified:
trunk/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/service/OAuthTokenProviderImpl.java
==============================================================================
---
trunk/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/service/OAuthTokenProviderImpl.java
(original)
+++
trunk/amdatu-authentication/oauth-server/src/main/java/org/amdatu/authentication/oauth/server/service/OAuthTokenProviderImpl.java
Tue Dec 7 11:39:18 2010
@@ -63,7 +63,7 @@
// try to load from local cache if not throw exception
String consumer_key = requestMessage.getConsumerKey();
if (consumer_key == null || "".equals(consumer_key)) {
- throw new OAuthProblemException("token_rejected");
+ throw new OAuthProblemException("No consumer key provided");
}
OAuthServiceConsumer serviceConsumer =
m_consumerRegistry.getConsumer(consumer_key);
if (serviceConsumer == null) {
Modified: trunk/amdatu-example/course-gadget/pom.xml
==============================================================================
--- trunk/amdatu-example/course-gadget/pom.xml (original)
+++ trunk/amdatu-example/course-gadget/pom.xml Tue Dec 7 11:39:18 2010
@@ -18,13 +18,20 @@
<artifactId>gadgetmanagement</artifactId>
<scope>provided</scope>
<type>bundle</type>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.amdatu.opensocial</groupId>
<artifactId>shindig</artifactId>
<scope>provided</scope>
<type>bundle</type>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>org.amdatu.authentication.oauth</groupId>
+ <artifactId>api</artifactId>
+ <version>${platform.version}</version>
+ <scope>provided</scope>
+ <type>bundle</type>
+ </dependency>
</dependencies>
<build>
Modified:
trunk/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/osgi/Activator.java
==============================================================================
---
trunk/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/osgi/Activator.java
(original)
+++
trunk/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/osgi/Activator.java
Tue Dec 7 11:39:18 2010
@@ -16,6 +16,7 @@
*/
package org.amdatu.example.course.gadget.osgi;
+import org.amdatu.authentication.oauth.api.OAuthServiceConsumerRegistry;
import org.amdatu.example.course.gadget.service.CourseGadgetServiceImpl;
import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
import org.amdatu.web.httpcontext.HttpContextServiceFactory;
@@ -44,6 +45,7 @@
.setImplementation(CourseGadgetServiceImpl.class)
.add(createServiceDependency().setService(LogService.class).setRequired(true))
.add(createServiceDependency().setService(GadgetManagement.class).setRequired(true))
+
.add(createServiceDependency().setService(OAuthServiceConsumerRegistry.class).setRequired(true))
.add(createServiceDependency().setService(HttpContextServiceFactory.class).setRequired(true))
.add(createConfigurationDependency().setPid(CourseGadgetServiceImpl.PID));
manager.add(friendsgadgetService);
Modified:
trunk/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/service/CourseGadgetServiceImpl.java
==============================================================================
---
trunk/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/service/CourseGadgetServiceImpl.java
(original)
+++
trunk/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/service/CourseGadgetServiceImpl.java
Tue Dec 7 11:39:18 2010
@@ -18,13 +18,19 @@
import java.net.URL;
import java.util.Dictionary;
+import java.util.Map;
-import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
+import org.amdatu.authentication.oauth.api.ConsumerAlreadyExistsException;
+import org.amdatu.authentication.oauth.api.ConsumerNotFoundException;
+import org.amdatu.authentication.oauth.api.ConsumerRegistryStorageException;
+import org.amdatu.authentication.oauth.api.OAuthServiceConsumer;
+import org.amdatu.authentication.oauth.api.OAuthServiceConsumerRegistry;
import org.amdatu.example.course.gadget.osgi.Activator;
-import org.amdatu.web.httpcontext.HttpContextServiceFactory;
-import org.amdatu.web.httpcontext.ResourceProvider;
+import org.amdatu.opensocial.gadgetmanagement.GadgetManagement;
import org.amdatu.opensocial.shindig.GadgetCategory;
import org.amdatu.opensocial.shindig.GadgetDefinition;
+import org.amdatu.web.httpcontext.HttpContextServiceFactory;
+import org.amdatu.web.httpcontext.ResourceProvider;
import org.apache.felix.dm.Component;
import org.osgi.framework.BundleContext;
import org.osgi.service.cm.ConfigurationException;
@@ -41,11 +47,18 @@
public final static String PID = "org.amdatu.example.coursegadget";
private final static String HOSTNAME = "hostname";
private final static String PORTNR = "portnr";
+
+ // oAuth properties of this gadget as service consumer
+ private final static String CONSUMER_CALLBACK_URL =
"/gadgets/oauthcallback";
+ private final static String CONSUMER_KEY = "CcourseExampleGadget";
+ private final static String CONSUMER_SECRET = "HEOAnKNjonBLlbBFjgF";
+ private final static String CONSUMER_NAME = "Course example gadget";
// Service and other dependencies, injected by the OSGi framework
private volatile LogService m_logService;
private volatile HttpContextServiceFactory m_httpContextFactoryService;
private volatile GadgetManagement m_gadgetManagement;
+ private volatile OAuthServiceConsumerRegistry m_consumerRegistry;
// Instance variables, injected by the OSGi framework
private BundleContext m_bundleContext;
@@ -70,8 +83,19 @@
GadgetDefinition gadgetDef =
new GadgetDefinition("http://" + m_hostname + ":" + m_portnr +
"/" + Activator.RESOURCE_ID
+ "/jsp/CourseGadget.jsp", GadgetCategory.AMDATU_EXAMPLES,
false);
- gadgetDef.setServiceName("course");
+
+ // Set oAuth parameters
+ gadgetDef.setServiceName(CONSUMER_NAME);
+ gadgetDef.setConsumerPublicKey(CONSUMER_KEY);
+ gadgetDef.setConsumerPrivateKey(CONSUMER_SECRET);
+ gadgetDef.setCallbackUrl(CONSUMER_CALLBACK_URL);
+
m_gadgetManagement.addGadget(gadgetDef);
+
+ // Register the service consumer in our own oAuth server such that
our own oAuth server
+ // can also handle oAuth of this gadget
+ registerConsumer();
+
m_logService.log(LogService.LOG_INFO, getClass().getName() + "
service initialized");
}
}
@@ -83,6 +107,25 @@
m_httpContextComponent.stop();
m_logService.log(LogService.LOG_INFO, getClass().getName() + " service
destroyed");
}
+
+ private void registerConsumer() {
+ try {
+ if (m_consumerRegistry.getConsumer(CONSUMER_KEY) == null) {
+ m_consumerRegistry.addConsumer(new
InternalOAuthServiceConsumer());
+ } else {
+ m_consumerRegistry.updateConsumer(new
InternalOAuthServiceConsumer());
+ }
+ }
+ catch (ConsumerAlreadyExistsException e) {
+ m_logService.log(LogService.LOG_DEBUG, "Could not properly add
service consumer '" + CONSUMER_KEY + "' in the service consumer registry");
+ }
+ catch (ConsumerRegistryStorageException e) {
+ m_logService.log(LogService.LOG_DEBUG, "Could not properly add or
update service consumer '" + CONSUMER_KEY + "' in the service consumer
registry");
+ }
+ catch (ConsumerNotFoundException e) {
+ m_logService.log(LogService.LOG_DEBUG, "Could not properly update
service consumer '" + CONSUMER_KEY + "' in the service consumer registry");
+ }
+ }
public URL getResource(String name) {
return null;
@@ -107,4 +150,12 @@
}
}
}
+
+ class InternalOAuthServiceConsumer implements OAuthServiceConsumer {
+ public String getCallbackUrl() {return CONSUMER_CALLBACK_URL;}
+ public String getConsumerKey() {return CONSUMER_KEY;}
+ public String getConsumerSecret() {return CONSUMER_SECRET;}
+ public String getName() {return CONSUMER_NAME;}
+ public Map<String, String> getProperties() {return null;}
+ }
}
Modified:
trunk/amdatu-example/course-gadget/src/main/resources/jsp/CourseGadget.jsp
==============================================================================
--- trunk/amdatu-example/course-gadget/src/main/resources/jsp/CourseGadget.jsp
(original)
+++ trunk/amdatu-example/course-gadget/src/main/resources/jsp/CourseGadget.jsp
Tue Dec 7 11:39:18 2010
@@ -26,21 +26,21 @@
<Module>
<ModulePrefs
- title="Course Gadget"
- description="Displays a list of available courses for the current user"
- author="Ivo Ladage-van Doorn"
- screenshot="${gadgetBaseUrl}/static/images/course.gif"
- icon="${gadgetBaseUrl}/static/images/course.gif">
-
+ title="Course Gadget"
+ description="Displays a list of available courses for the current user"
+ author="Ivo Ladage-van Doorn"
+ screenshot="${gadgetBaseUrl}/static/images/course.gif"
+ icon="${gadgetBaseUrl}/static/images/course.gif">
+
<Require feature="opensocial-0.9"/>
<Require feature="osapi"/>
<Require feature="oauthpopup" />
<Require feature="dynamic-height"/>
<OAuth>
- <Service name="course">
- <Request url="${baseUrl}/oauth/requestToken" />
- <Access url="${baseUrl}/oauth/accessToken" />
- <Authorization
url="${baseUrl}/oauth/authorize?oauth_callback=/gadgets/oauthcallback" />
+ <Service name="Course example gadget">
+ <Request url="${baseUrl}/oauth-server/requesttoken" />
+ <Access url="${baseUrl}/oauth-server/accesstoken" />
+ <Authorization url="${baseUrl}/oauth-server/authorizetoken" />
</Service>
</OAuth>
</ModulePrefs>
@@ -58,7 +58,7 @@
params[gadgets.io.RequestParameters.CONTENT_TYPE] =
gadgets.io.ContentType.JSON;
params[gadgets.io.RequestParameters.METHOD] =
gadgets.io.MethodType.GET;
params[gadgets.io.RequestParameters.AUTHORIZATION] =
gadgets.io.AuthorizationType.OAUTH;
- params[gadgets.io.RequestParameters.OAUTH_SERVICE_NAME] = "course";
+ params[gadgets.io.RequestParameters.OAUTH_SERVICE_NAME] = "Course
example gadget";
params[gadgets.io.RequestParameters.OAUTH_USE_TOKEN] = "if_available";
var url = "${baseUrl}/rest/services/course/course?getCourses";
gadgets.io.makeRequest(url, onLoadCourses, params);
@@ -90,25 +90,25 @@
function onLoadCourses(response) {
var jsonData = response.data;
if (jsonData) {
- var courseList = jsonData["courselist"];
- var user = courseList["user"];
- if (courseList && courseList["course"]
&& courseList["course"].length > 0) {
- var courses =
courseList["course"];
- var html = "<p>Overview of
available courses for " + user + ":</p><ul>";
- for (i=0; i<courses.length;i++)
{
- var course = courses[i];
- var courseName =
course["name"];
- var grade =
course["grade"];
- var education =
course["education"];
- html += "<li>" +
courseName + " ( " + education + " - " + grade + ")</li>";
- }
- html += "</ul>";
- } else {
- var html = "<p>No courses
available courses for " + user + "</p>";
- }
- } else {
- var html = "An error has occurred,
check the log files";
- }
+ var courseList = jsonData["courselist"];
+ var user = courseList["user"];
+ if (courseList && courseList["course"] &&
courseList["course"].length > 0) {
+ var courses = courseList["course"];
+ var html = "<p>Overview of available courses for " + user +
":</p><ul>";
+ for (i=0; i<courses.length;i++) {
+ var course = courses[i];
+ var courseName = course["name"];
+ var grade = course["grade"];
+ var education = course["education"];
+ html += "<li>" + courseName + " ( " + education + " - " + grade
+ ")</li>";
+ }
+ html += "</ul>";
+ } else {
+ var html = "<p>No courses available courses for " + user + "</p>";
+ }
+ } else {
+ var html = "An error has occurred, check the log files";
+ }
document.getElementById('courses').innerHTML = html;
gadgets.window.adjustHeight();
Modified:
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/module/SocialApiModuleImpl.java
==============================================================================
---
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/module/SocialApiModuleImpl.java
(original)
+++
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/module/SocialApiModuleImpl.java
Tue Dec 7 11:39:18 2010
@@ -83,8 +83,8 @@
// Register authentication handler providers
bind(new
TypeLiteral<List<AuthenticationHandler>>(){}).toProvider(AuthenticationHandlerProvider.class);
- // TODO: these are example bindings for now
- // See http://jira.amdatu.org/jira/browse/AMDATU-5.
+ // TODO: these are example bindings for now, needed until alternative
services are available for
+ // the ActivityService and MessageService
bind(String.class).annotatedWith(Names.named("shindig.canonical.json.db")).toInstance("/conf/canonicaldb.json");
bind(ActivityService.class).to(JsonDbOpensocialService.class);
bind(AppDataService.class).toInstance(m_appDataServiceStore);
@@ -99,7 +99,7 @@
// Use the sample oAuth datastore
bind(OAuthDataStore.class).to(org.apache.shindig.social.sample.oauth.SampleOAuthDataStore.class);
-
+
bind(new
TypeLiteral<Set<Object>>(){}).annotatedWith(Names.named("org.apache.shindig.social.handlers"))
.toInstance(getHandlers());
}
Modified:
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
==============================================================================
---
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
(original)
+++
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
Tue Dec 7 11:39:18 2010
@@ -32,7 +32,6 @@
import javax.servlet.Servlet;
import org.amdatu.opensocial.shindig.ShindigService;
-import org.amdatu.opensocial.shindig.oauth.AmdatuOAuthServlet;
import org.amdatu.opensocial.shindig.osgi.Activator;
import org.amdatu.web.httpcontext.HttpContextServiceFactory;
import org.amdatu.web.httpcontext.ResourceProvider;
@@ -73,7 +72,6 @@
private static final String JS_BASE = GADGETS_BASE + "/js";
private static final String METADATA_BASE = GADGETS_BASE + "/metadata";
private static final String OAUTH_CALLBACK_BASE = GADGETS_BASE +
"/oauthcallback";
- private static final String OAUTH_BASE = "/oauth";
private static final String ECHO_BASE = GADGETS_BASE + "/api/echo";
// These variables are injected by the Felix dependency manager
@@ -227,7 +225,6 @@
registerServlet(REST_BASE, new DataServiceServlet(),
servletProperties);
registerServlet(GADGETS_REST_BASE, new DataServiceServlet(),
servletProperties);
registerServlet(GADGETS_RPC_BASE, new JsonRpcServlet(),
servletProperties);
- registerServlet(OAUTH_BASE, new AmdatuOAuthServlet(),
servletProperties);
registerServlet(ECHO_BASE, new EchoServlet(), servletProperties);
// Since /gadgets is already registered automatically by the http
context factory service,
Modified:
trunk/amdatu-opensocial/shindig/src/main/resources/conf/canonicaldb.json
==============================================================================
--- trunk/amdatu-opensocial/shindig/src/main/resources/conf/canonicaldb.json
(original)
+++ trunk/amdatu-opensocial/shindig/src/main/resources/conf/canonicaldb.json
Tue Dec 7 11:39:18 2010
@@ -445,15 +445,7 @@
"http://${server.hostname}:${server.port}/gadgets/files/samplecontainer/examples/shindigoauth.xml"
:
{ "title" : "Demo OAuth Gadget",
"consumerSecret" : "secret",
- "icon" :
"http://${server.hostname}:${server.port}/gadgets/files/samplecontainer/examples/icon.png"},
- "FriendsConsumerKey" :
- { "title" : "Friends Gadget",
- "consumerSecret" : "FriendsConsumerSecret",
- "icon" :
"http://${server.hostname}:${server.port}/gadgets/samplecontainer/examples/icon.png"},
- "CourseConsumerKey" :
- { "title" : "Course Gadget",
- "consumerSecret" : "CourseConsumerSecret",
- "icon" :
"http://${server.hostname}:${server.port}/gadgets/samplecontainer/examples/icon.png"}
+ "icon" :
"http://${server.hostname}:${server.port}/gadgets/files/samplecontainer/examples/icon.png"},
},
// duplicates userApplications as above..