Emqx配置HTTP鉴权集成springboot

简介: Emqx配置HTTP鉴权集成springboot

一、emqx添加http登录鉴权认证

进入emqx映射出来的配置文件目录,编辑鉴权的配置文件

cd /home/egn/emqx/etc/plugins
vim emqx_auth_http.conf
auth.http.auth_req.url = http://127.0.0.1:8002/emqapi/auth【修改接口地址】
auth.http.super_req.url = http://127.0.0.1:8003/emqapi/superuser【放开注释并修改接口地址】
auth.http.super_req.method = post【放开注释】
auth.http.super_req.headers.content-type = application/x-www-form-urlencoded【放开注释】
auth.http.super_req.params = clientid=%c,username=%u【放开注释】【修改接口地址】
auth.http.acl_req.url = http://127.0.0.1:8003/emqapi/acl【修改接口地址】

重启容器,使配置文件生效

docker restart emqx

开启插件

588ace8414484858bb16f646dc2e7c1d.png

二、Springboot 鉴权接口

@RestController
@RequestMapping("/emqapi")
@Api(value="EMQAPI接口",tags={"EMQAPI接口"})
public class EmqApiController{
  private static Logger logger = LoggerFactory.getLogger(EmqApiController.class);
  @Autowired
  AuthService authService;
  @ApiOperation(value = "客户端连接授权" ,notes = "客户端连接授权" )
  @ApiImplicitParams({
      @ApiImplicitParam(name = "clientid" ,value = "客户端clientId" , required = false, dataType = "String"),
      @ApiImplicitParam(name = "username" ,value = "客户端username" , required = false, dataType = "String"),
      @ApiImplicitParam(name = "password" ,value = "客户端password" , required = false, dataType = "String")
  })
  @PostMapping(value = "/auth")
  public void checkUser(String clientid, String username, String password, HttpServletResponse response) throws Exception {
    //这里添加业务逻辑 200 允许登录,其他Stuatus不允许登录
        System.out.println("普通用户;clientid:" + clientid + ";username:" + username);
    response.setStatus(200);
  }
  @PostMapping("/superuser")
  public void mqttSuperuser(String clientid, String username, HttpServletResponse response) {
    logger.info("超级用户;clientid:" + clientid + ";username:" + username);
    System.out.println("超级用户;clientid:" + clientid + ";username:" + username);
    response.setStatus(200);
  }
  @PostMapping("/acl")
  public void mqttAcl(String access, String username, String clientid, String ipaddr, String topic, HttpServletResponse response) {
    //auth.http.acl_req.params = access=%A,username=%u,clientid=%c,ipaddr=%a,topic=%t
    logger.info("access: " + access + ";username: " + username + ";clientid: " + clientid + "; ipaddr: " + ipaddr + ";topic: " + topic);
    System.out.println("access: " + access + ";username: " + username + ";clientid: " + clientid + "; ipaddr: " + ipaddr + ";topic: " + topic);
    response.setStatus(200);
  }
}


目录
相关文章
|
1月前
|
网络协议
windows_server2012搭建iis并配置http重定向 iis转发
windows_server2012搭建iis并配置http重定向 iis转发
73 1
|
21天前
|
网络协议 应用服务中间件 nginx
Nginx的http块sendfile,keepalive_timeout的配置指令说明
Nginx的http块sendfile,keepalive_timeout的配置指令说明
|
1月前
|
前端开发 小程序 应用服务中间件
在服务器上正确配置域名https证书(ssl)及为什么不推荐使用宝塔申请免费ssl证书
在服务器上正确配置域名https证书(ssl)及为什么不推荐使用宝塔申请免费ssl证书
96 4
|
1月前
|
Linux Windows
Jmeter设置中文语言和配置https
Jmeter设置中文语言和配置https
57 0
Jmeter设置中文语言和配置https
|
1月前
|
运维 Java Serverless
Serverless 应用引擎产品使用合集之是否提供工具来给OSS配置HTTPS证书
阿里云Serverless 应用引擎(SAE)提供了完整的微服务应用生命周期管理能力,包括应用部署、服务治理、开发运维、资源管理等功能,并通过扩展功能支持多环境管理、API Gateway、事件驱动等高级应用场景,帮助企业快速构建、部署、运维和扩展微服务架构,实现Serverless化的应用部署与运维模式。以下是对SAE产品使用合集的概述,包括应用管理、服务治理、开发运维、资源管理等方面。
|
1月前
|
Java 应用服务中间件 Apache
Apache HTTP配置反向代理入门
Apache HTTP配置反向代理入门
73 0
Apache HTTP配置反向代理入门
|
29天前
|
Java API Spring
Spring Boot中使用Feign进行HTTP请求
Spring Boot中使用Feign进行HTTP请求
|
2月前
|
安全 网络协议 应用服务中间件
一文读懂HTTPS⭐揭秘加密传输背后的原理与Nginx配置攻略
一文读懂HTTPS⭐揭秘加密传输背后的原理与Nginx配置攻略
|
1月前
|
XML Web App开发 JSON
HTTP代理神器Fiddler的配置
HTTP代理神器Fiddler的配置
|
1月前
|
Windows
iis配置http重定向302转发get请求并去掉最后的斜杠/ iis重定向 iis去除url最后的斜杠 iis重定向链接斜杠(已解决)
iis配置http重定向302转发get请求并去掉最后的斜杠/ iis重定向 iis去除url最后的斜杠 iis重定向链接斜杠(已解决)
33 0