• dubbo filter实现接口认证springboot idea


    最近公司有业务需求,要对Dubbo接口调用者进行身份验证,验证通过才能调用,网上一些资料不够全面,遂整理了一下.

    provider方定义一个filter,需要实现com.alibaba.dubbo.rpc.Filter(需要引入com.alibaba.dubbo依赖)

    public class AuthorizationFilter implements Filter {
    
        @Override
    
        public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    
            String token = invocation.getAttachment("token");
    
            if("123456".equals(token)){
    
                return invoker.invoke(invocation);
            }
    
            Return new RpcResult();
        }
    }

    resources目录META-INF/dubbo下新建text文件com.alibaba.dubbo.rpc.Filter,内容如下:

    AuthorizationFilter = com.xxx.AuthorizationFilter

    修改dubboprovider配置文件,添加如下:

    <dubbo:provider filter="AuthorizationFilter" />  

    consumer方采用隐式传参:RpcContext.getContext().setAttachment("token","123456");

  • 相关阅读:
    non-blocking I/O
    jetty netty
    Azkaban_Oozie_action
    权限过大 ssh协议通过pem文件登陆
    交易准实时预警 kafka topic 主题 异常交易主题 低延迟 event topic alert topic 内存 算法测试
    flink_action
    netty
    1970 ted codd
    Data dictionary
    mina
  • 原文地址:https://www.cnblogs.com/fswhq/p/dubbo_filter.html
Copyright © 2020-2023  润新知