@ -179,7 +179,7 @@ public final class SecurityNamespaceHandler implements NamespaceHandler {
@@ -179,7 +179,7 @@ public final class SecurityNamespaceHandler implements NamespaceHandler {
## Access configuration attributes list that applies to all methods matching the pointcut, e.g. "ROLE_A,ROLE_B"
attribute access {xsd:token}
messages =
websocket-message-broker =
## Allows securing a Message Broker. There are two modes. If no id is specified: ensures that any SimpAnnotationMethodMessageHandler has the AuthenticationPrincipalArgumentResolver registered as a custom argument resolver; ensures that the SecurityContextChannelInterceptor is automatically registered for the clientInboundChannel; and that a ChannelSecurityInterceptor is registered with the clientInboundChannel. If the id is specified, creates a ChannelSecurityInterceptor that can be manually registered with the clientInboundChannel.
element messages { messages.attrlist, (message-interceptor*) }
element websocket-message-broker { websocket-message-broker.attrlist, (intercept-message*) }
messages.attrlist &=
websocket-message-broker.attrlist &=
## A bean identifier, used for referring to the bean elsewhere in the context. If specified, explicit configuration within clientInboundChannel is required. If not specified, ensures that any SimpAnnotationMethodMessageHandler has the AuthenticationPrincipalArgumentResolver registered as a custom argument resolver; ensures that the SecurityContextChannelInterceptor is automatically registered for the clientInboundChannel; and that a ChannelSecurityInterceptor is registered with the clientInboundChannel.
attribute id {xsd:token}?
message-interceptor =
## Creates an authorization rule for a message.
element message-interceptor {message-interceptor.attrlist}
intercept-message =
## Creates an authorization rule for a websocket message.
element intercept-message {intercept-message.attrlist}
message-interceptor.attrlist &=
intercept-message.attrlist &=
## The destination ant pattern which will be mapped to the access attribute. For example, /** matches any message with a destination, /admin/** matches any message that has a destination that starts with admin.
attribute pattern {xsd:token}?
message-interceptor.attrlist &=
intercept-message.attrlist &=
## The access configuration attributes that apply for the configured message. For example, permitAll grants access to anyone, hasRole('ROLE_ADMIN') requires the user have the role 'ROLE_ADMIN'.
@ -7790,15 +7790,15 @@ Enables the use of expressions in the 'access' attributes in <intercept-url> ele
@@ -7790,15 +7790,15 @@ Enables the use of expressions in the 'access' attributes in <intercept-url> ele
* <<nsa-intercept-url,intercept-url>>
[[nsa-message-security]]
=== Message/WebSocket Security
[[nsa-websocket-security]]
=== WebSocket Security
Spring Security 4.0+ provides support for authorizing messages. One concrete example of where this is useful is to provide authorization in WebSocket based applications.
[[nsa-messages]]
==== <messages>
[[nsa-websocket-message-broker]]
==== <websocket-message-broker>
The messages attribute has two different modes. If the <<nsa-messages-id>> is not specified, then it will do the following things:
The websocket-message-broker element has two different modes. If the <<nsa-websocket-id>> is not specified, then it will do the following things:
* Ensure that any SimpAnnotationMethodMessageHandler has the AuthenticationPrincipalArgumentResolver registered as a custom argument resolver. This allows the use of `@AuthenticationPrincipal` to resolve the principal of the current `Authentication`
* Ensures that the SecurityContextChannelInterceptor is automatically registered for the clientInboundChannel. This populates the SecurityContextHolder with the user that is found in the Message
@ -7809,38 +7809,38 @@ The messages attribute has two different modes. If the <<nsa-messages-id>> is no
@@ -7809,38 +7809,38 @@ The messages attribute has two different modes. If the <<nsa-messages-id>> is no
If additional control is necessary, the id can be specified and a ChannelSecurityInterceptor will be assigned to the specified id. All the wiring with Spring's messaging infrastructure can then be done manually. This is more cumbersome, but provides greater control over the configuration.
[[nsa-messages-attributes]]
===== <messages> Attributes
[[nsa-websocket-message-broker-attributes]]
===== <websocket-message-broker> Attributes
[[nsa-messages-id]]
* **id** A bean identifier, used for referring to the ChannelSecurityInterceptor bean elsewhere in the context. If specified, Spring Security requires explicit configuration within Spring Messaging. If not specified, Spring Security will automatically integrate with the messaging infrastructure as described in <<nsa-messages>>
[[nsa-websocket-message-broker-id]]
* **id** A bean identifier, used for referring to the ChannelSecurityInterceptor bean elsewhere in the context. If specified, Spring Security requires explicit configuration within Spring Messaging. If not specified, Spring Security will automatically integrate with the messaging infrastructure as described in <<nsa-websocket-message-broker>>
[[nsa-messages-children]]
===== Child Elements of <messages>
[[nsa-websocket-message-broker-children]]
===== Child Elements of <websocket-message-broker>
* **pattern** An ant based pattern that matches on the Message destination. For example, "/**" matches any Message with a destination; "/admin/**" matches any Message that has a destination that starts with "/admin/**".
[[nsa-message-interceptor-access]]
[[nsa-intercept-message-access]]
* **access** The expression used to secure the Message. For example, "denyAll" will deny access to all of the matching Messages; "permitAll" will grant access to all of the matching Messages; "hasRole('ADMIN') requires the current user to have the role 'ROLE_ADMIN' for the matching Messages.