Authentication 如何将经过身份验证的用户(主体)信息添加到ChannelHandlerContext(或其他任何地方?)

Authentication 如何将经过身份验证的用户(主体)信息添加到ChannelHandlerContext(或其他任何地方?),authentication,netty,Authentication,Netty,简而言之,我正在进行双向SSL,客户端证书用于标识最终用户。SSLHandler在这方面做得很好,而且SSLHandler知道关于校长的一切。我如何与其他处理程序共享该信息,以便他们能够在整个通道管道中完成工作 这里是我的SSLHandler扩展找到用户主体的地方 类MySslHandler扩展了SSLHandler{ public void messageReceived( ChannelHandlerContext ctx, MessageEvent e) throws E

简而言之,我正在进行双向SSL,客户端证书用于标识最终用户。SSLHandler在这方面做得很好,而且SSLHandler知道关于校长的一切。我如何与其他处理程序共享该信息,以便他们能够在整个通道管道中完成工作

这里是我的SSLHandler扩展找到用户主体的地方

类MySslHandler扩展了SSLHandler{

public void messageReceived(
        ChannelHandlerContext ctx, MessageEvent e) throws Exception{
    logger.info("messageReceived");
    super.messageReceived(ctx, e);
        try{
                System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " + getPrincipalCertificate().getSubjectDN().toString());
                        }
                        catch(Throwable t){
                            logger.error("Unable to see principal ", t);
                        }        

}    
/**
 * 
 * @return Return the user certificate of the principal
 * @throws SSLPeerUnverifiedException  if the peer is not yet verified
 */
public X509Certificate getPrincipalCertificate() throws SSLPeerUnverifiedException{
    return getEngine().getSession().getPeerCertificateChain()[0];
}

}
我想必应该向ChannelHandlerContext添加信息,以便在SSL会话期间以及我的所有其他处理程序中都可以使用这些信息,但我不知道如何做到这一点。这是错误的方法吗?有什么建议吗


谢谢!

如果您需要在ChannelHandler之间共享它,您需要使用静态ChannelLocal实例。这是必需的,因为ChannelHandlerContext是每个ChannelHandler的