-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
FailoverRealmTestCase.java
541 lines (490 loc) · 27.7 KB
/
FailoverRealmTestCase.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.elytron.realm;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
import static org.jboss.as.test.integration.security.common.Utils.makeCallWithTokenAuthn;
import static org.jboss.as.test.shared.CliUtils.asAbsolutePath;
import static org.jboss.as.test.shared.CliUtils.escapePath;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;
import java.io.File;
import java.io.PrintWriter;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Base64.Encoder;
import java.util.List;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.cli.Util;
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.test.integration.security.common.Utils;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.test.security.common.AbstractElytronSetupTask;
import org.wildfly.test.security.common.elytron.ConfigurableElement;
import org.wildfly.test.security.common.elytron.DirContext;
import org.wildfly.test.security.common.elytron.FailoverRealm;
import org.wildfly.test.security.common.elytron.FileAuditLog;
import org.wildfly.test.security.common.elytron.FileSystemRealm;
import org.wildfly.test.security.common.elytron.JdbcSecurityRealm;
import org.wildfly.test.security.common.elytron.LdapRealm;
import org.wildfly.test.security.common.elytron.MechanismConfiguration;
import org.wildfly.test.security.common.elytron.PropertiesRealm;
import org.wildfly.test.security.common.elytron.SimpleHttpAuthenticationFactory;
import org.wildfly.test.security.common.elytron.SimpleSecurityDomain;
import org.wildfly.test.security.common.elytron.TokenRealm;
import org.wildfly.test.security.common.elytron.UserWithAttributeValues;
import org.wildfly.test.undertow.common.UndertowApplicationSecurityDomain;
/**
* Tests the {@link FailoverRealm} within the Elytron subsystem. The tests cover filesystem-realm, jdbc-realm, ldap-realm,
* properties-realm, and token-realm, trying the failover to a properties-realm when the primary (delegate) realm is unavailable
* (throws RealmUnavailableException).
*
* It's also tested whether the SecurityRealmUnavailableEvent is emitted when expected.
*
* @author Ondrej Kotek
*/
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup({FailoverRealmTestCase.ServerSetup.class})
public class FailoverRealmTestCase {
private static final String DEPLOYMENT_FIRST_AVAILABLE = "FailoverRealmDeployment-FirstAvailable";
private static final String DEPLOYMENT_FILESYSTEM = "FailoverRealmDeployment-Filesystem";
private static final String DEPLOYMENT_JDBC = "FailoverRealmDeployment-JDBC";
private static final String DEPLOYMENT_LDAP = "FailoverRealmDeployment-LDAP";
private static final String DEPLOYMENT_PROPERTIES = "FailoverRealmDeployment-properties";
private static final String DEPLOYMENT_BOTH_UNAVAILABLE = "FailoverRealmDeployment-BothUnvailable";
private static final String DEPLOYMENT_EVENT_DISABLED = "FailoverRealmDeployment-EventDisabled";
private static final String DEPLOYMENT_BEARER_TOKEN = "FailoverRealmDeployment-BearerToken";
private static final String INDEX_PAGE_CONTENT = "index page content";
private static final Encoder B64_ENCODER = Base64.getUrlEncoder().withoutPadding();
private static final String JWT_HEADER_B64 = B64_ENCODER
.encodeToString("{\"alg\":\"none\",\"typ\":\"JWT\"}".getBytes(StandardCharsets.UTF_8));
private static final File AUDIT_LOG_FILE = Paths.get("target",
FailoverRealmTestCase.class.getSimpleName() + "-test-audit.log").toFile();
@Deployment(name = DEPLOYMENT_FIRST_AVAILABLE)
public static WebArchive deploymentForFirstRealmAvailable() {
return deployment(DEPLOYMENT_FIRST_AVAILABLE, "failover-realm-web.xml");
}
@Deployment(name = DEPLOYMENT_FILESYSTEM)
public static WebArchive deploymentForFilesystemRealm() {
return deployment(DEPLOYMENT_FILESYSTEM, "failover-realm-web.xml");
}
@Deployment(name = DEPLOYMENT_JDBC)
public static WebArchive deploymentForJdbcRealm() {
return deployment(DEPLOYMENT_JDBC, "failover-realm-web.xml");
}
@Deployment(name = DEPLOYMENT_LDAP)
public static WebArchive deploymentForLdapRealm() {
return deployment(DEPLOYMENT_LDAP, "failover-realm-web.xml");
}
@Deployment(name = DEPLOYMENT_PROPERTIES)
public static WebArchive deploymentForPropertiesRealmUnavailable() {
return deployment(DEPLOYMENT_PROPERTIES, "failover-realm-web.xml");
}
@Deployment(name = DEPLOYMENT_BOTH_UNAVAILABLE)
public static WebArchive deploymentForBothRealmsUnavailable() {
return deployment(DEPLOYMENT_BOTH_UNAVAILABLE, "failover-realm-web.xml");
}
@Deployment(name = DEPLOYMENT_EVENT_DISABLED)
public static WebArchive deploymentForEventDisabled() {
return deployment(DEPLOYMENT_EVENT_DISABLED, "failover-realm-web.xml");
}
@Deployment(name = DEPLOYMENT_BEARER_TOKEN)
public static WebArchive deploymentForBearerToken() {
return deployment(DEPLOYMENT_BEARER_TOKEN, "failover-realm-bearer-token-web.xml");
}
private static WebArchive deployment(String name, String webXml) {
final WebArchive war = ShrinkWrap.create(WebArchive.class, name + ".war");
war.add(new StringAsset(INDEX_PAGE_CONTENT), "index.html");
war.addAsWebInfResource(FailoverRealmTestCase.class.getPackage(), webXml, "web.xml");
war.addAsWebInfResource(Utils.getJBossWebXmlAsset(name), "jboss-web.xml");
return war;
}
@Test
@OperateOnDeployment(DEPLOYMENT_FIRST_AVAILABLE)
public void testFirstRealmAvailable(@ArquillianResource URL webAppUrl) throws Exception {
testCredentialBasedRealmsNoFailover(webAppUrl);
}
@Test
@OperateOnDeployment(DEPLOYMENT_FILESYSTEM)
public void testFilesystemRealmUnavailable(@ArquillianResource URL webAppUrl) throws Exception {
assumeFalse(Util.isWindows()); // no easy and robust way to prepare the conditions on Windows
testCredentialBasedRealmsFailover(webAppUrl);
}
@Test
@OperateOnDeployment(DEPLOYMENT_JDBC)
public void testJdbcRealmUnavailable(@ArquillianResource URL webAppUrl) throws Exception {
testCredentialBasedRealmsFailover(webAppUrl);
}
@Test
@OperateOnDeployment(DEPLOYMENT_LDAP)
public void testLdapRealmUnavailable(@ArquillianResource URL webAppUrl) throws Exception {
testCredentialBasedRealmsFailover(webAppUrl);
}
@Test
@OperateOnDeployment(DEPLOYMENT_PROPERTIES)
public void testPropertiesRealmUnavailable(@ArquillianResource URL webAppUrl) throws Exception {
cleanAuditLog();
String result = Utils.makeCallWithBasicAuthn(webAppUrl, "user1", "password1", SC_OK);
assertEquals(INDEX_PAGE_CONTENT, result);
assertTrue("SecurityRealmUnavailableEvent should be logged", isSecurityRealmUnavailableEventLogged());
cleanAuditLog();
result = Utils.makeCallWithBasicAuthn(webAppUrl, "user1", "wrongPassword1", SC_UNAUTHORIZED);
assertNotEquals(INDEX_PAGE_CONTENT, result);
assertTrue("SecurityRealmUnavailableEvent should be logged", isSecurityRealmUnavailableEventLogged());
// no failover, just user1 is known in the first realm (its unhashed password causes the failover)
cleanAuditLog();
result = Utils.makeCallWithBasicAuthn(webAppUrl, "non-existing-user1", "password1", SC_UNAUTHORIZED);
assertNotEquals(INDEX_PAGE_CONTENT, result);
assertFalse("SecurityRealmUnavailableEvent should not be logged", isSecurityRealmUnavailableEventLogged());
}
@Test
@OperateOnDeployment(DEPLOYMENT_BOTH_UNAVAILABLE)
public void testBothCredentialBasedRealmsUnavailable(@ArquillianResource URL webAppUrl) throws Exception {
cleanAuditLog();
String result = Utils.makeCallWithBasicAuthn(webAppUrl, "user1", "password1", SC_INTERNAL_SERVER_ERROR);
assertNotEquals(INDEX_PAGE_CONTENT, result);
assertTrue("SecurityRealmUnavailableEvent should be logged", isSecurityRealmUnavailableEventLogged());
}
@Test
@OperateOnDeployment(DEPLOYMENT_EVENT_DISABLED)
public void testEventDisabled(@ArquillianResource URL webAppUrl) throws Exception {
// failovers happen but are not logged, like in case of no failovers
testCredentialBasedRealmsNoFailover(webAppUrl);
}
@Test
@OperateOnDeployment(DEPLOYMENT_BEARER_TOKEN)
public void testTokenRealmUnvailable(@ArquillianResource URL webAppUrl) throws Exception {
cleanAuditLog();
String result = makeCallWithTokenAuthn(webAppUrl, createJwtToken("userA", "issuer.wildfly.org"), SC_OK);
assertEquals(INDEX_PAGE_CONTENT, result);
assertTrue("SecurityRealmUnavailableEvent should be logged", isSecurityRealmUnavailableEventLogged());
cleanAuditLog();
result = makeCallWithTokenAuthn(webAppUrl, createJwtToken("userC", "unknown_issuer"), SC_UNAUTHORIZED);
assertNotEquals(INDEX_PAGE_CONTENT, result);
assertTrue("SecurityRealmUnavailableEvent should be logged", isSecurityRealmUnavailableEventLogged());
}
private void testCredentialBasedRealmsFailover(URL webAppUrl) throws Exception {
cleanAuditLog();
String result = Utils.makeCallWithBasicAuthn(webAppUrl, "user1", "password1", SC_OK);
assertEquals(INDEX_PAGE_CONTENT, result);
assertTrue("SecurityRealmUnavailableEvent should be logged", isSecurityRealmUnavailableEventLogged());
cleanAuditLog();
result = Utils.makeCallWithBasicAuthn(webAppUrl, "user1", "wrongPassword1", SC_UNAUTHORIZED);
assertNotEquals(INDEX_PAGE_CONTENT, result);
assertTrue("SecurityRealmUnavailableEvent should be logged", isSecurityRealmUnavailableEventLogged());
cleanAuditLog();
result = Utils.makeCallWithBasicAuthn(webAppUrl, "non-existing-user1", "password1", SC_UNAUTHORIZED);
assertNotEquals(INDEX_PAGE_CONTENT, result);
assertTrue("SecurityRealmUnavailableEvent should be logged", isSecurityRealmUnavailableEventLogged());
}
private void testCredentialBasedRealmsNoFailover(URL webAppUrl) throws Exception {
cleanAuditLog();
String result = Utils.makeCallWithBasicAuthn(webAppUrl, "user1", "password1", SC_OK);
assertEquals(INDEX_PAGE_CONTENT, result);
assertFalse("SecurityRealmUnavailableEvent should not be logged", isSecurityRealmUnavailableEventLogged());
cleanAuditLog();
result = Utils.makeCallWithBasicAuthn(webAppUrl, "user1", "wrongPassword1", SC_UNAUTHORIZED);
assertNotEquals(INDEX_PAGE_CONTENT, result);
assertFalse("SecurityRealmUnavailableEvent should not be logged", isSecurityRealmUnavailableEventLogged());
cleanAuditLog();
result = Utils.makeCallWithBasicAuthn(webAppUrl, "non-existing-user1", "password1", SC_UNAUTHORIZED);
assertNotEquals(INDEX_PAGE_CONTENT, result);
assertFalse("SecurityRealmUnavailableEvent should not be logged", isSecurityRealmUnavailableEventLogged());
}
private static boolean isSecurityRealmUnavailableEventLogged() throws Exception {
List<String> lines = Files.readAllLines(AUDIT_LOG_FILE.toPath(), StandardCharsets.UTF_8);
for (String line : lines) {
if (line.contains("SecurityRealmUnavailableEvent")) {
return true;
}
}
return false;
}
private static void cleanAuditLog() throws Exception {
try (PrintWriter writer = new PrintWriter(AUDIT_LOG_FILE)) {
writer.print("");
}
}
private static String createJwtToken(String userName, String issuer) {
String jwtPayload = String.format("{"
+ "\"active\": true,"
+ "\"iss\": \"%1$s\","
+ "\"sub\": \"elytron@wildfly.org\","
+ "\"exp\": 2051222399,"
+ "\"aud\": \"%1$s\","
+ "\"groups\": [\"%2$s\"]"
+ "}", issuer, userName);
return JWT_HEADER_B64 + "." + B64_ENCODER.encodeToString(jwtPayload.getBytes(StandardCharsets.UTF_8)) + ".";
}
static class ServerSetup extends AbstractElytronSetupTask {
File unavailableFileSystemRealmDir;
@Override
protected ConfigurableElement[] getConfigurableElements() {
ArrayList<ConfigurableElement> configurableElements = new ArrayList<>();
// this audit log is checked for presence of SecurityRealmUnavailableEvent
configurableElements.add(FileAuditLog.builder()
.withName("audit_log_for_failover_realm")
.withPath(asAbsolutePath(AUDIT_LOG_FILE))
.build());
// this properties realm is used as a failover realm to test the other credential based failovers
configurableElements.add(PropertiesRealm.builder()
.withName("properties_realm_1")
.withUser(UserWithAttributeValues.builder()
.withName("user1")
.withPassword("password1")
.withValues("user")
.build())
.build());
// filesystem realm
FileSystemRealm unavailableFileSystemRealm = FileSystemRealm.builder()
.withName("unavailable_filesystem_realm")
.build();
String unavailableFileSystemRealmPath = unavailableFileSystemRealm.getPath().getPath();
// prevent accessing the temporary directory for the realm
unavailableFileSystemRealmDir = new File(escapePath(unavailableFileSystemRealmPath));
unavailableFileSystemRealmDir.setExecutable(false, false);
configurableElements.add(unavailableFileSystemRealm);
configurableElements.add(FailoverRealm.builder("failover_realm_filesystem")
.withDelegateRealm("unavailable_filesystem_realm")
.withFailoverRealm("properties_realm_1")
.build());
configurableElements.add(SimpleSecurityDomain.builder()
.withName("failover_realm_domain_filesystem")
.withDefaultRealm("failover_realm_filesystem")
.withPermissionMapper("default-permission-mapper")
.withSecurityEventListener("audit_log_for_failover_realm")
.withRealms(SimpleSecurityDomain.SecurityDomainRealm.builder()
.withRealm("failover_realm_filesystem")
.withRoleDecoder("groups-to-roles")
.build())
.build());
configurableElements.add(UndertowApplicationSecurityDomain.builder()
.withName(DEPLOYMENT_FILESYSTEM)
.withSecurityDomain("failover_realm_domain_filesystem")
.build());
// JDBC realm
configurableElements.add(JdbcSecurityRealm.builder("unavailable_jdbc_realm")
.withPrincipalQuery("ExampleDS", "invalid SQL")
.withPasswordMapper("clear-password-mapper", null, 1, -1, -1)
.build()
.build());
configurableElements.add(FailoverRealm.builder("failover_realm_jdbc")
.withDelegateRealm("unavailable_jdbc_realm")
.withFailoverRealm("properties_realm_1")
.build());
configurableElements.add(SimpleSecurityDomain.builder()
.withName("failover_realm_domain_jdbc")
.withDefaultRealm("failover_realm_jdbc")
.withPermissionMapper("default-permission-mapper")
.withSecurityEventListener("audit_log_for_failover_realm")
.withRealms(SimpleSecurityDomain.SecurityDomainRealm.builder()
.withRealm("failover_realm_jdbc")
.withRoleDecoder("groups-to-roles")
.build())
.build());
configurableElements.add(UndertowApplicationSecurityDomain.builder()
.withName(DEPLOYMENT_JDBC)
.withSecurityDomain("failover_realm_domain_jdbc")
.build());
// LDAP realm
configurableElements.add(DirContext.builder("unavailable_dir_context")
.withUrl("invalid_url")
.build());
configurableElements.add(LdapRealm.builder("unavailable_ldap_realm")
.withDirContext("unavailable_dir_context")
.withIdentityMapping(LdapRealm.identityMappingBuilder()
.withRdnIdentifier("invalid")
.withUserPasswordMapper(new LdapRealm.UserPasswordMapperBuilder()
.withFrom("invalid")
.build())
.build())
.build());
configurableElements.add(FailoverRealm.builder("failover_realm_ldap")
.withDelegateRealm("unavailable_ldap_realm")
.withFailoverRealm("properties_realm_1")
.build());
configurableElements.add(SimpleSecurityDomain.builder()
.withName("failover_realm_domain_ldap")
.withDefaultRealm("failover_realm_ldap")
.withPermissionMapper("default-permission-mapper")
.withSecurityEventListener("audit_log_for_failover_realm")
.withRealms(SimpleSecurityDomain.SecurityDomainRealm.builder()
.withRealm("failover_realm_ldap")
.withRoleDecoder("groups-to-roles")
.build())
.build());
configurableElements.add(UndertowApplicationSecurityDomain.builder()
.withName(DEPLOYMENT_LDAP)
.withSecurityDomain("failover_realm_domain_ldap")
.build());
// properties realm
configurableElements.add(PropertiesRealm.builder()
.withName("unavailable_properties_realm")
.withPlainText(false)
.withUser(UserWithAttributeValues.builder()
.withName("user1")
.withPassword("password1") // this is expected to be hashed but it isn't
.withValues("user")
.build())
.build());
configurableElements.add(FailoverRealm.builder("failover_realm_properties")
.withDelegateRealm("unavailable_properties_realm")
.withFailoverRealm("properties_realm_1")
.build());
configurableElements.add(SimpleSecurityDomain.builder()
.withName("failover_realm_domain_properties")
.withDefaultRealm("failover_realm_properties")
.withPermissionMapper("default-permission-mapper")
.withSecurityEventListener("audit_log_for_failover_realm")
.withRealms(SimpleSecurityDomain.SecurityDomainRealm.builder()
.withRealm("failover_realm_properties")
.withRoleDecoder("groups-to-roles")
.build())
.build());
configurableElements.add(UndertowApplicationSecurityDomain.builder()
.withName(DEPLOYMENT_PROPERTIES)
.withSecurityDomain("failover_realm_domain_properties")
.build());
// the delegate realm is available, the failover realm is not (LDAP)
configurableElements.add(FailoverRealm.builder("failover_realm_first_available")
.withDelegateRealm("properties_realm_1")
.withFailoverRealm("unavailable_ldap_realm")
.build());
configurableElements.add(SimpleSecurityDomain.builder()
.withName("failover_realm_domain_first_available")
.withDefaultRealm("failover_realm_first_available")
.withPermissionMapper("default-permission-mapper")
.withSecurityEventListener("audit_log_for_failover_realm")
.withRealms(SimpleSecurityDomain.SecurityDomainRealm.builder()
.withRealm("failover_realm_first_available")
.withRoleDecoder("groups-to-roles")
.build())
.build());
configurableElements.add(UndertowApplicationSecurityDomain.builder()
.withName(DEPLOYMENT_FIRST_AVAILABLE)
.withSecurityDomain("failover_realm_domain_first_available")
.build());
// both the credentaial based realms are not available
configurableElements.add(FailoverRealm.builder("failover_realm_both_unavailable")
.withDelegateRealm("unavailable_jdbc_realm")
.withFailoverRealm("unavailable_ldap_realm")
.build());
configurableElements.add(SimpleSecurityDomain.builder()
.withName("failover_realm_domain_both_unavailable")
.withDefaultRealm("failover_realm_both_unavailable")
.withPermissionMapper("default-permission-mapper")
.withSecurityEventListener("audit_log_for_failover_realm")
.withRealms(SimpleSecurityDomain.SecurityDomainRealm.builder()
.withRealm("failover_realm_both_unavailable")
.withRoleDecoder("groups-to-roles")
.build())
.build());
configurableElements.add(UndertowApplicationSecurityDomain.builder()
.withName(DEPLOYMENT_BOTH_UNAVAILABLE)
.withSecurityDomain("failover_realm_domain_both_unavailable")
.build());
// failover with SecurityRealmUnavailableEvent emitting disabled
configurableElements.add(FailoverRealm.builder("failover_realm_event_disabled")
.withDelegateRealm("unavailable_jdbc_realm")
.withFailoverRealm("properties_realm_1")
.withEmitEvents(false)
.build());
configurableElements.add(SimpleSecurityDomain.builder()
.withName("failover_realm_domain_event_disabled")
.withDefaultRealm("failover_realm_event_disabled")
.withPermissionMapper("default-permission-mapper")
.withSecurityEventListener("audit_log_for_failover_realm")
.withRealms(SimpleSecurityDomain.SecurityDomainRealm.builder()
.withRealm("failover_realm_event_disabled")
.withRoleDecoder("groups-to-roles")
.build())
.build());
configurableElements.add(UndertowApplicationSecurityDomain.builder()
.withName(DEPLOYMENT_EVENT_DISABLED)
.withSecurityDomain("failover_realm_domain_event_disabled")
.build());
// token realm
configurableElements.add(TokenRealm.builder("token_realm")
.withJwt(TokenRealm.jwtBuilder().withIssuer("issuer.wildfly.org").build())
.withPrincipalClaim("aud")
.build());
configurableElements.add(TokenRealm.builder("unavailable_token_realm")
.withOauth2Introspection(TokenRealm.oauth2IntrospectionBuilder()
.withClientId("failover_realm_client")
.withClientSecret("failover_realm_client_secret")
.withIntrospectionUrl("http://invalid")
.build())
.withPrincipalClaim("aud")
.build());
configurableElements.add(FailoverRealm.builder("failover_realm_bearer_token")
.withDelegateRealm("unavailable_token_realm")
.withFailoverRealm("token_realm")
.build());
configurableElements.add(SimpleSecurityDomain.builder()
.withName("failover_realm_domain_bearer_token")
.withDefaultRealm("failover_realm_bearer_token")
.withPermissionMapper("default-permission-mapper")
.withSecurityEventListener("audit_log_for_failover_realm")
.withRealms(SimpleSecurityDomain.SecurityDomainRealm.builder()
.withRealm("failover_realm_bearer_token")
.withRoleDecoder("groups-to-roles")
.build())
.build());
configurableElements.add(SimpleHttpAuthenticationFactory.builder()
.withName(DEPLOYMENT_BEARER_TOKEN)
.withHttpServerMechanismFactory("global")
.withSecurityDomain("failover_realm_domain_bearer_token")
.addMechanismConfiguration(MechanismConfiguration.builder()
.withMechanismName("BEARER_TOKEN")
.build())
.build());
configurableElements.add(UndertowApplicationSecurityDomain.builder()
.withName(DEPLOYMENT_BEARER_TOKEN)
.httpAuthenticationFactory(DEPLOYMENT_BEARER_TOKEN)
.build());
return configurableElements.toArray(new ConfigurableElement[configurableElements.size()]);
}
@Override
protected void tearDown(ModelControllerClient modelControllerClient) throws Exception {
super.tearDown(modelControllerClient);
Files.deleteIfExists(AUDIT_LOG_FILE.toPath());
}
}
}