Skip to content

Commit 0bce60e

Browse files
committed
Delete document
1 parent 39e8b30 commit 0bce60e

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ val logstashVersion = "6.6"
55
val springVersion = "2.5.5"
66
val testContainersVersion = "1.16.0"
77
val springFoxVersion = "3.0.0"
8+
val tokenValidationVersion = "1.3.9"
89

910
repositories {
1011
mavenCentral()
@@ -28,6 +29,8 @@ dependencies {
2829
implementation("org.springframework.boot:spring-boot-starter-webflux")
2930
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
3031

32+
implementation("no.nav.security:token-validation-spring:$tokenValidationVersion")
33+
3134
implementation("io.springfox:springfox-boot-starter:$springFoxVersion")
3235

3336
implementation("org.flywaydb:flyway-core")

src/main/kotlin/no/nav/klage/document/api/DocumentController.kt

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ package no.nav.klage.document.api
22

33
import io.swagger.annotations.Api
44
import io.swagger.annotations.ApiOperation
5-
import io.swagger.annotations.ApiParam
65
import no.nav.klage.document.api.views.CommentInput
76
import no.nav.klage.document.api.views.CommentView
87
import no.nav.klage.document.api.views.DocumentView
8+
import no.nav.klage.document.config.SecurityConfiguration.Companion.ISSUER_AAD
99
import no.nav.klage.document.domain.Comment
1010
import no.nav.klage.document.domain.Document
1111
import no.nav.klage.document.service.CommentService
1212
import no.nav.klage.document.service.DocumentService
1313
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
1417
import org.springframework.http.HttpHeaders
1518
import org.springframework.http.HttpStatus
1619
import org.springframework.http.MediaType
@@ -19,16 +22,19 @@ import org.springframework.web.bind.annotation.*
1922
import java.util.*
2023

2124
@RestController
25+
@ProtectedWithClaims(issuer = ISSUER_AAD)
2226
@Api(tags = ["kabal-smart-editor-api"])
2327
@RequestMapping("/documents")
2428
class DocumentController(
2529
private val documentService: DocumentService,
26-
private val commentService: CommentService
30+
private val commentService: CommentService,
31+
private val tokenValidationContextHolder: TokenValidationContextHolder
2732
) {
2833

2934
companion object {
3035
@Suppress("JAVA_CLASS_ON_COMPANION")
3136
private val logger = getLogger(javaClass.enclosingClass)
37+
private val secureLogger = getSecureLogger()
3238
}
3339

3440
@ApiOperation(
@@ -39,7 +45,8 @@ class DocumentController(
3945
fun createDocument(
4046
@RequestBody json: String
4147
): DocumentView {
42-
logger.debug("createDocument: received json: {}", json)
48+
log("createDocument")
49+
secureLogger.debug("createDocument: received json: {}", json)
4350
return mapToDocumentView(documentService.createDocument(json))
4451
}
4552

@@ -52,7 +59,8 @@ class DocumentController(
5259
@PathVariable("documentId") documentId: UUID,
5360
@RequestBody json: String
5461
): 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)
5664
return mapToDocumentView(documentService.updateDocument(documentId, json))
5765
}
5866

@@ -62,7 +70,7 @@ class DocumentController(
6270
)
6371
@GetMapping("/{documentId}")
6472
fun getDocument(@PathVariable("documentId") documentId: UUID): DocumentView {
65-
logger.debug("getDocument with id {}", documentId)
73+
log("getDocument called with id $documentId")
6674
return mapToDocumentView(documentService.getDocument(documentId))
6775
}
6876

@@ -72,7 +80,7 @@ class DocumentController(
7280
)
7381
@DeleteMapping("/{documentId}")
7482
fun deleteDocument(@PathVariable("documentId") documentId: UUID) {
75-
logger.debug("deleteDocument with id {}", documentId)
83+
log("deleteDocument called with id $documentId")
7684
documentService.deleteDocument(documentId)
7785
}
7886

@@ -85,7 +93,7 @@ class DocumentController(
8593
@PathVariable("documentId") documentId: UUID,
8694
@RequestBody commentInput: CommentInput
8795
): CommentView {
88-
logger.debug("createComment")
96+
log("createComment called with id $documentId")
8997
return mapCommentToView(
9098
commentService.createComment(
9199
documentId = documentId,
@@ -104,7 +112,7 @@ class DocumentController(
104112
fun getAllCommentsWithPossibleThreads(
105113
@PathVariable("documentId") documentId: UUID
106114
): List<CommentView> {
107-
logger.debug("getAllCommentsWithPossibleThreads")
115+
log("getAllCommentsWithPossibleThreads called with id $documentId")
108116
return commentService.getComments(documentId).map { mapCommentToView(it) }
109117
}
110118

@@ -118,7 +126,7 @@ class DocumentController(
118126
@PathVariable("commentId") commentId: UUID,
119127
@RequestBody commentInput: CommentInput,
120128
): CommentView {
121-
logger.debug("replyToComment")
129+
log("replyToComment called with id $documentId and commentId $commentId")
122130
return mapCommentToView(
123131
commentService.replyToComment(
124132
documentId = documentId,
@@ -139,7 +147,7 @@ class DocumentController(
139147
@PathVariable("documentId") documentId: UUID,
140148
@PathVariable("commentId") commentId: UUID
141149
): CommentView {
142-
logger.debug("getCommentWithPossibleThread")
150+
log("getCommentWithPossibleThread called with id $documentId and commentId $commentId")
143151
return mapCommentToView(commentService.getComment(commentId = commentId))
144152
}
145153

@@ -152,7 +160,7 @@ class DocumentController(
152160
fun getDocumentAsPDF(
153161
@PathVariable("documentId") documentId: UUID
154162
): ResponseEntity<ByteArray> {
155-
logger.debug("getDocumentAsPDF with id {}", documentId)
163+
log("getDocumentAsPDF with id : $documentId")
156164

157165
val pdfDocument = documentService.getDocumentAsPDF(documentId)
158166

@@ -187,4 +195,14 @@ class DocumentController(
187195
modified = comment.modified
188196
)
189197

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+
190208
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package no.nav.klage.document.config
2+
3+
import no.nav.security.token.support.spring.api.EnableJwtTokenValidation
4+
import org.springframework.context.annotation.Configuration
5+
6+
@EnableJwtTokenValidation(ignore = ["springfox"])
7+
@Configuration
8+
internal class SecurityConfiguration {
9+
10+
companion object {
11+
const val ISSUER_AAD = "aad"
12+
}
13+
}

0 commit comments

Comments
 (0)