Annotation Interface WithMockKeycloakAuth
@Target({METHOD,TYPE})
@Retention(RUNTIME)
@Inherited
@Documented
@WithSecurityContext(factory=Factory.class)
public @interface WithMockKeycloakAuth
Annotation to setup test SecurityContext with an KeycloakAuthenticationToken, the Keycloak default Authentication
You should use "authorities" properties with already transformed roles (aka with ROLE_ prefix, uppercase transformation or whatever). Realm and resource access configuration should be reserved to what is not authorities related.
Minimal effort to map realm and resource accesses (all of it, not just one) roles to authorities is made but application configured authorities mappers are not called (roles are not transformed at all).
impl Sample usage:
@Test
@WithMockKeycloakAuth(
authorities = { "USER", "AUTHORIZED_PERSONNEL" },
oidc = @OidcStandardClaims(
sub = "42",
email = "ch4mp@c4-soft.com",
emailVerified = true,
nickName = "Tonton-Pirate",
preferredUsername = "ch4mpy",
otherClaims = @ClaimSet(stringClaims = @StringClaim(name = "foo", value = "bar"))),
)
public void test() {
...
}
- Author:
- Jérôme Wacongne <ch4mp@c4-soft.com>
-
Element Details
-
value
- Default:
- {"offline_access", "uma_authorization"}
-
authorities
- Default:
- {"offline_access", "uma_authorization"}
-
accessToken
KeycloakAccessToken accessToken- Default:
- @com.c4_soft.springaddons.security.oauth2.test.annotations.keycloak.KeycloakAccessToken
-
claims
OpenIdClaims claims- Default:
- @com.c4_soft.springaddons.security.oauth2.test.annotations.OpenIdClaims
-
isInteractive
boolean isInteractive- Default:
- false
-
setupBefore
@AliasFor(annotation=org.springframework.security.test.context.support.WithSecurityContext.class) org.springframework.security.test.context.support.TestExecutionEvent setupBefore- Default:
- TEST_METHOD
-