Uploaded image for project: 'Spring Integration'
  1. Spring Integration
  2. INT-2166

Adding support for SecurityContext Propagation

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: None
    • Fix Version/s: 4.2 RC1
    • Component/s: Security
    • Labels:

      Description

      There are a lot of cases when it is necessary to use the SecurityContext in async mesage flow inside Web application.
      The principal is appeared in HttpRequest from springSecurityFilterChain and stored in the ThreadLocal holder.
      So, at first, I propose to add supoprt of some global ChannelInterceptor which can propagetes that securityContext to async mesasge flow.
      This is my solution. Sorry for Groovy code.

       
      class SecurityContextPropagationChannelInterceptor extends ChannelInterceptorAdapter {
          @Override
          Message<?> preSend(Message<?> message, MessageChannel channel) {
              if (!(channel in AbstractPollableChannel) || message.headers.securityContext || !SecurityContextHolder.context.authentication) return message
              return MessageBuilder.fromMessage(message).with {
                  setHeader 'securityContext', SecurityContextHolder.context
                  build()
              }
          }
      
          @Override
          Message<?> postReceive(Message<?> message, MessageChannel channel) {
              if (channel in AbstractPollableChannel && message.headers.securityContext) {
                  SecurityContextHolder.context = message.headers.securityContext
              }
              return message
          }
      
      
      }
      

      In this case the end-programmer can use

      SecurityContextHolder.getContext()

      As well as always in any place of his application.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                abilan Artem Bilan
                Reporter:
                abilan Artem Bilan
              • Votes:
                2 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: