|
36 | 36 | import org.springframework.http.client.ClientHttpResponse; |
37 | 37 | import org.springframework.integration.channel.DirectChannel; |
38 | 38 | import org.springframework.integration.channel.FixedSubscriberChannel; |
| 39 | +import org.springframework.integration.channel.QueueChannel; |
39 | 40 | import org.springframework.integration.config.EnableIntegration; |
| 41 | +import org.springframework.integration.dsl.DirectChannelSpec; |
40 | 42 | import org.springframework.integration.dsl.IntegrationFlow; |
| 43 | +import org.springframework.integration.dsl.MessageChannels; |
| 44 | +import org.springframework.integration.dsl.QueueChannelSpec; |
41 | 45 | import org.springframework.integration.dsl.context.IntegrationFlowContext; |
42 | 46 | import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; |
43 | 47 | import org.springframework.integration.http.multipart.UploadedMultipartFile; |
44 | 48 | import org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler; |
| 49 | +import org.springframework.integration.scheduling.PollerMetadata; |
45 | 50 | import org.springframework.messaging.Message; |
46 | | -import org.springframework.messaging.MessageChannel; |
47 | 51 | import org.springframework.messaging.PollableChannel; |
48 | 52 | import org.springframework.messaging.support.ErrorMessage; |
49 | 53 | import org.springframework.mock.web.MockPart; |
|
56 | 60 | import org.springframework.security.core.userdetails.UserDetailsService; |
57 | 61 | import org.springframework.security.crypto.factory.PasswordEncoderFactories; |
58 | 62 | import org.springframework.security.messaging.access.intercept.AuthorizationChannelInterceptor; |
| 63 | +import org.springframework.security.messaging.context.SecurityContextPropagationChannelInterceptor; |
59 | 64 | import org.springframework.security.provisioning.InMemoryUserDetailsManager; |
60 | 65 | import org.springframework.security.web.SecurityFilterChain; |
61 | 66 | import org.springframework.security.web.util.matcher.AntPathRequestMatcher; |
@@ -330,21 +335,33 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { |
330 | 335 | .build(); |
331 | 336 | } |
332 | 337 |
|
| 338 | + @Bean(PollerMetadata.DEFAULT_POLLER) |
| 339 | + PollerMetadata pollerMetadata() { |
| 340 | + return new PollerMetadata(); |
| 341 | + } |
| 342 | + |
| 343 | + @Bean |
| 344 | + public QueueChannelSpec securityPropagationChannel() { |
| 345 | + return MessageChannels.queue() |
| 346 | + .interceptor(new SecurityContextPropagationChannelInterceptor()); |
| 347 | + } |
| 348 | + |
333 | 349 | @Bean |
334 | | - public MessageChannel transformSecuredChannel() { |
335 | | - DirectChannel directChannel = new DirectChannel(); |
336 | | - directChannel.addInterceptor( |
337 | | - new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasRole("ADMIN"))); |
338 | | - return directChannel; |
| 350 | + public DirectChannelSpec transformSecuredChannel() { |
| 351 | + return MessageChannels.direct() |
| 352 | + .interceptor(new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasRole("ADMIN"))); |
339 | 353 | } |
340 | 354 |
|
341 | 355 | @Bean |
342 | | - public IntegrationFlow httpInternalServiceFlow() { |
| 356 | + public IntegrationFlow httpInternalServiceFlow(QueueChannel securityPropagationChannel, |
| 357 | + DirectChannel transformSecuredChannel) { |
| 358 | + |
343 | 359 | return IntegrationFlow |
344 | 360 | .from(Http.inboundGateway("/service/internal") |
345 | 361 | .requestMapping(r -> r.params("name")) |
346 | 362 | .payloadExpression("#requestParams.name")) |
347 | | - .channel(transformSecuredChannel()) |
| 363 | + .channel(securityPropagationChannel) |
| 364 | + .channel(transformSecuredChannel) |
348 | 365 | .<List<String>, String>transform(p -> p.get(0).toUpperCase()) |
349 | 366 | .get(); |
350 | 367 | } |
|
0 commit comments