Spring security Spring集成和http入站适配器,如何提取主要用户?

Spring security Spring集成和http入站适配器,如何提取主要用户?,spring-security,spring-integration,Spring Security,Spring Integration,这是我正在尝试更换的控制器: @RequestMapping("/user") public @ResponseBody UserRsp callUserService(Principal principal) { String authenticatedUsername = principal.getName(); return userService.getUser(authenticatedUsername); } 我想用映射到服务适配器的inthttp:inbound网

这是我正在尝试更换的控制器:

@RequestMapping("/user")
public @ResponseBody UserRsp callUserService(Principal principal) {
    String authenticatedUsername = principal.getName();
    return userService.getUser(authenticatedUsername);
}
我想用映射到服务适配器的inthttp:inbound网关来替换它。我找不到这方面的任何文档,但我想做的是:

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


但校长是我编出来的。关于正确的方法有什么想法吗?

假设您使用的是Spring安全性,类似的方法应该可以

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

假设您使用的是Spring安全性,类似的东西应该可以工作

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

杰出的我现在在SPeL文档中看到了这一特性,它是有意义的。结果是返回一个org.springframework.security.core.userdetails.User对象,而不是java.security.Principal,但我可以调用.username并获得相同的结果。顺便说一句,Principal(如果存在)总是映射到一个头。。。Message Message=messageBuilder.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_URL,REQUEST.getURI().toString()).setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_方法,REQUEST.getMethod().toString()).setHeader(org.springframework.integration.http.HttpHeaders.USER_PRINCIPAL,servletRequest.getUserPrincipal()).build();太好了!我现在在SPeL文档中看到了这一功能,它是有意义的。结果是返回org.springframework.security.core.userdetails.User对象而不是java.security.Principal,但我可以调用.username并获得相同的结果。顺便说一句,Principal(如果存在的话),始终映射到标头…Message Message=messageBuilder.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_URL,REQUEST.getURI().toString()).setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_方法,REQUEST.getMethod().toString()).setHeader(org.springframework.integration.http.HttpHeaders.USER_PRINCIPAL,servletRequest.getUserPrincipal()).build();