HiveMQ ClientData对象中的证书

时间:2016-09-15 11:32:23

标签: certificate mqtt hivemq

我目前正在深入研究HiveMQ插件开发。我开发了基于AfterLoginCallback的自定义功能。我配置了一个有效的TLS连接,并且我能够连接客户端证书。

mosquitto_pub.exe -t test -m "testMessage" --cafile myCertificates/hivemq-server-cert.pem  --cert myCertificates/sender.crt --key myCertificates/sender.key -p 8883"

然而,当我调试AfterLoginCallback代码时,我发现我的" ClientData - >证书"是" null"访问时抛出IllegalStateExcpetion。

[INFO] java.lang.IllegalStateException: Optional.get() cannot be called on an absent value
[INFO]  at com.google.common.base.Absent.get(Unknown Source)
[INFO]  at mycode.hivemq.plugins.first_plugin.callbacks.AfterLoginCallbackTest.afterSuccessfulLogin(AfterLoginCallbackTest.java:33)

有人可以解释一下,为什么证书是空的?

谢谢, Lomungo

1 个答案:

答案 0 :(得分:6)

在用于检查凭据的回调中,clientData必须作为ClientCredentialData处理

这里是一个示例:

public class AuthorizationCallback implements OnAuthenticationCallback, OnAuthorizationCallback {

    @Override
    public Boolean checkCredentials(@NotNull final ClientCredentialsData clientData) throws AuthenticationException {

        //Throw out clients which didn't provide a client certificate
        if (!clientData.getCertificate().isPresent()) {
            log.debug("Client {} didn't provide a client certificate. Disconnecting client", clientData.getClientId());
            throw AuthenticationExceptions.WRONG_CERTIFICATE;
        }

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

}

希望有帮助!