On Thu, Nov 22, 2012 at 12:33 AM, Senaka Fernando <sen...@wso2.com> wrote:
> Hi Shariq, > > In the past, this code was written in a way, that some upstream code will > actually set stuff to the CarbonContext, but I think that practice. is no > longer followed. Anyway though we tried to mandate that sometime back, it > seems to be more natural to do what you've done, because what we have been > doing is not very maintainable. > > Now, there is a method to retrieve a getConfigUserRegistry(), which will > return the registry instance of an anonymous user. This is an > unauthenticated user. When it comes to tenants, we don't quite have the > same concept and the user name must actually be passed when requesting for > a registry. Also, in the case of the ST, the anonymous user's registry is > not what we should be returning from that CarbonContext, but that of the > logged in user. If a user is not logged in, we can probably return null or > throw an exception if someone tries to use the CarbonContext. This fact is > briefly explained in the RegistryService Java API docs. > I've modified the CC code to use the following methods in Registry service in order to return the appropriate User registries; - RegistryService#getGovernanceUserRegistry(String userName, int tenantId) - RegistryService#getConfigUserRegistry(String userName, int tenantId) > > Thanks, > Senaka. > > > On Wed, Nov 21, 2012 at 11:57 PM, Muhammed Shariq <sha...@wso2.com> wrote: > >> Hi folks, >> >> While debugging some CC related issue, we figured that the CarbonContext >> was not setting the Registry in a tenant aware manner, it was simple >> returning the ST registry as follows, >> >> - carbonContextDataHolder.getConfigSystemRegistry(); >> - carbonContextDataHolder.getConfigUserRegistry(); >> >> I have modified it to return the particular tenant's registries. However >> I couldn't find appropriate methods to in the registryService to obtain >> UserConfig registry and UserGovernance registry, so after a chat with Azeez >> we decided to return null instead of returning the ST registry .. >> >> GReg folks, how do we retrieve the tenant specific UserConfig and >> UserGovernance registry ?! >> >> Also please review the commit and holler if there are any concerns / >> issues .. >> >> ---------- Forwarded message ---------- >> From: <sha...@wso2.com> >> Date: Wed, Nov 21, 2012 at 11:21 PM >> Subject: [Commits] [Carbon-kernel] svn commit r148829 - >> carbon/kernel/branches/4.0.0/core/org.wso2.carbon.utils/4.0.5/src/main/java/org/wso2/carbon/context >> To: comm...@wso2.org >> >> >> Author: shariq >> Date: Wed Nov 21 23:21:17 2012 >> New Revision: 148829 >> URL: http://wso2.org/svn/browse/wso2?view=rev&revision=148829 >> >> Log: >> Set the correct tenant's registry in CarbonContext. >> >> >> Modified: >> >> >> carbon/kernel/branches/4.0.0/core/org.wso2.carbon.utils/4.0.5/src/main/java/org/wso2/carbon/context/CarbonContext.java >> >> Modified: >> carbon/kernel/branches/4.0.0/core/org.wso2.carbon.utils/4.0.5/src/main/java/org/wso2/carbon/context/CarbonContext.java >> URL: >> http://wso2.org/svn/browse/wso2/carbon/kernel/branches/4.0.0/core/org.wso2.carbon.utils/4.0.5/src/main/java/org/wso2/carbon/context/CarbonContext.java?rev=148829&r1=148828&r2=148829&view=diff >> >> ============================================================================== >> --- >> carbon/kernel/branches/4.0.0/core/org.wso2.carbon.utils/4.0.5/src/main/java/org/wso2/carbon/context/CarbonContext.java >> (original) >> +++ >> carbon/kernel/branches/4.0.0/core/org.wso2.carbon.utils/4.0.5/src/main/java/org/wso2/carbon/context/CarbonContext.java >> Wed Nov 21 23:21:17 2012 >> @@ -22,10 +22,12 @@ >> import net.sf.jsr107cache.CacheManager; >> import org.wso2.carbon.base.CarbonBaseUtils; >> import org.wso2.carbon.context.internal.CarbonContextDataHolder; >> +import org.wso2.carbon.context.internal.OSGiDataHolder; >> import org.wso2.carbon.queuing.CarbonQueue; >> import org.wso2.carbon.queuing.CarbonQueueManager; >> import org.wso2.carbon.registry.api.Registry; >> import org.wso2.carbon.user.api.UserRealm; >> +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; >> >> import javax.naming.Context; >> import javax.naming.InitialContext; >> @@ -49,6 +51,7 @@ >> // cleaner and easy to use API around the CarbonContext holder. >> >> private CarbonContextDataHolder carbonContextHolder = null; >> + private static OSGiDataHolder dataHolder = >> OSGiDataHolder.getInstance(); >> >> /** >> * Creates a CarbonContext using the given CarbonContext holder as >> its backing instance. >> @@ -127,18 +130,51 @@ >> * @return the requested registry instance. >> */ >> public Registry getRegistry(RegistryType type) { >> + int tenantId = getTenantId(); >> CarbonContextDataHolder carbonContextDataHolder = >> getCarbonContextDataHolder(); >> + Registry registry; >> switch (type) { >> case USER_CONFIGURATION: >> - return carbonContextDataHolder.getConfigUserRegistry(); >> + // No registry service method to obtain user config >> registry by tenant id ?! >> + return null; >> + //return carbonContextDataHolder.getConfigUserRegistry(); >> case SYSTEM_CONFIGURATION: >> - return carbonContextDataHolder.getConfigSystemRegistry(); >> + if (tenantId != MultitenantConstants.INVALID_TENANT_ID) { >> + try { >> + registry = >> dataHolder.getRegistryService().getConfigSystemRegistry(tenantId); >> + return null; >> + } catch (Exception e) { >> + // If we can't obtain an instance of the >> registry, we'll simply return null. The >> + // errors that lead to this situation will be >> logged by the Registry Kernel. >> + } >> + return null; >> + } >> case USER_GOVERNANCE: >> - return >> carbonContextDataHolder.getGovernanceUserRegistry(); >> + // No registry service method to obtain user governance >> registry by tenant id ?! >> + return null; >> + //return >> carbonContextDataHolder.getGovernanceUserRegistry(); >> case SYSTEM_GOVERNANCE: >> - return >> carbonContextDataHolder.getGovernanceSystemRegistry(); >> + if (tenantId != MultitenantConstants.INVALID_TENANT_ID) { >> + try { >> + registry = >> dataHolder.getRegistryService().getGovernanceSystemRegistry(tenantId); >> + return registry; >> + } catch (Exception e) { >> + // If we can't obtain an instance of the >> registry, we'll simply return null. The >> + // errors that lead to this situation will be >> logged by the Registry Kernel. >> + } >> + return null; >> + } >> case LOCAL_REPOSITORY: >> - return carbonContextDataHolder.getLocalRepository(); >> + if (tenantId != MultitenantConstants.INVALID_TENANT_ID) { >> + try { >> + registry = >> dataHolder.getRegistryService().getLocalRepository(tenantId); >> + return registry; >> + } catch (Exception e) { >> + // If we can't obtain an instance of the >> registry, we'll simply return null. The >> + // errors that lead to this situation will be >> logged by the Registry Kernel. >> + } >> + return null; >> + } >> default: >> return null; >> } >> _______________________________________________ >> Commits mailing list >> comm...@wso2.org >> http://wso2.org/cgi-bin/mailman/listinfo/commits >> >> >> >> -- >> Thanks, >> Shariq. >> Phone: +94 777 202 225 >> >> > > > -- > *Senaka Fernando* > Member - Integration Technologies Management Committee; > Technical Lead; WSO2 Inc.; http://wso2.com* > Member; Apache Software Foundation; http://apache.org > > E-mail: senaka AT wso2.com > **P: +1 408 754 7388; ext: 51736*; *M: +94 77 322 1818 > Linked-In: http://linkedin.com/in/senakafernando > > *Lean . Enterprise . Middleware > > -- Thanks, Shariq. Phone: +94 777 202 225
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev