Java Code Examples for io.netty.handler.codec.mqtt.MqttTopicSubscription#topicName()
The following examples show how to use
io.netty.handler.codec.mqtt.MqttTopicSubscription#topicName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Authorizator.java From cassandana with Apache License 2.0 | 5 votes |
/** * @param clientID * the clientID * @param username * the username * @param msg * the subscribe message to verify * @return the list of verified topics for the given subscribe message. */ List<MqttTopicSubscription> verifyTopicsReadAccess(String clientID, String username, MqttSubscribeMessage msg) { List<MqttTopicSubscription> ackTopics = new ArrayList<>(); final int messageId = messageId(msg); for (MqttTopicSubscription req : msg.payload().topicSubscriptions()) { Topic topic = new Topic(req.topicName()); if (!policy.canRead(topic, username, clientID)) { // send SUBACK with 0x80, the user hasn't credentials to read the topic LOG.warn("Client does not have read permissions on the topic CId={}, username: {}, messageId: {}, " + "topic: {}", clientID, username, messageId, topic); ackTopics.add(new MqttTopicSubscription(topic.toString(), FAILURE)); } else { MqttQoS qos; if (topic.isValid()) { LOG.debug("Client will be subscribed to the topic CId={}, username: {}, messageId: {}, topic: {}", clientID, username, messageId, topic); qos = req.qualityOfService(); } else { LOG.warn("Topic filter is not valid CId={}, username: {}, messageId: {}, topic: {}", clientID, username, messageId, topic); qos = FAILURE; } ackTopics.add(new MqttTopicSubscription(topic.toString(), qos)); } } return ackTopics; }
Example 2
Source File: SubscribeProcessor.java From iot-mqtt with Apache License 2.0 | 5 votes |
/** * 返回校验合法的topic */ private List<Topic> validTopics(ClientSession clientSession,List<MqttTopicSubscription> topics){ List<Topic> topicList = new ArrayList<>(); for(MqttTopicSubscription subscription : topics){ if(!pubSubPermission.subscribeVerfy(clientSession.getClientId(),subscription.topicName())){ log.warn("[SubPermission] -> this clientId:{} have no permission to subscribe this topic:{}",clientSession.getClientId(),subscription.topicName()); clientSession.getCtx().close(); return null; } Topic topic = new Topic(subscription.topicName(),subscription.qualityOfService().value()); topicList.add(topic); } return topicList; }
Example 3
Source File: SubscribeProcessor.java From jmqtt with Apache License 2.0 | 5 votes |
/** * 返回校验合法的topic */ private List<Topic> validTopics(ClientSession clientSession,List<MqttTopicSubscription> topics){ List<Topic> topicList = new ArrayList<>(); for(MqttTopicSubscription subscription : topics){ if(!pubSubPermission.subscribeVerfy(clientSession.getClientId(),subscription.topicName())){ log.warn("[SubPermission] this clientId:{} have no permission to subscribe this topic:{}",clientSession.getClientId(),subscription.topicName()); clientSession.getCtx().close(); return null; } Topic topic = new Topic(subscription.topicName(),subscription.qualityOfService().value()); topicList.add(topic); } return topicList; }
Example 4
Source File: MqttTransportHandler.java From iotplatform with Apache License 2.0 | 4 votes |
private void processSubscribe(ChannelHandlerContext ctx, MqttSubscribeMessage mqttMsg) { if (!checkConnected(ctx)) { return; } log.trace("[{}] Processing subscription [{}]!", sessionId, mqttMsg.variableHeader().messageId()); List<Integer> grantedQoSList = new ArrayList<>(); for (MqttTopicSubscription subscription : mqttMsg.payload().topicSubscriptions()) { String topicName = subscription.topicName(); // TODO: handle this qos level. MqttQoS reqQoS = subscription.qualityOfService(); try { if (topicName.equals(DEVICE_ATTRIBUTES_TOPIC)) { // AdaptorToSessionActorMsg msg = // adaptor.convertToActorMsg(deviceSessionCtx, // SUBSCRIBE_ATTRIBUTES_REQUEST, // mqttMsg); // BasicToDeviceActorSessionMsg basicToDeviceActorSessionMsg = new // BasicToDeviceActorSessionMsg( // deviceSessionCtx.getDevice(), msg); // processor.process(basicToDeviceActorSessionMsg); grantedQoSList.add(getMinSupportedQos(reqQoS)); } else if (topicName.equals(DEVICE_RPC_REQUESTS_SUB_TOPIC)) { // AdaptorToSessionActorMsg msg = // adaptor.convertToActorMsg(deviceSessionCtx, // SUBSCRIBE_RPC_COMMANDS_REQUEST, // mqttMsg); // processor.process(new // BasicToDeviceActorSessionMsg(deviceSessionCtx.getDevice(), msg)); grantedQoSList.add(getMinSupportedQos(reqQoS)); } else if (topicName.equals(DEVICE_RPC_RESPONSE_SUB_TOPIC)) { grantedQoSList.add(getMinSupportedQos(reqQoS)); } else if (topicName.equals(DEVICE_ATTRIBUTES_RESPONSES_TOPIC)) { deviceSessionCtx.setAllowAttributeResponses(); grantedQoSList.add(getMinSupportedQos(reqQoS)); } else if (topicName.equals(DEVICE_TELEMETRY_TOPIC)) { grantedQoSList.add(getMinSupportedQos(reqQoS)); } else { log.warn("[{}] Failed to subscribe to [{}][{}]", sessionId, topicName, reqQoS); grantedQoSList.add(FAILURE.value()); } ChannelEntity channelEntity = new TcpChannelEntity(ctx.channel()); MemoryMetaPool.registerTopic(channelEntity, topicName); } catch (Exception e) { e.printStackTrace(); log.warn("[{}] Failed to subscribe to [{}][{}]", sessionId, topicName, reqQoS); grantedQoSList.add(FAILURE.value()); } } ctx.writeAndFlush(createSubAckMessage(mqttMsg.variableHeader().messageId(), grantedQoSList)); }