/
TSPolicyConfigurationImpl.java
1004 lines (904 loc) · 38.2 KB
/
TSPolicyConfigurationImpl.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
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2007, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
/*
* $Id$
*
* @author Raja Perumal
*/
package com.sun.ts.tests.jacc.provider;
import java.security.Permission;
import java.security.PermissionCollection;
import java.util.Date;
import java.util.Enumeration;
import java.util.Map;
import java.util.Vector;
import java.util.logging.Level;
import jakarta.security.jacc.EJBMethodPermission;
import jakarta.security.jacc.EJBRoleRefPermission;
import jakarta.security.jacc.PolicyConfiguration;
import jakarta.security.jacc.PolicyConfigurationFactory;
import jakarta.security.jacc.PolicyContextException;
import jakarta.security.jacc.WebResourcePermission;
import jakarta.security.jacc.WebRoleRefPermission;
import jakarta.security.jacc.WebUserDataPermission;
/**
* Jacc PolicyConfiguration delegates the policy configuration tasks to vendor's
* PolicyConfiguration implementation class.
*
*/
public class TSPolicyConfigurationImpl implements PolicyConfiguration {
private PolicyConfiguration policyConfiguration = null;
private PolicyConfigurationFactory pcf = null;
private static TSLogger logger = null;
private String applicationContext = null;
private String appTime = null;
private Vector applicationLinkTable = new Vector();
public TSPolicyConfigurationImpl(String contextId, boolean remove,
TSLogger lgr) throws PolicyContextException {
Date date = new Date();
appTime = "" + date.getTime();
logger = lgr;
// Add timeStamp to the contextId,
applicationContext = contextId;
if (logger.isLoggable(Level.FINER)) {
logger.entering("TSPolicyConfigurationImpl", "TSPolicyConfigurationImpl");
}
// set vendor's PolicyConfigurationFactory
pcf = TSPolicyConfigurationFactoryImpl.getPolicyConfigurationFactory();
// **** This covers two assertions JACC:SPEC:33 and JACC:SPEC:56 ****
// set vendor's PolicyConfiguration
policyConfiguration = pcf.getPolicyConfiguration(contextId, remove);
// This(appId record) will be used as an identifier
// for isolating the logs associated with each test run.
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO,
"appId :: " + stuffData(applicationContext) + " , " + appTime);
}
if (logger.isLoggable(Level.FINER)) {
logger.exiting("TSPolicyConfigurationImpl", "TSPolicyConfigurationImpl");
}
}
/**
* This method returns this object's policy context identifier.
*
* @return this object's policy context identifier.
*
* @throws java.lang.SecurityException
* if called by an AccessControlContext that has not been granted
* the "setPolicy" SecurityPermission.
*
* @throws jakarta.security.jacc.PolicyContextException
* if the implementation throws a checked exception that has not
* been accounted for by the getContextID method signature. The
* exception thrown by the implementation class will be encapsulated
* (during construction) in the thrown PolicyContextException.
*/
public String getContextID() throws PolicyContextException {
boolean bWasInservice = policyConfiguration.inService();
String contextId = policyConfiguration.getContextID();
// if the state was inService for our getContextID call, then it must remain
// in that state as its next transitional state (per javadoc table)
if (bWasInservice) {
assertIsInserviceState("getContextID");
} else {
// state was not inService so make sure it is still NOT in the
// inService state after calling policyConfiguration.getContextID()
assertStateNotInservice("getContextID");
}
if (logger.isLoggable(Level.FINER)) {
logger.log(Level.FINER, "contextId =" + contextId);
}
return contextId;
}
/**
* Used to add permissions to a named role in this PolicyConfiguration. If the
* named Role does not exist in the PolicyConfiguration, it is created as a
* result of the call to this function.
* <P>
* It is the job of the Policy provider to ensure that all the permissions
* added to a role are granted to principals "mapped to the role".
* <P>
*
* @param roleName
* the name of the Role to which the permissions are to be added.
* <P>
* @param permissions
* the collection of permissions to be added to the role. The
* collection may be either a homogenous or heterogenous collection.
*
* @throws java.lang.SecurityException
* if called by an AccessControlContext that has not been granted
* the "setPolicy" SecurityPermission.
*
* @throws java.lang.UnsupportedOperationException
* if the state of the policy context whose interface is this
* PolicyConfiguration Object is "deleted" or "inService" when this
* method is called.
*
* @throws jakarta.security.jacc.PolicyContextException
* if the implementation throws a checked exception that has not
* been accounted for by the addToRole method signature. The
* exception thrown by the implementation class will be encapsulated
* (during construction) in the thrown PolicyContextException.
*/
public void addToRole(String roleName, PermissionCollection permissions)
throws PolicyContextException {
String permissionType = null;
if (logger.isLoggable(Level.FINER)) {
logger.entering("TSPolicyConfigurationImpl", "addToRole");
}
if (roleName == null || permissions == null)
return;
policyConfiguration = pcf.getPolicyConfiguration(applicationContext, false);
policyConfiguration.addToRole(roleName, permissions);
assertStateNotInservice("addToRole");
if (logger.isLoggable(Level.INFO)) {
StringBuffer sbuf = new StringBuffer("");
int bufLength = 0;
for (Enumeration en = permissions.elements(); en.hasMoreElements();) {
sbuf.append("addToRole :: ");
sbuf.append(applicationContext + " , ");
sbuf.append(appTime + " , ");
Permission p = (Permission) en.nextElement();
// Get the permission type,
// valid permission types are
// 1) WebResourcePermission
// 2) WebUserDataPermission
// 3) WebRoleRefPermission
// 4) EJBMethodPermission
// 5) EJBRoleRefPermission
permissionType = getPermissionType(p);
sbuf.append(permissionType + " , ");
sbuf.append(p.getName() + " , ");
sbuf.append(p.getActions());
logger.log(Level.INFO, sbuf.toString());
// Re-initialize string buffer.
bufLength = sbuf.length();
sbuf.delete(0, bufLength);
if (permissionType.equals("WebResourcePermission")
|| permissionType.equals("WebRoleRefPermission")
|| permissionType.equals("EJBMethodPermission")
|| permissionType.equals("EJBRoleRefPermission")) {
// logged so we can check roleNames and resourcePerms
logger.log(Level.INFO, "MSG_TAG :: " + permissionType + " :: "
+ roleName + " :: " + applicationContext + " :: " + p.getName());
} else {
// logger.log(Level.INFO, "MSG_TAG :: nothing logged for " +
// permissionType + " :: " + roleName + " :: " + applicationContext +
// " :: " + p.getName());
}
}
}
if (logger.isLoggable(Level.FINER)) {
logger.exiting("TSPolicyConfigurationImpl", "addToRole");
}
}
/**
* Used to add a single permission to a named role in this
* PolicyConfiguration. If the named Role does not exist in the
* PolicyConfiguration, it is created as a result of the call to this
* function.
* <P>
* It is the job of the Policy provider to ensure that all the permissions
* added to a role are granted to principals "mapped to the role".
* <P>
*
* @param roleName
* the name of the Role to which the permission is to be added.
* <P>
* @param permission
* the permission to be added to the role.
*
* @throws java.lang.SecurityException
* if called by an AccessControlContext that has not been granted
* the "setPolicy" SecurityPermission.
*
* @throws java.lang.UnsupportedOperationException
* if the state of the policy context whose interface is this
* PolicyConfiguration Object is "deleted" or "inService" when this
* method is called.
*
* @throws jakarta.security.jacc.PolicyContextException
* if the implementation throws a checked exception that has not
* been accounted for by the addToRole method signature. The
* exception thrown by the implementation class will be encapsulated
* (during construction) in the thrown PolicyContextException.
*/
public void addToRole(String roleName, Permission permission)
throws PolicyContextException {
String permissionType = null;
if (logger.isLoggable(Level.FINER)) {
logger.entering("TSPolicyConfigurationImpl", "addToRole");
}
if (roleName == null || permission == null)
return;
policyConfiguration = pcf.getPolicyConfiguration(applicationContext, false);
policyConfiguration.addToRole(roleName, permission);
assertStateNotInservice("addToRole");
// Get the permission type,
// valid permission types are
// 1) WebResourcePermission
// 2) WebUserDataPermission
// 3) WebRoleRefPermission
// 4) EJBMethodPermission
// 5) EJBRoleRefPermission
permissionType = getPermissionType(permission);
if (logger.isLoggable(Level.INFO)) {
String sbuf = new String("addToRole :: " + applicationContext + " , "
+ appTime + " , " + permissionType + " , " + permission.getName()
+ " , " + permission.getActions());
logger.log(Level.INFO, sbuf);
}
if (permissionType.equals("WebResourcePermission")
|| permissionType.equals("WebRoleRefPermission")
|| permissionType.equals("EJBMethodPermission")
|| permissionType.equals("EJBRoleRefPermission")) {
// logged so we can check roleNames and resourcePerms
logger.log(Level.INFO, "MSG_TAG :: " + permissionType + " :: " + roleName
+ " :: " + applicationContext + " :: " + permission.getName());
} else {
// logger.log(Level.INFO, "MSG_TAG :: nothing logged for " +
// permissionType + " :: " + roleName + " :: " + applicationContext + " ::
// " + permission.getName());
}
if (logger.isLoggable(Level.FINER)) {
logger.exiting("TSPolicyConfigurationImpl", "addToRole");
}
}
/**
* Used to add unchecked policy statements to this PolicyConfiguration.
* <P>
*
* @param permissions
* the collection of permissions to be added as unchecked policy
* statements. The collection may be either a homogenous or
* heterogenous collection.
*
* @throws java.lang.SecurityException
* if called by an AccessControlContext that has not been granted
* the "setPolicy" SecurityPermission.
*
* @throws java.lang.UnsupportedOperationException
* if the state of the policy context whose interface is this
* PolicyConfiguration Object is "deleted" or "inService" when this
* method is called.
*
* @throws jakarta.security.jacc.PolicyContextException
* if the implementation throws a checked exception that has not
* been accounted for by the addToUncheckedPolicy method signature.
* The exception thrown by the implementation class will be
* encapsulated (during construction) in the thrown
* PolicyContextException.
*/
public void addToUncheckedPolicy(PermissionCollection permissions)
throws PolicyContextException {
String permissionType = null;
if (logger.isLoggable(Level.FINER)) {
logger.entering("TSPolicyConfigurationImpl", "addToUncheckedPolicy");
}
if (permissions == null)
return;
policyConfiguration = pcf.getPolicyConfiguration(applicationContext, false);
policyConfiguration.addToUncheckedPolicy(permissions);
assertStateNotInservice("addToUncheckedPolicy");
if (logger.isLoggable(Level.INFO)) {
StringBuffer sbuf = new StringBuffer("");
int bufLength = 0;
for (Enumeration en = permissions.elements(); en.hasMoreElements();) {
sbuf.append("unchecked :: ");
sbuf.append(applicationContext + " , ");
sbuf.append(appTime + " , ");
Permission p = (Permission) en.nextElement();
// Get the permission type,
// valid permission types are
// 1) WebResourcePermission
// 2) WebUserDataPermission
// 3) WebRoleRefPermission
// 4) EJBMethodPermission
// 5) EJBRoleRefPermission
permissionType = getPermissionType(p);
sbuf.append(permissionType + " , ");
sbuf.append(p.getName() + " , ");
sbuf.append(p.getActions());
logger.log(Level.INFO, sbuf.toString());
// Re-initialize string buffer
bufLength = sbuf.length();
sbuf.delete(0, bufLength);
}
}
if (logger.isLoggable(Level.FINER)) {
logger.exiting("TSPolicyConfigurationImpl", "addToUncheckedPolicy");
}
}
/**
* Used to add a single unchecked policy statement to this
* PolicyConfiguration.
* <P>
*
* @param permission
* the permission to be added to the unchecked policy statements.
*
* @throws java.lang.SecurityException
* if called by an AccessControlContext that has not been granted
* the "setPolicy" SecurityPermission.
*
* @throws java.lang.UnsupportedOperationException
* if the state of the policy context whose interface is this
* PolicyConfiguration Object is "deleted" or "inService" when this
* method is called.
*
* @throws jakarta.security.jacc.PolicyContextException
* if the implementation throws a checked exception that has not
* been accounted for by the addToUncheckedPolicy method signature.
* The exception thrown by the implementation class will be
* encapsulated (during construction) in the thrown
* PolicyContextException.
*/
public void addToUncheckedPolicy(Permission permission)
throws PolicyContextException {
if (logger.isLoggable(Level.FINER)) {
logger.entering("TSPolicyConfigurationImpl", "addToUncheckedPolicy");
}
if (permission == null)
return;
policyConfiguration = pcf.getPolicyConfiguration(applicationContext, false);
policyConfiguration.addToUncheckedPolicy(permission);
assertStateNotInservice("addToUncheckedPolicy");
// Get the permission type,
// valid permission types are
// 1) WebResourcePermission
// 2) WebUserDataPermission
// 3) WebRoleRefPermission
// 4) EJBMethodPermission
// 5) EJBRoleRefPermission
String permissionType = getPermissionType(permission);
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO,
"unchecked :: " + applicationContext + " , " + appTime + " , "
+ permissionType + " , " + permission.getName() + " , "
+ permission.getActions());
}
if (logger.isLoggable(Level.FINER)) {
logger.exiting("TSPolicyConfigurationImpl", "addToUncheckedPolicy");
}
}
/**
* Used to add excluded policy statements to this PolicyConfiguration.
* <P>
*
* @param permissions
* the collection of permissions to be added to the excluded policy
* statements. The collection may be either a homogenous or
* heterogenous collection.
*
* @throws java.lang.SecurityException
* if called by an AccessControlContext that has not been granted
* the "setPolicy" SecurityPermission.
*
* @throws java.lang.UnsupportedOperationException
* if the state of the policy context whose interface is this
* PolicyConfiguration Object is "deleted" or "inService" when this
* method is called.
*
* @throws jakarta.security.jacc.PolicyContextException
* if the implementation throws a checked exception that has not
* been accounted for by the addToExcludedPolicy method signature.
* The exception thrown by the implementation class will be
* encapsulated (during construction) in the thrown
* PolicyContextException.
*/
public void addToExcludedPolicy(PermissionCollection permissions)
throws PolicyContextException {
String permissionType = null;
if (logger.isLoggable(Level.FINER)) {
logger.entering("TSPolicyConfigurationImpl", "addToExcludedPolicy");
}
if (permissions == null)
return;
policyConfiguration = pcf.getPolicyConfiguration(applicationContext, false);
policyConfiguration.addToExcludedPolicy(permissions);
assertStateNotInservice("addToExcludedPolicy");
if (logger.isLoggable(Level.INFO)) {
StringBuffer sbuf = new StringBuffer("");
int bufLength = 0;
for (Enumeration en = permissions.elements(); en.hasMoreElements();) {
sbuf.append("excluded :: ");
sbuf.append(applicationContext + " , ");
sbuf.append(appTime + " , ");
Permission p = (Permission) en.nextElement();
// Get the permission type,
// valid permission types are
// 1) WebResourcePermission
// 2) WebUserDataPermission
// 3) WebRoleRefPermission
// 4) EJBMethodPermission
// 5) EJBRoleRefPermission
permissionType = getPermissionType(p);
sbuf.append(permissionType + " , ");
sbuf.append(p.getName() + " , ");
sbuf.append(p.getActions());
logger.log(Level.INFO, sbuf.toString());
// Re-initialize string buffer.
bufLength = sbuf.length();
sbuf.delete(0, bufLength);
}
}
if (logger.isLoggable(Level.FINER)) {
logger.exiting("TSPolicyConfigurationImpl", "addToExcludedPolicy");
}
}
/**
* Used to add a single excluded policy statement to this PolicyConfiguration.
* <P>
*
* @param permission
* the permission to be added to the excluded policy statements.
*
* @throws java.lang.SecurityException
* if called by an AccessControlContext that has not been granted
* the "setPolicy" SecurityPermission.
*
* @throws java.lang.UnsupportedOperationException
* if the state of the policy context whose interface is this
* PolicyConfiguration Object is "deleted" or "inService" when this
* method is called.
*
* @throws jakarta.security.jacc.PolicyContextException
* if the implementation throws a checked exception that has not
* been accounted for by the addToExcludedPolicy method signature.
* The exception thrown by the implementation class will be
* encapsulated (during construction) in the thrown
* PolicyContextException.
*/
public void addToExcludedPolicy(Permission permission)
throws PolicyContextException {
String permissionType = null;
if (logger.isLoggable(Level.FINER)) {
logger.entering("TSPolicyConfigurationImpl", "addToExcludedPolicy");
}
if (permission == null)
return;
policyConfiguration = pcf.getPolicyConfiguration(applicationContext, false);
policyConfiguration.addToExcludedPolicy(permission);
assertStateNotInservice("addToExcludedPolicy");
// Get the permission type,
// valid permission types are
// 1) WebResourcePermission
// 2) WebUserDataPermission
// 3) WebRoleRefPermission
// 4) EJBMethodPermission
// 5) EJBRoleRefPermission
permissionType = getPermissionType(permission);
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO,
"excluded :: " + applicationContext + " , " + appTime + " , "
+ permissionType + " , " + permission.getName() + " , "
+ permission.getActions());
}
if (logger.isLoggable(Level.FINER)) {
logger.exiting("TSPolicyConfigurationImpl", "addToExcludedPolicy");
}
}
/**
* Used to remove a role and all its permissions from this
* PolicyConfiguration.
* <P>
*
* @param roleName
* the name of the Role to remove from this PolicyConfiguration.
*
* @throws java.lang.SecurityException
* if called by an AccessControlContext that has not been granted
* the "setPolicy" SecurityPermission.
*
* @throws java.lang.UnsupportedOperationException
* if the state of the policy context whose interface is this
* PolicyConfiguration Object is "deleted" or "inService" when this
* method is called.
*
* @throws jakarta.security.jacc.PolicyContextException
* if the implementation throws a checked exception that has not
* been accounted for by the removeRole method signature. The
* exception thrown by the implementation class will be encapsulated
* (during construction) in the thrown PolicyContextException.
*/
public void removeRole(String roleName) throws PolicyContextException {
if (logger.isLoggable(Level.FINER)) {
logger.entering("TSPolicyConfigurationImpl", "removeRole");
}
if (roleName == null)
return;
policyConfiguration = pcf.getPolicyConfiguration(applicationContext, false);
policyConfiguration.removeRole(roleName);
assertStateNotInservice("removeRole");
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, "Removed Role :: " + roleName);
}
if (logger.isLoggable(Level.FINER)) {
logger.exiting("TSPolicyConfigurationImpl", "removeRole");
}
}
/**
* Used to remove any unchecked policy statements from this
* PolicyConfiguration.
*
* @throws java.lang.SecurityException
* if called by an AccessControlContext that has not been granted
* the "setPolicy" SecurityPermission.
*
* @throws java.lang.UnsupportedOperationException
* if the state of the policy context whose interface is this
* PolicyConfiguration Object is "deleted" or "inService" when this
* method is called.
*
* @throws jakarta.security.jacc.PolicyContextException
* if the implementation throws a checked exception that has not
* been accounted for by the removeUncheckedPolicy method signature.
* The exception thrown by the implementation class will be
* encapsulated (during construction) in the thrown
* PolicyContextException.
*/
public void removeUncheckedPolicy() throws PolicyContextException {
if (logger.isLoggable(Level.FINER)) {
logger.entering("TSPolicyConfigurationImpl", "removeUncheckedPolicy");
}
policyConfiguration = pcf.getPolicyConfiguration(applicationContext, false);
policyConfiguration.removeUncheckedPolicy();
assertStateNotInservice("removeUncheckedPolicy");
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, "Removed all unchecked policy statements");
}
if (logger.isLoggable(Level.FINER)) {
logger.exiting("TSPolicyConfigurationImpl", "removeUncheckedPolicy");
}
}
/**
* Used to remove any excluded policy statements from this
* PolicyConfiguration.
*
* @throws java.lang.SecurityException
* if called by an AccessControlContext that has not been granted
* the "setPolicy" SecurityPermission.
*
* @throws java.lang.UnsupportedOperationException
* if the state of the policy context whose interface is this
* PolicyConfiguration Object is "deleted" or "inService" when this
* method is called.
*
* @throws jakarta.security.jacc.PolicyContextException
* if the implementation throws a checked exception that has not
* been accounted for by the removeExcludedPolicy method signature.
* The exception thrown by the implementation class will be
* encapsulated (during construction) in the thrown
* PolicyContextException.
*/
public void removeExcludedPolicy() throws PolicyContextException {
if (logger.isLoggable(Level.FINER)) {
logger.entering("TSPolicyConfigurationImpl", "removeExcludedPolicy");
}
policyConfiguration = pcf.getPolicyConfiguration(applicationContext, false);
policyConfiguration.removeExcludedPolicy();
assertStateNotInservice("removeExcludedPolicy");
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, "Removed all excluded policy statements");
}
if (logger.isLoggable(Level.FINER)) {
logger.exiting("TSPolicyConfigurationImpl", "removeExcludedPolicy");
}
}
/**
* This method is used to set to "inService" the state of the policy context
* whose interface is this PolicyConfiguration Object. Only those policy
* contexts whose state is "inService" will be included in the policy contexts
* processed by the Policy.refresh method. A policy context whose state is
* "inService" may be returned to the "open" state by calling the
* getPolicyConfiguration method of the PolicyConfiguration factory with the
* policy context identifier of the policy context.
* <P>
* When the state of a policy context is "inService", calling any method other
* than commit, delete, getContextID, or inService on its PolicyConfiguration
* Object will cause an UnsupportedOperationException to be thrown.
*
* @throws java.lang.SecurityException
* if called by an AccessControlContext that has not been granted
* the "setPolicy" SecurityPermission.
*
* @throws java.lang.UnsupportedOperationException
* if the state of the policy context whose interface is this
* PolicyConfiguration Object is "deleted" when this method is
* called.
*
* @throws jakarta.security.jacc.PolicyContextException
* if the implementation throws a checked exception that has not
* been accounted for by the commit method signature. The exception
* thrown by the implementation class will be encapsulated (during
* construction) in the thrown PolicyContextException.
*/
public void commit() throws PolicyContextException {
// Date date= new Date();
if (logger.isLoggable(Level.FINER)) {
logger.entering("TSPolicyConfigurationImpl", "commit");
}
boolean bWasInservice = policyConfiguration.inService();
policyConfiguration.commit();
assertIsInserviceState("commit");
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, "PolicyConfiguration.commit() called");
}
if (logger.isLoggable(Level.FINER)) {
logger.exiting("TSPolicyConfigurationImpl", "commit");
}
}
/**
* Creates a relationship between this configuration and another such that
* they share the same principal-to-role mappings. PolicyConfigurations are
* linked to apply a common principal-to-role mapping to multiple seperately
* manageable PolicyConfigurations, as is required when an application is
* composed of multiple modules.
* <P>
* Note that the policy statements which comprise a role, or comprise the
* excluded or unchecked policy collections in a PolicyConfiguration are
* unaffected by the configuration being linked to another.
* <P>
*
* @param link
* a reference to a different PolicyConfiguration than this
* PolicyConfiguration.
* <P>
* The relationship formed by this method is symetric, transitive and
* idempotent. If the argument PolicyConfiguration does not have a
* different Policy context identifier than this PolicyConfiguration
* no relationship is formed, and an exception, as described below,
* is thrown.
*
* @throws java.lang.SecurityException
* if called by an AccessControlContext that has not been granted
* the "setPolicy" SecurityPermission.
*
* @throws java.lang.UnsupportedOperationException
* if the state of the policy context whose interface is this
* PolicyConfiguration Object is "deleted" or "inService" when this
* method is called.
*
* @throws java.lang.IllegalArgumentException
* if called with an argument PolicyConfiguration whose Policy
* context is equivalent to that of this PolicyConfiguration.
*
* @throws jakarta.security.jacc.PolicyContextException
* if the implementation throws a checked exception that has not
* been accounted for by the linkConfiguration method signature. The
* exception thrown by the implementation class will be encapsulated
* (during construction) in the thrown PolicyContextException.
*/
public void linkConfiguration(PolicyConfiguration link)
throws PolicyContextException {
String contextId = null;
if (logger.isLoggable(Level.FINER)) {
logger.entering("TSPolicyConfigurationImpl", "linkConfiguration");
}
if (link != null) {
contextId = link.getContextID();
// Check if the application name already exists
if (applicationLinkTable != null) {
// Now add the contextId that is being linked to applicationLinkTable
if (!applicationLinkTable.contains(contextId)) {
applicationLinkTable.add(contextId);
}
// Now add this.applicationContextId to applicationLinkTable
if (!applicationLinkTable.contains(applicationContext)) {
applicationLinkTable.add(applicationContext);
}
}
if (logger.isLoggable(Level.INFO)) {
StringBuffer sbuf = new StringBuffer("");
int bufLength = 0;
sbuf.append("link :: ");
for (Enumeration appEnum = applicationLinkTable.elements(); appEnum
.hasMoreElements();) {
String stuffedAppName = stuffData((String) appEnum.nextElement());
sbuf.append(stuffedAppName);
if (appEnum.hasMoreElements())
sbuf.append(",");
}
sbuf.append(" : ");
sbuf.append(appTime);
// Log all the linked application names
logger.log(Level.INFO, sbuf.toString());
}
}
// policyConfiguration.linkConfiguration(link);
// Note:
// The Passed varibale "link" may be an instance of
// delegating Provider's PolicyConfiguration, so before
// linking it with Vendor's PolicyConfiguration, first
// get the vendor's equivalent PolicyConfiguration from "link"
// get contextId from link
String vendorContextId = link.getContextID();
// get vendor's Policy configuration from "link"
// Note: pcf is vendor's PolicyConfigurationFactory
PolicyConfiguration vendorPC = pcf.getPolicyConfiguration(vendorContextId,
false);
// Now link the vendor's PolicyConfiguration
boolean bWasInservice = policyConfiguration.inService();
policyConfiguration.linkConfiguration(vendorPC);
assertStateNotInservice("linkConfiguration");
if (logger.isLoggable(Level.FINER)) {
logger.exiting("TSPolicyConfigurationImpl", "linkConfiguration");
}
}
/**
* Causes all policy statements to be deleted from this PolicyConfiguration
* and sets its internal state such that calling any method, other than
* delete, getContextID, or inService on the PolicyConfiguration will be
* rejected and cause an UnsupportedOperationException to be thrown.
* <P>
* This operation has no affect on any linked PolicyConfigurations other than
* removing any links involving the deleted PolicyConfiguration.
*
* @throws java.lang.SecurityException
* if called by an AccessControlContext that has not been granted
* the "setPolicy" SecurityPermission.
*
* @throws jakarta.security.jacc.PolicyContextException
* if the implementation throws a checked exception that has not
* been accounted for by the delete method signature. The exception
* thrown by the implementation class will be encapsulated (during
* construction) in the thrown PolicyContextException.
*/
public void delete() throws PolicyContextException {
if (logger.isLoggable(Level.FINER)) {
logger.entering("TSPolicyConfigurationImpl", "delete");
}
policyConfiguration.delete();
assertStateNotInservice("delete");
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, "Deleted all policy statements");
}
if (logger.isLoggable(Level.FINER)) {
logger.exiting("TSPolicyConfigurationImpl", "delete");
}
}
/**
* This method is used to determine if the policy context whose interface is
* this PolicyConfiguration Object is in the "inService" state.
*
* @return true if the state of the associated policy context is "inService";
* false otherwise.
*
* @throws java.lang.SecurityException
* if called by an AccessControlContext that has not been granted
* the "setPolicy" SecurityPermission.
*
* @throws jakarta.security.jacc.PolicyContextException
* if the implementation throws a checked exception that has not
* been accounted for by the inService method signature. The
* exception thrown by the implementation class will be encapsulated
* (during construction) in the thrown PolicyContextException.
*/
public boolean inService() throws PolicyContextException {
if (logger.isLoggable(Level.FINER)) {
logger.entering("TSPolicyConfigurationImpl", "inService");
}
boolean bWasInservice = policyConfiguration.inService();
boolean ret = policyConfiguration.inService();
// if the state was inService befor our policyConfiguration.inService()
// call, then it must remain in that state as its next transitional
// state (per javadoc table)
if (bWasInservice) {
assertIsInserviceState("inService");
} else {
// state was not inService so must've been OPEN or DELETED but
// either way, the next state must remain the same so we know
// we should NOT trasition to different state
assertStateNotInservice("inService");
}
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "PolicyConfiguration.inService() called");
}
if (logger.isLoggable(Level.FINER)) {
logger.exiting("TSPolicyConfigurationImpl", "inService");
}
return ret;
}
public String getPermissionType(Permission permission) {
if (permission instanceof WebResourcePermission)
return "WebResourcePermission";
else if (permission instanceof WebUserDataPermission)
return "WebUserDataPermission";
else if (permission instanceof WebRoleRefPermission)
return "WebRoleRefPermission";
else if (permission instanceof EJBMethodPermission)
return "EJBMethodPermission";
else if (permission instanceof EJBRoleRefPermission)
return "EJBRoleRefPermission";
else
return null;
}
// This method process the input string and stuffs the character twice if
// the processed character is not an alphabet
public static String stuffData(String inputStr) {
char[] outStr = new char[2048];
char[] str = inputStr.toCharArray();
for (int i = 0, j = 0; i < str.length; i++) {
int a = (new Character(str[i])).getNumericValue(str[i]);
// Don't stuff extra character if the character is an alphabet
//
// Numeric values for alphabets falls in 10 to 35, this includes
// both upper and lower cases
if ((a > 9) && (a < 36)) {
outStr[j++] = str[i];
} else { // stuff the character
outStr[j++] = str[i];
outStr[j++] = str[i];
}
}
return ((new String(outStr)).trim());
}
public PermissionCollection getExcludedPermissions(){
return policyConfiguration.getExcludedPermissions();
}
public PermissionCollection getUncheckedPermissions(){
return policyConfiguration.getUncheckedPermissions();
}
public Map<String, PermissionCollection> getPerRolePermissions(){
return policyConfiguration.getPerRolePermissions();
}
private void assertIsInserviceState(String callingMethod) {
try {
if (!policyConfiguration.inService()) {
String msg1 = "ERROR - our policy config should be in the INSERVICE state.";
String msg2 = "In the wrong state after having called: "
+ callingMethod;
debugOut(msg1);
debugOut(msg2);
logger.log(Level.SEVERE, msg1);
}
} catch (SecurityException ex) {
String err = "ERROR - got securityException calling policyConfiguration.inService().";
err += " You likely need to have 'setPolicy' grant set";
debugOut(err);
debugOut(ex.toString());
} catch (Exception ex) {
debugOut("ERROR - Exception calling policyConfiguration.inService(): "
+ ex.toString());
ex.printStackTrace();
}
}
private void assertStateNotInservice(String callingMethod) {
try {
if (policyConfiguration.inService()) {
String msg1 = "ERROR - our policy config should not be in the INSERVICE state.";
String msg2 = "In the wrong state after having called: "
+ callingMethod;
debugOut(msg1);
debugOut(msg2);
logger.log(Level.SEVERE, msg1);
}
} catch (SecurityException ex) {
String err = "ERROR - got securityException calling policyConfiguration.inService().";
err += " You likely need to have 'setPolicy' grant set";
debugOut(err);
debugOut(ex.toString());
} catch (Exception ex) {
debugOut("ERROR - Exception calling policyConfiguration.inService(): "
+ ex.toString());
ex.printStackTrace();
}
}
private void debugOut(String str) {