@Test public void testTheCreatedProcessorWithToken() { ThymeleafCsrfDialect component = new ThymeleafCsrfDialect(); component.csrf = new CSRFServiceImpl(); ((CSRFServiceImpl) component.csrf).crypto = new CryptoServiceSingleton(CSRFServiceImplTest.SECRET, Hash.MD5, 128, Crypto.AES_CBC_ALGORITHM, 20); final Configuration configuration = mock(Configuration.class); when(configuration.getWithDefault("token.name", "csrfToken")).thenReturn("csrfToken"); ((CSRFServiceImpl) component.csrf).configuration = configuration; FakeContext ctxt = new FakeContext(); ctxt.getFakeRequest().data().put(CSRFServiceImpl.TOKEN_KEY, "token"); Context.CONTEXT.set(ctxt); IDialect dialect = component.createDialect(); assertThat(dialect.getPrefix()).isEqualToIgnoringCase("csrf"); assertThat(dialect.getProcessors()).hasSize(1); IProcessor processor = dialect.getProcessors().iterator().next(); assertThat(processor).isInstanceOf(ThymeleafCsrfDialect.CSRFElementProcessor.class); List<Node> nodes = ((ThymeleafCsrfDialect.CSRFElementProcessor) processor).getMarkupSubstitutes(null, null); assertThat(nodes).hasSize(1); assertThat(nodes.get(0)).isInstanceOf(Element.class); Element element = (Element) nodes.get(0); assertThat(element.getNormalizedName()).isEqualTo("input"); assertThat(element.getAttributeFromNormalizedName("type").getValue()).isEqualTo("hidden"); assertThat(element.getAttributeFromNormalizedName("name").getValue()).isEqualTo("csrfToken"); assertThat(element.getAttributeFromNormalizedName("value").getValue()).isEqualTo("token"); }
protected IDialect createDialect() { return new AbstractDialect() { @Override public String getPrefix() { return "csrf"; } @Override public Set<IProcessor> getProcessors() { return ImmutableSet.<IProcessor>of(new CSRFElementProcessor()); } }; }
ThymeleafCsrfDialect { protected IDialect createDialect() { return new AbstractDialect() { @Override public String getPrefix() { return "csrf"; } @Override public Set<IProcessor> getProcessors() { return ImmutableSet.<IProcessor>of(new CSRFElementProcessor()); } }; } }
ThymeleafCsrfDialect { protected IDialect createDialect() { return new AbstractDialect() { @Override public String getPrefix() { return "csrf"; } @Override public Set<IProcessor> getProcessors() { return ImmutableSet.<IProcessor>of(new CSRFElementProcessor()); } }; }  }
ThymeleafCsrfDialect { protected IDialect createDialect() { return new AbstractDialect() { @Override public String getPrefix() { return "csrf"; } @Override public Set<IProcessor> getProcessors() { return ImmutableSet.<IProcessor>of(new CSRFElementProcessor()); } }; }  @Bind(aggregate = true) void bindTemplateEngine(TemplateEngine engine); @Unbind void unbindTemplateEngine(TemplateEngine engine); }
ThymeleafCsrfDialect { protected IDialect createDialect() { return new AbstractDialect() { @Override public String getPrefix() { return "csrf"; } @Override public Set<IProcessor> getProcessors() { return ImmutableSet.<IProcessor>of(new CSRFElementProcessor()); } }; }  @Bind(aggregate = true) void bindTemplateEngine(TemplateEngine engine); @Unbind void unbindTemplateEngine(TemplateEngine engine);  }