我的emqx配置:
我的java后台代码:
@RestController
@RequestMapping("/mqtt")
public class AuthController {
private static final Logger log = LoggerFactory.getLogger(AuthController.class);
private HashMap<String,String> user;
@PostConstruct
public void init(){
user = new HashMap<>();
user.put("user", "123456");
user.put("emq-client2", "123456");
user.put("emq-client3", "123456");
}
@PostMapping("/auth")
public ResponseEntity auth(@RequestParam("username") String username, @RequestParam("password") String password){
log.info("emqx http认证组件调用,参数为,username={},password={}", username, password);
// String value = user.get(username);
//认证结果构造
Map<String,Object> responseBody = new HashMap<>();
responseBody.put("result","allow");
// if(StrUtil.isEmpty(value)){
// return new ResponseEntity(HttpStatus.UNAUTHORIZED);
// }
// if (!value.equals(password)){
// return new ResponseEntity(HttpStatus.UNAUTHORIZED);
// }
return ResponseEntity.ok()
.header("Content-Type","application/json")
.body(responseBody);
}
}
我的mqttx配置:
我每次点击mqttx的连接按钮,idea后台会有username未提供的警告,mqttx会报错未授权