Skip to content

Commit 375c652

Browse files
Fix potential inconsistent result errors when using certain OGNL expressions (#499)
* Initial basic fix for escaped OGNL * Remove unneeded error return from ClientStruct method * Add tests to cover escaped OGNL expressions * Mark locations that need to have json Unmarshal removed * Remove json unmarshal from attribute_sources client struct build * Remove json Unmarshal from issuance_criteria Client Struct build * Remove json Unmarshal from oauth_token_exchange_token_generator_mapping CRUD * Remove unnecessary error return from common methods * Generate client struct build logic for policy actions * Changelog
1 parent f1aa7c6 commit 375c652

File tree

32 files changed

+420
-606
lines changed

32 files changed

+420
-606
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Fixed plan validation logic in various resources that did not correctly handle unknown values, such as values that depend on the output of another resource. ([#488](https://github.com/pingidentity/terraform-provider-pingfederate/pull/488))
55
* Fixed missing `false` default for `pingfederate_incoming_proxy_settings.enable_client_cert_header_auth`. ([#494](https://github.com/pingidentity/terraform-provider-pingfederate/pull/494))
66
* Fixed the `encrypted_value` fields of sensitive configuration fields not being correctly written to state. ([#497](https://github.com/pingidentity/terraform-provider-pingfederate/pull/497))
7+
* Fixed potential inconsistent result errors when using certain escaped OGNL expressions in resource configuration. ([#499](https://github.com/pingidentity/terraform-provider-pingfederate/pull/499))
78

89
# v1.4.4 April 8, 2025
910
### Bug fixes

internal/acctest/config/authenticationpolicies/fragments/authentication_policies_fragment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ resource "pingfederate_authentication_policies_fragment" "%[1]s" {
224224
source = {
225225
type = "EXPRESSION"
226226
},
227-
value = "fullName"
227+
value = "'test1|test2|test3'.split(\"\\\\|\")[1]"
228228
}
229229
"photo" : {
230230
source = {

internal/acctest/config/oauth/accesstokenmapping/oauth_access_token_mapping_resource_gen_test.go

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/acctest/config/sp/idpconnection/sp_idp_connection_resource_gen_inbound_provisioning_test.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/resource/common/attributecontractfulfillment/attribute_contract_fulfillment_client_struct.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@
33
package attributecontractfulfillment
44

55
import (
6-
"encoding/json"
7-
86
"github.com/hashicorp/terraform-plugin-framework/types"
97
client "github.com/pingidentity/pingfederate-go-client/v1220/configurationapi"
10-
internaljson "github.com/pingidentity/terraform-provider-pingfederate/internal/json"
118
)
129

13-
func ClientStruct(attributeContractFulfillmentAttr types.Map) (map[string]client.AttributeFulfillmentValue, error) {
10+
func ClientStruct(attributeContractFulfillmentAttr types.Map) map[string]client.AttributeFulfillmentValue {
1411
attributeContractFulfillment := map[string]client.AttributeFulfillmentValue{}
15-
attributeContractFulfillmentErr := json.Unmarshal([]byte(internaljson.FromValue(attributeContractFulfillmentAttr, false)), &attributeContractFulfillment)
16-
return attributeContractFulfillment, attributeContractFulfillmentErr
12+
for key, fulfillment := range attributeContractFulfillmentAttr.Elements() {
13+
fulfillmentValue := client.AttributeFulfillmentValue{}
14+
fulfillmentAttrs := fulfillment.(types.Object).Attributes()
15+
fulfillmentValue.Value = fulfillmentAttrs["value"].(types.String).ValueString()
16+
fulfillmentValue.Source = client.SourceTypeIdKey{}
17+
sourceAttrs := fulfillmentAttrs["source"].(types.Object).Attributes()
18+
fulfillmentValue.Source.Type = sourceAttrs["type"].(types.String).ValueString()
19+
fulfillmentValue.Source.Id = sourceAttrs["id"].(types.String).ValueStringPointer()
20+
attributeContractFulfillment[key] = fulfillmentValue
21+
}
22+
return attributeContractFulfillment
1723
}

internal/resource/common/attributesources/attribute_sources_client_struct.go

Lines changed: 103 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,132 @@
33
package attributesources
44

55
import (
6-
"encoding/json"
7-
86
"github.com/hashicorp/terraform-plugin-framework/types"
97
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
108
client "github.com/pingidentity/pingfederate-go-client/v1220/configurationapi"
11-
internaljson "github.com/pingidentity/terraform-provider-pingfederate/internal/json"
129
internaltypes "github.com/pingidentity/terraform-provider-pingfederate/internal/types"
1310
)
1411

15-
func ClientStruct(attributeSourcesAttr basetypes.SetValue) ([]client.AttributeSourceAggregation, error) {
12+
func ClientStruct(attributeSourcesAttr basetypes.SetValue) []client.AttributeSourceAggregation {
1613
attributeSourceAggregation := []client.AttributeSourceAggregation{}
1714
for _, source := range attributeSourcesAttr.Elements() {
1815
//Determine which attribute source type this is
1916
sourceAttrs := source.(types.Object).Attributes()
2017
attributeSourceInner := client.AttributeSourceAggregation{}
2118
if internaltypes.IsDefined(sourceAttrs["custom_attribute_source"]) {
2219
attributeSourceInner.CustomAttributeSource = &client.CustomAttributeSource{}
23-
customAttributeSourceErr := json.Unmarshal([]byte(internaljson.FromValue(sourceAttrs["custom_attribute_source"], true)), attributeSourceInner.CustomAttributeSource)
24-
if customAttributeSourceErr != nil {
25-
return nil, customAttributeSourceErr
20+
customAttributeSourceAttrs := sourceAttrs["custom_attribute_source"].(types.Object).Attributes()
21+
if !customAttributeSourceAttrs["attribute_contract_fulfillment"].IsNull() && !customAttributeSourceAttrs["attribute_contract_fulfillment"].IsUnknown() {
22+
attributeSourceInner.CustomAttributeSource.AttributeContractFulfillment = &map[string]client.AttributeFulfillmentValue{}
23+
for key, attributeContractFulfillmentElement := range customAttributeSourceAttrs["attribute_contract_fulfillment"].(types.Map).Elements() {
24+
attributeContractFulfillmentValue := client.AttributeFulfillmentValue{}
25+
attributeContractFulfillmentAttrs := attributeContractFulfillmentElement.(types.Object).Attributes()
26+
attributeContractFulfillmentSourceValue := client.SourceTypeIdKey{}
27+
attributeContractFulfillmentSourceAttrs := attributeContractFulfillmentAttrs["source"].(types.Object).Attributes()
28+
attributeContractFulfillmentSourceValue.Id = attributeContractFulfillmentSourceAttrs["id"].(types.String).ValueStringPointer()
29+
attributeContractFulfillmentSourceValue.Type = attributeContractFulfillmentSourceAttrs["type"].(types.String).ValueString()
30+
attributeContractFulfillmentValue.Source = attributeContractFulfillmentSourceValue
31+
attributeContractFulfillmentValue.Value = attributeContractFulfillmentAttrs["value"].(types.String).ValueString()
32+
(*attributeSourceInner.CustomAttributeSource.AttributeContractFulfillment)[key] = attributeContractFulfillmentValue
33+
}
34+
}
35+
customAttributeSourceDataStoreRefValue := client.ResourceLink{}
36+
customAttributeSourceDataStoreRefAttrs := customAttributeSourceAttrs["data_store_ref"].(types.Object).Attributes()
37+
customAttributeSourceDataStoreRefValue.Id = customAttributeSourceDataStoreRefAttrs["id"].(types.String).ValueString()
38+
attributeSourceInner.CustomAttributeSource.DataStoreRef = customAttributeSourceDataStoreRefValue
39+
attributeSourceInner.CustomAttributeSource.Description = customAttributeSourceAttrs["description"].(types.String).ValueStringPointer()
40+
if !customAttributeSourceAttrs["filter_fields"].IsNull() && !customAttributeSourceAttrs["filter_fields"].IsUnknown() {
41+
attributeSourceInner.CustomAttributeSource.FilterFields = []client.FieldEntry{}
42+
for _, filterFieldsElement := range customAttributeSourceAttrs["filter_fields"].(types.Set).Elements() {
43+
filterFieldsValue := client.FieldEntry{}
44+
filterFieldsAttrs := filterFieldsElement.(types.Object).Attributes()
45+
filterFieldsValue.Name = filterFieldsAttrs["name"].(types.String).ValueString()
46+
filterFieldsValue.Value = filterFieldsAttrs["value"].(types.String).ValueStringPointer()
47+
attributeSourceInner.CustomAttributeSource.FilterFields = append(attributeSourceInner.CustomAttributeSource.FilterFields, filterFieldsValue)
48+
}
2649
}
50+
attributeSourceInner.CustomAttributeSource.Id = customAttributeSourceAttrs["id"].(types.String).ValueStringPointer()
51+
attributeSourceInner.CustomAttributeSource.Type = customAttributeSourceAttrs["type"].(types.String).ValueString()
2752
}
2853
if internaltypes.IsDefined(sourceAttrs["jdbc_attribute_source"]) {
2954
attributeSourceInner.JdbcAttributeSource = &client.JdbcAttributeSource{}
30-
jdbcAttributeSourceErr := json.Unmarshal([]byte(internaljson.FromValue(sourceAttrs["jdbc_attribute_source"], true)), attributeSourceInner.JdbcAttributeSource)
31-
if jdbcAttributeSourceErr != nil {
32-
return nil, jdbcAttributeSourceErr
55+
jdbcAttributeSourceAttrs := sourceAttrs["jdbc_attribute_source"].(types.Object).Attributes()
56+
if !jdbcAttributeSourceAttrs["attribute_contract_fulfillment"].IsNull() && !jdbcAttributeSourceAttrs["attribute_contract_fulfillment"].IsUnknown() {
57+
attributeSourceInner.JdbcAttributeSource.AttributeContractFulfillment = &map[string]client.AttributeFulfillmentValue{}
58+
for key, attributeContractFulfillmentElement := range jdbcAttributeSourceAttrs["attribute_contract_fulfillment"].(types.Map).Elements() {
59+
attributeContractFulfillmentValue := client.AttributeFulfillmentValue{}
60+
attributeContractFulfillmentAttrs := attributeContractFulfillmentElement.(types.Object).Attributes()
61+
attributeContractFulfillmentSourceValue := client.SourceTypeIdKey{}
62+
attributeContractFulfillmentSourceAttrs := attributeContractFulfillmentAttrs["source"].(types.Object).Attributes()
63+
attributeContractFulfillmentSourceValue.Id = attributeContractFulfillmentSourceAttrs["id"].(types.String).ValueStringPointer()
64+
attributeContractFulfillmentSourceValue.Type = attributeContractFulfillmentSourceAttrs["type"].(types.String).ValueString()
65+
attributeContractFulfillmentValue.Source = attributeContractFulfillmentSourceValue
66+
attributeContractFulfillmentValue.Value = attributeContractFulfillmentAttrs["value"].(types.String).ValueString()
67+
(*attributeSourceInner.JdbcAttributeSource.AttributeContractFulfillment)[key] = attributeContractFulfillmentValue
68+
}
69+
}
70+
if !jdbcAttributeSourceAttrs["column_names"].IsNull() && !jdbcAttributeSourceAttrs["column_names"].IsUnknown() {
71+
attributeSourceInner.JdbcAttributeSource.ColumnNames = []string{}
72+
for _, columnNamesElement := range jdbcAttributeSourceAttrs["column_names"].(types.List).Elements() {
73+
attributeSourceInner.JdbcAttributeSource.ColumnNames = append(attributeSourceInner.JdbcAttributeSource.ColumnNames, columnNamesElement.(types.String).ValueString())
74+
}
3375
}
76+
jdbcAttributeSourceDataStoreRefValue := client.ResourceLink{}
77+
jdbcAttributeSourceDataStoreRefAttrs := jdbcAttributeSourceAttrs["data_store_ref"].(types.Object).Attributes()
78+
jdbcAttributeSourceDataStoreRefValue.Id = jdbcAttributeSourceDataStoreRefAttrs["id"].(types.String).ValueString()
79+
attributeSourceInner.JdbcAttributeSource.DataStoreRef = jdbcAttributeSourceDataStoreRefValue
80+
attributeSourceInner.JdbcAttributeSource.Description = jdbcAttributeSourceAttrs["description"].(types.String).ValueStringPointer()
81+
attributeSourceInner.JdbcAttributeSource.Filter = jdbcAttributeSourceAttrs["filter"].(types.String).ValueString()
82+
attributeSourceInner.JdbcAttributeSource.Id = jdbcAttributeSourceAttrs["id"].(types.String).ValueStringPointer()
83+
attributeSourceInner.JdbcAttributeSource.Schema = jdbcAttributeSourceAttrs["schema"].(types.String).ValueStringPointer()
84+
attributeSourceInner.JdbcAttributeSource.Table = jdbcAttributeSourceAttrs["table"].(types.String).ValueString()
85+
attributeSourceInner.JdbcAttributeSource.Type = jdbcAttributeSourceAttrs["type"].(types.String).ValueString()
3486
}
3587
if internaltypes.IsDefined(sourceAttrs["ldap_attribute_source"]) {
3688
attributeSourceInner.LdapAttributeSource = &client.LdapAttributeSource{}
37-
ldapAttributeSourceErr := json.Unmarshal([]byte(internaljson.FromValue(sourceAttrs["ldap_attribute_source"], true)), attributeSourceInner.LdapAttributeSource)
38-
if ldapAttributeSourceErr != nil {
39-
return nil, ldapAttributeSourceErr
89+
ldapAttributeSourceAttrs := sourceAttrs["ldap_attribute_source"].(types.Object).Attributes()
90+
if !ldapAttributeSourceAttrs["attribute_contract_fulfillment"].IsNull() && !ldapAttributeSourceAttrs["attribute_contract_fulfillment"].IsUnknown() {
91+
attributeSourceInner.LdapAttributeSource.AttributeContractFulfillment = &map[string]client.AttributeFulfillmentValue{}
92+
for key, attributeContractFulfillmentElement := range ldapAttributeSourceAttrs["attribute_contract_fulfillment"].(types.Map).Elements() {
93+
attributeContractFulfillmentValue := client.AttributeFulfillmentValue{}
94+
attributeContractFulfillmentAttrs := attributeContractFulfillmentElement.(types.Object).Attributes()
95+
attributeContractFulfillmentSourceValue := client.SourceTypeIdKey{}
96+
attributeContractFulfillmentSourceAttrs := attributeContractFulfillmentAttrs["source"].(types.Object).Attributes()
97+
attributeContractFulfillmentSourceValue.Id = attributeContractFulfillmentSourceAttrs["id"].(types.String).ValueStringPointer()
98+
attributeContractFulfillmentSourceValue.Type = attributeContractFulfillmentSourceAttrs["type"].(types.String).ValueString()
99+
attributeContractFulfillmentValue.Source = attributeContractFulfillmentSourceValue
100+
attributeContractFulfillmentValue.Value = attributeContractFulfillmentAttrs["value"].(types.String).ValueString()
101+
(*attributeSourceInner.LdapAttributeSource.AttributeContractFulfillment)[key] = attributeContractFulfillmentValue
102+
}
103+
}
104+
attributeSourceInner.LdapAttributeSource.BaseDn = ldapAttributeSourceAttrs["base_dn"].(types.String).ValueStringPointer()
105+
if !ldapAttributeSourceAttrs["binary_attribute_settings"].IsNull() && !ldapAttributeSourceAttrs["binary_attribute_settings"].IsUnknown() {
106+
attributeSourceInner.LdapAttributeSource.BinaryAttributeSettings = &map[string]client.BinaryLdapAttributeSettings{}
107+
for key, binaryAttributeSettingsElement := range ldapAttributeSourceAttrs["binary_attribute_settings"].(types.Map).Elements() {
108+
binaryAttributeSettingsValue := client.BinaryLdapAttributeSettings{}
109+
binaryAttributeSettingsAttrs := binaryAttributeSettingsElement.(types.Object).Attributes()
110+
binaryAttributeSettingsValue.BinaryEncoding = binaryAttributeSettingsAttrs["binary_encoding"].(types.String).ValueStringPointer()
111+
(*attributeSourceInner.LdapAttributeSource.BinaryAttributeSettings)[key] = binaryAttributeSettingsValue
112+
}
113+
}
114+
ldapAttributeSourceDataStoreRefValue := client.ResourceLink{}
115+
ldapAttributeSourceDataStoreRefAttrs := ldapAttributeSourceAttrs["data_store_ref"].(types.Object).Attributes()
116+
ldapAttributeSourceDataStoreRefValue.Id = ldapAttributeSourceDataStoreRefAttrs["id"].(types.String).ValueString()
117+
attributeSourceInner.LdapAttributeSource.DataStoreRef = ldapAttributeSourceDataStoreRefValue
118+
attributeSourceInner.LdapAttributeSource.Description = ldapAttributeSourceAttrs["description"].(types.String).ValueStringPointer()
119+
attributeSourceInner.LdapAttributeSource.Id = ldapAttributeSourceAttrs["id"].(types.String).ValueStringPointer()
120+
attributeSourceInner.LdapAttributeSource.MemberOfNestedGroup = ldapAttributeSourceAttrs["member_of_nested_group"].(types.Bool).ValueBoolPointer()
121+
if !ldapAttributeSourceAttrs["search_attributes"].IsNull() && !ldapAttributeSourceAttrs["search_attributes"].IsUnknown() {
122+
attributeSourceInner.LdapAttributeSource.SearchAttributes = []string{}
123+
for _, searchAttributesElement := range ldapAttributeSourceAttrs["search_attributes"].(types.Set).Elements() {
124+
attributeSourceInner.LdapAttributeSource.SearchAttributes = append(attributeSourceInner.LdapAttributeSource.SearchAttributes, searchAttributesElement.(types.String).ValueString())
125+
}
40126
}
127+
attributeSourceInner.LdapAttributeSource.SearchFilter = ldapAttributeSourceAttrs["search_filter"].(types.String).ValueString()
128+
attributeSourceInner.LdapAttributeSource.SearchScope = ldapAttributeSourceAttrs["search_scope"].(types.String).ValueString()
129+
attributeSourceInner.LdapAttributeSource.Type = ldapAttributeSourceAttrs["type"].(types.String).ValueString()
41130
}
42131
attributeSourceAggregation = append(attributeSourceAggregation, attributeSourceInner)
43132
}
44-
return attributeSourceAggregation, nil
133+
return attributeSourceAggregation
45134
}

0 commit comments

Comments
 (0)