问题
Here's a controller I'm trying to replace:
@RequestMapping("/user")
public @ResponseBody UserRsp callUserService(Principal principal) {
String authenticatedUsername = principal.getName();
return userService.getUser(authenticatedUsername);
}
I'd like to replace it with an int-http:inbound-gateway that's mapped to a service adapter. I can't find any documentation on this, but what I'd like to do is something like this:
<int-http:inbound-gateway
request-channel="requests"
reply-channel="replies"
path="/user"
view-name="/user"
payload-expression="#payload.principal.name"
supported-methods="GET"/>
But payload.principal is something I made up. Any ideas on the right way to do this?
回答1:
Assuming you are using Spring Security, something like this should work...
payload-expression="T(org.springframework.security.core.context.SecurityContextHolder).context.authentication.principal"
来源:https://stackoverflow.com/questions/11461436/spring-integration-and-http-inbound-adapter-how-do-i-extract-a-principal-user