package com.marklogic.samplestack.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.JsonNode;


@RestController
public class SessionController {

	@Autowired
	private JsonHttpResponse errors;
	
	@RequestMapping(value = "session", method = RequestMethod.GET)
	public @ResponseBody JsonNode hello(HttpServletRequest request) {
		return errors.makeJsonResponse(200, "New Session");
	}
}

@@ -78,16 +78,117 @@
 Request;
+%0Aimport javax.servlet.http.HttpServletResponse;%0Aimport javax.servlet.http.HttpServletResponseWrapper;
 %0A%0Aimport
@@ -244,16 +244,72 @@
 owired;%0A
+import org.springframework.security.web.csrf.CsrfToken;%0A
 import o
@@ -599,17 +599,16 @@
 nNode;%0A%0A
-%0A
 @RestCon
@@ -699,10 +699,9 @@
 rs;%0A
-%09
 %0A
+
 %09@Re
@@ -827,11 +827,344 @@
 uest
-) %7B
+,%0A%09%09%09HttpServletResponse response) %7B%0A%0A%09%09CsrfToken csrfToken = (CsrfToken) request.getAttribute(%22_csrf%22);%0A%0A%09%09String headerName = csrfToken.getHeaderName();%0A%09%09String token = csrfToken.getToken();%0A%09%09HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(%0A%09%09%09%09response);%0A%0A%09%09responseWrapper.addHeader(headerName, token);
 %0A%09%09r

put csrf header back on session