Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the decision strategy setting to the openid client #392

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions docs/resources/openid_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ is set to `true`.
- `exclude_session_state_from_auth_response` - (Optional) When `true`, the parameter `session_state` will not be included in OpenID Connect Authentication Response.
- `authorization` - (Optional) When this block is present, fine-grained authorization will be enabled for this client. The client's `access_type` must be `CONFIDENTIAL`, and `service_accounts_enabled` must be `true`. This block has the following arguments:
- `policy_enforcement_mode` - (Required) Dictates how policies are enforced when evaluating authorization requests. Can be one of `ENFORCING`, `PERMISSIVE`, or `DISABLED`.
- `decision_strategy` - (Optional) Dictates how the policies associated with a given permission are evaluated and how a final decision is obtained. Could be one of `AFFIRMATIVE`, `CONSENSUS`, or `UNANIMOUS`. Applies to permissions.
- `allow_remote_resource_management` - (Optional) When `true`, resources can be managed remotely by the resource server. Defaults to `false`.
- `keep_defaults` - (Optional) When `true`, defaults set by Keycloak will be respected. Defaults to `false`.

Expand Down
1 change: 1 addition & 0 deletions keycloak/openid_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type OpenidClientSecret struct {

type OpenidClientAuthorizationSettings struct {
PolicyEnforcementMode string `json:"policyEnforcementMode,omitempty"`
DecisionStrategy string `json:"decisionStrategy,omitempty"`
AllowRemoteResourceManagement bool `json:"allowRemoteResourceManagement,omitempty"`
KeepDefaults bool `json:"-"`
}
Expand Down
4 changes: 4 additions & 0 deletions provider/data_source_keycloak_openid_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func dataSourceKeycloakOpenidClient() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"decision_strategy": {
Type: schema.TypeString,
Computed: true,
},
"allow_remote_resource_management": {
Type: schema.TypeBool,
Computed: true,
Expand Down
17 changes: 13 additions & 4 deletions provider/resource_keycloak_openid_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ package provider
import (
"errors"
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/mrparkers/terraform-provider-keycloak/keycloak"
"strings"
)

var (
keycloakOpenidClientAccessTypes = []string{"CONFIDENTIAL", "PUBLIC", "BEARER-ONLY"}
keycloakOpenidClientAuthorizationPolicyEnforcementMode = []string{"ENFORCING", "PERMISSIVE", "DISABLED"}
keycloakOpenidClientPkceCodeChallengeMethod = []string{"", "plain", "S256"}
keycloakOpenidClientAccessTypes = []string{"CONFIDENTIAL", "PUBLIC", "BEARER-ONLY"}
keycloakOpenidClientAuthorizationPolicyEnforcementMode = []string{"ENFORCING", "PERMISSIVE", "DISABLED"}
keycloakOpenidClientResourcePermissionDecisionStrategies = []string{"UNANIMOUS", "AFFIRMATIVE", "CONSENSUS"}
keycloakOpenidClientPkceCodeChallengeMethod = []string{"", "plain", "S256"}
)

func resourceKeycloakOpenidClient() *schema.Resource {
Expand Down Expand Up @@ -136,6 +138,12 @@ func resourceKeycloakOpenidClient() *schema.Resource {
Required: true,
ValidateFunc: validation.StringInSlice(keycloakOpenidClientAuthorizationPolicyEnforcementMode, false),
},
"decision_strategy": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(keycloakOpenidClientResourcePermissionDecisionStrategies, false),
Default: "UNANIMOUS",
},
"allow_remote_resource_management": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -274,6 +282,7 @@ func getOpenidClientFromData(data *schema.ResourceData) (*keycloak.OpenidClient,
authorizationSettings := authorizationSettingsData.(map[string]interface{})
openidClient.AuthorizationSettings = &keycloak.OpenidClientAuthorizationSettings{
PolicyEnforcementMode: authorizationSettings["policy_enforcement_mode"].(string),
DecisionStrategy: authorizationSettings["decision_strategy"].(string),
AllowRemoteResourceManagement: authorizationSettings["allow_remote_resource_management"].(bool),
KeepDefaults: authorizationSettings["keep_defaults"].(bool),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
)

var (
keycloakOpenidClientResourcePermissionDecisionStrategies = []string{"UNANIMOUS", "AFFIRMATIVE", "CONSENSUS"}
keycloakOpenidClientPermissionTypes = []string{"resource", "scope"}
keycloakOpenidClientPermissionTypes = []string{"resource", "scope"}
)

func resourceKeycloakOpenidClientAuthorizationPermission() *schema.Resource {
Expand Down