Arun, This was not a request to you, but to the committers of the project.
Best regards, Pierre Smits *ORRTIZ.COM <http://www.orrtiz.com>* Services & Solutions for Cloud- Based Manufacturing, Professional Services and Retail & Trade http://www.orrtiz.com On Fri, Jan 30, 2015 at 8:35 AM, Arun Patidar <arun.pati...@hotwaxmedia.com> wrote: > Hi Pierre, > > We have provided backward compatibility with this feature so it does not > seem to break functionality. I am looking into the few issues reported over > user mailing list. I will fix or reply to issues if they are related to > this commit. > > Thanks & Regards > --- > Arun Patidar > Manager,Enterprise Software Development > HotWax Media > www.hotwaxsystems.com > > On Friday 30 January 2015 12:19 PM, Pierre Smits wrote: > > Please revert this commit. It breaks back-end multi-tenancy. >> >> Regards, >> >> Pierre Smits >> >> *ORRTIZ.COM <http://www.orrtiz.com>* >> >> Services & Solutions for Cloud- >> Based Manufacturing, Professional >> Services and Retail & Trade >> http://www.orrtiz.com >> >> On Sat, Dec 6, 2014 at 10:22 AM, <ash...@apache.org> wrote: >> >> Author: ashish >>> Date: Sat Dec 6 09:22:23 2014 >>> New Revision: 1643510 >>> >>> URL: http://svn.apache.org/r1643510 >>> Log: >>> Applied patch from jira issue - OFBIZ-5898 - Tenant should run with >>> specified domain name. Front store should support multi tenant feature. >>> Thanks so much Arun for the contribution. >>> >>> Modified: >>> ofbiz/trunk/build.xml >>> ofbiz/trunk/framework/common/src/org/ofbiz/common/ >>> UrlServletHelper.java >>> ofbiz/trunk/framework/entity/entitydef/entitygroup.xml >>> ofbiz/trunk/framework/entity/entitydef/entitymodel.xml >>> ofbiz/trunk/framework/resources/templates/ >>> AdminNewTenantData-Derby.xml >>> ofbiz/trunk/framework/resources/templates/ >>> AdminNewTenantData-MySQL.xml >>> ofbiz/trunk/framework/resources/templates/ >>> AdminNewTenantData-Oracle.xml >>> >>> ofbiz/trunk/framework/resources/templates/AdminNewTenantData-PostgreSQL. >>> xml >>> >>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ >>> ContextFilter.java >>> >>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ >>> LoginWorker.java >>> >>> Modified: ofbiz/trunk/build.xml >>> URL: >>> http://svn.apache.org/viewvc/ofbiz/trunk/build.xml?rev= >>> 1643510&r1=1643509&r2=1643510&view=diff >>> >>> ============================================================ >>> ================== >>> --- ofbiz/trunk/build.xml (original) >>> +++ ofbiz/trunk/build.xml Sat Dec 6 09:22:23 2014 >>> @@ -924,6 +924,7 @@ under the License. >>> <target name="get-tenant-data"> >>> <input addproperty="tenantId" message="Enter Id for the tenant: >>> "/> >>> <input addproperty="tenantName" message="Enter name for tenant: >>> "/> >>> + <input addproperty="domainName" message="Enter domain name for >>> tenant (Optional): "/> >>> <input addproperty="data-readers" message="Enter data to >>> install. >>> Choices are e.g. seed,seed-initial,ext,demo. >>> Multipe datasets must be separated with a comma: "/> >>> @@ -955,6 +956,7 @@ under the License. >>> <filterset> >>> <filter token="tenantId" value="${tenantId}"/> >>> <filter token="tenantName" value="${tenantName}"/> >>> + <filter token="domainName" value="${domainName}"/> >>> </filterset> >>> </copy> >>> <antcall target="load-file"> >>> @@ -975,6 +977,7 @@ under the License. >>> <filterset> >>> <filter token="tenantId" value="${tenantId}"/> >>> <filter token="tenantName" value="${tenantName}"/> >>> + <filter token="domainName" value="${domainName}"/> >>> <filter token="db-IP" value="${db-IP}"/> >>> <filter token="db-User" value="${db-User}"/> >>> <filter token="db-Password" value="${db-Password}"/> >>> @@ -998,6 +1001,7 @@ under the License. >>> <filterset> >>> <filter token="tenantId" value="${tenantId}"/> >>> <filter token="tenantName" value="${tenantName}"/> >>> + <filter token="domainName" value="${domainName}"/> >>> <filter token="db-IP" value="${db-IP}"/> >>> <filter token="db-User" value="${db-User}"/> >>> <filter token="db-Password" value="${db-Password}"/> >>> @@ -1021,6 +1025,7 @@ under the License. >>> <filterset> >>> <filter token="tenantId" value="${tenantId}"/> >>> <filter token="tenantName" value="${tenantName}"/> >>> + <filter token="domainName" value="${domainName}"/> >>> <filter token="db-IP" value="${db-IP}"/> >>> <filter token="db-User" value="${db-User}"/> >>> <filter token="db-Password" value="${db-Password}"/> >>> @@ -1041,6 +1046,7 @@ under the License. >>> <echo>------------------------------------</echo> >>> <echo message="tenantId = ${tenantId}"/> >>> <echo>tenantName = ${tenantName}</echo> >>> + <echo>domainName = ${domainName}</echo> >>> <echo>db-Platform = ${db-Platform}</echo> >>> <echo>db-IP = ${db-IP}</echo> >>> <echo>db-User = ${db-User}</echo> >>> >>> Modified: >>> ofbiz/trunk/framework/common/src/org/ofbiz/common/UrlServletHelper.java >>> URL: >>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/ >>> src/org/ofbiz/common/UrlServletHelper.java?rev= >>> 1643510&r1=1643509&r2=1643510&view=diff >>> >>> ============================================================ >>> ================== >>> --- >>> ofbiz/trunk/framework/common/src/org/ofbiz/common/UrlServletHelper.java >>> (original) >>> +++ >>> ofbiz/trunk/framework/common/src/org/ofbiz/common/UrlServletHelper.java >>> Sat >>> Dec 6 09:22:23 2014 >>> @@ -57,15 +57,17 @@ public class UrlServletHelper extends Co >>> try { >>> // if tenant was specified, replace delegator with the >>> new per-tenant delegator and set tenantId to session attribute >>> delegator = getDelegator(servletContext); >>> - List<GenericValue> tenants = >>> delegator.findList("Tenant", >>> EntityCondition.makeCondition("domainName", serverName), null, >>> UtilMisc.toList("-createdStamp"), null, false); >>> - if (UtilValidate.isNotEmpty(tenants)) { >>> - GenericValue tenant = EntityUtil.getFirst(tenants); >>> - String tenantId = tenant.getString("tenantId"); >>> - >>> + >>> + //Use base delegator for fetching data from entity of >>> entityGroup org.ofbiz.tenant >>> + Delegator baseDelegator = >>> DelegatorFactory.getDelegator(delegator.getDelegatorBaseName()); >>> + GenericValue tenantDomainName = >>> baseDelegator.findOne("TenantDomainName", UtilMisc.toMap("domainName", >>> serverName), false); >>> + >>> + if (UtilValidate.isNotEmpty(tenantDomainName)) { >>> + String tenantId = >>> tenantDomainName.getString("tenantId"); >>> // make that tenant active, setup a new delegator >>> and >>> a new dispatcher >>> String tenantDelegatorName = >>> delegator.getDelegatorBaseName() + "#" + tenantId; >>> >>> httpRequest.getSession().setAttribute("delegatorName", >>> tenantDelegatorName); >>> - >>> + >>> // after this line the delegator is replaced with >>> the >>> new per-tenant delegator >>> delegator = >>> DelegatorFactory.getDelegator(tenantDelegatorName); >>> servletContext.setAttribute("delegator", >>> delegator); >>> >>> Modified: ofbiz/trunk/framework/entity/entitydef/entitygroup.xml >>> URL: >>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/ >>> entitydef/entitygroup.xml?rev=1643510&r1=1643509&r2=1643510&view=diff >>> >>> ============================================================ >>> ================== >>> --- ofbiz/trunk/framework/entity/entitydef/entitygroup.xml (original) >>> +++ ofbiz/trunk/framework/entity/entitydef/entitygroup.xml Sat Dec 6 >>> 09:22:23 2014 >>> @@ -29,4 +29,5 @@ under the License. >>> <!-- <entity-group group="org.ofbiz.tenant" >>> entity="TenantUserLogin"/> --> >>> <entity-group group="org.ofbiz.tenant" entity="Component"/> >>> <entity-group group="org.ofbiz.tenant" entity="TenantComponent"/> >>> + <entity-group group="org.ofbiz.tenant" entity="TenantDomainName"/> >>> </entitygroup> >>> >>> Modified: ofbiz/trunk/framework/entity/entitydef/entitymodel.xml >>> URL: >>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/ >>> entitydef/entitymodel.xml?rev=1643510&r1=1643509&r2=1643510&view=diff >>> >>> ============================================================ >>> ================== >>> --- ofbiz/trunk/framework/entity/entitydef/entitymodel.xml (original) >>> +++ ofbiz/trunk/framework/entity/entitydef/entitymodel.xml Sat Dec 6 >>> 09:22:23 2014 >>> @@ -66,7 +66,6 @@ under the License. >>> <entity entity-name="Tenant" package-name="org.ofbiz. >>> entity.tenant"> >>> <field name="tenantId" type="id-ne"/> >>> <field name="tenantName" type="name"/> >>> - <field name="domainName" type="long-varchar"/> >>> <field name="initialPath" type="value"/> >>> <field name="disabled" type="indicator"><description>Disabled >>> if >>> 'Y', defaults to 'N' (not disabled).</description></field> >>> <prim-key field="tenantId"/> >>> @@ -153,4 +152,13 @@ under the License. >>> <key-map field-name="componentName"/> >>> </relation> >>> </entity> >>> + <entity entity-name="TenantDomainName" >>> package-name="org.ofbiz.entity.tenant" >>> + title="Tenant and its Domain Name"> >>> + <field name="tenantId" type="id-ne"></field> >>> + <field name="domainName" type="long-varchar"></field> >>> + <prim-key field="domainName"/> >>> + <relation type="one" fk-name="TNNT_DMNAM" >>> rel-entity-name="Tenant"> >>> + <key-map field-name="tenantId"/> >>> + </relation> >>> + </entity> >>> </entitymodel> >>> >>> Modified: >>> ofbiz/trunk/framework/resources/templates/AdminNewTenantData-Derby.xml >>> URL: >>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/resources/templates/ >>> AdminNewTenantData-Derby.xml?rev=1643510&r1=1643509&r2=1643510&view=diff >>> >>> ============================================================ >>> ================== >>> --- ofbiz/trunk/framework/resources/templates/ >>> AdminNewTenantData-Derby.xml >>> (original) >>> +++ ofbiz/trunk/framework/resources/templates/ >>> AdminNewTenantData-Derby.xml >>> Sat Dec 6 09:22:23 2014 >>> @@ -1,6 +1,7 @@ >>> <?xml version="1.0" encoding="UTF-8"?> >>> <entity-engine-xml> >>> <Tenant tenantId="@tenantId@" tenantName="@tenantName@" /> >>> + <TenantDomainName tenantId="@tenantId@" domainName="@domainName@" >>> /> >>> <TenantDataSource tenantId="@tenantId@" >>> entityGroupName="org.ofbiz" >>> jdbcUri="jdbc:derby:ofbiz_@tenantId@;create=true" >>> jdbcUsername="ofbiz" jdbcPassword="ofbiz"/> >>> <TenantDataSource tenantId="@tenantId@" >>> entityGroupName="org.ofbiz.olap" >>> >>> Modified: >>> ofbiz/trunk/framework/resources/templates/AdminNewTenantData-MySQL.xml >>> URL: >>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/resources/templates/ >>> AdminNewTenantData-MySQL.xml?rev=1643510&r1=1643509&r2=1643510&view=diff >>> >>> ============================================================ >>> ================== >>> --- ofbiz/trunk/framework/resources/templates/ >>> AdminNewTenantData-MySQL.xml >>> (original) >>> +++ ofbiz/trunk/framework/resources/templates/ >>> AdminNewTenantData-MySQL.xml >>> Sat Dec 6 09:22:23 2014 >>> @@ -1,6 +1,7 @@ >>> <?xml version="1.0" encoding="UTF-8"?> >>> <entity-engine-xml> >>> <Tenant tenantId="@tenantId@" tenantName="@tenantName@"/> >>> + <TenantDomainName tenantId="@tenantId@" domainName="@domainName@" >>> /> >>> <TenantDataSource tenantId="@tenantId@" >>> entityGroupName="org.ofbiz" >>> jdbcUri="jdbc:mysql://@db-IP@/ofbiz_@tenantId@" >>> jdbcUsername="@db-User@" jdbcPassword="@db-Password@"/> >>> <TenantDataSource tenantId="@tenantId@" >>> entityGroupName="org.ofbiz.olap" >>> >>> Modified: >>> ofbiz/trunk/framework/resources/templates/AdminNewTenantData-Oracle.xml >>> URL: >>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/resources/templates/ >>> AdminNewTenantData-Oracle.xml?rev=1643510&r1=1643509&r2= >>> 1643510&view=diff >>> >>> ============================================================ >>> ================== >>> --- >>> ofbiz/trunk/framework/resources/templates/AdminNewTenantData-Oracle.xml >>> (original) >>> +++ >>> ofbiz/trunk/framework/resources/templates/AdminNewTenantData-Oracle.xml >>> Sat >>> Dec 6 09:22:23 2014 >>> @@ -1,6 +1,7 @@ >>> <?xml version="1.0" encoding="UTF-8"?> >>> <entity-engine-xml> >>> <Tenant tenantId="@tenantId@" tenantName="@tenantName@"/> >>> + <TenantDomainName tenantId="@tenantId@" domainName="@domainName@" >>> /> >>> <TenantDataSource tenantId="@tenantId@" >>> entityGroupName="org.ofbiz" >>> jdbcUri="jdbc:oracle:thin:@@db-IP@:ofbiz_@tenantId@" >>> jdbcUsername="@db-User@" jdbcPassword="@db-Password@"/> >>> <TenantDataSource tenantId="@tenantId@" >>> entityGroupName="org.ofbiz.olap" >>> >>> Modified: >>> ofbiz/trunk/framework/resources/templates/AdminNewTenantData-PostgreSQL. >>> xml >>> URL: >>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/resources/templates/ >>> AdminNewTenantData-PostgreSQL.xml?rev=1643510&r1=1643509&r2= >>> 1643510&view=diff >>> >>> ============================================================ >>> ================== >>> --- >>> ofbiz/trunk/framework/resources/templates/AdminNewTenantData-PostgreSQL. >>> xml >>> (original) >>> +++ >>> ofbiz/trunk/framework/resources/templates/AdminNewTenantData-PostgreSQL. >>> xml >>> Sat Dec 6 09:22:23 2014 >>> @@ -1,6 +1,7 @@ >>> <?xml version="1.0" encoding="UTF-8"?> >>> <entity-engine-xml> >>> <Tenant tenantId="@tenantId@" tenantName="@tenantName@"/> >>> + <TenantDomainName tenantId="@tenantId@" domainName="@domainName@" >>> /> >>> <TenantDataSource tenantId="@tenantId@" >>> entityGroupName="org.ofbiz" >>> jdbcUri="jdbc:postgresql://@db-IP@/ofbiz_@tenantId@" >>> jdbcUsername="@db-User@" jdbcPassword="@db-Password@"/> >>> <TenantDataSource tenantId="@tenantId@" >>> entityGroupName="org.ofbiz.olap" >>> >>> Modified: >>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ >>> ContextFilter.java >>> URL: >>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/ >>> src/org/ofbiz/webapp/control/ContextFilter.java?rev= >>> 1643510&r1=1643509&r2=1643510&view=diff >>> >>> ============================================================ >>> ================== >>> --- >>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ >>> ContextFilter.java >>> (original) >>> +++ >>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ >>> ContextFilter.java >>> Sat Dec 6 09:22:23 2014 >>> @@ -255,13 +255,17 @@ public class ContextFilter implements Fi >>> try { >>> // if tenant was specified, replace delegator with the >>> new per-tenant delegator and set tenantId to session attribute >>> Delegator delegator = >>> getDelegator(config.getServletContext()); >>> - List<GenericValue> tenants = >>> delegator.findList("Tenant", >>> EntityCondition.makeCondition("domainName", serverName), null, >>> UtilMisc.toList("-createdStamp"), null, false); >>> - if (UtilValidate.isNotEmpty(tenants)) { >>> - GenericValue tenant = EntityUtil.getFirst(tenants); >>> - String tenantId = tenant.getString("tenantId"); >>> + >>> + //Use base delegator for fetching data from entity of >>> entityGroup org.ofbiz.tenant >>> + Delegator baseDelegator = >>> DelegatorFactory.getDelegator(delegator.getDelegatorBaseName()); >>> + GenericValue tenantDomainName = >>> baseDelegator.findOne("TenantDomainName", UtilMisc.toMap("domainName", >>> serverName), false); >>> + >>> + if (UtilValidate.isNotEmpty(tenantDomainName)) { >>> + String tenantId = >>> tenantDomainName.getString("tenantId"); >>> >>> // if the request path is a root mount then >>> redirect >>> to the initial path >>> if (UtilValidate.isNotEmpty(requestPath) && >>> requestPath.equals(contextUri)) { >>> + GenericValue tenant = >>> baseDelegator.findOne("Tenant", UtilMisc.toMap("tenantId", tenantId), >>> false); >>> String initialPath = >>> tenant.getString("initialPath"); >>> if (UtilValidate.isNotEmpty(initialPath) && >>> !"/".equals(initialPath)) { >>> >>> ((HttpServletResponse)response).sendRedirect(initialPath); >>> @@ -291,6 +295,30 @@ public class ContextFilter implements Fi >>> request.setAttribute("security", security); >>> >>> request.setAttribute("tenantId", tenantId); >>> + } else if (delegator.getDelegatorBaseName() != >>> delegator.getDelegatorName()) { >>> + >>> + // Set default delegator >>> + Debug.logInfo("No tenant found for requested domain >>> name " + serverName, module); >>> + Debug.logInfo("Setting default delegator and >>> dispatcher", module); >>> + String delegatorName = >>> delegator.getDelegatorBaseName(); >>> + >>> httpRequest.getSession().setAttribute("delegatorName", delegatorName); >>> + >>> + // after this line the delegator is replaced with >>> the >>> new per-tenant delegator >>> + delegator = >>> DelegatorFactory.getDelegator(delegatorName); >>> + config.getServletContext(). >>> setAttribute("delegator", >>> delegator); >>> + >>> + // clear web context objects >>> + config.getServletContext().setAttribute("security", >>> null); >>> + config.getServletContext(). >>> setAttribute("dispatcher", >>> null); >>> + >>> + // initialize security >>> + Security security = getSecurity(); >>> + // initialize the services dispatcher >>> + LocalDispatcher dispatcher = >>> getDispatcher(config.getServletContext()); >>> + >>> + // set web context objects >>> + request.setAttribute("dispatcher", dispatcher); >>> + request.setAttribute("security", security); >>> } >>> >>> // NOTE DEJ20101130: do NOT always put the delegator >>> name >>> in the user's session because the user may >>> >>> Modified: >>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ >>> LoginWorker.java >>> URL: >>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/ >>> src/org/ofbiz/webapp/control/LoginWorker.java?rev=1643510& >>> r1=1643509&r2=1643510&view=diff >>> >>> ============================================================ >>> ================== >>> --- >>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ >>> LoginWorker.java >>> (original) >>> +++ >>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ >>> LoginWorker.java >>> Sat Dec 6 09:22:23 2014 >>> @@ -394,9 +394,13 @@ public class LoginWorker { >>> >>> LocalDispatcher dispatcher = (LocalDispatcher) >>> request.getAttribute("dispatcher"); >>> Delegator delegator = (Delegator) >>> request.getAttribute("delegator"); >>> + ServletContext servletContext = session.getServletContext(); >>> >>> // if a tenantId was passed in, see if the userLoginId is >>> associated with that tenantId (can use any delegator for this, entity is >>> not tenant-specific) >>> String tenantId = request.getParameter("tenantId"); >>> + if (UtilValidate.isEmpty(tenantId)) { >>> + tenantId = (String) request.getAttribute("tenantId"); >>> + } >>> if (UtilValidate.isNotEmpty(tenantId)) { >>> // see if we need to activate a tenant delegator, only do >>> if >>> the current delegatorName has a hash symbol in it, and if the passed in >>> tenantId doesn't match the one in the delegatorName >>> String oldDelegatorName = delegator.getDelegatorName(); >>> @@ -438,7 +442,6 @@ public class LoginWorker { >>> } >>> */ >>> >>> - ServletContext servletContext = >>> session.getServletContext(); >>> >>> // make that tenant active, setup a new delegator and a >>> new dispatcher >>> String delegatorName = delegator.getDelegatorBaseName() >>> + >>> "#" + tenantId; >>> @@ -458,6 +461,22 @@ public class LoginWorker { >>> // NOTE: these will be local for now and set in the >>> request and session later, after we've verified that the user >>> setupNewDelegatorEtc = true; >>> } >>> + } else { >>> + // Set default delegator >>> + Debug.logInfo("Setting default delegator", module); >>> + String delegatorName = delegator.getDelegatorBaseName(); >>> + try { >>> + // after this line the delegator is replaced with >>> default >>> delegator >>> + delegator = DelegatorFactory.getDelegator( >>> delegatorName); >>> + dispatcher = >>> ContextFilter.makeWebappDispatcher(servletContext, delegator); >>> + } catch (NullPointerException e) { >>> + Debug.logError(e, "Error getting default delegator", >>> module); >>> + Map<String, String> messageMap = >>> UtilMisc.toMap("errorMessage", "Error getting default delegator"); >>> + String errMsg = UtilProperties.getMessage( >>> resourceWebapp, >>> "loginevents.following_error_occurred_during_login", messageMap, >>> UtilHttp.getLocale(request)); >>> + request.setAttribute("_ERROR_MESSAGE_", errMsg); >>> + return "error"; >>> + } >>> + setupNewDelegatorEtc = true; >>> } >>> >>> Map<String, Object> result = null; >>> @@ -514,7 +533,6 @@ public class LoginWorker { >>> } >>> } >>> } >>> - >>> if (setupNewDelegatorEtc) { >>> // now set the delegator and dispatcher in a bunch of >>> places just in case they were changed >>> setWebContextObjects(request, response, delegator, >>> dispatcher); >>> @@ -696,10 +714,11 @@ public class LoginWorker { >>> >>> if (currCatalog != null) >>> session.setAttribute("CURRENT_CATALOG_ID", currCatalog); >>> if (delegatorName != null) { >>> + //Commented it as multi tenancy support is now available for >>> front-store application as well. >>> // if there is a tenantId in the delegatorName remove it >>> now >>> so that tenant selection doesn't last beyond logout >>> - if (delegatorName.indexOf('#') > 0) { >>> + /*if (delegatorName.indexOf('#') > 0) { >>> delegatorName = delegatorName.substring(0, >>> delegatorName.indexOf('#')); >>> - } >>> + }*/ >>> session.setAttribute("delegatorName", delegatorName); >>> >>> delegator = DelegatorFactory.getDelegator(delegatorName); >>> >>> >>> >>> >