|
|
|
@ -21,10 +21,7 @@ package org.wso2.carbon.device.mgt.core.authorization;
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
|
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.*;
|
|
|
|
|
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.DeviceAuthorizationResult;
|
|
|
|
@ -74,7 +71,7 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori
|
|
|
|
|
String username = this.getUserName();
|
|
|
|
|
int tenantId = this.getTenantId();
|
|
|
|
|
if (username == null || username.isEmpty()) {
|
|
|
|
|
return false;
|
|
|
|
|
return !DeviceManagementDataHolder.getInstance().requireDeviceAuthorization(deviceIdentifier.getType());
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
//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() {
|
|
|
|
|
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
if (username != null && username.isEmpty()) {
|
|
|
|
|
String tenantDomain = MultitenantUtils.getTenantDomain(username);
|
|
|
|
|
if (username.endsWith(tenantDomain)) {
|
|
|
|
|
return username.substring(0, username.lastIndexOf("@"));
|
|
|
|
|
}
|
|
|
|
|
return username;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getTenantId() {
|
|
|
|
|
return PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|