【问题标题】:How to preauthorize access to a Http.InboundGateway?如何预授权对 Http.InboundGateway 的访问?
【发布时间】:2020-07-22 14:09:28
【问题描述】:

我知道可以将 @PreAuthorize 注释添加到 Rest Controller...

@RestController
public class WebController {
    @PreAuthorize("hasAuthority('Foo')")
    @GetMapping("/restricted")
    public ResponseEntity<String> restricted() {
        return ResponseEntity.ok("Restricted section");
    }
}

如何预授权对 Spring Integration Http.inbound 网关的访问?我知道我可以在集成流中添加一个组件,并在转换器或服务激活器方法上添加注释,但我宁愿没有单独的对象。

@Bean
//@PreAuthorize("hasAuthority('Foo')") ?
public HttpRequestHandlingMessagingGateway restrictedGateway() {
    return Http.inboundGateway("/restricted")
            ...
            .get();
}

@Bean
public IntegrationFlow myFlow(HttpRequestHandlingMessagingGateway restrictedGateway) {
    return IntegrationFlows
            .from(restrictedGateway)
            .transform(source -> "Restricted section")
            .get();
}

【问题讨论】:

  • 在流程中的网关之后是否需要一个中间“securedChannel”来实现这一点?

标签: spring-security spring-integration spring-integration-dsl spring-integration-http


【解决方案1】:
  • 我认为你是对的,看看https://docs.spring.io/spring-integration/reference/html/security.htm,它允许将频道声明为@Secured

  • 即使我们在没有集成的情况下考虑普通 Spring Boot 应用程序上的 Spring Security,它也处于过滤器级别,因此我认为 HttpRequestHandlingMessagingGateway 作为 http 请求的侦听器似乎是有道理的

你可以试试

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

    @Bean
    public IntegrationFlow myFlow(HttpRequestHandlingMessagingGateway 
                                  restrictedGateway) {
    return IntegrationFlows
            .from(restrictedGateway)
            .channel(secureChannel())
            .transform(source -> "Restricted section")
            .get();
}

【讨论】:

  • sendAccess 是否可以成为 hasAuthority?
  • 对不起。我没有可玩的示例应用程序。但我正在检查代码 sendAccess 参数是在 spring 安全源代码中传递给的。它作为accessDecisionManager 的配置属性使用,这与在没有 sprint 集成的情况下拥有 spring 安全性时使用的相同。所以据我了解,它应该适用于hasAuthority
猜你喜欢
  • 2018-06-10
  • 1970-01-01
  • 1970-01-01
  • 2016-05-05
  • 2016-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多