Fix credentials precedence over introspector in Kotlin

Fixes: gh-7878
This commit is contained in:
Eleftheria Stein
2020-02-06 11:01:42 +01:00
parent 1fed688f05
commit 8c0b754a49
2 changed files with 53 additions and 3 deletions

View File

@@ -138,6 +138,41 @@ class OpaqueTokenDslTests {
}
}
@Test
fun `opaque token when custom introspector set after client credentials then introspector used`() {
this.spring.register(IntrospectorAfterClientCredentialsConfig::class.java, AuthenticationController::class.java).autowire()
`when`(IntrospectorAfterClientCredentialsConfig.INTROSPECTOR.introspect(ArgumentMatchers.anyString()))
.thenReturn(DefaultOAuth2AuthenticatedPrincipal(mapOf(Pair(JwtClaimNames.SUB, "mock-subject")), emptyList()))
this.mockMvc.get("/authenticated") {
header("Authorization", "Bearer token")
}
verify(IntrospectorAfterClientCredentialsConfig.INTROSPECTOR).introspect("token")
}
@EnableWebSecurity
open class IntrospectorAfterClientCredentialsConfig : WebSecurityConfigurerAdapter() {
companion object {
var INTROSPECTOR: OpaqueTokenIntrospector = mock(OpaqueTokenIntrospector::class.java)
}
override fun configure(http: HttpSecurity) {
http {
authorizeRequests {
authorize(anyRequest, authenticated)
}
oauth2ResourceServer {
opaqueToken {
introspectionUri = "/introspect"
introspectionClientCredentials("clientId", "clientSecret")
introspector = INTROSPECTOR
}
}
}
}
}
@RestController
class AuthenticationController {
@GetMapping("/authenticated")