Skip to content

Commit 279ac69

Browse files
authored
Client scope / Mappers / Custom protocol mapper (#340)
* add custom protocol mapper
1 parent f20003d commit 279ac69

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

REFERENCE.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3201,6 +3201,8 @@ The following parameters are available in the `keycloak_protocol_mapper` type.
32013201
* [`realm`](#-keycloak_protocol_mapper--realm)
32023202
* [`resource_name`](#-keycloak_protocol_mapper--resource_name)
32033203
* [`type`](#-keycloak_protocol_mapper--type)
3204+
* [`custom_type`](#-keycloak_protocol_mapper--custom_type)
3205+
* [`custom_config`](#-keycloak_protocol_mapper--custom_config)
32043206

32053207
##### <a name="-keycloak_protocol_mapper--client_scope"></a>`client_scope`
32063208

@@ -3231,13 +3233,21 @@ The protocol mapper name. Defaults to `name`.
32313233

32323234
##### <a name="-keycloak_protocol_mapper--type"></a>`type`
32333235

3234-
Valid values: `oidc-usermodel-property-mapper`, `oidc-usermodel-attribute-mapper`, `oidc-full-name-mapper`, `oidc-group-membership-mapper`, `oidc-audience-mapper`, `saml-group-membership-mapper`, `saml-user-property-mapper`, `saml-user-attribute-mapper`, `saml-role-list-mapper`
3236+
Valid values: `oidc-usermodel-property-mapper`, `oidc-usermodel-attribute-mapper`, `oidc-full-name-mapper`, `oidc-group-membership-mapper`, `oidc-audience-mapper`, `saml-group-membership-mapper`, `saml-user-property-mapper`, `saml-user-attribute-mapper`, `saml-role-list-mapper`, `custom`
32353237

32363238
protocolMapper.
32373239

32383240
Default is `oidc-usermodel-property-mapper` for `protocol` `openid-connect` and
32393241
`saml-user-property-mapper` for `protocol` `saml`.
32403242

3243+
##### <a name="-keycloak_protocol_mapper--custom_type"></a>`custom_type`
3244+
3245+
Custom mapper type if `type` is set to `custom`.
3246+
3247+
##### <a name="-keycloak_protocol_mapper--custom_config"></a>`custom_config`
3248+
3249+
Custom mapper config for custom type. Simple hash with key-value pair, which will be converted to JSON.
3250+
32413251
### <a name="keycloak_realm"></a>`keycloak_realm`
32423252

32433253
Manage Keycloak realms

lib/puppet/provider/keycloak_protocol_mapper/kcadm.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ def self.instances
7575
protocol_mapper[:single] = d['config']['single'].to_s.to_sym
7676
end
7777
protocol_mapper[:multivalued] = d['config']['multivalued'].to_s.to_sym if d['config']['multivalued']
78+
unless ['oidc-usermodel-property-mapper', 'oidc-usermodel-attribute-mapper', 'oidc-full-name-mapper', 'oidc-group-membership-mapper', 'oidc-audience-mapper',
79+
'saml-group-membership-mapper', 'saml-user-property-mapper', 'saml-user-attribute-mapper', 'saml-role-list-mapper', 'saml-javascript-mapper',].include?(d['protocolMapper'])
80+
protocol_mapper[:type] = 'custom'
81+
protocol_mapper[:custom_type] = d['protocolMapper']
82+
protocol_mapper[:custom_config] = d['config']
83+
end
7884
protocol_mappers << new(protocol_mapper)
7985
end
8086
end
@@ -106,6 +112,10 @@ def create
106112
data[:protocol] = resource[:protocol]
107113
data[:protocolMapper] = resource[:type]
108114
data[:config] = {}
115+
if resource[:type] == 'custom'
116+
data[:protocolMapper] = resource[:custom_type]
117+
data[:config] = resource[:custom_config]
118+
end
109119
if ['oidc-usermodel-property-mapper', 'saml-user-property-mapper', 'saml-user-attribute-mapper', 'oidc-usermodel-attribute-mapper'].include?(resource[:type]) && resource[:user_attribute]
110120
data[:config][:'user.attribute'] = resource[:user_attribute]
111121
end
@@ -194,6 +204,10 @@ def flush
194204
data[:protocol] = resource[:protocol]
195205
data[:protocolMapper] = resource[:type]
196206
config = {}
207+
if resource[:type] == 'custom'
208+
data[:protocolMapper] = resource[:custom_type]
209+
config = resource[:custom_config]
210+
end
197211
if ['oidc-usermodel-property-mapper', 'saml-user-property-mapper', 'saml-user-attribute-mapper', 'oidc-usermodel-attribute-mapper'].include?(resource[:type]) && resource[:user_attribute]
198212
config[:'user.attribute'] = resource[:user_attribute]
199213
end

lib/puppet/type/keycloak_protocol_mapper.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
'saml-user-attribute-mapper',
6868
'saml-role-list-mapper',
6969
%r{script-.+},
70+
'custom',
7071
)
7172
defaultto do
7273
case @resource[:protocol]
@@ -222,6 +223,14 @@
222223
desc 'included.client.audience Required for `type` of `oidc-audience-mapper`'
223224
end
224225

226+
newproperty(:custom_config) do
227+
desc 'custom configuration data for `custom` protocolMapper type'
228+
end
229+
230+
newproperty(:custom_type) do
231+
desc 'custom protocolMapper type'
232+
end
233+
225234
autorequire(:keycloak_client_scope) do
226235
requires = []
227236
catalog.resources.each do |resource|
@@ -261,6 +270,7 @@ def self.title_patterns
261270
'oidc-group-membership-mapper',
262271
'oidc-audience-mapper',
263272
'oidc-usermodel-attribute-mapper',
273+
'custom',
264274
]
265275
if self[:protocol] == 'openid-connect' && !openid_connect_types.include?(self[:type]) && self[:type] !~ %r{script-.+}
266276
raise Puppet::Error, "type #{self[:type]} is not valid for protocol openid-connect"
@@ -285,5 +295,11 @@ def self.title_patterns
285295
if self[:type] == 'oidc-audience-mapper' && self[:included_client_audience].nil?
286296
raise Puppet::Error, 'included_client_audience is required for oidc-audience-mapper'
287297
end
298+
if self[:type] == 'custom' && !self[:custom_type]
299+
raise Puppet::Error, 'custom_type is required for `custom` protocol mapper type'
300+
end
301+
if self[:type] == 'custom' && !self[:custom_config]
302+
raise Puppet::Error, 'custom_config is required for `custom` protocol mapper type'
303+
end
288304
end
289305
end

0 commit comments

Comments
 (0)