如何在Java 代码中 使发布订阅等操作,经过自定义的http授权?

我有自己写的http认证以及http授权demo,但是不知道如何让发布代码走我的授权代码
目前测试,发布,认证,授权都是可以单独工作的,发布也会走认证,但是不走授权
以下是我的demo代码。

@Override
public String publishMessageToBroker(String topic, String msg, Integer qos) {
String broker = “tcp://127.0.0.1:1883”;
String clientId = MqttClient.generateClientId();
MemoryPersistence persistence = new MemoryPersistence();
try {
MqttClient client = new MqttClient(broker, clientId, persistence);
// 设置回调
client.setCallback(new SampleCallback());
// MQTT 连接选项
MqttConnectOptions connOpts = new MqttConnectOptions();
// 设置认证信息
connOpts.setUserName(“emqx_u”);
connOpts.setPassword(“public”.toCharArray());
client.connect(connOpts);
// 发布消息
MqttMessage mqttMessage = new MqttMessage(msg.getBytes());
mqttMessage.setQos(qos);
client.publish(topic, mqttMessage);
log.info("mqttMessage : " + mqttMessage);
return “Publish success!”;
} catch (MqttException e) {
log.error(“发布异常”, e);
return “Publish fail!”;
}
}

@Override
public ResponseEntity<LoginResponse> doLogin(String username, String password) {
    LambdaQueryWrapper<MqttUser> eq = new LambdaQueryWrapper<MqttUser>()
            .select(MqttUser::getPasswordHash, MqttUser::getSalt)
            .eq(MqttUser::getUsername, username);
    MqttUser mqttUser = mqttMapper.selectOne(eq);
    if (mqttUser == null) {
        return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
    }
    String currentPassword = DigestUtil.sha256Hex(password + mqttUser.getSalt());
    if (currentPassword.equals(mqttUser.getPasswordHash())) {
        // 设置响应头信息
        HttpHeaders headers = new HttpHeaders();
        headers.set("Content-Type", "application/json");
        LoginResponse loginResponse = new LoginResponse("allow", true);
        return new ResponseEntity<>(loginResponse, headers, HttpStatus.OK);
    } else {
        return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
    }
}

@Override
public ResponseEntity<AuthResponse> checkAuth(AuthUser authUser) {
    // 设置响应头信息
    HttpHeaders headers = new HttpHeaders();
    headers.set("Content-Type", "application/json");
    AuthResponse authResponse = new AuthResponse("deny");
    return new ResponseEntity<>(authResponse, headers, HttpStatus.OK);
}


预期应该是,发布一条消息,应该会先走认证,再走授权,最后决定是否能发布,但是目前不知道怎么把授权代码加入到流程中

https://www.emqx.io/docs/zh/v5.1/access-control/authz/http.html

这个已经配置操作过了,但是不知道怎么融入到发布的流程