0

我目前正在研究 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)

谁能解释一下,为什么证书为空?

谢谢,洛蒙戈

4

1 回答 1

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();
        ...
        }

}

希望有帮助!

于 2019-01-29T12:26:29.053 回答