<commit_before>package es.com.blogspot.elblogdepicodev.plugintapestry.mixins;

import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.InjectContainer;
import org.apache.tapestry5.annotations.MixinAfter;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.corelib.components.ActionLink;
import org.apache.tapestry5.corelib.components.BeanEditForm;
import org.apache.tapestry5.corelib.components.EventLink;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.dom.Element;
import org.apache.tapestry5.dom.Node;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.runtime.Component;
import org.apache.tapestry5.services.Request;

import es.com.blogspot.elblogdepicodev.plugintapestry.services.sso.Sid;

@MixinAfter
public class Csrf {

	 @SessionState(create = false)
	 private Sid sid;

	 @Inject
	 private Request request;

	 @Inject
	 private ComponentResources resources;

	 @InjectContainer
	 private Component container;

	 void beginRender(MarkupWriter writer) {
		  buildSid();

		  if (container instanceof EventLink || container instanceof ActionLink) {
				Element element = writer.getElement();
				String href = element.getAttribute("href");
				String character = (href.indexOf('?') == -1) ? "?" : "&";
				element.forceAttributes("href", String.format("%s%st:sid=%s", href, character, sid.getSid()));
		  }
	 }

	 void afterRenderTemplate(MarkupWriter writer) {
		  buildSid();

		  if (container instanceof BeanEditForm) {
				Element form = null;
				for (Node node : writer.getElement().getChildren()) {
					 if (node instanceof Element) {
						  Element element = (Element) node;
						  if (element.getName().equals("form")) {
								form = element;
								break;
						  }
					 }
				}
				if (form != null) {
					 Element e = form.element("input", "type", "hidden", "name", "t:sid", "value", sid.getSid());
					 e.moveToTop(form);
				}
		  }
	 }

	 void beforeRenderBody(MarkupWriter writer) {
		  buildSid();
		  
		  if (container instanceof Form) {
				Element form = (Element) writer.getElement();
				form.element("input", "type", "hidden", "name", "t:sid", "value", sid.getSid());
		  } else if (container instanceof BeanEditForm) {
				Element form = (Element) writer.getElement();
				form.element("input", "type", "hidden", "name", "t:sid", "value", sid.getSid());
		  }
	 }
	 <commit_msg>No crear Sid en sesión a menos que sea necesario<commit_after>package es.com.blogspot.elblogdepicodev.plugintapestry.mixins;

import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.InjectContainer;
import org.apache.tapestry5.annotations.MixinAfter;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.corelib.components.ActionLink;
import org.apache.tapestry5.corelib.components.BeanEditForm;
import org.apache.tapestry5.corelib.components.EventLink;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.dom.Element;
import org.apache.tapestry5.dom.Node;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.runtime.Component;
import org.apache.tapestry5.services.Request;

import es.com.blogspot.elblogdepicodev.plugintapestry.services.sso.Sid;

@MixinAfter
public class Csrf {

	 @SessionState(create = false)
	 private Sid sid;

	 @Inject
	 private Request request;

	 @Inject
	 private ComponentResources resources;

	 @InjectContainer
	 private Component container;

	 void beginRender(MarkupWriter writer) {
		  if (container instanceof EventLink || container instanceof ActionLink) {
				buildSid();

				Element element = writer.getElement();
				String href = element.getAttribute("href");
				String character = (href.indexOf('?') == -1) ? "?" : "&";
				element.forceAttributes("href", String.format("%s%st:sid=%s", href, character, sid.getSid()));
		  }
	 }

	 void afterRenderTemplate(MarkupWriter writer) {
		  if (container instanceof BeanEditForm) {
				Element form = null;
				for (Node node : writer.getElement().getChildren()) {
					 if (node instanceof Element) {
						  Element element = (Element) node;
						  if (element.getName().equals("form")) {
								form = element;
								break;
						  }
					 }
				}
				if (form != null) {
					 buildSid();

					 Element e = form.element("input", "type", "hidden", "name", "t:sid", "value", sid.getSid());
					 e.moveToTop(form);
				}
		  }
	 }

	 void beforeRenderBody(MarkupWriter writer) {
		  if (container instanceof Form) {
				buildSid();

				Element form = (Element) writer.getElement();
				form.element("input", "type", "hidden", "name", "t:sid", "value", sid.getSid());
		  } else if (container instanceof BeanEditForm) {
				buildSid();

				Element form = (Element) writer.getElement();
				form.element("input", "type", "hidden", "name", "t:sid", "value", sid.getSid());
		  }
	 }

{'fraction_non_alphanumeric': 0.1348605577689243, 'fraction_numerical': 0.00597609561752988, 'mean_word_length': 4.061491935483871, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3755881', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1494, 'n_words': 320}