CarbonContext is populated only if you login through carbon authenticators for management console login, or calling admin services.
In your case the code snippet you have shown should be the way to get locally authenticated username from previous authentication steps. As you might see there is a restriction in the admin UI in choosing which locally authenticated step to pick as username. Currently we there is no way to give this in UI. So you may continue assuming that all local authenticators return same username for now and choose first local authenticator. Later we have to see how to improve this design. On Sun, Jan 25, 2015 at 1:06 AM, Lasitha Wattaladeniya <[email protected]> wrote: > Hi devs, > > I'm trying to access the authorized user using the following code snippet, > > String currentUser = > CarbonContext.getThreadLocalCarbonContext().getUsername(); > > But .getUsername() returns null. > > The scenario is , I'm using two authenticators, basicauth => custom > authenticator (two authentication steps) . I need to access the logged in > user once it passed the basic authentication. I'm using IS 5.0.0 , Carbon > 4.2.0. I'm logging in using default username/password admin/admin. I can > access the tenantdomain and tenantID but not the username. > > I can access the username if the AuthenticationContext is available, as > the following way, > > String username = ""; > for (int i = context.getSequenceConfig().getStepMap().size() - 1; > i >= 0; i--) { > if > (context.getSequenceConfig().getStepMap().get(i).getAuthenticatedUser() != > null && > > context.getSequenceConfig().getStepMap().get(i).getAuthenticatedAutenticator() > .getApplicationAuthenticator() instanceof > LocalApplicationAuthenticator) { > username = > context.getSequenceConfig().getStepMap().get(i).getAuthenticatedUser(); > if (log.isDebugEnabled()) { > log.debug("username :" + username); > } > break; > } > } > > But it's not possible to always access the user from the > authenticationContext. Anyone knows how to get this done through > CarbonContext ? > > Found this thread [1] about the same topic but no luck. > > [1]. > http://wso2-oxygen-tank.10903.n7.nabble.com/Dev-PrivilegedCarbonContext-getThreadLocalCarbonContext-getUsername-returns-null-td73948.html > > -- > Lasitha Wattaladeniya > Software Engineer > WSO2, Inc. | http://wso2.com > lean. enterprise. middleware > > Mobile : +94719397528 > Blog : techreadme.blogspot.com > > _______________________________________________ > Dev mailing list > [email protected] > http://wso2.org/cgi-bin/mailman/listinfo/dev > > -- Thanks & Regards, *Johann Dilantha Nallathamby* Associate Technical Lead & Product Lead of WSO2 Identity Server Integration Technologies Team WSO2, Inc. lean.enterprise.middleware Mobile - *+94777776950* Blog - *http://nallaa.wordpress.com <http://nallaa.wordpress.com>*
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
