Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 7 additions & 32 deletions lib/fixtures/keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ func setupKeycloakWithConfig(ctx context.Context, kcConnectParams KeycloakConnec
if _, err := client.CreateRealm(ctx, token.AccessToken, realm); err != nil {
return err
}
//nolint:sloglint // allow existing emojis
slog.Info("✅ realm created", slog.String("realm", kcConnectParams.Realm))

// update realm users profile via upconfig
Expand All @@ -184,10 +183,8 @@ func setupKeycloakWithConfig(ctx context.Context, kcConnectParams KeycloakConnec
if err != nil {
return err
}
//nolint:sloglint // allow existing emojis
slog.Info("✅ realm users profile updated", slog.String("realm", kcConnectParams.Realm))
} else {
//nolint:sloglint // allow existing emojis
slog.Info("⏭️ realm already exists", slog.String("realm", kcConnectParams.Realm))
}

Expand All @@ -211,13 +208,11 @@ func setupKeycloakWithConfig(ctx context.Context, kcConnectParams KeycloakConnec
if err != nil {
switch kcErrCode(err) {
case http.StatusConflict:
//nolint:sloglint // allow existing emojis
slog.Warn("⏭️ role already exists", slog.String("role", role))
default:
return err
}
} else {
//nolint:sloglint // allow existing emojis
slog.Info("✅ role created", slog.String("role", role))
}
}
Expand All @@ -233,7 +228,6 @@ func setupKeycloakWithConfig(ctx context.Context, kcConnectParams KeycloakConnec
return err
}

//nolint:sloglint // allow existing emojis
slog.Info("✅ roles found", slog.Int("count", len(realmRoles)))
for _, role := range realmRoles {
switch *role.Name {
Expand Down Expand Up @@ -277,7 +271,7 @@ func setupKeycloakWithConfig(ctx context.Context, kcConnectParams KeycloakConnec
Name: gocloak.StringP("testscope"),
Description: gocloak.StringP("a scope for testing"),
Protocol: gocloak.StringP("openid-connect"),
ClientScopeAttributes: &gocloak.ClientScopeAttributes{IncludeInTokenScope: gocloak.StringP("true")},
ClientScopeAttributes: &gocloak.ClientScopeAttributes{IncludeInTokenScope: gocloak.StringP(keycloakBoolTrue)},
}

testScopeID, err = client.CreateClientScope(ctx, token.AccessToken, kcConnectParams.Realm, *testScope)
Expand Down Expand Up @@ -402,8 +396,8 @@ func defaultProtocolMappers(audience string, includeCustomDPoPMapper bool) []goc
Config: &map[string]string{
"included.client.audience": audience,
"included.custom.audience": "custom_audience",
"access.token.claim": "true",
"id.token.claim": "true",
"access.token.claim": keycloakBoolTrue,
"id.token.claim": keycloakBoolTrue,
},
},
}
Expand All @@ -414,9 +408,9 @@ func defaultProtocolMappers(audience string, includeCustomDPoPMapper bool) []goc
ProtocolMapper: gocloak.StringP("virtru-oidc-protocolmapper"),
Config: &map[string]string{
"claim.name": "tdf_claims",
"client.dpop": "true",
"tdf_claims.enabled": "true",
"access.token.claim": "true",
"client.dpop": keycloakBoolTrue,
"tdf_claims.enabled": keycloakBoolTrue,
"access.token.claim": keycloakBoolTrue,
"client.publickey": "X-VirtruPubKey",
},
})
Expand Down Expand Up @@ -713,10 +707,8 @@ func createRealmWithTokenManager(ctx context.Context, kcConnectParams KeycloakCo
if _, err := client.CreateRealm(ctx, token.AccessToken, realm); err != nil {
return err
}
//nolint:sloglint // allow existing emojis
slog.Info("✅ realm created", slog.String("realm", *realm.Realm))
} else {
//nolint:sloglint // allow existing emojis
slog.Info("⏭️ realm already exists", slog.String("realm", *realm.Realm))
}

