Close Hikari CP around external auth database on shutdown (RPCSecurityManagerImpl.kt) (#2359)

This commit is contained in:
igor nitto 2018-01-15 09:57:44 +00:00 committed by GitHub
parent fb1d3087de
commit 2082168cf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,6 +25,7 @@ import org.apache.shiro.realm.AuthorizingRealm
import org.apache.shiro.realm.jdbc.JdbcRealm
import org.apache.shiro.subject.PrincipalCollection
import org.apache.shiro.subject.SimplePrincipalCollection
import java.io.Closeable
import javax.security.auth.login.FailedLoginException
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.TimeUnit
@ -43,10 +44,6 @@ class RPCSecurityManagerImpl(config: AuthServiceConfig) : RPCSecurityManager {
manager = buildImpl(config)
}
override fun close() {
manager.destroy()
}
@Throws(FailedLoginException::class)
override fun authenticate(principal: String, password: Password): AuthorizingSubject {
password.use {
@ -67,6 +64,10 @@ class RPCSecurityManagerImpl(config: AuthServiceConfig) : RPCSecurityManager {
subjectId = SimplePrincipalCollection(principal, id.value),
manager = manager)
override fun close() {
manager.realms?.filterIsInstance<Closeable>()?.forEach { it.close() }
manager.destroy()
}
companion object {
@ -240,7 +241,7 @@ private class InMemoryRealm(users: List<User>,
authorizationInfoByUser[principals.primaryPrincipal as String]
}
private class NodeJdbcRealm(config: SecurityConfiguration.AuthService.DataSource) : JdbcRealm() {
private class NodeJdbcRealm(config: SecurityConfiguration.AuthService.DataSource) : JdbcRealm(), Closeable {
init {
credentialsMatcher = buildCredentialMatcher(config.passwordEncryption)
@ -248,6 +249,10 @@ private class NodeJdbcRealm(config: SecurityConfiguration.AuthService.DataSource
dataSource = HikariDataSource(HikariConfig(config.connection!!))
permissionResolver = RPCPermissionResolver
}
override fun close() {
(dataSource as? Closeable)?.close()
}
}
private typealias ShiroCache<K, V> = org.apache.shiro.cache.Cache<K, V>