• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ClientData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.hivemq.spi.security.ClientData的典型用法代码示例。如果您正苦于以下问题:Java ClientData类的具体用法?Java ClientData怎么用?Java ClientData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ClientData类属于com.hivemq.spi.security包,在下文中一共展示了ClientData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getConnectedClients

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
private List<Client> getConnectedClients(boolean includeSubscriptions) {
    return clientService.getLocalConnectedClients().stream()
            .map(clientId -> {
                ClientData clientData = clientService.getClientData(clientId);

                String ip = null;
                if (clientData.getInetAddress().isPresent()) {
                    ip = clientData.getInetAddress().get().getHostAddress();
                }

                List<String> subscriptions = includeSubscriptions ? getSubscriptions(clientId) : null;

                return new Client(clientId, true, ip, subscriptions);
            })
            .collect(Collectors.toList());
}
 
开发者ID:artcom,项目名称:hivemq-client-status-plugin,代码行数:17,代码来源:ClientsResource.java


示例2: onConnect

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
@Override
public void onConnect(final CONNECT connect, final ClientData clientData) throws RefusedConnectionException {

    //Throw out clients which didn't provide a client certificate
    if (!clientData.getCertificate().isPresent()) {
        log.error("Client {} didn't provide a X509 client certificate. Disconnecting client", clientData.getClientId());
        throw new RefusedConnectionException(ReturnCode.REFUSED_NOT_AUTHORIZED);
    }
    log.info("Client {} connected with X509 client certificate", clientData.getClientId());

    final Certificate certificate = clientData.getCertificate().get().certificate();

    //We need to downcast to the X509 certificate
    if (certificate instanceof X509Certificate) {

        final X509Certificate x509Certificate = (X509Certificate) certificate;
        log.info("X509 client certificate provided by client {} has the serial number {}",
                clientData.getClientId(), x509Certificate.getSerialNumber());
    }

}
 
开发者ID:hivemq,项目名称:x509-client-cert-hivemq-example-plugin,代码行数:22,代码来源:ClientConnectCallback.java


示例3: onPublishReceived

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
/**
 * This method is called from the HiveMQ, when a new MQTT {@link com.hivemq.spi.message.PUBLISH} message arrives
 * at the broker. In this acme the method is just logging each message to the console.
 *
 * @param publish    The publish message send by the client.
 * @param clientData Useful information about the clients authentication state and credentials.
 * @throws com.hivemq.spi.callback.exception.OnPublishReceivedException When the exception is thrown, the publish is not
 *                                                                      accepted and will NOT be delivered to the subscribing clients.
 */
@Override
public void onPublishReceived(final PUBLISH publish, final ClientData clientData) throws OnPublishReceivedException {
    if (publish.getTopic().equals("fetch/all/clients")) {

        String clientID = clientData.getClientId();
        String topic = publish.getTopic();
        String message = new String(publish.getPayload(), Charsets.UTF_8);

        logger.info("Client " + clientID + " sent a message to topic " + topic + ": " + message);

        // Get all clients
        String allClients = getAllClients();
        publish.setPayload(allClients.getBytes(Charsets.UTF_8));

        // This redirects the message with the help of the PublishService
        redirectPublish(allClientsTopic, publish);

        logger.info("Ignoring message and sending list of all clients to topic {}", allClientsTopic);
        throw new OnPublishReceivedException("This message should not be published", false);
    }

}
 
开发者ID:hivemq,项目名称:hivemq-hello-world-plugin,代码行数:32,代码来源:SendListOfAllClientsOnPublish.java


