PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/server/zanata-war/src/main/java/org/zanata/security/FixedClientUidSelector.java

https://code.google.com/p/flies/
Java | 64 lines | 47 code | 10 blank | 7 comment | 3 complexity | 2648fa5a6c8424cb1c2fd1b4a28e389e MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause
  1. package org.zanata.security;
  2. import javax.faces.context.FacesContext;
  3. import org.jboss.seam.annotations.Create;
  4. import org.jboss.seam.annotations.Install;
  5. import org.jboss.seam.annotations.Name;
  6. import org.jboss.seam.ui.ClientUidSelector;
  7. import org.jboss.seam.util.RandomStringUtils;
  8. @Name("org.jboss.seam.ui.clientUidSelector")
  9. @Install(precedence = Install.DEPLOYMENT)
  10. /**
  11. * Workaround for https://jira.jboss.org/browse/JBSEAM-4503
  12. * supplied by "wolfgang geck" in
  13. * http://seamframework.org/Community/SeamTokenTagProblemCSRF#comment110227
  14. */
  15. public class FixedClientUidSelector extends ClientUidSelector
  16. {
  17. private static final long serialVersionUID = -4923235748771706010L;
  18. private String clientUid;
  19. @Create
  20. public void onCreate()
  21. {
  22. String requestContextPath = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
  23. // workaround for https://issues.jboss.org/browse/JBSEAM-4701
  24. if (requestContextPath.isEmpty()) {
  25. requestContextPath = "/";
  26. }
  27. setCookiePath(requestContextPath);
  28. setCookieMaxAge(-1);
  29. setCookieEnabled(true);
  30. clientUid = getCookieValue();
  31. }
  32. public void seed()
  33. {
  34. if (!isSet())
  35. {
  36. // workaround for https://issues.jboss.org/browse/JBSEAM-4503
  37. clientUid = RandomStringUtils.random(50, true, true); // Fixed
  38. setCookieValueIfEnabled(clientUid);
  39. }
  40. }
  41. public boolean isSet()
  42. {
  43. return clientUid != null;
  44. }
  45. public String getClientUid()
  46. {
  47. return clientUid;
  48. }
  49. @Override
  50. protected String getCookieName()
  51. {
  52. return "javax.faces.ClientToken";
  53. }
  54. }