Search in sources :

Example 1 with SimpMessageType

use of org.springframework.messaging.simp.SimpMessageType in project spring-framework by spring-projects.

the class AbstractSubscriptionRegistry method findSubscriptions.

@Override
public final MultiValueMap<String, String> findSubscriptions(Message<?> message) {
    MessageHeaders headers = message.getHeaders();
    SimpMessageType type = SimpMessageHeaderAccessor.getMessageType(headers);
    if (!SimpMessageType.MESSAGE.equals(type)) {
        throw new IllegalArgumentException("Unexpected message type: " + type);
    }
    String destination = SimpMessageHeaderAccessor.getDestination(headers);
    if (destination == null) {
        if (logger.isErrorEnabled()) {
            logger.error("No destination in " + message);
        }
        return EMPTY_MAP;
    }
    return findSubscriptionsInternal(destination, message);
}
Also used : SimpMessageType(org.springframework.messaging.simp.SimpMessageType) MessageHeaders(org.springframework.messaging.MessageHeaders)

Example 2 with SimpMessageType

use of org.springframework.messaging.simp.SimpMessageType in project spring-framework by spring-projects.

the class AbstractSubscriptionRegistry method unregisterSubscription.

@Override
public final void unregisterSubscription(Message<?> message) {
    MessageHeaders headers = message.getHeaders();
    SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(headers);
    if (!SimpMessageType.UNSUBSCRIBE.equals(messageType)) {
        throw new IllegalArgumentException("Expected UNSUBSCRIBE: " + message);
    }
    String sessionId = SimpMessageHeaderAccessor.getSessionId(headers);
    if (sessionId == null) {
        if (logger.isErrorEnabled()) {
            logger.error("No sessionId in " + message);
        }
        return;
    }
    String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers);
    if (subscriptionId == null) {
        if (logger.isErrorEnabled()) {
            logger.error("No subscriptionId " + message);
        }
        return;
    }
    removeSubscriptionInternal(sessionId, subscriptionId, message);
}
Also used : SimpMessageType(org.springframework.messaging.simp.SimpMessageType) MessageHeaders(org.springframework.messaging.MessageHeaders)

Example 3 with SimpMessageType

use of org.springframework.messaging.simp.SimpMessageType in project spring-framework by spring-projects.

the class StompCommandTests method getMessageType.

@Test
public void getMessageType() throws Exception {
    for (StompCommand stompCommand : StompCommand.values()) {
        SimpMessageType simp = messageTypes.get(stompCommand);
        if (simp == null) {
            simp = SimpMessageType.OTHER;
        }
        assertSame(simp, stompCommand.getMessageType());
    }
}
Also used : SimpMessageType(org.springframework.messaging.simp.SimpMessageType) Test(org.junit.Test)

Example 4 with SimpMessageType

use of org.springframework.messaging.simp.SimpMessageType in project spring-security by spring-projects.

the class SimpMessageTypeMatcher method matches.

public boolean matches(Message<? extends Object> message) {
    MessageHeaders headers = message.getHeaders();
    SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(headers);
    return typeToMatch == messageType;
}
Also used : SimpMessageType(org.springframework.messaging.simp.SimpMessageType) MessageHeaders(org.springframework.messaging.MessageHeaders)

Example 5 with SimpMessageType

use of org.springframework.messaging.simp.SimpMessageType in project spring-security by spring-projects.

the class MessageSecurityMetadataSourceRegistry method simpTypeMatchers.

/**
	 * Maps a {@link List} of {@link SimpDestinationMessageMatcher} instances.
	 *
	 * @param typesToMatch the {@link SimpMessageType} instance to match on
	 * @return the {@link Constraint} associated to the matchers.
	 */
public Constraint simpTypeMatchers(SimpMessageType... typesToMatch) {
    MessageMatcher<?>[] typeMatchers = new MessageMatcher<?>[typesToMatch.length];
    for (int i = 0; i < typesToMatch.length; i++) {
        SimpMessageType typeToMatch = typesToMatch[i];
        typeMatchers[i] = new SimpMessageTypeMatcher(typeToMatch);
    }
    return matchers(typeMatchers);
}
Also used : MessageMatcher(org.springframework.security.messaging.util.matcher.MessageMatcher) SimpDestinationMessageMatcher(org.springframework.security.messaging.util.matcher.SimpDestinationMessageMatcher) SimpMessageType(org.springframework.messaging.simp.SimpMessageType) SimpMessageTypeMatcher(org.springframework.security.messaging.util.matcher.SimpMessageTypeMatcher)

Aggregations

SimpMessageType (org.springframework.messaging.simp.SimpMessageType)10 MessageHeaders (org.springframework.messaging.MessageHeaders)6 Principal (java.security.Principal)2 SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Test (org.junit.Test)1 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)1 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)1 Message (org.springframework.messaging.Message)1 StompHeaderAccessor (org.springframework.messaging.simp.stomp.StompHeaderAccessor)1 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)1 MessageMatcher (org.springframework.security.messaging.util.matcher.MessageMatcher)1 SimpDestinationMessageMatcher (org.springframework.security.messaging.util.matcher.SimpDestinationMessageMatcher)1 SimpMessageTypeMatcher (org.springframework.security.messaging.util.matcher.SimpMessageTypeMatcher)1