示例4: onPublishReceived

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
@Override
public void onPublishReceived(PUBLISH message, ClientData cd) throws OnPublishReceivedException {
	if (!noPuts) {
		Integer mi = message.getMessageId();
		boolean delivered = false;
		//for both qos 1 and 2
		if (message.isDuplicateDelivery()) {
			//check against registry
			delivered = msgRegistry.get(mi) != null;
		}
		if (!delivered) {
			Future<RecordMetadata> f = producer.send(new ProducerRecord<String, byte[]>(sinkTopic, message.getTopic().substring(kafkaRecordKeyRange[0], kafkaRecordKeyRange[1]), message.getPayload()));
			if (!asyncPuts) {
				try {
					RecordMetadata rm = f.get();
					msgRegistry.put(mi, dummy);
				}
				catch (ExecutionException | InterruptedException ee) {
					//check offset before putting again?
					log.error("Failed when putting to kafka", ee);
				}
			}
			else {
				msgRegistry.put(mi, dummy);
			}
		}
	}
	if (logFrequency != -1) {
		int np = puts.incrementAndGet();
		if (np % logFrequency == 0) {
			log.info("Put {} in {} ms. Size of registry {}", puts, System.currentTimeMillis() - start, msgRegistry.size());
			start = System.currentTimeMillis();
			puts.set(0);
		}
	}
}
 
开发者ID:sabarishs,项目名称:hivemq-kafka-plugin,代码行数:37,代码来源:KafkaPluginMain.java


示例5: getPermissionsForClient

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
/**
 * This is an example authorization method, which shows how to allow a client only
 * to access topics, which have its client id up front.
 * This can be easily changed to implement your authorization logic of choice: read from a database
 * or call your authorization webservice.
 *
 * @param clientData All information from the MQTT client requesting authorization.
 * @return a list of valid topic permissions
 */
@Override
@Cached(timeToLive = 5, timeUnit = TimeUnit.MINUTES)
public List<MqttTopicPermission> getPermissionsForClient(ClientData clientData) {
    ArrayList<MqttTopicPermission> mqttTopicPermissions = new ArrayList<>();
    mqttTopicPermissions.add(
            new MqttTopicPermission(
                    clientData.getClientId() + "/#",            // Topic
                    MqttTopicPermission.TYPE.ALLOW,        // Type
                    MqttTopicPermission.QOS.ALL,        // QoS
                    MqttTopicPermission.ACTIVITY.ALL)); // Publish, Subscribe, All

    return mqttTopicPermissions;
}
 
开发者ID:hivemq,项目名称:hivemq-authorization-example,代码行数:23,代码来源:AuthorizationCallback.java


示例6: getPermissionsForClient

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
@Override
@Cached(timeToLive = 10, timeUnit = TimeUnit.SECONDS)
public List<MqttTopicPermission> getPermissionsForClient(ClientData clientData) {

    final List<MqttTopicPermission> permissions = new ArrayList<>();
    permissions.add(new MqttTopicPermission("debug/#", ALLOW));
    permissions.add(new MqttTopicPermission("system/#", DENY));

    return permissions;
}
 
开发者ID:hivemq,项目名称:hivemq-authorization-blacklist-whitelist-example,代码行数:11,代码来源:NextAuthorisation.java


示例7: getPermissionsForClient

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
@Override
@Cached(timeToLive = 10, timeUnit = TimeUnit.SECONDS)
public List<MqttTopicPermission> getPermissionsForClient(ClientData clientData) {

    final List<MqttTopicPermission> permissions = new ArrayList<>();
    permissions.add(new MqttTopicPermission("client/" + clientData.getClientId(), TYPE.ALLOW, QOS.ONE, ACTIVITY.SUBSCRIBE));
    permissions.add(new MqttTopicPermission("client/#", TYPE.ALLOW, QOS.ALL, ACTIVITY.PUBLISH, RETAIN.NOT_RETAINED));

    return permissions;
}
 
开发者ID:hivemq,项目名称:hivemq-authorization-blacklist-whitelist-example,代码行数:11,代码来源:WhitelistAuthorisation.java


示例8: getPermissionsForClient

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
@Override
@Cached(timeToLive = 10, timeUnit = TimeUnit.SECONDS)
public List<MqttTopicPermission> getPermissionsForClient(ClientData clientData) {

    final List<MqttTopicPermission> permissions = new ArrayList<>();
    permissions.add(new MqttTopicPermission("client/" + clientData.getClientId(), TYPE.ALLOW, QOS.ONE));
    permissions.add(new MqttTopicPermission("client/#", TYPE.DENY, ACTIVITY.SUBSCRIBE));

    return permissions;
}
 
