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

Loading…
Cancel
Save