@SuppressWarnings({ "rawtypes", "unchecked" }) public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException { final Message message = (Message) object; for (Map.Entry<MessageMatcher<?>, Collection<ConfigAttribute>> entry : messageMap .entrySet()) { if (entry.getKey().matches(message)) { return entry.getValue(); } } return null; }
public boolean matches(Message<? extends T> message) { for (MessageMatcher<T> matcher : getMessageMatchers()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Trying to match using " + matcher); } if (matcher.matches(message)) { LOGGER.debug("matched"); return true; } } LOGGER.debug("No matches found"); return false; } }
public boolean matches(Message<? extends T> message) { for (MessageMatcher<T> matcher : getMessageMatchers()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Trying to match using " + matcher); } if (!matcher.matches(message)) { LOGGER.debug("Did not match"); return false; } } LOGGER.debug("All messageMatchers returned true"); return true; } }
public boolean matches(Message<? extends Object> message) { if (!messageTypeMatcher.matches(message)) { return false; } String destination = SimpMessageHeaderAccessor.getDestination(message .getHeaders()); return destination != null && matcher.match(pattern, destination); }
@Override public Message<?> preSend(Message<?> message, MessageChannel channel) { if (!matcher.matches(message)) { return message; } Map<String, Object> sessionAttributes = SimpMessageHeaderAccessor .getSessionAttributes(message.getHeaders()); CsrfToken expectedToken = sessionAttributes == null ? null : (CsrfToken) sessionAttributes.get(CsrfToken.class.getName()); if (expectedToken == null) { throw new MissingCsrfTokenException(null); } String actualTokenValue = SimpMessageHeaderAccessor.wrap(message) .getFirstNativeHeader(expectedToken.getHeaderName()); boolean csrfCheckPassed = expectedToken.getToken().equals(actualTokenValue); if (csrfCheckPassed) { return message; } throw new InvalidCsrfTokenException(expectedToken, actualTokenValue); } }
@Test public void createExpressionMessageMetadataSourceMatchSecond() { when(matcher2.matches(message)).thenReturn(true); Collection<ConfigAttribute> attrs = source.getAttributes(message); assertThat(attrs).hasSize(1); ConfigAttribute attr = attrs.iterator().next(); assertThat(attr).isInstanceOf(MessageExpressionConfigAttribute.class); assertThat( ((MessageExpressionConfigAttribute) attr).getAuthorizeExpression() .getValue(rootObject)).isEqualTo(false); } }
@Test public void createExpressionMessageMetadataSourceMatchFirst() { when(matcher1.matches(message)).thenReturn(true); Collection<ConfigAttribute> attrs = source.getAttributes(message); assertThat(attrs).hasSize(1); ConfigAttribute attr = attrs.iterator().next(); assertThat(attr).isInstanceOf(MessageExpressionConfigAttribute.class); assertThat( ((MessageExpressionConfigAttribute) attr).getAuthorizeExpression() .getValue(rootObject)).isEqualTo(true); }
@Test public void matchersTrue() { when(matcher.matches(message)).thenReturn(true); messages.matchers(matcher).permitAll(); assertThat(getAttribute()).isEqualTo("permitAll"); }
@Test public void getAttributesFirst() { when(matcher1.matches(message)).thenReturn(true); assertThat(source.getAttributes(message)).containsOnly(config1); }
@Test public void getAttributesSecond() { when(matcher1.matches(message)).thenReturn(true); assertThat(source.getAttributes(message)).containsOnly(config2); }