Skip to content

Commit

Permalink
GH-2170 Allow custom authenticators to be registered (#2170)
Browse files Browse the repository at this point in the history
* Allow custom authenticators to be registered

* fix test
  • Loading branch information
xanderume authored Jul 11, 2024
1 parent d5714e5 commit 512570c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import java.util.concurrent.TimeUnit.MINUTES

class AuthenticationFacade(
private val journalist: Journalist,
private val authenticators: List<Authenticator>,
private val authenticators: MutableList<Authenticator>,
private val accessTokenFacade: AccessTokenFacade
) : Journalist, Facade {

Expand All @@ -44,6 +44,10 @@ class AuthenticationFacade(
.expireAfterAccess(1, MINUTES)
.build()

fun registerAuthenticator(authenticator: Authenticator) {
this.authenticators.add(authenticator)
}

fun authenticateByCredentials(credentials: Credentials): Result<out AccessTokenDto, ErrorResponse> =
authenticationCache.getIfPresent(credentials)
?.asSuccess()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ class AuthenticationComponents(
disableUserPasswordAuthentication = disableUserPasswordAuthentication,
)

private fun authenticators(): List<Authenticator> =
listOf(
private fun authenticators(): MutableList<Authenticator> =
arrayListOf(
basicAuthenticator(),
ldapAuthenticator()
)

fun authenticationFacade(authenticators: List<Authenticator> = authenticators()): AuthenticationFacade =
fun authenticationFacade(authenticators: MutableList<Authenticator> = authenticators()): AuthenticationFacade =
AuthenticationFacade(
journalist = journalist,
authenticators = authenticators,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal abstract class AuthenticationSpecification : AccessTokenSpecification()
fun createAuthenticationFacade() {
this.authenticationFacade = AuthenticationFacade(
journalist = logger,
authenticators = listOf(
authenticators = mutableListOf(
BasicAuthenticator(accessTokenFacade),
LdapAuthenticator(
journalist = logger,
Expand Down

0 comments on commit 512570c

Please sign in to comment.