|
|
@ -20,10 +20,12 @@ package io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.bean.RoleMapping;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.bean.RoleMapping;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.bean.UserStoreRoleMappingConfig;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.bean.UserStoreRoleMappingConfig;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.internal.UserStoreRoleMappingDataHolder;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper.internal.UserStoreRoleMappingDataHolder;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.exception.HeartBeatManagementException;
|
|
|
|
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;
|
|
|
|
import org.wso2.carbon.core.ServerStartupObserver;
|
|
|
|
import org.wso2.carbon.core.ServerStartupObserver;
|
|
|
|
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreManager;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreManager;
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
|
|
|
|
|
|
|
|
|
@ -36,6 +38,8 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
public class UserStoreRoleMapper implements ServerStartupObserver {
|
|
|
|
public class UserStoreRoleMapper implements ServerStartupObserver {
|
|
|
|
private static final Log log = LogFactory.getLog(UserStoreRoleMapper.class);
|
|
|
|
private static final Log log = LogFactory.getLog(UserStoreRoleMapper.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private UserStoreRoleMappingConfig config = null;
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void completingServerStartup() {
|
|
|
|
public void completingServerStartup() {
|
|
|
|
|
|
|
|
|
|
|
@ -43,6 +47,16 @@ public class UserStoreRoleMapper implements ServerStartupObserver {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void completedServerStartup() {
|
|
|
|
public void completedServerStartup() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config = UserStoreRoleMappingDataHolder.getInstance()
|
|
|
|
|
|
|
|
.getUserStoreRoleMappingConfigManager().getUserStoreRoleMappingConfig();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if ((config.isEnabled() &&
|
|
|
|
|
|
|
|
UserStoreRoleMappingDataHolder.getInstance().getHeartBeatService().isTaskPartitioningEnabled() &&
|
|
|
|
|
|
|
|
UserStoreRoleMappingDataHolder.getInstance().getHeartBeatService().isQualifiedToExecuteTask())
|
|
|
|
|
|
|
|
|| (config.isEnabled() &&
|
|
|
|
|
|
|
|
!UserStoreRoleMappingDataHolder.getInstance().getHeartBeatService().isTaskPartitioningEnabled())) {
|
|
|
|
Runnable periodicTask = new Runnable() {
|
|
|
|
Runnable periodicTask = new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
updateRoleMapping();
|
|
|
|
updateRoleMapping();
|
|
|
@ -53,7 +67,11 @@ public class UserStoreRoleMapper implements ServerStartupObserver {
|
|
|
|
ScheduledExecutorService executor =
|
|
|
|
ScheduledExecutorService executor =
|
|
|
|
Executors.newSingleThreadScheduledExecutor();
|
|
|
|
Executors.newSingleThreadScheduledExecutor();
|
|
|
|
|
|
|
|
|
|
|
|
executor.scheduleAtFixedRate(periodicTask,30, 60, TimeUnit.SECONDS);
|
|
|
|
executor.scheduleAtFixedRate(periodicTask, config.getInitialDelayInSeconds(), config.getPeriodInSeconds(), TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (HeartBeatManagementException e) {
|
|
|
|
|
|
|
|
log.error("Error while accessing heart beat service " + e.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void updateRoleMapping() {
|
|
|
|
private void updateRoleMapping() {
|
|
|
@ -64,9 +82,6 @@ public class UserStoreRoleMapper implements ServerStartupObserver {
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
|
|
|
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
|
|
|
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
|
|
|
|
|
|
|
|
|
|
|
UserStoreRoleMappingConfig config = UserStoreRoleMappingDataHolder.getInstance()
|
|
|
|
|
|
|
|
.getUserStoreRoleMappingConfigManager().getUserStoreRoleMappingConfig();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<RoleMapping> roleMappings = config.getMappings();
|
|
|
|
List<RoleMapping> roleMappings = config.getMappings();
|
|
|
|
|
|
|
|
|
|
|
|
if (!roleMappings.isEmpty()) {
|
|
|
|
if (!roleMappings.isEmpty()) {
|
|
|
@ -115,7 +130,7 @@ public class UserStoreRoleMapper implements ServerStartupObserver {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
log.error("Error while getting user store..." + e.getMessage());
|
|
|
|
log.error("Error while getting user store..." + e.getMessage());
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|