Hi Dimuthu, Thanks a lot for the explanation and pointing to the mail thread.
Regards, Dulanja On Wed, Jan 9, 2013 at 4:19 PM, Dimuthu Leelarathne <[email protected]>wrote: > Hi Dulanja, > > It is correct to use CurrentCarbonContext instead of > ThreadLocalCarbonContext. You can read the mail titled "UserRegistry sends > null to JDBCAuthorizationManager" from archives. Basically this is the > code that finds you the correct CurrentCarbonContext. So correct thing is > to first get CarbonContext from MessageContext and if it is not available > try the TreadLocal one. > > public static CarbonContextDataHolder getCurrentCarbonContextHolder() { > try { > MessageContext messageContext = > MessageContext.getCurrentMessageContext(); > if (messageContext != null) { > return getCurrentCarbonContextHolder(messageContext); > } else { > return > getCurrentCarbonContextHolder((ConfigurationContext) null); > } > } catch (NullPointerException ignore) { > // This is thrown when the message context is not initialized > // So return the Threadlocal > return getThreadLocalCarbonContextHolder(); > } catch (NoClassDefFoundError ignore) { > // There can be situations where the CarbonContext is > accessed, when there is no Axis2 > // library on the classpath. > return getThreadLocalCarbonContextHolder(); > } > } > > thanks, > dimuthu > > > On Wed, Jan 9, 2013 at 2:15 PM, Dulanja Liyanage <[email protected]> wrote: > >> Hi, >> >> Appreciate if you can guide me whether it's safe/appropriate to use >> the CurrentContext rather than the ThreadLocalCarbonContext, to get the >> username and tenant domain. >> >> I'm not much knowledgeable about the design, but I feel using it will be >> "plastering" the root cause. >> >> Thanks, >> Dulanja >> >> On Wed, Jan 9, 2013 at 12:18 PM, Dulanja Liyanage <[email protected]>wrote: >> >>> Hi Shariq, >>> >>> I did as you suggested and now the username is available. >>> >>> What I'm not sure is how appropriate/safe this is. >>> >>> Thanks for the help. >>> >>> Regards, >>> Dulanja >>> >>> >>> On Tue, Jan 8, 2013 at 6:17 PM, Dulanja Liyanage <[email protected]>wrote: >>> >>>> Hi Shariq, >>>> >>>> I will try that. Thanks! >>>> >>>> Dulanja >>>> >>>> >>>> On Tue, Jan 8, 2013 at 6:12 PM, Muhammed Shariq <[email protected]>wrote: >>>> >>>>> Hi, >>>>> >>>>> This looks like an issue I encountered sometime back. We had to revert >>>>> the fixes I did in TomcatValve cz it was causing some other issue .. Can >>>>> you try CarbonContext.getCurrentContext.getUsername() and see what happens >>>>> .. AFAIR its getUsername simple does a return .. we should fix it to check >>>>> if username is null and if so set it properly .. usually that is the >>>>> behavior but there are some edge cases it seem ... >>>>> >>>>> On Tue, Jan 8, 2013 at 3:53 PM, Dulanja Liyanage <[email protected]>wrote: >>>>> >>>>>> Hi, >>>>>> >>>>>> I'm testing IS 4.1.0 running on Carbon 4.0.6. While debugging an >>>>>> issue, I encountered the $subject. >>>>>> >>>>>> I logged in as 'admin', so, the username should return as such. But >>>>>> it returns 'null'. >>>>>> >>>>>> However the >>>>>> PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain() >>>>>> returns 'carbon.super' as expected. >>>>>> >>>>>> I'm still debugging this and trying to figure out how CarbonContext >>>>>> works in threads. If someone is already aware of a reason/solution for >>>>>> this >>>>>> it will save time. :) >>>>>> >>>>>> Thanks! >>>>>> Dulanja >>>>>> >>>>>> _______________________________________________ >>>>>> Dev mailing list >>>>>> [email protected] >>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev >>>>>> >>>>>> >>>>> >>>>> >>>>> -- >>>>> Thanks, >>>>> Shariq. >>>>> Phone: +94 777 202 225 >>>>> >>>> >>>> >>> >> >> _______________________________________________ >> Dev mailing list >> [email protected] >> http://wso2.org/cgi-bin/mailman/listinfo/dev >> >> >
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
