Skip to content

Commit dfcaf3d

Browse files
committed
Make LoginAuditService creation unconditional
1 parent bda6a0d commit dfcaf3d

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/main/kotlin/fi/hsl/jore4/auth/audit/LoginAuditService.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@ package fi.hsl.jore4.auth.audit
22

33
import org.slf4j.Logger
44
import org.slf4j.LoggerFactory
5-
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
5+
import org.springframework.beans.factory.annotation.Autowired
66
import org.springframework.stereotype.Service
77
import org.springframework.transaction.annotation.Transactional
88

99
/**
1010
* Service for logging login events.
11-
* Only enabled when JPA is available.
1211
*/
1312
@Service
14-
@ConditionalOnBean(LoginAuditRepository::class)
1513
open class LoginAuditService(
16-
private val loginAuditRepository: LoginAuditRepository
14+
@Autowired(required = false)
15+
private val loginAuditRepository: LoginAuditRepository?
1716
) {
1817
companion object {
1918
private val LOGGER: Logger = LoggerFactory.getLogger(LoginAuditService::class.java)
@@ -27,6 +26,11 @@ open class LoginAuditService(
2726
userId: String,
2827
userName: String?
2928
) {
29+
if (loginAuditRepository == null) {
30+
LOGGER.warn("LoginAuditRepository is not available, cannot record login")
31+
return
32+
}
33+
3034
try {
3135
val auditRecord =
3236
LoginAudit(

0 commit comments

Comments
 (0)