Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/keycloak_user_federation/tasks/main.yml

raw
1 ---
2 # Copyright (c) Ansible Project
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 - name: Create realm
7 community.general.keycloak_realm:
8 auth_keycloak_url: "{{ url }}"
9 auth_realm: "{{ admin_realm }}"
10 auth_username: "{{ admin_user }}"
11 auth_password: "{{ admin_password }}"
12 id: "{{ realm }}"
13 realm: "{{ realm }}"
14 state: present
15
16 - name: Create new user federation
17 community.general.keycloak_user_federation:
18 auth_keycloak_url: "{{ url }}"
19 auth_realm: "{{ admin_realm }}"
20 auth_username: "{{ admin_user }}"
21 auth_password: "{{ admin_password }}"
22 realm: "{{ realm }}"
23 name: "{{ federation }}"
24 state: present
25 provider_id: ldap
26 provider_type: org.keycloak.storage.UserStorageProvider
27 config:
28 enabled: true
29 priority: 0
30 fullSyncPeriod: -1
31 changedSyncPeriod: -1
32 cachePolicy: DEFAULT
33 batchSizeForSync: 1000
34 editMode: READ_ONLY
35 importEnabled: true
36 syncRegistrations: false
37 vendor: other
38 usernameLDAPAttribute: uid
39 rdnLDAPAttribute: uid
40 uuidLDAPAttribute: entryUUID
41 userObjectClasses: "inetOrgPerson, organizationalPerson"
42 connectionUrl: "ldaps://ldap.example.com:636"
43 usersDn: "ou=Users,dc=example,dc=com"
44 authType: simple
45 bindDn: cn=directory reader
46 bindCredential: secret
47 searchScope: 1
48 validatePasswordPolicy: false
49 trustEmail: false
50 useTruststoreSpi: "ldapsOnly"
51 connectionPooling: true
52 pagination: true
53 allowKerberosAuthentication: false
54 useKerberosForPasswordAuthentication: false
55 debug: false
56 register: result
57
58 - name: Debug
59 debug:
60 var: result
61
62 - name: Assert user federation created
63 assert:
64 that:
65 - result is changed
66 - result.existing == {}
67 - result.end_state.name == federation
68
69 - name: Create new user federation in admin realm
70 community.general.keycloak_user_federation:
71 auth_keycloak_url: "{{ url }}"
72 auth_realm: "{{ admin_realm }}"
73 auth_username: "{{ admin_user }}"
74 auth_password: "{{ admin_password }}"
75 realm: "{{ admin_realm }}"
76 name: "{{ federation }}"
77 state: present
78 provider_id: ldap
79 provider_type: org.keycloak.storage.UserStorageProvider
80 config:
81 enabled: true
82 priority: 0
83 fullSyncPeriod: -1
84 changedSyncPeriod: -1
85 cachePolicy: DEFAULT
86 batchSizeForSync: 1000
87 editMode: READ_ONLY
88 importEnabled: true
89 syncRegistrations: false
90 vendor: other
91 usernameLDAPAttribute: uid
92 rdnLDAPAttribute: uid
93 uuidLDAPAttribute: entryUUID
94 userObjectClasses: "inetOrgPerson, organizationalPerson"
95 connectionUrl: "ldaps://ldap.example.com:636"
96 usersDn: "ou=Users,dc=example,dc=com"
97 authType: simple
98 bindDn: cn=directory reader
99 bindCredential: secret
100 searchScope: 1
101 validatePasswordPolicy: false
102 trustEmail: false
103 useTruststoreSpi: "ldapsOnly"
104 connectionPooling: true
105 pagination: true
106 allowKerberosAuthentication: false
107 useKerberosForPasswordAuthentication: false
108 debug: false
109 register: result
110
111 - name: Debug
112 debug:
113 var: result
114
115 - name: Assert user federation created (admin realm)
116 assert:
117 that:
118 - result is changed
119 - result.existing == {}
120 - result.end_state.name == federation
121
122 - name: Update existing user federation (no change)
123 community.general.keycloak_user_federation:
124 auth_keycloak_url: "{{ url }}"
125 auth_realm: "{{ admin_realm }}"
126 auth_username: "{{ admin_user }}"
127 auth_password: "{{ admin_password }}"
128 realm: "{{ realm }}"
129 name: "{{ federation }}"
130 state: present
131 provider_id: ldap
132 provider_type: org.keycloak.storage.UserStorageProvider
133 config:
134 enabled: true
135 priority: 0
136 fullSyncPeriod: -1
137 changedSyncPeriod: -1
138 cachePolicy: DEFAULT
139 batchSizeForSync: 1000
140 editMode: READ_ONLY
141 importEnabled: true
142 syncRegistrations: false
143 vendor: other
144 usernameLDAPAttribute: uid
145 rdnLDAPAttribute: uid
146 uuidLDAPAttribute: entryUUID
147 userObjectClasses: "inetOrgPerson, organizationalPerson"
148 connectionUrl: "ldaps://ldap.example.com:636"
149 usersDn: "ou=Users,dc=example,dc=com"
150 authType: simple
151 bindDn: cn=directory reader
152 bindCredential: "**********"
153 searchScope: 1
154 validatePasswordPolicy: false
155 trustEmail: false
156 useTruststoreSpi: "ldapsOnly"
157 connectionPooling: true
158 pagination: true
159 allowKerberosAuthentication: false
160 useKerberosForPasswordAuthentication: false
161 debug: false
162 register: result
163
164 - name: Debug
165 debug:
166 var: result
167
168 - name: Assert user federation unchanged
169 assert:
170 that:
171 - result is not changed
172 - result.existing != {}
173 - result.existing.name == federation
174 - result.end_state != {}
175 - result.end_state.name == federation
176
177 - name: Update existing user federation (no change, admin realm)
178 community.general.keycloak_user_federation:
179 auth_keycloak_url: "{{ url }}"
180 auth_realm: "{{ admin_realm }}"
181 auth_username: "{{ admin_user }}"
182 auth_password: "{{ admin_password }}"
183 realm: "{{ admin_realm }}"
184 name: "{{ federation }}"
185 state: present
186 provider_id: ldap
187 provider_type: org.keycloak.storage.UserStorageProvider
188 config:
189 enabled: true
190 priority: 0
191 fullSyncPeriod: -1
192 changedSyncPeriod: -1
193 cachePolicy: DEFAULT
194 batchSizeForSync: 1000
195 editMode: READ_ONLY
196 importEnabled: true
197 syncRegistrations: false
198 vendor: other
199 usernameLDAPAttribute: uid
200 rdnLDAPAttribute: uid
201 uuidLDAPAttribute: entryUUID
202 userObjectClasses: "inetOrgPerson, organizationalPerson"
203 connectionUrl: "ldaps://ldap.example.com:636"
204 usersDn: "ou=Users,dc=example,dc=com"
205 authType: simple
206 bindDn: cn=directory reader
207 bindCredential: "**********"
208 searchScope: 1
209 validatePasswordPolicy: false
210 trustEmail: false
211 useTruststoreSpi: "ldapsOnly"
212 connectionPooling: true
213 pagination: true
214 allowKerberosAuthentication: false
215 useKerberosForPasswordAuthentication: false
216 debug: false
217 register: result
218
219 - name: Debug
220 debug:
221 var: result
222
223 - name: Assert user federation unchanged (admin realm)
224 assert:
225 that:
226 - result is not changed
227 - result.existing != {}
228 - result.existing.name == federation
229 - result.end_state != {}
230 - result.end_state.name == federation
231
232 - name: Update existing user federation (with change)
233 community.general.keycloak_user_federation:
234 auth_keycloak_url: "{{ url }}"
235 auth_realm: "{{ admin_realm }}"
236 auth_username: "{{ admin_user }}"
237 auth_password: "{{ admin_password }}"
238 realm: "{{ realm }}"
239 name: "{{ federation }}"
240 state: present
241 provider_id: ldap
242 provider_type: org.keycloak.storage.UserStorageProvider
243 config:
244 enabled: true
245 priority: 0
246 fullSyncPeriod: -1
247 changedSyncPeriod: -1
248 cachePolicy: DEFAULT
249 batchSizeForSync: 1000
250 editMode: READ_ONLY
251 importEnabled: true
252 syncRegistrations: false
253 vendor: other
254 usernameLDAPAttribute: uid
255 rdnLDAPAttribute: uid
256 uuidLDAPAttribute: entryUUID
257 userObjectClasses: "inetOrgPerson, organizationalPerson"
258 connectionUrl: "ldaps://ldap.example.com:636"
259 usersDn: "ou=Users,dc=example,dc=com"
260 authType: simple
261 bindDn: cn=directory reader
262 bindCredential: "**********"
263 searchScope: 1
264 validatePasswordPolicy: false
265 trustEmail: false
266 useTruststoreSpi: "ldapsOnly"
267 connectionPooling: true
268 pagination: true
269 allowKerberosAuthentication: false
270 useKerberosForPasswordAuthentication: false
271 debug: false
272 mappers:
273 # overwrite / update pre existing default mapper
274 - name: "username"
275 providerId: "user-attribute-ldap-mapper"
276 config:
277 ldap.attribute: ldap_user
278 user.model.attribute: usr
279 read.only: true
280 # create new mapper
281 - name: "full name"
282 providerId: "full-name-ldap-mapper"
283 providerType: "org.keycloak.storage.ldap.mappers.LDAPStorageMapper"
284 config:
285 ldap.full.name.attribute: cn
286 read.only: true
287 write.only: false
288 register: result
289
290 - name: Debug
291 debug:
292 var: result
293
294 - name: Assert user federation created
295 assert:
296 that:
297 - result is changed
298 - result.existing != {}
299 - result.existing.name == federation
300 - result.end_state != {}
301 - result.end_state.name == federation
302
303 - name: Delete existing user federation
304 community.general.keycloak_user_federation:
305 auth_keycloak_url: "{{ url }}"
306 auth_realm: "{{ admin_realm }}"
307 auth_username: "{{ admin_user }}"
308 auth_password: "{{ admin_password }}"
309 realm: "{{ realm }}"
310 name: "{{ federation }}"
311 state: absent
312 register: result
313
314 - name: Debug
315 debug:
316 var: result
317
318 - name: Assert user federation deleted
319 assert:
320 that:
321 - result is changed
322 - result.existing != {}
323 - result.end_state == {}
324
325 - name: Delete absent user federation
326 community.general.keycloak_user_federation:
327 auth_keycloak_url: "{{ url }}"
328 auth_realm: "{{ admin_realm }}"
329 auth_username: "{{ admin_user }}"
330 auth_password: "{{ admin_password }}"
331 realm: "{{ realm }}"
332 name: "{{ federation }}"
333 state: absent
334 register: result
335
336 - name: Debug
337 debug:
338 var: result
339
340 - name: Assert user federation unchanged
341 assert:
342 that:
343 - result is not changed
344 - result.existing == {}
345 - result.end_state == {}
346
347 - name: Create new user federation together with mappers
348 community.general.keycloak_user_federation:
349 auth_keycloak_url: "{{ url }}"
350 auth_realm: "{{ admin_realm }}"
351 auth_username: "{{ admin_user }}"
352 auth_password: "{{ admin_password }}"
353 realm: "{{ realm }}"
354 name: "{{ federation }}"
355 state: present
356 provider_id: ldap
357 provider_type: org.keycloak.storage.UserStorageProvider
358 config:
359 enabled: true
360 priority: 0
361 fullSyncPeriod: -1
362 changedSyncPeriod: -1
363 cachePolicy: DEFAULT
364 batchSizeForSync: 1000
365 editMode: READ_ONLY
366 importEnabled: true
367 syncRegistrations: false
368 vendor: other
369 usernameLDAPAttribute: uid
370 rdnLDAPAttribute: uid
371 uuidLDAPAttribute: entryUUID
372 userObjectClasses: "inetOrgPerson, organizationalPerson"
373 connectionUrl: "ldaps://ldap.example.com:636"
374 usersDn: "ou=Users,dc=example,dc=com"
375 authType: simple
376 bindDn: cn=directory reader
377 bindCredential: secret
378 searchScope: 1
379 validatePasswordPolicy: false
380 trustEmail: false
381 useTruststoreSpi: "ldapsOnly"
382 connectionPooling: true
383 pagination: true
384 allowKerberosAuthentication: false
385 useKerberosForPasswordAuthentication: false
386 debug: false
387 mappers:
388 # overwrite / update pre existing default mapper
389 - name: "username"
390 providerId: "user-attribute-ldap-mapper"
391 config:
392 ldap.attribute: ldap_user
393 user.model.attribute: usr
394 read.only: true
395 # create new mapper
396 - name: "full name"
397 providerId: "full-name-ldap-mapper"
398 providerType: "org.keycloak.storage.ldap.mappers.LDAPStorageMapper"
399 config:
400 ldap.full.name.attribute: cn
401 read.only: true
402 write.only: false
403 register: result
404
405 - name: Debug
406 debug:
407 var: result
408
409 - name: Assert user federation created
410 assert:
411 that:
412 - result is changed
413 - result.existing == {}
414 - result.end_state.name == federation
415
416 ## no point in retesting this, just doing it to clean up introduced server changes
417 - name: Delete absent user federation
418 community.general.keycloak_user_federation:
419 auth_keycloak_url: "{{ url }}"
420 auth_realm: "{{ admin_realm }}"
421 auth_username: "{{ admin_user }}"
422 auth_password: "{{ admin_password }}"
423 realm: "{{ realm }}"
424 name: "{{ federation }}"
425 state: absent