Added requireDeviceAuthorization support

revert-70aa11f8
harshanl 9 years ago
parent dc2e41e083
commit e14f09b8a8

@ -150,4 +150,11 @@ public interface DeviceManager {
void addLicense(License license) throws LicenseManagementException; void addLicense(License license) throws LicenseManagementException;
/**
* Method to enable to device-authentication for the device-platform.
*
* @return Returns boolean status to enable or disable device-authentication.
*/
boolean requireDeviceAuthorization();
} }

@ -21,6 +21,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagerStartupListener; import org.wso2.carbon.device.mgt.core.internal.DeviceManagerStartupListener;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
@ -48,6 +49,8 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
/* Initializing Device Management Service Provider */ /* Initializing Device Management Service Provider */
provider.init(); provider.init();
DeviceManagerUtil.registerDeviceType(deviceType); DeviceManagerUtil.registerDeviceType(deviceType);
DeviceManagementDataHolder.getInstance().setRequireDeviceAuthorization(deviceType,
provider.getDeviceManager().requireDeviceAuthorization());
} }
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new DeviceManagementException("Error occurred while adding device management provider '" + throw new DeviceManagementException("Error occurred while adding device management provider '" +

@ -21,10 +21,7 @@ package org.wso2.carbon.device.mgt.core.authorization;
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.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAuthorizationResult; import org.wso2.carbon.device.mgt.common.authorization.DeviceAuthorizationResult;
@ -74,7 +71,7 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori
String username = this.getUserName(); String username = this.getUserName();
int tenantId = this.getTenantId(); int tenantId = this.getTenantId();
if (username == null || username.isEmpty()) { if (username == null || username.isEmpty()) {
return false; return !DeviceManagementDataHolder.getInstance().requireDeviceAuthorization(deviceIdentifier.getType());
} }
try { try {
//Check for admin users. If the user is an admin user we authorize the access to that device. //Check for admin users. If the user is an admin user we authorize the access to that device.
@ -227,12 +224,15 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori
private String getUserName() { private String getUserName() {
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (username != null && username.isEmpty()) {
String tenantDomain = MultitenantUtils.getTenantDomain(username); String tenantDomain = MultitenantUtils.getTenantDomain(username);
if (username.endsWith(tenantDomain)) { if (username.endsWith(tenantDomain)) {
return username.substring(0, username.lastIndexOf("@")); return username.substring(0, username.lastIndexOf("@"));
} }
return username; return username;
} }
return null;
}
private int getTenantId() { private int getTenantId() {
return PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); return PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();

@ -44,7 +44,7 @@ public class DeviceManagementDataHolder {
private AppManagementConfig appManagerConfig; private AppManagementConfig appManagerConfig;
private OperationManager operationManager; private OperationManager operationManager;
private ConfigurationContextService configurationContextService; private ConfigurationContextService configurationContextService;
private HashMap<String,Boolean> isUserLevelAutherizationAllowMap; private HashMap<String,Boolean> requireDeviceAuthorization = new HashMap<>();
private DeviceAccessAuthorizationService deviceAccessAuthorizationService; private DeviceAccessAuthorizationService deviceAccessAuthorizationService;
private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder(); private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder();
@ -148,12 +148,12 @@ public class DeviceManagementDataHolder {
this.configurationContextService = configurationContextService; this.configurationContextService = configurationContextService;
} }
public void setIsUserLevelAutherizationAllow(String pluginType, boolean isAllowUserAuthentication) { public void setRequireDeviceAuthorization(String pluginType, boolean requireAuthentication) {
isUserLevelAutherizationAllowMap.put(pluginType,isAllowUserAuthentication); requireDeviceAuthorization.put(pluginType,requireAuthentication);
} }
public boolean getIsUserLevelAutherizationAllow(String pluginType) { public boolean requireDeviceAuthorization(String pluginType) {
return isUserLevelAutherizationAllowMap.get(pluginType); return requireDeviceAuthorization.get(pluginType);
} }
public DeviceAccessAuthorizationService getDeviceAccessAuthorizationService() { public DeviceAccessAuthorizationService getDeviceAccessAuthorizationService() {

@ -116,4 +116,9 @@ public class TestDeviceManager implements DeviceManager {
} }
@Override
public boolean requireDeviceAuthorization() {
return false;
}
} }

Loading…
Cancel
Save