|
|
@ -17,6 +17,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.wso2.carbon.device.mgt.core.util;
|
|
|
|
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.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
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.Permission;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreManager;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreManager;
|
|
|
|
|
|
|
|
import io.entgra.application.mgt.common.services.ApplicationManager;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
@ -46,12 +50,12 @@ public class DeviceMgtTenantMgtListener implements TenantMgtListener {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onTenantCreate(TenantInfoBean tenantInfoBean) {
|
|
|
|
public void onTenantCreate(TenantInfoBean tenantInfoBean) {
|
|
|
|
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
|
|
|
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
|
|
|
if (config.getDefaultRoles().isEnabled()) {
|
|
|
|
try {
|
|
|
|
Map<String, List<Permission>> roleMap = getValidRoleMap(config);
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
try {
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantInfoBean.getTenantDomain(), true);
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
|
|
|
if (config.getDefaultRoles().isEnabled()) {
|
|
|
|
.setTenantDomain(tenantInfoBean.getTenantDomain(), true);
|
|
|
|
Map<String, List<Permission>> roleMap = getValidRoleMap(config);
|
|
|
|
UserStoreManager userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService()
|
|
|
|
UserStoreManager userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService()
|
|
|
|
.getTenantUserRealm(tenantInfoBean.getTenantId()).getUserStoreManager();
|
|
|
|
.getTenantUserRealm(tenantInfoBean.getTenantId()).getUserStoreManager();
|
|
|
|
|
|
|
|
|
|
|
@ -59,14 +63,24 @@ public class DeviceMgtTenantMgtListener implements TenantMgtListener {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
userStoreManager.addRole(key, null, value.toArray(new Permission[0]));
|
|
|
|
userStoreManager.addRole(key, null, value.toArray(new Permission[0]));
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|