boolean isLoggedIn = false;
isLoggedIn = login(username, password, remoteAddress);
if (isLoggedIn) {
String key = UUIDGenerator.getUUID();
try {
RegistryService registryService = TokenAuthBEDataHolder.getInstance().getRegistryService();
RealmService realmService = TokenAuthBEDataHolder.getInstance().getRealmService();
String tenantDomain = UserCoreUtil.getTenantDomain(realmService, username);
int tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
UserRealm realm = registryService.getUserRealm(tenantId);
int userId = realm.getUserStoreManager().getUserId(username);
String baseString = "TenantId:=" + tenantId + "&UserId:=" + userId;
String signature = getHMAC(key,baseString);
baseString = baseString + "&Signature:=" + signature;
Registry registry = registryService.getConfigSystemRegistry(tenantId);
String path = RegistryConstants.PROFILES_PATH + username;
Collection profile = null;
if (!registry.resourceExists(path)) {
profile = registry.newCollection();
registry.put(path, profile);