【问题标题】:Spring Integration Security with REST service exampleSpring Integration Security with REST 服务示例
【发布时间】:2016-04-04 10:25:46
【问题描述】:

我正在为 REST 服务实现 Spring 集成。我正在关注 XPadro 的 githib 示例 - https://github.com/xpadro/spring-integration

我创建了简单的读、写和更新操作。 示例取自 int-http-dsl 项目。

我想用 oath2 实现 spring-security。我正在参考http://docs.spring.io/spring-integration/reference/html/security.html

我无法将两者连接在一起。因为下面是他们映射请求的方式

@Bean
    public IntegrationFlow httpGetFlow() {
        return IntegrationFlows.from(httpGetGate()).channel("httpGetChannel").handle("personEndpoint", "get").get();
    }
@Bean
    public MessagingGatewaySupport httpGetGate() {
        HttpRequestHandlingMessagingGateway handler = new HttpRequestHandlingMessagingGateway();
        handler.setRequestMapping(createMapping(new HttpMethod[]{HttpMethod.GET}, "/persons/{personId}"));
        handler.setPayloadExpression(parser().parseExpression("#pathVariables.personId"));
        handler.setHeaderMapper(headerMapper());

        return handler;
    }

以下是我们如何集成安全性

@Bean
    @SecuredChannel(interceptor = "channelSecurityInterceptor", sendAccess = "ROLE_ADMIN")
    public SubscribableChannel adminChannel() {
        return new DirectChannel();
    }

我无法在第一个示例中找到创建渠道的方法,因此如何集成。

我的方向是正确的还是完全错了?

有没有更好的教程来处理 spring-integration (http) 和 spring-security(使用 oauth)?

【问题讨论】:

    标签: spring-security spring-integration spring-security-oauth2


    【解决方案1】:

    Spring Integration Java DSL 允许将外部@Beans 用于流定义中的消息通道。因此,您的 httpGetChannel 可以这样声明和使用:

    @Bean
    @SecuredChannel(interceptor = "channelSecurityInterceptor", sendAccess = "ROLE_ADMIN")
    public SubscribableChannel httpGetChannel() {
        return new DirectChannel();
    }
    
    @Bean
    public IntegrationFlow httpGetFlow() {
        return IntegrationFlows.from(httpGetGate())
                      .channel(httpGetChannel())
                      .handle("personEndpoint", "get")
                      .get();
    }
    

    请随意提出 GitHub 问题,以便直接从 DSL 的 .channel() 定义:https://github.com/spring-projects/spring-integration-java-dsl/issues 中使框架中的内容更明显:https://github.com/spring-projects/spring-integration-java-dsl/issues

    【讨论】:

    • 你能在 Http.inboundGateway 上使用这个注解吗?
    • 什么注释? @SecuredChannel?查看它的用途:它只能用于MessageChannel beans:docs.spring.io/spring-integration/docs/current/reference/html/…
    • 我知道你可以将 Preauthorize 和 RequestMapping 放在 RestController 端点上,你能在 Http.InboundGateway 或 IntegrationFlow 上实现同样的效果吗?
    • 好的。看起来您的请求与此 SO 线程无关。请考虑提出一个包含更多信息的新问题。在这里进行这样的聊天会使社区感到困惑。
    • 好的,谢谢,我想我想我需要弄清楚我想问什么,哈哈
    猜你喜欢
    • 2019-08-04
    • 1970-01-01
    • 2023-04-03
    • 2013-09-07
    • 1970-01-01
    • 2017-05-13
    • 2018-11-07
    • 2017-05-27
    • 2014-01-15
    相关资源
    最近更新 更多