-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vet Service: adds infrastructure.config.security.CustomIdTokenClaimsV…
…alidator Temporal workaround suggested in (micronaut-projects/micronaut-security#1543)
- Loading branch information
1 parent
926390d
commit d1274ee
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...aaregall/lab/petclinic/vet/infrastructure/config/security/CustomIdTokenClaimsValidator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package tech.aaregall.lab.petclinic.vet.infrastructure.config.security | ||
|
||
import io.micronaut.context.annotation.Replaces | ||
import io.micronaut.security.oauth2.client.IdTokenClaimsValidator | ||
import io.micronaut.security.oauth2.configuration.OauthClientConfiguration | ||
import io.micronaut.security.token.Claims | ||
import jakarta.inject.Singleton | ||
|
||
/** | ||
* Custom claim validator to not restrict azp to clientId | ||
* See https://github.com/micronaut-projects/micronaut-security/issues/1543 | ||
*/ | ||
@Singleton | ||
@Replaces(IdTokenClaimsValidator::class) | ||
class CustomIdTokenClaimsValidator<T>(oauthClientConfigurations: Collection<OauthClientConfiguration>): IdTokenClaimsValidator<T>(oauthClientConfigurations) { | ||
|
||
override fun validateAzp(claims: Claims, clientId: String, audiences: MutableList<String>): Boolean { | ||
if (audiences.size < 2) { | ||
return true | ||
} | ||
return parseAzpClaim(claims) | ||
.filter { clientId.equals(it, ignoreCase = true) || audiences.containsIgnoreCase(it) } | ||
.isPresent | ||
} | ||
|
||
} | ||
|
||
private fun List<String>.containsIgnoreCase(element: String): Boolean { | ||
return this.any { it.equals(element, ignoreCase = true) } | ||
} |