Author: [email protected]
Date: Tue Sep 13 16:57:47 2011
New Revision: 1358
Log:
[AMDATUOPENSOCIAL-42] Fixed simple multi-tenancy solution by introducing the
expression %tenant_host%, which is replaced with the hostname resolved from the
current tenant at runtime
Added:
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/MultiTenantContainerConfig.java
Modified:
trunk/amdatu-opensocial/config/src/main/resources/org.amdatu.opensocial.shindig.cfg
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/module/SocialApiModuleImpl.java
trunk/amdatu-opensocial/opensocial-shindig/src/main/resources/conf/container.js
Modified:
trunk/amdatu-opensocial/config/src/main/resources/org.amdatu.opensocial.shindig.cfg
==============================================================================
---
trunk/amdatu-opensocial/config/src/main/resources/org.amdatu.opensocial.shindig.cfg
(original)
+++
trunk/amdatu-opensocial/config/src/main/resources/org.amdatu.opensocial.shindig.cfg
Tue Sep 13 16:57:47 2011
@@ -149,7 +149,10 @@
# the one that threw the exception.
shindig.accelerate.remapInternalServerError=true
-shindig.host=${server.hostname}
+# shindig.host is not used anymore, but remains here since Guice requires this
config
+# entry to invoke the container coniguration
+shindig.host=null
+
shindig.port=${server.port}
shindig.proxy.remapInternalServerError=false
Modified:
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/module/SocialApiModuleImpl.java
==============================================================================
---
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/module/SocialApiModuleImpl.java
(original)
+++
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/module/SocialApiModuleImpl.java
Tue Sep 13 16:57:47 2011
@@ -15,39 +15,41 @@
*/
package org.amdatu.opensocial.shindig.module;
-import java.util.List;
-import java.util.Set;
-
-import org.amdatu.opensocial.shindig.SocialApiModule;
-import org.amdatu.opensocial.shindig.service.PersonServiceDispatcher;
-import org.apache.shindig.auth.AnonymousAuthenticationHandler;
-import org.apache.shindig.auth.AuthenticationHandler;
-import org.apache.shindig.common.servlet.ParameterFetcher;
-import org.apache.shindig.protocol.DataServiceServletFetcher;
-import org.apache.shindig.protocol.conversion.BeanConverter;
-import org.apache.shindig.protocol.conversion.BeanJsonConverter;
-import org.apache.shindig.protocol.conversion.BeanXStreamConverter;
-import org.apache.shindig.protocol.conversion.xstream.XStreamConfiguration;
-import org.apache.shindig.social.core.oauth.AuthenticationHandlerProvider;
-import org.apache.shindig.social.core.util.BeanXStreamAtomConverter;
-import org.apache.shindig.social.core.util.xstream.XStream081Configuration;
-import org.apache.shindig.social.opensocial.oauth.OAuthDataStore;
-import org.apache.shindig.social.opensocial.service.ActivityHandler;
-import org.apache.shindig.social.opensocial.service.AppDataHandler;
-import org.apache.shindig.social.opensocial.service.MessageHandler;
-import org.apache.shindig.social.opensocial.service.PersonHandler;
-import org.apache.shindig.social.opensocial.spi.ActivityService;
-import org.apache.shindig.social.opensocial.spi.AppDataService;
-import org.apache.shindig.social.opensocial.spi.MessageService;
-import org.apache.shindig.social.opensocial.spi.PersonService;
-import org.apache.shindig.social.sample.spi.JsonDbOpensocialService;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.log.LogService;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.TypeLiteral;
-import com.google.inject.internal.ImmutableSet;
-import com.google.inject.name.Names;
+import java.util.List;
+import java.util.Set;
+
+import org.amdatu.opensocial.shindig.SocialApiModule;
+import org.amdatu.opensocial.shindig.service.MultiTenantContainerConfig;
+import org.amdatu.opensocial.shindig.service.PersonServiceDispatcher;
+import org.apache.shindig.auth.AnonymousAuthenticationHandler;
+import org.apache.shindig.auth.AuthenticationHandler;
+import org.apache.shindig.common.servlet.ParameterFetcher;
+import org.apache.shindig.config.ContainerConfig;
+import org.apache.shindig.protocol.DataServiceServletFetcher;
+import org.apache.shindig.protocol.conversion.BeanConverter;
+import org.apache.shindig.protocol.conversion.BeanJsonConverter;
+import org.apache.shindig.protocol.conversion.BeanXStreamConverter;
+import org.apache.shindig.protocol.conversion.xstream.XStreamConfiguration;
+import org.apache.shindig.social.core.oauth.AuthenticationHandlerProvider;
+import org.apache.shindig.social.core.util.BeanXStreamAtomConverter;
+import org.apache.shindig.social.core.util.xstream.XStream081Configuration;
+import org.apache.shindig.social.opensocial.oauth.OAuthDataStore;
+import org.apache.shindig.social.opensocial.service.ActivityHandler;
+import org.apache.shindig.social.opensocial.service.AppDataHandler;
+import org.apache.shindig.social.opensocial.service.MessageHandler;
+import org.apache.shindig.social.opensocial.service.PersonHandler;
+import org.apache.shindig.social.opensocial.spi.ActivityService;
+import org.apache.shindig.social.opensocial.spi.AppDataService;
+import org.apache.shindig.social.opensocial.spi.MessageService;
+import org.apache.shindig.social.opensocial.spi.PersonService;
+import org.apache.shindig.social.sample.spi.JsonDbOpensocialService;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.TypeLiteral;
+import com.google.inject.internal.ImmutableSet;
+import com.google.inject.name.Names;
/**
* This module binds the Social API services.
@@ -102,7 +104,9 @@
bind(PersonService.class).toInstance(personService);
// Use the sample oAuth data store
-
bind(OAuthDataStore.class).to(org.apache.shindig.social.sample.oauth.SampleOAuthDataStore.class);
+
bind(OAuthDataStore.class).to(org.apache.shindig.social.sample.oauth.SampleOAuthDataStore.class);
+
+ bind(ContainerConfig.class).to(MultiTenantContainerConfig.class);
bind(new TypeLiteral<Set<Object>>() {
}).annotatedWith(Names.named("org.apache.shindig.social.handlers"))
Added:
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/MultiTenantContainerConfig.java
==============================================================================
--- (empty file)
+++
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/MultiTenantContainerConfig.java
Tue Sep 13 16:57:47 2011
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.amdatu.opensocial.shindig.service;
+
+import org.amdatu.core.tenant.Tenant;
+import org.apache.shindig.common.Nullable;
+import org.apache.shindig.config.ContainerConfigException;
+import org.apache.shindig.config.JsonContainerConfig;
+import org.apache.shindig.expressions.Expressions;
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+
+/**
+ * This class implements a tenant aware Shindig container configuration. See
issue AMDATUOPENSOCIAL-42
+ * In the ideal situation, a Shindig container would be spawned per tenant
(such that themes, features,
+ * security tokens, etc. etc. are configurable per tenant). This class however
provides a simple fix to
+ * support multi-tenancy. It simply replaces %tenant_host% occurrences in the
container.js configuration
+ * of the single container with the hostname revolved from the current tenant.
+ *
+ * @author ivol
+ */
+public class MultiTenantContainerConfig extends JsonContainerConfig {
+ private String m_host;
+
+ /**
+ * Creates a new configuration from files.
+ * @throws ContainerConfigException
+ */
+ @Inject
+ public MultiTenantContainerConfig(@Named("shindig.containers.default")
String containers,
+ @Nullable @Named("shindig.host") String host, @Nullable
@Named("shindig.port") String port,
+ Expressions expressions) throws ContainerConfigException {
+ super(containers, host, port, expressions);
+ m_host = host;
+ }
+
+ public Object getProperty(String container, String property) {
+ Object value = super.getProperty(container, property);
+
+ if (value instanceof String && ((String)
value).indexOf("%tenant_host%") != -1) {
+ Tenant tenant = TenantHostnameDispatchExtenderFilter.getTenant();
+ String replacement;
+ if (tenant != null) {
+ replacement =
tenant.getProperties().get(Tenant.HOSTNAME_PROPERTY);
+ } else {
+ replacement = m_host;
+ }
+ value = ((String) value).replace("%tenant_host%", replacement);
+ }
+ return value;
+ }
+}
Modified:
trunk/amdatu-opensocial/opensocial-shindig/src/main/resources/conf/container.js
==============================================================================
---
trunk/amdatu-opensocial/opensocial-shindig/src/main/resources/conf/container.js
(original)
+++
trunk/amdatu-opensocial/opensocial-shindig/src/main/resources/conf/container.js
Tue Sep 13 16:57:47 2011
@@ -103,10 +103,10 @@
"gadgets.securityTokenKeyFile" : "conf/securitytokenkey.txt",
// URI for the default shindig test instance.
-"defaultShindigTestHost": "http://${SERVER_HOST}:${SERVER_PORT}",
+"defaultShindigTestHost": "http://%tenant_host%:${SERVER_PORT}",
// Authority (host:port without scheme) for the proxy and concat servlets.
-"defaultShindigProxyConcatAuthority": "${SERVER_HOST}:${SERVER_PORT}",
+"defaultShindigProxyConcatAuthority": "%tenant_host%:${SERVER_PORT}",
// Default Uri config: these must be overridden - specified here for testing
purposes
"gadgets.uri.iframe.unlockedDomain": "${Cur['defaultShindigTestHost']}",
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits