The idea here is to authenticate a user at the back end and set the
appropriate parameters so that the authenticated
users name is available at carboncontext.getUserName();
public static void onSuccessAdminLogin(
HttpSession httpSess, String username, int tenantId,
String tenantDomain, String remoteAddress) throws Exception {
As Thilina mentioned the above function has written keeping in mind an admin
console user login. But for a generic authentication we may have a better
function like this,
public static void onSucessLogin(String userName, String tenantDomain){
}
thanks,
Amila.
On Tue, Feb 22, 2011 at 9:21 AM, Manjula Rathnayake <[email protected]>wrote:
>
>
> On Mon, Feb 21, 2011 at 8:24 PM, Senaka Fernando <[email protected]> wrote:
>
>> Hi Manjula,
>>
>> For the benefit of the others, please do update this thread with the
>> summary of the offline discussion that we had on this.
>>
>
> Yes, There is already developed code at
> CarbonAuthenticationUtil.onSuccessAdminLogin() as follows.
>
> public static void onSuccessAdminLogin(HttpSession httpSess, String
> username, int tenantId,
> String tenantDomain, String remoteAddress) throws Exception {
>
> RegistryService registryService =
> CarbonServicesServiceComponent.getRegistryService();
> UserRegistry userRegistry =
> registryService.getConfigUserRegistry(username, tenantId);
> UserRegistry governanceUserRegistry =
> registryService.getGovernanceUserRegistry(username,
> tenantId);
> UserRegistry systemRegistry =
> registryService.getConfigSystemRegistry(tenantId);
> UserRegistry governanceRegistry =
> registryService.getGovernanceSystemRegistry(tenantId);
> if (httpSess != null) {
> httpSess.setAttribute(ServerConstants.ADMIN_LOGGED_IN, "true");
> But at this line, admin log in is set to true. So I am in doubt if this can
> be used for all users.
> httpSess.setAttribute(ServerConstants.ADMIN_USERNAME,
> username);
> httpSess.setAttribute(RegistryConstants.ROOT_REGISTRY_INSTANCE,
> registryService
> .getRegistry(username, tenantId));
>
> SuperTenantCarbonContext carbonContext =
> SuperTenantCarbonContext.getCurrentContext(httpSess);
> carbonContext.setUsername(username);
>
> carbonContext.setTenantDomain(tenantDomain);
> carbonContext.setTenantId(tenantId);
> carbonContext.setRegistry(RegistryType.SYSTEM_CONFIGURATION,
> systemRegistry);
> carbonContext.setRegistry(RegistryType.SYSTEM_GOVERNANCE,
> governanceRegistry);
> carbonContext.setRegistry(RegistryType.USER_CONFIGURATION,
> userRegistry);
> carbonContext.setRegistry(RegistryType.USER_GOVERNANCE,
> governanceUserRegistry);
>
> carbonContext.setUserRealm(governanceUserRegistry.getUserRealm());
> }
>
> Date currentTime = Calendar.getInstance().getTime();
> SimpleDateFormat date = new SimpleDateFormat("'['yyyy-MM-dd
> HH:mm:ss,SSSS']'");
>
> if(tenantDomain == null){
> log.info("\'" + username + "\' logged in at " +
> date.format(currentTime) + " from IP address " +
> remoteAddress);
> } else {
> log.info("\'" + username + "@" + tenantDomain +" [" + tenantId
> + "]\' logged in at " +
> date.format(currentTime) + " from IP address " +
> remoteAddress);
> }
>
> // trigger the callbacks subscribe to the login event
> LoginSubscriptionManagerServiceImpl
> loginSubscriptionManagerServiceImpl = CarbonServicesServiceComponent
> .getLoginSubscriptionManagerServiceImpl();
> UserRegistry configRegistry =
> CarbonServicesServiceComponent.getRegistryService()
> .getConfigSystemRegistry(tenantId);
> loginSubscriptionManagerServiceImpl.triggerEvent(configRegistry,
> username, tenantId);
>
> if (log.isDebugEnabled()) {
> log.debug("User Registry instance is set in the session for
> user " + username);
> }
> LoginAttempt loginAttempt = new LoginAttempt(username, tenantId,
> remoteAddress, new Date(),
> true, null);
> LoginStatDatabase.recordLoginAttempt(loginAttempt);
> }
>
>>
>> Thanks,
>> Senaka.
>>
>> On Mon, Feb 21, 2011 at 3:21 PM, Manjula Rathnayake <[email protected]>wrote:
>>
>>> Hi all,
>>>
>>> I am completing the sqs based authentication handler, so once we have
>>> identified that the user is authenticated,
>>> what parameters should be set in carbon context to get the user name at a
>>> later time?
>>>
>>> The idea is that,
>>> 1. A user register with sqs service(user is given a secret id)
>>> 2. When user consume the service, set of headers are provided with a
>>> signature signed by the secret id.
>>> 3. An authentication handler verify the signature.
>>> 4. At the back-end, to connect to qpid, user name is needed. This is
>>> taken from CarbonContext.getCurrentContext().getUsername().
>>>
>>> So setting up the user name is required after successful authentication.
>>>
>>>
>>> Thank you.
>>>
>>> --
>>> Manjula Rathnayaka
>>> Software Engineer
>>> WSO2, Inc.
>>> Mobile: <%2B94%2077%20743%201987>+94 77 743 1987
>>>
>>> _______________________________________________
>>> Carbon-dev mailing list
>>> [email protected]
>>> http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev
>>>
>>>
>>
>>
>> --
>> *Senaka Fernando*
>> Product Manager - WSO2 Governance Registry;
>> Associate 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://www.linkedin.com/in/senakafernando
>>
>> *Lean . Enterprise . Middleware
>>
>>
>
>
> --
> Manjula Rathnayaka
> Software Engineer
> WSO2, Inc.
> Mobile:+94 77 743 1987
>
> _______________________________________________
> Carbon-dev mailing list
> [email protected]
> http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev
>
>
_______________________________________________
Carbon-dev mailing list
[email protected]
http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev