在使用WSSecurityPolicy和CXF回调处理程序时,如何存储请求者标识?



当使用CallBackHandler(从javax.security.auth.callback.CallbackHandler实现)来验证UsernameToken时,如何存储请求者的身份以供以后使用?

我的用例是用户A请求method1并接收到用户A的数据。用户B请求method1并接收到用户B的数据。

在返回响应之前,我使用camel来处理请求,但是我需要能够跟踪请求者是谁。

您应该能够使用Exchange.AUTHENTICATION的密钥查找主题。blow代码向您展示了camel如何将UserPrincipal从cxf消息存储到camel消息头。

    // propagate the security subject from CXF security context
    SecurityContext securityContext = cxfMessage.get(SecurityContext.class);
    if (securityContext != null && securityContext.getUserPrincipal() != null) {
        Subject subject = new Subject();
        subject.getPrincipals().add(securityContext.getUserPrincipal());
        camelExchange.getIn().getHeaders().put(Exchange.AUTHENTICATION, subject);
    }

最新更新