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.USER_LOGGED_IN, 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);