Compare commits

Invalid templates have been ignored

1 invalid template(s) found pull_request_template.md: frontmatter must start with a separator line

..

No commits in common. '881b9bf64d840b3dcb77d5edcbd7a880e19add34' and '993a96ab60dd98b7544990909a02b216bc6da5fd' have entirely different histories.

@ -44,14 +44,13 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class ExServer { public class ExServer {
private static final Log logger = LogFactory.getLog(ExServer.class.getName()); private static final Log logger = LogFactory.getLog(ExServer.class.getName());
private static Map<String, String> accessTokenMap = new ConcurrentHashMap<>(); private static Map<String, String> accessTokenMap = new HashMap<>();
private static Map<String, String> authorizedScopeMap = new ConcurrentHashMap<>(); private static Map<String, String> authorizedScopeMap = new HashMap<>();
private Server server; private Server server;
public ExServer() { public ExServer() {
@ -178,27 +177,25 @@ public class ExServer {
if (request.getResultCode().equals("success")) { if (request.getResultCode().equals("success")) {
String accessToken = accessTokenMap.get(request.getConninfo().getClientid()); String accessToken = accessTokenMap.get(request.getConninfo().getClientid());
String scopeString = authorizedScopeMap.get(accessToken); String scopeString = authorizedScopeMap.get(accessToken);
if (!StringUtils.isEmpty(scopeString)) { String[] scopeArray = scopeString.split(" ");
String[] scopeArray = scopeString.split(" "); String deviceType = null;
String deviceType = null; String deviceId = null;
String deviceId = null; for (String scope : scopeArray) {
for (String scope : scopeArray) { if (scope.startsWith("device_")) {
if (scope.startsWith("device_")) { String[] scopeParts = scope.split("_");
String[] scopeParts = scope.split("_"); deviceType = scopeParts[1];
deviceType = scopeParts[1]; deviceId = scopeParts[2];
deviceId = scopeParts[2]; break;
break;
}
} }
if (!StringUtils.isEmpty(deviceType) && !StringUtils.isEmpty(deviceId)) { }
try { if (!StringUtils.isEmpty(deviceType) && !StringUtils.isEmpty(deviceId)) {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain("carbon.super"); try {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(-1234); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain("carbon.super");
DeviceManagementProviderService deviceManagementProviderService = getDeviceManagementService(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(-1234);
deviceManagementProviderService.changeDeviceStatus(new DeviceIdentifier(deviceId, deviceType), EnrolmentInfo.Status.ACTIVE); DeviceManagementProviderService deviceManagementProviderService = getDeviceManagementService();
} catch (DeviceManagementException e) { deviceManagementProviderService.changeDeviceStatus(new DeviceIdentifier(deviceId, deviceType), EnrolmentInfo.Status.ACTIVE);
logger.error("onClientConnack: Error while setting device status"); } catch (DeviceManagementException e) {
} logger.error("onClientConnack: Error while setting device status");
} }
} }
} }
@ -318,57 +315,53 @@ public class ExServer {
if (StringUtils.isEmpty(accessToken) || !accessToken.startsWith(request.getClientinfo().getUsername())) { if (StringUtils.isEmpty(accessToken) || !accessToken.startsWith(request.getClientinfo().getUsername())) {
logger.info("Valid access token not found"); logger.info("Valid access token not found");
responseObserver.onError(new Exception("not authorized")); responseObserver.onError(new Exception("not authorized"));
return;
} }
String authorizedScopeList = authorizedScopeMap.get(accessToken); String authorizedScopeList = authorizedScopeMap.get(accessToken);
String[] scopeArray = authorizedScopeList.split(" ");
List<String> scopeList = Arrays.asList(scopeArray);
boolean isFound = false; boolean isFound = false;
if (!StringUtils.isEmpty(authorizedScopeList)) {
String[] scopeArray = authorizedScopeList.split(" ");
List<String> scopeList = Arrays.asList(scopeArray);
String tempScope = null;
String requestTopic = request.getTopic();
String tempScope = null; if (request.getType().equals(ClientCheckAclRequest.AclReqType.PUBLISH)) {
String requestTopic = request.getTopic(); requestTopic = requestTopic.replace("/", ":");
if (request.getType().equals(ClientCheckAclRequest.AclReqType.PUBLISH)) { String[] requestTopicParts = requestTopic.split(":");
requestTopic = requestTopic.replace("/", ":");
String[] requestTopicParts = requestTopic.split(":"); if (requestTopicParts.length >= 4 && "operation".equals(requestTopicParts[3])) {
// publishing operation from iot server to emqx
tempScope = "perm:topic:pub:" + requestTopicParts[0] + ":+:+:operation";
} else {
// publishing operation response from device to emqx
// publishing events from device to emqx
tempScope = "perm:topic:pub:" + requestTopic;
}
if (requestTopicParts.length >= 4 && "operation".equals(requestTopicParts[3])) { for (String scope : scopeList) {
// publishing operation from iot server to emqx if (scope.startsWith(tempScope)) {
tempScope = "perm:topic:pub:" + requestTopicParts[0] + ":+:+:operation"; isFound = true;
} else { break;
// publishing operation response from device to emqx
// publishing events from device to emqx
tempScope = "perm:topic:pub:" + requestTopic;
} }
}
}
for (String scope : scopeList) { if (request.getType().equals(ClientCheckAclRequest.AclReqType.SUBSCRIBE)) {
if (scope.startsWith(tempScope)) { if (requestTopic.endsWith("/#")) {
isFound = true; requestTopic = requestTopic.substring(0, requestTopic.indexOf("/#"));
break;
}
}
} }
if (request.getType().equals(ClientCheckAclRequest.AclReqType.SUBSCRIBE)) { requestTopic = requestTopic.replace("/", ":");
if (requestTopic.endsWith("/#")) { // subscribing for events from iotserver to emqx
requestTopic = requestTopic.substring(0, requestTopic.indexOf("/#")); // subscribing for operation from device to emqx
} // subscribing for operation response from iotserver to emqx
tempScope = "perm:topic:sub:" + requestTopic;
requestTopic = requestTopic.replace("/", ":"); for (String scope : scopeList) {
// subscribing for events from iotserver to emqx if (scope.startsWith(tempScope)) {
// subscribing for operation from device to emqx isFound = true;
// subscribing for operation response from iotserver to emqx break;
tempScope = "perm:topic:sub:" + requestTopic;
for (String scope : scopeList) {
if (scope.startsWith(tempScope)) {
isFound = true;
break;
}
} }
} }
} }

Loading…
Cancel
Save