Skip to content

Commit

Permalink
Add introspection_token_claim to protocol mapper types
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Nov 26, 2024
1 parent 149c85b commit 7471950
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/puppet/provider/keycloak_client_protocol_mapper/kcadm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def self.instances
if protocol_mapper[:protocol] == 'openid-connect'
protocol_mapper[:id_token_claim] = d['config']['id.token.claim']
protocol_mapper[:access_token_claim] = d['config']['access.token.claim']
protocol_mapper[:introspection_token_claim] = d['config']['introspection.token.claim']
end
unless ['oidc-audience-mapper'].include?(protocol_mapper[:type])
protocol_mapper[:userinfo_token_claim] = d['config']['userinfo.token.claim']
Expand Down Expand Up @@ -127,6 +128,7 @@ def create
if resource[:protocol] == 'openid-connect'
data[:config][:'id.token.claim'] = resource[:id_token_claim] if resource[:id_token_claim]
data[:config][:'access.token.claim'] = resource[:access_token_claim] if resource[:access_token_claim]
data[:config][:'introspection.token.claim'] = resource[:introspection_token_claim] if resource[:introspection_token_claim]
end
if !['oidc-audience-mapper'].include?(resource[:type]) && resource[:userinfo_token_claim]
data[:config][:'userinfo.token.claim'] = resource[:userinfo_token_claim]
Expand Down Expand Up @@ -216,6 +218,7 @@ def flush
if resource[:protocol] == 'openid-connect'
config[:'id.token.claim'] = resource[:id_token_claim] if resource[:id_token_claim]
config[:'access.token.claim'] = resource[:access_token_claim] if resource[:access_token_claim]
config[:'introspection.token.claim'] = resource[:introspection_token_claim] if resource[:introspection_token_claim]
end
if !['oidc-audience-mapper'].include?(resource[:type]) && resource[:userinfo_token_claim]
config[:'userinfo.token.claim'] = resource[:userinfo_token_claim]
Expand Down
3 changes: 3 additions & 0 deletions lib/puppet/provider/keycloak_protocol_mapper/kcadm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def self.instances
if protocol_mapper[:protocol] == 'openid-connect'
protocol_mapper[:id_token_claim] = d['config']['id.token.claim']
protocol_mapper[:access_token_claim] = d['config']['access.token.claim']
protocol_mapper[:introspection_token_claim] = d['config']['introspection.token.claim']
end
unless ['oidc-audience-mapper'].include?(protocol_mapper[:type])
protocol_mapper[:userinfo_token_claim] = d['config']['userinfo.token.claim']
Expand Down Expand Up @@ -123,6 +124,7 @@ def create
if resource[:protocol] == 'openid-connect'
data[:config][:'id.token.claim'] = resource[:id_token_claim] if resource[:id_token_claim]
data[:config][:'access.token.claim'] = resource[:access_token_claim] if resource[:access_token_claim]
data[:config][:'introspection.token.claim'] = resource[:introspection_token_claim] if resource[:introspection_token_claim]
end
if !['oidc-audience-mapper'].include?(resource[:type]) && resource[:userinfo_token_claim]
data[:config][:'userinfo.token.claim'] = resource[:userinfo_token_claim]
Expand Down Expand Up @@ -210,6 +212,7 @@ def flush
if resource[:protocol] == 'openid-connect'
config[:'id.token.claim'] = resource[:id_token_claim] if resource[:id_token_claim]
config[:'access.token.claim'] = resource[:access_token_claim] if resource[:access_token_claim]
config[:'introspection.token.claim'] = resource[:introspection_token_claim] if resource[:introspection_token_claim]
end
if !['oidc-audience-mapper'].include?(resource[:type]) && resource[:userinfo_token_claim]
config[:'userinfo.token.claim'] = resource[:userinfo_token_claim]
Expand Down
12 changes: 12 additions & 0 deletions lib/puppet/type/keycloak_client_protocol_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@
end
end

newproperty(:introspection_token_claim, boolean: true) do
desc 'introspection.token.claim. Default to `true` for `protocol` `openid-connect`.'
newvalues(:true, :false)
defaultto do
if @resource['protocol'] == 'openid-connect'
:true
else
nil
end
end
end

newproperty(:attribute_nameformat) do
desc 'attribute.nameformat'
validate do |v|
Expand Down
12 changes: 12 additions & 0 deletions lib/puppet/type/keycloak_protocol_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,18 @@
end
end

newproperty(:introspection_token_claim, boolean: true) do
desc 'introspection.token.claim. Default to `true` for `protocol` `openid-connect`.'
newvalues(:true, :false)
defaultto do
if @resource['protocol'] == 'openid-connect'
:true
else
nil
end
end
end

newproperty(:attribute_nameformat) do
desc 'attribute.nameformat'
validate do |v|
Expand Down
30 changes: 30 additions & 0 deletions spec/unit/puppet/type/keycloak_client_protocol_mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,36 @@
}.to raise_error(%r{foo})
end

it 'defaults for introspection_token_claim' do
expect(resource[:introspection_token_claim]).to eq(:true)
end

it 'does not default introspection_token_claim for saml' do
config[:protocol] = 'saml'
expect(resource[:introspection_token_claim]).to be_nil
end

it 'accepts true for introspection_token_claim' do
config[:introspection_token_claim] = true
expect(resource[:introspection_token_claim]).to eq(:true)
config[:introspection_token_claim] = 'true'
expect(resource[:introspection_token_claim]).to eq(:true)
end

it 'accepts false for introspection_token_claim' do
config[:introspection_token_claim] = false
expect(resource[:introspection_token_claim]).to eq(:false)
config[:introspection_token_claim] = 'false'
expect(resource[:introspection_token_claim]).to eq(:false)
end

it 'does not accept strings for introspection_token_claim' do
config[:introspection_token_claim] = 'foo'
expect {
resource
}.to raise_error(%r{foo})
end

defaults = {}

describe 'basic properties' do
Expand Down
30 changes: 30 additions & 0 deletions spec/unit/puppet/type/keycloak_protocol_mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,36 @@
}.to raise_error(%r{foo})
end

it 'defaults for introspection_token_claim' do
expect(resource[:introspection_token_claim]).to eq(:true)
end

it 'does not default introspection_token_claim for saml' do
config[:protocol] = 'saml'
expect(resource[:introspection_token_claim]).to be_nil
end

it 'accepts true for introspection_token_claim' do
config[:introspection_token_claim] = true
expect(resource[:introspection_token_claim]).to eq(:true)
config[:introspection_token_claim] = 'true'
expect(resource[:introspection_token_claim]).to eq(:true)
end

it 'accepts false for introspection_token_claim' do
config[:introspection_token_claim] = false
expect(resource[:introspection_token_claim]).to eq(:false)
config[:introspection_token_claim] = 'false'
expect(resource[:introspection_token_claim]).to eq(:false)
end

it 'does not accept strings for introspection_token_claim' do
config[:introspection_token_claim] = 'foo'
expect {
resource
}.to raise_error(%r{foo})
end

defaults = {}

describe 'basic properties' do
Expand Down

0 comments on commit 7471950

Please sign in to comment.