Search in sources :

Example 1 with SecurityContextChannelInterceptor

use of org.springframework.security.messaging.context.SecurityContextChannelInterceptor in project spring-security by spring-projects.

the class AbstractSecurityWebSocketMessageBrokerConfigurerTests method securityContextChannelInterceptorDefinedByBean.

@Test
public void securityContextChannelInterceptorDefinedByBean() {
    loadConfig(SockJsProxylessSecurityConfig.class);
    MessageChannel messageChannel = clientInboundChannel();
    SecurityContextChannelInterceptor securityContextChannelInterceptor = this.context.getBean(SecurityContextChannelInterceptor.class);
    assertThat(((AbstractMessageChannel) messageChannel).getInterceptors()).contains(securityContextChannelInterceptor);
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) AbstractMessageChannel(org.springframework.messaging.support.AbstractMessageChannel) AbstractMessageChannel(org.springframework.messaging.support.AbstractMessageChannel) SecurityContextChannelInterceptor(org.springframework.security.messaging.context.SecurityContextChannelInterceptor) Test(org.junit.jupiter.api.Test)

Example 2 with SecurityContextChannelInterceptor

use of org.springframework.security.messaging.context.SecurityContextChannelInterceptor in project spring-security by spring-projects.

the class SecurityContextChannelInterceptorTests method preSendCustomHeader.

@Test
public void preSendCustomHeader() throws Exception {
    String headerName = "header";
    interceptor = new SecurityContextChannelInterceptor(headerName);
    messageBuilder.setHeader(headerName, authentication);
    interceptor.preSend(messageBuilder.build(), channel);
    assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(authentication);
}
Also used : SecurityContextChannelInterceptor(org.springframework.security.messaging.context.SecurityContextChannelInterceptor) Test(org.junit.Test)

Aggregations

SecurityContextChannelInterceptor (org.springframework.security.messaging.context.SecurityContextChannelInterceptor)2 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 MessageChannel (org.springframework.messaging.MessageChannel)1 AbstractMessageChannel (org.springframework.messaging.support.AbstractMessageChannel)1