Skip to content

Commit 4a95f90

Browse files
committed
add some logging in login/auth filter
1 parent 23aa945 commit 4a95f90

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/main/kotlin/ch/derlin/bbdata/output/api/apikeys/ApikeyController.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import io.swagger.v3.oas.annotations.Operation
1515
import io.swagger.v3.oas.annotations.tags.Tag
1616
import org.joda.time.DateTime
1717
import org.joda.time.MutablePeriod
18+
import org.slf4j.Logger
19+
import org.slf4j.LoggerFactory
1820
import org.springframework.http.ResponseEntity
1921
import org.springframework.web.bind.annotation.*
2022
import javax.validation.Valid
@@ -32,6 +34,8 @@ class ApikeyController(
3234
private val apikeyRepository: ApikeyRepository,
3335
private val userRepository: UserRepository) {
3436

37+
private val log: Logger = LoggerFactory.getLogger(ApikeyController::class.java)
38+
3539
class LoginBody {
3640
@NotNull
3741
val username: String? = null
@@ -64,6 +68,7 @@ class ApikeyController(
6468
expirationDate = DateTime().plus(AUTOLOGIN_EXPIRE)
6569
))
6670
}
71+
log.info("invalid login for username='${loginBody.username}' password='${loginBody.password}'")
6772
throw ForbiddenException("Wrong username or password.")
6873
}
6974

src/main/kotlin/ch/derlin/bbdata/output/security/SecurityFilter.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import ch.derlin.bbdata.output.api.apikeys.ApikeyRepository
1010
import ch.derlin.bbdata.output.security.SecurityConstants.HEADER_TOKEN
1111
import ch.derlin.bbdata.output.security.SecurityConstants.HEADER_USER
1212
import ch.derlin.bbdata.output.security.SecurityConstants.SCOPE_WRITE
13+
import org.slf4j.Logger
1314
import org.slf4j.LoggerFactory
1415
import org.springframework.beans.factory.annotation.Autowired
1516
import org.springframework.beans.factory.annotation.Value
@@ -71,6 +72,7 @@ class AuthInterceptor : HandlerInterceptor {
7172
@Autowired
7273
lateinit var apikeyRepository: ApikeyRepository
7374

75+
private val log: Logger = LoggerFactory.getLogger(AuthInterceptor::class.java)
7476

7577
override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
7678

@@ -110,12 +112,13 @@ class AuthInterceptor : HandlerInterceptor {
110112
bbuser.toIntOrNull()?.let { userId ->
111113
// check valid tokens
112114
val apikey = apikeyRepository.findValid(userId, bbtoken).orElseThrow {
115+
log.info("wrong apikey for userId=$userId token='$bbtoken'")
113116
BadApikeyException("Access denied for user $userId : bad apikey")
114117
}
115118
// check if write access is necessary
116119
if (apikey.readOnly && writeRequired) {
117120
// check write permissions
118-
throw ForbiddenException("Access denied for user $userId : this apikey is read-only")
121+
throw ForbiddenException("Access denied for user $userId: this apikey is read-only")
119122
}
120123
// every checks passed !
121124
return true

src/test/kotlin/ch/derlin/bbdata/caching/CachingTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import org.junit.jupiter.api.Test
99
import org.junit.jupiter.api.TestMethodOrder
1010
import org.junit.jupiter.api.extension.ExtendWith
1111
import org.springframework.beans.factory.annotation.Autowired
12-
import org.springframework.beans.factory.annotation.Value
1312
import org.springframework.boot.test.context.SpringBootTest
1413
import org.springframework.boot.test.web.client.TestRestTemplate
1514
import org.springframework.cache.CacheManager

0 commit comments

Comments
 (0)