Spring Integration and http inbound adapter, how do I extract a principal user?

岁酱吖の 提交于 2019-12-11 08:55:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!