开发者ID:hivemq,项目名称:hivemq-authorization-blacklist-whitelist-example,代码行数:11,代码来源:BlacklistAuthorisation.java


示例9: getPermissionsForClient

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
@Override
public List<MqttTopicPermission> getPermissionsForClient(final ClientData clientData) {

    final List<MqttTopicPermission> permissions = new ArrayList<>();

    final X509Certificate certificate = (X509Certificate) clientData.getCertificate().get();

    if ("dc-square".equals(certificate.getIssuerDN().getName())) {
        log.info("Issuer was dc-square, client is allowed to use all topics with all permissions");
        permissions.add(new MqttTopicPermission("#", MqttTopicPermission.TYPE.ALLOW));
    }

    return permissions;
}
 
开发者ID:hivemq,项目名称:x509-client-cert-hivemq-example-plugin,代码行数:15,代码来源:AuthorizationCallback.java


示例10: onPublishReceived

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
/**
 * This method is called from the HiveMQ, when a new MQTT {@link PUBLISH} message arrives
 * at the broker. In this acme the method is just logging each message to the console.
 *
 * @param publish    The publish message send by the client.
 * @param clientData Useful information about the clients authentication state and credentials.
 * @throws OnPublishReceivedException When the exception is thrown, the publish is not
 *                                    accepted and will NOT be delivered to the subscribing clients.
 */
@Override
public void onPublishReceived(PUBLISH publish, ClientData clientData) throws OnPublishReceivedException {
    String clientID = clientData.getClientId();
    String topic = publish.getTopic();
    String message = new String(publish.getPayload(), Charsets.UTF_8);

    logger.info("Client " + clientID + " sent a message to topic " + topic + ": " + message);

}
 
开发者ID:hivemq,项目名称:hivemq-hello-world-plugin,代码行数:19,代码来源:PublishReceived.java


示例11: onPublishReceived

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
@Override
public void onPublishReceived(final PUBLISH publish, final ClientData clientData) throws OnPublishReceivedException {
    final String clientID = clientData.getClientId();
    final String topic = publish.getTopic();
    final String payload = new String(publish.getPayload(), Charsets.UTF_8);

    log.info("Client {} sent a message to topic \"{}\": \"{}\" (QoS: {}, retained: {})",
            clientID, topic, payload, publish.getQoS().getQosNumber(), publish.isRetain());
}
 
开发者ID:hivemq,项目名称:mqtt-message-log,代码行数:10,代码来源:PublishReceived.java


示例12: onConnect

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
@Override
public void onConnect(final CONNECT connect, final ClientData clientData) throws RefusedConnectionException {
    log.info("Client {} connected", clientData.getClientId());

    if (connect.isWill()) {
        log.info("Client {} set Last Will and Testament. Topic: \"{}\", Payload: \"{}\", QoS: {}, retain: {}",
                clientData.getClientId(), connect.getWillTopic(), connect.getWillMessage(), connect.getWillQos().getQosNumber(), connect.isWillRetain());
    }
}
 
开发者ID:hivemq,项目名称:mqtt-message-log,代码行数:10,代码来源:ClientConnect.java


示例13: onDisconnect

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
@Override
public void onDisconnect(final ClientData clientData, final boolean abruptDisconnect) {
    if (!abruptDisconnect) {
        log.info("Client {} sent DISCONNECT message", clientData.getClientId());
    } else {
        log.info("Client {} disconnected", clientData.getClientId());
    }
}
 
开发者ID:hivemq,项目名称:mqtt-message-log,代码行数:9,代码来源:ClientDisconnect.java


示例14: onPubrelReceived

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
@Override
public void onPubrelReceived(PUBREL pubrel, ClientData clientData) {
	//QoS 2 workflow complete. cleanup so that same message id can be reused as per MQTT spec
	msgRegistry.remove(pubrel.getMessageId());
}
 
开发者ID:sabarishs,项目名称:hivemq-kafka-plugin,代码行数:6,代码来源:KafkaPluginMain.java


