Spring 集成和 http 入站适配器,如何提取主要用户? [英] Spring Integration and http inbound adapter, how do I extract a principal user?

查看:27
本文介绍了Spring 集成和 http 入站适配器,如何提取主要用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我要替换的控制器:

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);
}

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

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"/>

但是payload.principal 是我编造的.任何关于正确方法的想法?

But payload.principal is something I made up. Any ideas on the right way to do this?

推荐答案

假设您使用的是 Spring Security,这样的事情应该可以工作...

Assuming you are using Spring Security, something like this should work...

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

这篇关于Spring 集成和 http 入站适配器,如何提取主要用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