Spring Integration和http入站适配器,如何提取主体用户?

时间:2012-07-12 22:06:24

标签: spring-security spring-integration

这是我想要替换的控制器:

@RequestMapping("/user")
public @ResponseBody UserRsp callUserService(Principal principal) {
    String authenticatedUsername = principal.getName();
    return userService.getUser(authenticatedUsername);
}

我想将它替换为映射到服务适配器的int-http:inbound-gateway。我找不到任何关于此的文档,但我想做的是这样的事情:

<int-http:inbound-gateway
 request-channel="requests" 
reply-channel="replies" 
path="/user" 
view-name="/user" 
payload-expression="#payload.principal.name"
supported-methods="GET"/>

但有效载荷。主要是我编造的东西。有关正确方法的任何想法吗?

1 个答案:

答案 0 :(得分:1)

假设您正在使用Spring Security,那么这样的事情应该有效......

payload-expression="T(org.springframework.security.core.context.SecurityContextHolder).context.authentication.principal"