-
Notifications
You must be signed in to change notification settings - Fork 30
/
SoapUnitTest.java
606 lines (511 loc) · 22.6 KB
/
SoapUnitTest.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
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
package ee.jakarta.tck.authentication.test.basic;
import static ee.jakarta.tck.authentication.test.basic.servlet.JASPICData.TSSV_ACF;
import static jakarta.security.auth.message.config.AuthConfigFactory.DEFAULT_FACTORY_SECURITY_PROPERTY;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import ee.jakarta.tck.authentication.test.basic.sam.ProviderConfigurationEntry;
import ee.jakarta.tck.authentication.test.basic.sam.ProviderConfigurationXMLFileProcessor;
import ee.jakarta.tck.authentication.test.basic.sam.config.TSAuthConfigFactoryForStandalone;
import ee.jakarta.tck.authentication.test.basic.sam.config.TSRegistrationListener;
import ee.jakarta.tck.authentication.test.basic.servlet.CommonTests;
import ee.jakarta.tck.authentication.test.basic.servlet.JASPICData;
import jakarta.security.auth.message.config.AuthConfigFactory;
import jakarta.security.auth.message.config.AuthConfigProvider;
import jakarta.security.auth.message.config.RegistrationListener;
import java.security.Security;
import java.util.Collection;
import java.util.Iterator;
import java.util.logging.Logger;
import org.junit.Before;
import org.junit.Test;
public class SoapUnitTest {
Logger logger = Logger.getLogger(SoapUnitTest.class.getName());
private String logFileLocation = System.getProperty("log.file.location");
private String providerConfigFileLocation = System.getProperty("provider.configuration.file");
private String vendorACFClass = System.getProperty("vendor.authconfig.factory");
private String soapAppContext = "localhost /Hello_web/Hello";
private transient ProviderConfigurationXMLFileProcessor configFileProcessor;
private Collection<ProviderConfigurationEntry> providerConfigurationEntriesCollection;
private CommonTests commonTests = new CommonTests();
@Before
public void setup() {
AuthConfigFactory.setFactory(null);
Security.setProperty(DEFAULT_FACTORY_SECURITY_PROPERTY, TSSV_ACF);
}
/**
* @keywords: jaspic_soap
*
* @testName: ACFGetFactory
*
* @assertion_ids: JASPIC:SPEC:329; JASPIC:SPEC:335; JASPIC:SPEC:7;
*
* @test_Strategy: This s mainly concerned with testing the runtimes handling of ACF as follows: - get current (CTS) ACF
* - switch to use different (CTS) ACF - verify calls to ACF use the newer/expected ACF - restore original ACF
*/
@Test
public void ACFGetFactory() {
boolean passed = false;
try {
commonTests._ACF_getFactory();
passed = true;
} catch (Exception ex) {
ex.printStackTrace();
}
assertTrue(passed);
}
/**
*
* @keywords: jaspic_soap
*
* @testName: ACFSwitchFactorys
*
* @assertion_ids:
*
*
* @test_Strategy: This test does the following: - gets current (CTS) factory - sets the vendors ACF thus replacing the
* CTS ACF - verify ACF's were correctly set - reset factory back to the original CTS factory
*
* 1. Use the static setFactory method to set an ACF and this should always work. and use the getFactory to verify it
* worked.
*
* Description
*
*/
@Test
public void ACFSwitchFactorys() {
boolean passed = false;
try {
commonTests._ACFSwitchFactorys(vendorACFClass);
passed = true;
} catch (Exception ex) {
ex.printStackTrace();
}
assertTrue(passed);
}
/**
* @keywords: jaspic_soap
*
* @testName: testACFComesFromSecFile
*
* @assertion_ids: JASPIC:SPEC:329; JASPIC:SPEC:330;
*
* @test_Strategy: This is calling a method on the server(actually servlet) side that will invoke getFactory() to verify
* a non-null facotry instance is returned. It will also verify that the authconfigprovider.factory security property is
* properly set/used.
*
*/
@Test
public void testACFComesFromSecFile() {
boolean passed = false;
try {
commonTests._testACFComesFromSecFile();
passed = true;
} catch (Exception ex) {
ex.printStackTrace();
}
assertTrue(passed);
}
/**
* @keywords: jaspic_soap
*
* @testName: ACFPersistentRegisterOnlyOneACP
*
* @assertion_ids: JASPIC:SPEC:329; JASPIC:SPEC:331; JASPIC:SPEC:332; JASPIC:SPEC:340; JASPIC:SPEC:341;
*
* @test_Strategy: This will make a server (actually servlet) side method call that will do the following: - load
* vendors ACF - (persistent) register of CTS ACP's in the vendors ACF - get list of vendors registered provider ID's -
* register another persistent ACP (this is standalone ACP profile) - verify another regId was added for standalone ACP
* - try to re-register (persistently) standalone provider - verify 2nd attempt at added standalone provider REPLACED
* the first but it should NOT have added another nor failed. - also confirm that regID for standalone ACP stayed the
* same after 1st and 2nd attempt to register standalone ACP - verify that the 2nd re-registering of ACP replaced the
* ACP AND the description. - unregister standalone ACP and setFactory back to CTS default
*
*/
@Test
public void ACFPersistentRegisterOnlyOneACP() {
boolean passed = false;
try {
commonTests._ACFRegisterOnlyOneACP(logFileLocation, providerConfigFileLocation, vendorACFClass, true);
passed = true;
} catch (Exception ex) {
ex.printStackTrace();
}
assertTrue(passed);
}
/**
* @keywords: jaspic_soap
*
* @testName: ACFInMemoryRegisterOnlyOneACP
*
* @assertion_ids: JASPIC:SPEC:334; JASPIC:SPEC:342; JASPIC:SPEC:343;
*
* @test_Strategy: This will make a server (actually servlet) side method call that will do the following: - load
* vendors ACF - (persistent) register of CTS ACP's in the vendors ACF - get list of vendors registered provider ID's -
* register (in-memory) ACP (this is standalone ACP profile) - verify another regId was added for standalone ACP - try
* to re-register (in-memory) standalone provider - verify 2nd attempt at added standalone provider REPLACED the first
* but it should NOT have added another nor failed. - also confirm that regID for standalone ACP stayed the same after
* 1st and 2nd attempt to register standalone ACP - verify that the 2nd re-registering of ACP replaced the ACP AND the
* description. - unregister standalone ACP and setFactory back to CTS default
*
*/
@Test
public void ACFInMemoryRegisterOnlyOneACP() {
boolean passed = false;
try {
commonTests._ACFRegisterOnlyOneACP(logFileLocation, providerConfigFileLocation, vendorACFClass, false);
passed = true;
} catch (Exception ex) {
ex.printStackTrace();
}
assertTrue(passed);
}
/**
* @keywords: jaspic_soap
*
* @testName: ACFUnregisterACP
*
* @assertion_ids: JASPIC:SPEC:344;
*
* @test_Strategy: This will make a server (actually servlet) side method call that will do the following: - load
* vendors ACF - (persistent) register of CTS ACP's in the vendors ACF - get list of vendors registered provider ID's -
* register (in-memory) ACP (this is standalone ACP profile) - verify another regId was added for standalone ACP -
* unregister the in-memory ACP we just registered - verify removeRegistration() method call returned proper boolean -
* verify expected # of registry eentries - verify 2nd call to removeRegistration() with regId that was previously
* removed and should expect return val of false
*
*/
@Test
public void ACFUnregisterACP() {
boolean passed = false;
try {
commonTests._ACFUnregisterACP(logFileLocation, providerConfigFileLocation, vendorACFClass);
passed = true;
} catch (Exception ex) {
ex.printStackTrace();
}
assertTrue(passed);
}
/**
*
* @keywords: jaspic_soap
*
* @testName: ACFRemoveRegistrationWithBadId
*
* @assertion_ids: JASPIC:SPEC:345;
*
*
* @test_Strategy: This test verifies we get a return value of False when invoking ACF.removeRegistration(some_bad_id);
*
* 1. Use the static setFactory method to get an ACF and then attempt to invoke removeRegistration() with an invalid (ie
* non-existant) regId. This should return False (per javadoc).
*
* Description
*
*/
@Test
public void ACFRemoveRegistrationWithBadId() {
boolean passed = false;
try {
commonTests._ACFRemoveRegistrationWithBadId();
passed = true;
} catch (Exception ex) {
ex.printStackTrace();
}
assertTrue(passed);
}
/**
* @keywords: jaspic_soap
*
* @testName: getRegistrationContextId
*
* @assertion_ids: JASPIC:JAVADOC:77
*
* @test_Strategy: 1. Get System properties log.file.location, provider.configuration.file and vendor.authconfig.factory
*
* 2. Use the system properties to read the TestSuite providers defined in ProviderConfigruation.xml file and register
* them with vendor's authconfig factory.
*
*
* Description This will use an appContext value that was used to register a provider, and it will see if it can use the
* AuthConfigFactory.RegistrationContext API to try and access the same appContext value that was used during the
* registration process.
*
*/
@Test
public void getRegistrationContextId() {
String appContext = "localhost /Hello_web/Hello";
// register providers in vendor factory
assertTrue(register(logFileLocation, providerConfigFileLocation, vendorACFClass));
// verify we can access a given provider (any provider) appcontext id
boolean bVerified = false;
AuthConfigFactory acf = null;
try {
acf = AuthConfigFactory.getFactory();
} catch (SecurityException ex) {
// if here we may not have permission to invoke ACF.getFactory...
String msg = "SecurityException: make sure you have permission to call ACF.getFactory.";
msg = msg + " Check your server side security policies.";
logger.info(msg);
ex.printStackTrace();
}
assertNotNull(
"getRegistrationContextId failed : could not get acf",
acf);
String[] regIDs = acf.getRegistrationIDs(null);
for (int ii = 0; ii < regIDs.length; ii++) {
// loop through the ACF's registration ids
if (regIDs[ii] != null) {
AuthConfigFactory.RegistrationContext acfReg;
acfReg = acf.getRegistrationContext(regIDs[ii]);
if (acfReg != null) {
logger.info("appContext = " + appContext);
logger.info("acfReg.getAppContext() = " + acfReg.getAppContext());
logger.info("layer = " + acfReg.getMessageLayer());
String str = acfReg.getAppContext();
if ((str != null) && (str.equals(appContext))) {
// we found our provider info
logger.info("Found it : RegistrationID for our ACP=" + regIDs[ii]);
bVerified = true;
break;
}
}
}
}
String msg = "Could not find appContext=" + appContext;
msg += " in the ACF's list of registration id info";
assertTrue(msg, bVerified);
logger.info("TestSuite Providers registration successful");
}
/**
* @keywords: jaspic_soap
*
* @testName: AuthConfigFactoryRegistration
*
* @assertion_ids: JASPIC:JAVADOC:80
*
* @test_Strategy: 1. Get System properties log.file.location, provider.configuration.file and vendor.authconfig.factory
*
* 2. Use the system properties to read the TestSuite providers defined in ProviderConfigruation.xml file and register
* them with vendor's authconfig factory.
*
*
* Description
*
*
*/
@Test
public void AuthConfigFactoryRegistration() {
assertTrue(
register(logFileLocation, providerConfigFileLocation, vendorACFClass));
}
public boolean register(String logFileLocation, String providerConfigFileLocation, String vendorACFClass) {
try {
printVerticalIndent();
// Get an instance of Vendor's AuthConfigFactory
AuthConfigFactory vendorFactory = getVendorAuthConfigFactory(vendorACFClass);
// Set vendor's AuthConfigFactory
AuthConfigFactory.setFactory(vendorFactory);
// Get system default AuthConfigFactory
AuthConfigFactory systemAuthConfigFactory = AuthConfigFactory.getFactory();
if (systemAuthConfigFactory != null) {
logger.info("Default AuthConfigFactory class name = " + systemAuthConfigFactory.getClass().getName());
} else {
logger.severe("Default AuthConfigFactory is null" + " can't register TestSuite Providers with null");
return false;
}
/**
* Read the ProviderConfiguration XML file This file contains the list of providers that needs to be loaded by the
* vendor's default AuthConfigFactory
*/
providerConfigurationEntriesCollection = readProviderConfigurationXMLFile();
ProviderConfigurationEntry pce = null;
printVerticalIndent();
Iterator<ProviderConfigurationEntry> iterator = providerConfigurationEntriesCollection.iterator();
while (iterator.hasNext()) {
// obtain each ProviderConfigurationEntry and register it
// with vendor's default AuthConfigFactory
pce = iterator.next();
if (pce != null) {
logger.info("Registering Provider " + pce.getProviderClassName() + " ...");
systemAuthConfigFactory.registerConfigProvider(
pce.getProviderClassName(),
pce.getProperties(),
pce.getMessageLayer(),
pce.getApplicationContextId(),
pce.getRegistrationDescription());
logger.info("Registration Successful");
}
}
printVerticalIndent();
// Check whether the providers are registered for the right message layer
// and appContext
// verifyRegistrations(acf);
} catch (SecurityException ex) {
// if here we may not have permission to invoke ACF.getFactory...
String msg = "SecurityException: make sure you have permission to call ACF.getFactory";
msg = msg + "or ACF.setFactory(). Check your server side security policies.";
logger.info(msg);
ex.printStackTrace();
} catch (Exception e) {
logger.info("Error Registering TestSuite AuthConfig Providers");
e.printStackTrace();
}
return true;
}
/**
* @keywords: jaspic_soap
*
* @testName: AuthConfigFactoryVerifyPersistence
*
* @assertion_ids: JASPIC:JAVADOC:75
*
* @test_Strategy: 1. Get System properties log.file.location, provider.configuration.file and vendor.authconfig.factory
*
* 2. Load vendor's AuthConfigFactory and make sure the registered providers return properly for the right message layer
* and appContextId
*
* Note: We test the persistance behaviour for vendor's AuthConfigFactory by registering providers from a persisted
* file, then we verify the registrations went correctly.
*
* Description
*
*
*/
public void AuthConfigFactoryVerifyPersistence() {
try {
// register providers in vendor factory
assertTrue(register(logFileLocation, providerConfigFileLocation, vendorACFClass));
// Get system default AuthConfigFactory
AuthConfigFactory acf = AuthConfigFactory.getFactory();
if (acf != null) {
logger.info("Default AuthConfigFactory class name = " + acf.getClass().getName());
assertTrue(verifyRegistrations(acf));
} else {
logger.severe("Default AuthConfigFactory is null" + " can't verify registrations for TestSuite Providers");
}
} catch (SecurityException ex) {
// if here we may not have permission to invoke ACF.getFactory...
String msg = "SecurityException: make sure you have permission to call ACF.getFactory.";
msg = msg + " Check your server side security policies.";
logger.info(msg);
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
*
* @keywords: jaspic_soap
*
* @testName: AuthConfigFactorySetFactory
*
* @assertion_ids: JASPIC:SPEC:7; JASPIC:SPEC:10; JASPIC:JAVADOC:87; JASPIC:JAVADOC:80
*
* @test_Strategy: 1. Use the static setFactory method to set an ACF and this should always work.
*
* Description This method uses the getFactory() method to get the current factory, then it uses the setFactory() to
* change the current ACF. This method then verifies that the ACF's were indeed changed. We know that the setFactory()
* works as it is used in the bootstrap process - but this is an additional level of testing that allows us to set the
* factory in a slightly different manner than the bootstrap (eg reading it out of the java.security file.
*/
@Test
public void AuthConfigFactorySetFactory() {
// Get current AuthConfigFactory
AuthConfigFactory currentAcf = AuthConfigFactory.getFactory();
assertNotNull(
"FAILURE - Could not get current AuthConfigFactory.",
currentAcf);
String currentACFClass = currentAcf.getClass().getName();
logger.info("currentACFClass = " + currentACFClass);
// Set our ACF to a new/different AuthConfigFactory
TSAuthConfigFactoryForStandalone newAcf = new TSAuthConfigFactoryForStandalone();
AuthConfigFactory.setFactory(newAcf);
String newACFClass = newAcf.getClass().getName();
logger.info("newACFClass = " + newACFClass);
// Verify our calls to getFactory() are getting the newly set factory
// instance and not the original ACF instance
AuthConfigFactory testAcf = AuthConfigFactory.getFactory();
assertNotNull(
"FAILURE - Could not get newly set AuthConfigFactory.",
testAcf);
String newlySetACFClass = testAcf.getClass().getName();
logger.info("newlySetACFClass = " + newlySetACFClass);
assertEquals(
"FAILURE - our current ACF does not match our newly set ACF",
newACFClass, newlySetACFClass);
logger.info("newlySetACFClass == newACFClass == " + newACFClass);
// Restore original factory class
AuthConfigFactory.setFactory(currentAcf);
logger.info("AuthConfigFactorySetFactory : PASSED");
}
private void printVerticalIndent() {
logger.info("**********************************************************");
logger.info("\n");
}
/**
* This method instantiates and returns a AuthConfigFactory based on the specified className
*/
private AuthConfigFactory getVendorAuthConfigFactory(String className) {
AuthConfigFactory vFactory = null;
if (className != null) {
try {
vFactory = (AuthConfigFactory)
Class.forName(className, true, Thread.currentThread()
.getContextClassLoader())
.getDeclaredConstructor()
.newInstance();
logger.info("Instantiated Vendor's AuthConfigFactory");
} catch (Exception e) {
logger.info("Error instantiating vendor's " + "AuthConfigFactory class :" + className);
e.printStackTrace();
}
}
return vFactory;
}
/*
* Read the provider configuration XML file and registers each provider with Vendor's default AuthConfigFactory
*/
private Collection<ProviderConfigurationEntry> readProviderConfigurationXMLFile() {
Collection<ProviderConfigurationEntry> providerConfigurationEntriesCollection = null;
logger.info("Reading TestSuite Providers from :" + providerConfigFileLocation);
try {
// Given the provider configuration xml file
// This reader parses the xml file and stores the configuration
// entries as a collection.
configFileProcessor = new ProviderConfigurationXMLFileProcessor(providerConfigFileLocation);
// Retrieve the ProviderConfigurationEntries collection
providerConfigurationEntriesCollection = configFileProcessor.getProviderConfigurationEntriesCollection();
logger.info("TestSuite Providers read successfully " + "from ProviderConfiguration.xml file");
return providerConfigurationEntriesCollection;
} catch (Exception e) {
logger.info("Error loading Providers");
e.printStackTrace();
}
return null;
}
private boolean verifyRegistrations(AuthConfigFactory acf) {
logger.info("Verifying Provider Registrations ...");
try {
// Create a Registration listener
RegistrationListener rlis = new TSRegistrationListener();
// Get AuthConfigProvider for soap layer
AuthConfigProvider acp = acf.getConfigProvider(JASPICData.LAYER_SOAP, soapAppContext, rlis);
if (acp != null) {
if (acp.getClass().getName().equals("com.sun.ts.tests.jaspic.tssv.config.TSAuthConfigProvider")) {
logger.info("TSAuthConfigProvider registered for" + " message layer=SOAP" + " and appContextId=" + soapAppContext);
} else {
logger.info("Wrong provider registerd for " + " message layer=SOAP" + " and appContextId=" + soapAppContext);
return false;
}
} else {
logger.info(
"Error : No AuthConfigprovider registerd for" + " message layer=SOAP" + " and appContextId=" + soapAppContext);
return false;
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
}