Skip to content

Commit

Permalink
Implement thread local clearing when tenant creation is failed
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanChathusanda93 committed Oct 13, 2021
1 parent eba748c commit ac6c67c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,20 @@ public String addTenant(TenantInfoBean tenantInfoBean) throws Exception {
TenantMgtUtil.validateDomain(tenantDomain);
checkIsSuperTenantInvoking();
notifyPreTenantAddition(tenantInfoBean);
//Set a thread local variable to identify the operations triggered for a tenant admin user
TenantMgtUtil.setTenantAdminCreationOperation(true);
int tenantId;
Tenant tenant;
try {
// Set a thread local variable to identify the operations triggered for a tenant admin user.
TenantMgtUtil.setTenantAdminCreationOperation(true);

Tenant tenant = TenantMgtUtil.initializeTenant(tenantInfoBean);
tenant.setTenantUniqueID(UUIDGenerator.generateUUID());
TenantPersistor persistor = new TenantPersistor();
// not validating the domain ownership, since created by super tenant
int tenantId = persistor.persistTenant(tenant, false, tenantInfoBean.getSuccessKey(),
tenantInfoBean.getOriginatedService(), false);
tenantInfoBean.setTenantId(tenantId);
tenant = TenantMgtUtil.initializeTenant(tenantInfoBean);
tenant.setTenantUniqueID(UUIDGenerator.generateUUID());
TenantPersistor persistor = new TenantPersistor();
// Not validating the domain ownership, since created by super tenant.
tenantId = persistor.persistTenant(tenant, false, tenantInfoBean.getSuccessKey(),
tenantInfoBean.getOriginatedService(), false);
tenantInfoBean.setTenantId(tenantId);

try {
PrivilegedCarbonContext.startTenantFlow();

PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
Expand All @@ -87,7 +89,7 @@ public String addTenant(TenantInfoBean tenantInfoBean) throws Exception {

TenantMgtUtil.addClaimsToUserStoreManager(tenant);
} finally {
//Remove thread local variable set to identify operation triggered for a tenant admin user.
// Remove thread local variable set to identify operation triggered for a tenant admin user.
TenantMgtUtil.clearTenantAdminCreationOperation();

PrivilegedCarbonContext.endTenantFlow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public String addTenant(Tenant tenant) throws TenantMgtException {
} else {
throw new TenantManagementServerException(e.getMessage(), e);
}
} finally {
// Remove thread local variable set to identify operation triggered for a tenant admin user.
TenantMgtUtil.clearTenantAdminCreationOperation();
}
log.info("Added the tenant '" + tenantDomain + " [" + tenantId +
"]' by '" + PrivilegedCarbonContext.getThreadLocalCarbonContext().
Expand Down

0 comments on commit ac6c67c

Please sign in to comment.