@@ -2,15 +2,18 @@ package no.nav.klage.document.api
2
2
3
3
import io.swagger.annotations.Api
4
4
import io.swagger.annotations.ApiOperation
5
- import io.swagger.annotations.ApiParam
6
5
import no.nav.klage.document.api.views.CommentInput
7
6
import no.nav.klage.document.api.views.CommentView
8
7
import no.nav.klage.document.api.views.DocumentView
8
+ import no.nav.klage.document.config.SecurityConfiguration.Companion.ISSUER_AAD
9
9
import no.nav.klage.document.domain.Comment
10
10
import no.nav.klage.document.domain.Document
11
11
import no.nav.klage.document.service.CommentService
12
12
import no.nav.klage.document.service.DocumentService
13
13
import no.nav.klage.document.util.getLogger
14
+ import no.nav.klage.document.util.getSecureLogger
15
+ import no.nav.security.token.support.core.api.ProtectedWithClaims
16
+ import no.nav.security.token.support.core.context.TokenValidationContextHolder
14
17
import org.springframework.http.HttpHeaders
15
18
import org.springframework.http.HttpStatus
16
19
import org.springframework.http.MediaType
@@ -19,16 +22,19 @@ import org.springframework.web.bind.annotation.*
19
22
import java.util.*
20
23
21
24
@RestController
25
+ @ProtectedWithClaims(issuer = ISSUER_AAD )
22
26
@Api(tags = [" kabal-smart-editor-api" ])
23
27
@RequestMapping(" /documents" )
24
28
class DocumentController (
25
29
private val documentService : DocumentService ,
26
- private val commentService : CommentService
30
+ private val commentService : CommentService ,
31
+ private val tokenValidationContextHolder : TokenValidationContextHolder
27
32
) {
28
33
29
34
companion object {
30
35
@Suppress(" JAVA_CLASS_ON_COMPANION" )
31
36
private val logger = getLogger(javaClass.enclosingClass)
37
+ private val secureLogger = getSecureLogger()
32
38
}
33
39
34
40
@ApiOperation(
@@ -39,7 +45,8 @@ class DocumentController(
39
45
fun createDocument (
40
46
@RequestBody json : String
41
47
): DocumentView {
42
- logger.debug(" createDocument: received json: {}" , json)
48
+ log(" createDocument" )
49
+ secureLogger.debug(" createDocument: received json: {}" , json)
43
50
return mapToDocumentView(documentService.createDocument(json))
44
51
}
45
52
@@ -52,7 +59,8 @@ class DocumentController(
52
59
@PathVariable(" documentId" ) documentId : UUID ,
53
60
@RequestBody json : String
54
61
): DocumentView {
55
- logger.debug(" updateDocument with id {}: received json: {}" , documentId, json)
62
+ log(" updateDocument called with id $documentId " )
63
+ secureLogger.debug(" updateDocument with id {}: received json: {}" , documentId, json)
56
64
return mapToDocumentView(documentService.updateDocument(documentId, json))
57
65
}
58
66
@@ -62,7 +70,7 @@ class DocumentController(
62
70
)
63
71
@GetMapping(" /{documentId}" )
64
72
fun getDocument (@PathVariable(" documentId" ) documentId : UUID ): DocumentView {
65
- logger.debug (" getDocument with id {} " , documentId)
73
+ log (" getDocument called with id $ documentId" )
66
74
return mapToDocumentView(documentService.getDocument(documentId))
67
75
}
68
76
@@ -72,7 +80,7 @@ class DocumentController(
72
80
)
73
81
@DeleteMapping(" /{documentId}" )
74
82
fun deleteDocument (@PathVariable(" documentId" ) documentId : UUID ) {
75
- logger.debug (" deleteDocument with id {} " , documentId)
83
+ log (" deleteDocument called with id $ documentId" )
76
84
documentService.deleteDocument(documentId)
77
85
}
78
86
@@ -85,7 +93,7 @@ class DocumentController(
85
93
@PathVariable(" documentId" ) documentId : UUID ,
86
94
@RequestBody commentInput : CommentInput
87
95
): CommentView {
88
- logger.debug (" createComment" )
96
+ log (" createComment called with id $documentId " )
89
97
return mapCommentToView(
90
98
commentService.createComment(
91
99
documentId = documentId,
@@ -104,7 +112,7 @@ class DocumentController(
104
112
fun getAllCommentsWithPossibleThreads (
105
113
@PathVariable(" documentId" ) documentId : UUID
106
114
): List <CommentView > {
107
- logger.debug (" getAllCommentsWithPossibleThreads" )
115
+ log (" getAllCommentsWithPossibleThreads called with id $documentId " )
108
116
return commentService.getComments(documentId).map { mapCommentToView(it) }
109
117
}
110
118
@@ -118,7 +126,7 @@ class DocumentController(
118
126
@PathVariable(" commentId" ) commentId : UUID ,
119
127
@RequestBody commentInput : CommentInput ,
120
128
): CommentView {
121
- logger.debug (" replyToComment" )
129
+ log (" replyToComment called with id $documentId and commentId $commentId " )
122
130
return mapCommentToView(
123
131
commentService.replyToComment(
124
132
documentId = documentId,
@@ -139,7 +147,7 @@ class DocumentController(
139
147
@PathVariable(" documentId" ) documentId : UUID ,
140
148
@PathVariable(" commentId" ) commentId : UUID
141
149
): CommentView {
142
- logger.debug (" getCommentWithPossibleThread" )
150
+ log (" getCommentWithPossibleThread called with id $documentId and commentId $commentId " )
143
151
return mapCommentToView(commentService.getComment(commentId = commentId))
144
152
}
145
153
@@ -152,7 +160,7 @@ class DocumentController(
152
160
fun getDocumentAsPDF (
153
161
@PathVariable(" documentId" ) documentId : UUID
154
162
): ResponseEntity <ByteArray > {
155
- logger.debug (" getDocumentAsPDF with id {} " , documentId)
163
+ log (" getDocumentAsPDF with id : $ documentId" )
156
164
157
165
val pdfDocument = documentService.getDocumentAsPDF(documentId)
158
166
@@ -187,4 +195,14 @@ class DocumentController(
187
195
modified = comment.modified
188
196
)
189
197
198
+ private fun log (message : String ) {
199
+ logger.debug(message)
200
+ secureLogger.debug(" {}. On-behalf-of: {}" , message, getIdent())
201
+ }
202
+
203
+ fun getIdent (): String =
204
+ tokenValidationContextHolder.tokenValidationContext.getJwtToken(ISSUER_AAD )
205
+ .jwtTokenClaims?.get(" NAVident" )?.toString()
206
+ ? : throw RuntimeException (" Ident not found in token" )
207
+
190
208
}
0 commit comments