|
1 | 1 | package graphql.kickstart.autoconfigure.editor.voyager; |
2 | 2 |
|
| 3 | +import static graphql.kickstart.autoconfigure.editor.EditorConstants.CSRF_ATTRIBUTE_NAME; |
| 4 | + |
3 | 5 | import java.io.IOException; |
4 | 6 | import java.util.Map; |
5 | 7 | import javax.servlet.http.HttpServletRequest; |
6 | | -import org.springframework.beans.factory.annotation.Autowired; |
| 8 | +import lombok.RequiredArgsConstructor; |
7 | 9 | import org.springframework.http.MediaType; |
8 | 10 | import org.springframework.http.ResponseEntity; |
9 | 11 | import org.springframework.stereotype.Controller; |
10 | 12 | import org.springframework.web.bind.annotation.GetMapping; |
11 | 13 | import org.springframework.web.bind.annotation.PathVariable; |
| 14 | +import org.springframework.web.bind.annotation.RequestAttribute; |
12 | 15 |
|
13 | 16 | /** @author Max David Günther */ |
14 | 17 | @Controller |
| 18 | +@RequiredArgsConstructor |
15 | 19 | public class VoyagerController { |
16 | 20 |
|
17 | | - @Autowired private VoyagerIndexHtmlTemplate indexTemplate; |
| 21 | + private final VoyagerIndexHtmlTemplate indexTemplate; |
18 | 22 |
|
19 | 23 | @GetMapping(value = "${graphql.voyager.mapping:/voyager}") |
20 | 24 | public ResponseEntity<String> voyager( |
21 | | - HttpServletRequest request, @PathVariable Map<String, String> params) throws IOException { |
| 25 | + HttpServletRequest request, |
| 26 | + final @RequestAttribute(value = CSRF_ATTRIBUTE_NAME, required = false) Object csrf, |
| 27 | + @PathVariable Map<String, String> params) |
| 28 | + throws IOException { |
22 | 29 | String contextPath = request.getContextPath(); |
23 | | - String indexHtmlContent = indexTemplate.fillIndexTemplate(contextPath, params); |
| 30 | + String indexHtmlContent = indexTemplate.fillIndexTemplate(contextPath, csrf, params); |
24 | 31 | return ResponseEntity.ok() |
25 | 32 | .contentType(MediaType.valueOf("text/html; charset=UTF-8")) |
26 | 33 | .body(indexHtmlContent); |
|
0 commit comments