示例15: onPubackSend

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
@Override
public void onPubackSend(PUBACK puback, ClientData clientData) {
	//QoS 1 workflow complete. cleanup so that same message id can be reused as per MQTT spec
	msgRegistry.remove(puback.getMessageId());
}
 
开发者ID:sabarishs,项目名称:hivemq-kafka-plugin,代码行数:6,代码来源:KafkaPluginMain.java


示例16: onSubscribe

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
@Override
public void onSubscribe(final SUBSCRIBE message, final ClientData clientData) throws InvalidSubscriptionException {
    log.info("Subscribe from client {} received: {}", clientData.getClientId(), buildSubscriptionString(message.getTopics()));
}
 
开发者ID:hivemq,项目名称:mqtt-message-log,代码行数:5,代码来源:SubscribeReceived.java


示例17: onUnsubscribe

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
@Override
public void onUnsubscribe(UNSUBSCRIBE message, ClientData clientData) {
    log.info("Unsubscribe from client {} received: {}", clientData.getClientId(), buildSubscriptionString(message.getTopics()));

}
 
开发者ID:hivemq,项目名称:mqtt-message-log,代码行数:6,代码来源:UnsubscribeReceived.java


示例18: onConnect

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
/**
 * This is the callback method, which is called by the HiveMQ core, if a client has sent,
 * a {@link com.hivemq.spi.message.CONNECT} Message and was successfully authenticated. In this acme there is only
 * a logging statement, normally the behavior would be implemented in here.
 *
 * @param connect    The {@link com.hivemq.spi.message.CONNECT} message from the client.
 * @param clientData Useful information about the clients authentication state and credentials.
 * @throws com.hivemq.spi.callback.exception.RefusedConnectionException This exception should be thrown, if the client is
 *                                                                      not allowed to connect.
 */
@Override
public void onConnect(CONNECT connect, ClientData clientData) throws RefusedConnectionException {
    final String clientId = clientData.getClientId();

    log.info("Client {} is connecting", clientId);

    // Adding a subscription without automatically for the client
    addClientToTopic(clientId, "devices/" + clientId + "/sensor");
}
 
开发者ID:hivemq,项目名称:hivemq-hello-world-plugin,代码行数:20,代码来源:AddSubscriptionOnClientConnect.java


示例19: onConnect

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
/**
 * This is the callback method, which is called by the HiveMQ core, if a client has sent,
 * a {@link CONNECT} Message and was successfully authenticated. In this acme there is only
 * a logging statement, normally the behavior would be implemented in here.
 *
 * @param connect    The {@link CONNECT} message from the client.
 * @param clientData Useful information about the clients authentication state and credentials.
 * @throws RefusedConnectionException This exception should be thrown, if the client is
 *                                    not allowed to connect.
 */
@Override
public void onConnect(CONNECT connect, ClientData clientData) throws RefusedConnectionException {
    log.info("Client {} is connecting", clientData.getClientId());
}
 
开发者ID:hivemq,项目名称:hivemq-hello-world-plugin,代码行数:15,代码来源:ClientConnect.java


示例20: onDisconnect

import com.hivemq.spi.security.ClientData; //导入依赖的package包/类
/**
 * This method is called from the HiveMQ on a client disconnect.
 *
 * @param clientData       Useful information about the clients authentication state and credentials.
 * @param abruptDisconnect When true the connection of the client broke down without a
 *                         {@link com.hivemq.spi.message.DISCONNECT} message and if false then the client
 *                         disconnected properly with a {@link com.hivemq.spi.message.DISCONNECT} message.
 */
@Override
public void onDisconnect(ClientData clientData, boolean abruptDisconnect) {
    log.info("Client {} is disconnected", clientData.getClientId());
}
 
开发者ID:hivemq,项目名称:hivemq-hello-world-plugin,代码行数:13,代码来源:ClientDisconnect.java



注:本文中的com.hivemq.spi.security.ClientData类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ContextedRuntimeException类代码示例发布时间:2022-05-22
下一篇:
Java EntityArrow类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap