ch4mpy / spring-addons

Ease spring OAuth2 resource-servers configuration and testing
Apache License 2.0
559 stars 90 forks source link

Multitenancy with spring boot and keycloak #18

Closed tha022 closed 3 years ago

tha022 commented 3 years ago

Hi guys

I implemented multi-tenancy support for Spring Boot and Keycloak following this guide, but after that my tests doesn't run correctly anymore, I get HTTP 403.

@WithMockKeycloakAuth(
            authorities = "user",
            otherClaims = @ClaimSet(
                    stringClaims = @StringClaim(name = "ssn", value = "03058241111")
            )
    )

I tried to debug through the code described in the blog and this spring-addons lib, but didn't manage to find a clue.

Any help, advice or pointer in right direction would be highly appreciated.

Thanks in advance!

ch4mpy commented 3 years ago

Hi @tha022,

For some reason I wasn't notified when this issue was created and missed it. Sorry. Hope you found a way to solve or work around it :/

If not, would you share the security constraints you configured for the endpoint you get a 403 from ? Any reference to an Authentication impl in method signature ? Did you check at runtime you actually get a KeycloakAuthenticationToken from SecurityContext (set a break-point in a controller running in debug and inspect Authentication type and structure (when you get a 2xx, not in a test returning a 403) ?

ch4mpy commented 3 years ago

Fell like I'll never have enough feedback to investigate. Plz re-open if I'm wrong.