Skip to content

Commit 28470a3

Browse files
Implement password policy property (#315)
1 parent 8f51082 commit 28470a3

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

lib/puppet/type/keycloak_realm.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,10 @@ def should_to_s(_newvalue)
420420
defaultto :false
421421
end
422422

423+
newproperty(:password_policy) do
424+
desc 'passwordPolicy'
425+
end
426+
423427
newproperty(:roles, array_matching: :all, parent: PuppetX::Keycloak::ArrayProperty) do
424428
desc 'roles'
425429
defaultto ['offline_access', 'uma_authorization']

spec/acceptance/2_realm_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ class { 'keycloak': }
229229
otp_policy_digits => 8,
230230
otp_policy_period => 30,
231231
otp_policy_code_reusable => true,
232+
password_policy => 'length(12) and notUsername(undefined) and notEmail(undefined) and forceExpiredPasswordChange(365) and hashIterations(27500) and passwordHistory(3) and specialChars(1) and upperCase(1) and lowerCase(1) and digits(1) and maxLength(64)',
232233
web_authn_policy_rp_entity_name => 'Keycloak',
233234
web_authn_policy_signature_algorithms => ['ES256', 'ES384', 'ES512', 'RS256', 'RS384', 'RS512'],
234235
web_authn_policy_rp_id => 'https://example.com',
@@ -258,6 +259,20 @@ class { 'keycloak': }
258259

259260
it 'has updated the realm' do
260261
on hosts, '/opt/keycloak/bin/kcadm-wrapper.sh get realms/test' do
262+
password_policy_value = [
263+
'length(12)',
264+
'notUsername(undefined)',
265+
'notEmail(undefined)',
266+
'forceExpiredPasswordChange(365)',
267+
'hashIterations(27500)',
268+
'passwordHistory(3)',
269+
'specialChars(1)',
270+
'upperCase(1)',
271+
'lowerCase(1)',
272+
'digits(1)',
273+
'maxLength(64)'
274+
]
275+
261276
data = JSON.parse(stdout)
262277
expect(data['rememberMe']).to eq(true)
263278
expect(data['registrationAllowed']).to eq(true)
@@ -311,6 +326,7 @@ class { 'keycloak': }
311326
expect(data['otpPolicyDigits']).to eq(8)
312327
expect(data['otpPolicyPeriod']).to eq(30)
313328
expect(data['otpPolicyCodeReusable']).to eq(true)
329+
expect(data['passwordPolicy']).to eq(password_policy_value.join(' and '))
314330
expect(data['webAuthnPolicyRpEntityName']).to eq('Keycloak')
315331
expect(data['webAuthnPolicySignatureAlgorithms']).to eq(['ES256', 'ES384', 'ES512', 'RS256', 'RS384', 'RS512'])
316332
expect(data['webAuthnPolicyRpId']).to eq('https://example.com')

spec/unit/puppet/type/keycloak_realm_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@
219219
:smtp_server_reply_to,
220220
:smtp_server_reply_to_display_name,
221221
:default_locale,
222+
:password_policy,
222223
:web_authn_policy_rp_entity_name,
223224
:web_authn_policy_rp_id,
224225
:web_authn_policy_passwordless_rp_entity_name,

0 commit comments

Comments
 (0)