Expand All @@ -737,7 +729,6 @@ func createRealmWithTokenManager(ctx context.Context, kcConnectParams KeycloakCo
if err != nil {
return err
}
//nolint:sloglint // allow existing emojis
slog.Info("✅ realm users profile updated", slog.String("realm", *realm.Realm))

return nil
Expand All @@ -759,13 +750,11 @@ func createGroup(ctx context.Context, tm *TokenManager, realmName string, group
if err != nil {
kcErr := err.(*gocloak.APIError) //nolint:errcheck,errorlint,forcetypeassert // kc error checked below
if kcErr.Code == http.StatusConflict {
//nolint:sloglint // allow existing emojis
slog.Warn("⏭️ group already exists", slog.String("group", *group.Name))
} else {
return err
}
} else {
//nolint:sloglint // allow existing emojis
slog.Info("✅ group created", slog.String("group", *group.Name))
}
return nil
Expand All @@ -787,13 +776,11 @@ func createRealmRole(ctx context.Context, tm *TokenManager, realmName string, ro
if err != nil {
kcErr := err.(*gocloak.APIError) //nolint:errcheck,errorlint,forcetypeassert // kc error checked below
if kcErr.Code == http.StatusConflict {
//nolint:sloglint // allow existing emojis
slog.Warn("⏭️ role already exists", slog.String("role", *role.Name))
} else {
return err
}
} else {
//nolint:sloglint // allow existing emojis
slog.Info("✅ role created", slog.String("role", *role.Name))
}
return nil
Expand Down Expand Up @@ -824,15 +811,13 @@ func createClientRole(ctx context.Context, tm *TokenManager, realmName string, c
if err != nil {
kcErr := err.(*gocloak.APIError) //nolint:errcheck,errorlint,forcetypeassert // kc error checked below
if kcErr.Code == http.StatusConflict {
//nolint:sloglint // allow existing emojis
slog.Warn("⏭️ role already exists for client",
slog.String("role", *role.Name),
slog.String("client_id", clientID))
} else {
return err
}
} else {
//nolint:sloglint // allow existing emojis
slog.Info("✅ client role created",
slog.String("client_id", clientID),
slog.String("role", *role.Name))
Expand All @@ -855,7 +840,6 @@ func createClient(ctx context.Context, tm *TokenManager, connectParams *Keycloak
if err != nil {
switch kcErrCode(err) {
case http.StatusConflict:
//nolint:sloglint // allow existing emojis
slog.Warn("⏭️ client already exists", slog.String("client_id", clientID))
clients, err := client.GetClients(ctx, token.AccessToken, connectParams.Realm, gocloak.GetClientsParams{ClientID: newClient.ClientID})
if err != nil {
Expand All @@ -874,7 +858,6 @@ func createClient(ctx context.Context, tm *TokenManager, connectParams *Keycloak
return "", err
}
} else {
//nolint:sloglint // allow existing emojis
slog.Info("✅ client created",
slog.String("client_id", clientID),
slog.String("client_identifier", longClientID))
Expand All @@ -895,7 +878,6 @@ func createClient(ctx context.Context, tm *TokenManager, connectParams *Keycloak
slog.String("username", *user.Username))

if realmRoles != nil {
//nolint:sloglint // allow existing emojis
slog.Info("⏭️ adding realm roles to client via service account",
slog.String("client_id", longClientID),
slog.String("username", *user.Username))
Expand All @@ -906,14 +888,12 @@ func createClient(ctx context.Context, tm *TokenManager, connectParams *Keycloak
return "", err
}
for _, role := range realmRoles {
//nolint:sloglint // allow existing emojis
slog.Info("✅ realm role added to client",
slog.String("role", *role.Name),
slog.String("client_id", longClientID))
}
}
if clientRoles != nil {
//nolint:sloglint // allow existing emojis
slog.Info("⏭️ adding client roles to client via service account",
slog.String("client_id", longClientID),
slog.String("username", *user.Username))
Expand All @@ -925,7 +905,6 @@ func createClient(ctx context.Context, tm *TokenManager, connectParams *Keycloak
return "", err
}
for _, role := range roles {
//nolint:sloglint // allow existing emojis
slog.Info("✅ client role added to client",
slog.String("role", *role.Name),
slog.String("client_id", longClientID))
Expand Down Expand Up @@ -971,7 +950,6 @@ func createUser(ctx context.Context, tm *TokenManager, connectParams *KeycloakCo
return nil, fmt.Errorf("error, multiple users found with username %s", username)
}
} else {
//nolint:sloglint // allow existing emojis
slog.Info("✅ user created",
slog.String("username", username),
slog.String("user_identifier", longUserID))
Expand Down Expand Up @@ -1016,7 +994,6 @@ func createUser(ctx context.Context, tm *TokenManager, connectParams *KeycloakCo
return nil, err
}
for _, role := range clientRoles {
//nolint:sloglint // allow existing emojis
slog.Info("✅ client role added to user",
slog.String("role", *role.Name),
slog.String("user_id", longUserID))
Expand Down Expand Up @@ -1195,7 +1172,7 @@ func withClientAudienceMapper(client gocloak.Client, audience string) gocloak.Cl
ProtocolMapper: gocloak.StringP(oidcAudienceMapper),
Config: &map[string]string{
"included.client.audience": audience,
"access.token.claim": "true",
"access.token.claim": keycloakBoolTrue,
},
})
client.ProtocolMappers = &mappers
Expand Down Expand Up @@ -1235,7 +1212,6 @@ func createCertExchange(ctx context.Context, connectParams *KeycloakConnectParam
}); err != nil {
switch kcErrCode(err) {
case http.StatusConflict:
//nolint:sloglint // allow existing emojis
slog.Warn("⏭️ authentication flow already exists; skipping remainder of cert exchange creation", slog.String("flow_name", topLevelFlowName))
return nil
default:
Expand Down Expand Up @@ -1340,7 +1316,6 @@ func createCertExchange(ctx context.Context, connectParams *KeycloakConnectParam
return err
}

//nolint:sloglint // allow existing emojis
slog.Info("✅ created Cert Exchange Authentication",
slog.String("flow_id", *flowID),
)
Expand Down
Loading