You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CsrfButtonConnector.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.widgetset.client.csrf;
  17. import java.util.logging.Level;
  18. import java.util.logging.Logger;
  19. import com.google.gwt.core.shared.GWT;
  20. import com.google.gwt.event.dom.client.ClickEvent;
  21. import com.google.gwt.event.dom.client.ClickHandler;
  22. import com.vaadin.client.ui.AbstractComponentConnector;
  23. import com.vaadin.client.ui.VButton;
  24. import com.vaadin.shared.ui.Connect;
  25. import com.vaadin.tests.widgetset.client.MockApplicationConnection;
  26. import com.vaadin.tests.widgetset.server.csrf.CsrfButton;
  27. /**
  28. * Dummy connector to test our CSRF bug. See #14111.
  29. *
  30. * @author Vaadin Ltd
  31. */
  32. @SuppressWarnings("serial")
  33. @Connect(CsrfButton.class)
  34. public class CsrfButtonConnector extends AbstractComponentConnector {
  35. static Logger logger = Logger
  36. .getLogger(CsrfButtonConnector.class.getName());
  37. static {
  38. logger.setLevel(Level.ALL);
  39. }
  40. @Override
  41. public VButton getWidget() {
  42. return (VButton) super.getWidget();
  43. }
  44. @Override
  45. protected VButton createWidget() {
  46. return GWT.create(VButton.class);
  47. }
  48. public final static String ID = "CsrfButton";
  49. @Override
  50. public void init() {
  51. super.init();
  52. getWidget().getElement().setId(ID);
  53. getWidget().setText(csrfTokenInfo());
  54. getWidget().addClickHandler(new ClickHandler() {
  55. @Override
  56. public void onClick(ClickEvent event) {
  57. getWidget().setText(csrfTokenInfo());
  58. }
  59. });
  60. }
  61. private String csrfTokenInfo() {
  62. return getMockConnection().getServerMessageHandler().getCsrfToken()
  63. + ", " + getMockConnection().getLastCsrfTokenReceiver() + ", "
  64. + getMockConnection().getLastCsrfTokenSent();
  65. }
  66. private MockApplicationConnection getMockConnection() {
  67. return (MockApplicationConnection) getConnection();
  68. }
  69. }