SEC-2833: Rossen's feedback on WebSocket

This commit is contained in:
Rob Winch 2015-02-04 10:42:34 -06:00
parent 72e256b95a
commit 9b5f76f3d6
4 changed files with 19 additions and 10 deletions

View File

@ -113,7 +113,7 @@ public class MessageSecurityMetadataSourceRegistry {
* @return the {@link Constraint} that is associated to the {@link MessageMatcher} * @return the {@link Constraint} that is associated to the {@link MessageMatcher}
* @see {@link MessageSecurityMetadataSourceRegistry#simpDestPathMatcher(PathMatcher)} * @see {@link MessageSecurityMetadataSourceRegistry#simpDestPathMatcher(PathMatcher)}
*/ */
public Constraint simpDestMessageMatchers(String... patterns) { public Constraint simpMessageDestMatchers(String... patterns) {
return simpDestMatchers(SimpMessageType.MESSAGE, patterns); return simpDestMatchers(SimpMessageType.MESSAGE, patterns);
} }
@ -128,7 +128,7 @@ public class MessageSecurityMetadataSourceRegistry {
* @return the {@link Constraint} that is associated to the {@link MessageMatcher} * @return the {@link Constraint} that is associated to the {@link MessageMatcher}
* @see {@link MessageSecurityMetadataSourceRegistry#simpDestPathMatcher(PathMatcher)} * @see {@link MessageSecurityMetadataSourceRegistry#simpDestPathMatcher(PathMatcher)}
*/ */
public Constraint simpDestSubscribeMatchers(String... patterns) { public Constraint simpSubscribeDestMatchers(String... patterns) {
return simpDestMatchers(SimpMessageType.SUBSCRIBE, patterns); return simpDestMatchers(SimpMessageType.SUBSCRIBE, patterns);
} }

View File

@ -46,8 +46,8 @@ import java.util.List;
* @Override * @Override
* protected void configureInbound(MessageSecurityMetadataSourceRegistry messages) { * protected void configureInbound(MessageSecurityMetadataSourceRegistry messages) {
* messages * messages
* .antMatchers("/user/queue/errors").permitAll() * .simpDestMatchers("/user/queue/errors").permitAll()
* .antMatchers("/admin/**").hasRole("ADMIN") * .simpDestMatchers("/admin/**").hasRole("ADMIN")
* .anyMessage().authenticated(); * .anyMessage().authenticated();
* } * }
* } * }
@ -61,7 +61,7 @@ import java.util.List;
public abstract class AbstractSecurityWebSocketMessageBrokerConfigurer extends AbstractWebSocketMessageBrokerConfigurer { public abstract class AbstractSecurityWebSocketMessageBrokerConfigurer extends AbstractWebSocketMessageBrokerConfigurer {
private final WebSocketMessageSecurityMetadataSourceRegistry inboundRegistry = new WebSocketMessageSecurityMetadataSourceRegistry(); private final WebSocketMessageSecurityMetadataSourceRegistry inboundRegistry = new WebSocketMessageSecurityMetadataSourceRegistry();
public final void registerStompEndpoints(StompEndpointRegistry registry) {} public void registerStompEndpoints(StompEndpointRegistry registry) {}
@Override @Override
public void addArgumentResolvers( public void addArgumentResolvers(
@ -76,6 +76,15 @@ public abstract class AbstractSecurityWebSocketMessageBrokerConfigurer extends A
if(inboundRegistry.containsMapping()) { if(inboundRegistry.containsMapping()) {
registration.setInterceptors(securityContextChannelInterceptor(),inboundChannelSecurity); registration.setInterceptors(securityContextChannelInterceptor(),inboundChannelSecurity);
} }
customizeClientInboundChannel(registration);
}
/**
* Allows subclasses to customize the configuration of the {@link ChannelRegistration}.
*
* @param registration the {@link ChannelRegistration} to customize
*/
protected void customizeClientInboundChannel(ChannelRegistration registration) {
} }
@Bean @Bean

View File

@ -225,7 +225,7 @@ public class MessageSecurityMetadataSourceRegistryTests {
@Test @Test
public void simpDestMessageMatchersNotMatch() { public void simpDestMessageMatchersNotMatch() {
messages messages
.simpDestMessageMatchers("admin/**").denyAll() .simpMessageDestMatchers("admin/**").denyAll()
.anyMessage().permitAll(); .anyMessage().permitAll();
assertThat(getAttribute()).isEqualTo("permitAll"); assertThat(getAttribute()).isEqualTo("permitAll");
@ -234,7 +234,7 @@ public class MessageSecurityMetadataSourceRegistryTests {
@Test @Test
public void simpDestMessageMatchersMatch() { public void simpDestMessageMatchersMatch() {
messages messages
.simpDestMessageMatchers("location/**").denyAll() .simpMessageDestMatchers("location/**").denyAll()
.anyMessage().permitAll(); .anyMessage().permitAll();
assertThat(getAttribute()).isEqualTo("denyAll"); assertThat(getAttribute()).isEqualTo("denyAll");
@ -243,7 +243,7 @@ public class MessageSecurityMetadataSourceRegistryTests {
@Test @Test
public void simpDestSubscribeMatchersNotMatch() { public void simpDestSubscribeMatchersNotMatch() {
messages messages
.simpDestSubscribeMatchers("location/**").denyAll() .simpSubscribeDestMatchers("location/**").denyAll()
.anyMessage().permitAll(); .anyMessage().permitAll();
assertThat(getAttribute()).isEqualTo("permitAll"); assertThat(getAttribute()).isEqualTo("permitAll");
@ -256,7 +256,7 @@ public class MessageSecurityMetadataSourceRegistryTests {
.build(); .build();
messages messages
.simpDestSubscribeMatchers("location/**").denyAll() .simpSubscribeDestMatchers("location/**").denyAll()
.anyMessage().permitAll(); .anyMessage().permitAll();
assertThat(getAttribute()).isEqualTo("denyAll"); assertThat(getAttribute()).isEqualTo("denyAll");

View File

@ -30,7 +30,7 @@ import org.springframework.security.core.Authentication;
* @author Rob Winch * @author Rob Winch
* @since 4.0 * @since 4.0
* *
* @see AuthenticationPrincipalArgumentResolver * @see org.springframework.security.messaging.context.AuthenticationPrincipalArgumentResolver
*/ */
@Target({ ElementType.PARAMETER, ElementType.ANNOTATION_TYPE }) @Target({ ElementType.PARAMETER, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)