Update tenant management listner

fix-default-category-issue
Rajitha Kumara 2 years ago
parent c8c18c4f3d
commit c5c90dd5a4

@ -358,6 +358,14 @@
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>io.entgra.notification.logger</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>io.entgra.application.mgt.core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>io.entgra.application.mgt.common</artifactId>
</dependency>
</dependencies>
</project>

@ -17,6 +17,9 @@
package org.wso2.carbon.device.mgt.core.util;
import io.entgra.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.application.mgt.core.config.ConfigurationManager;
import io.entgra.application.mgt.core.util.ApplicationManagementUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
@ -32,6 +35,7 @@ import org.wso2.carbon.stratos.common.listeners.TenantMgtListener;
import org.wso2.carbon.user.api.Permission;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
import io.entgra.application.mgt.common.services.ApplicationManager;
import java.util.ArrayList;
import java.util.HashMap;
@ -46,12 +50,12 @@ public class DeviceMgtTenantMgtListener implements TenantMgtListener {
@Override
public void onTenantCreate(TenantInfoBean tenantInfoBean) {
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
if (config.getDefaultRoles().isEnabled()) {
Map<String, List<Permission>> roleMap = getValidRoleMap(config);
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext()
.setTenantDomain(tenantInfoBean.getTenantDomain(), true);
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantInfoBean.getTenantDomain(), true);
if (config.getDefaultRoles().isEnabled()) {
Map<String, List<Permission>> roleMap = getValidRoleMap(config);
UserStoreManager userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService()
.getTenantUserRealm(tenantInfoBean.getTenantId()).getUserStoreManager();
@ -59,14 +63,24 @@ public class DeviceMgtTenantMgtListener implements TenantMgtListener {
try {
userStoreManager.addRole(key, null, value.toArray(new Permission[0]));
} catch (UserStoreException e) {
log.error("Error occurred while adding default roles into user store.", e);
log.error("Error occurred while adding default roles into user store", e);
}
});
} catch (UserStoreException e) {
log.error("Error occurred while getting user store manager.", e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
List<String> defaultCategories = ConfigurationManager.getInstance().getConfiguration().getAppCategories();
if(defaultCategories != null && !defaultCategories.isEmpty()) {
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance();
applicationManager.addApplicationCategories(defaultCategories);
log.info("Successfully registered default categories into tenant "+tenantInfoBean.getTenantDomain());
}
} catch (UserStoreException e) {
log.error("Error occurred while getting user store manager", e);
} catch (ApplicationManagementException e) {
log.error("Error occurred while registering default categories to tenant "+tenantInfoBean.getTenantDomain());
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}

Loading…
Cancel
Save