25
25
26
26
package javax .security .auth ;
27
27
28
- import java .util .*;
29
- import java .io .*;
28
+ import java .io .IOException ;
29
+ import java .io .ObjectInputStream ;
30
+ import java .io .ObjectOutputStream ;
31
+ import java .io .ObjectStreamField ;
32
+ import java .security .*;
30
33
import java .text .MessageFormat ;
31
- import java .security .AccessController ;
32
- import java .security .AccessControlContext ;
33
- import java .security .DomainCombiner ;
34
- import java .security .Principal ;
35
- import java .security .PrivilegedExceptionAction ;
36
- import java .security .PrivilegedActionException ;
37
- import java .security .ProtectionDomain ;
34
+ import java .util .*;
38
35
import java .util .concurrent .Callable ;
39
36
import java .util .concurrent .CompletionException ;
40
37
41
- import sun .security .action .GetBooleanAction ;
42
38
import sun .security .util .ResourcesMgr ;
43
39
44
40
/**
90
86
* While the Principals associated with the {@code Subject} are serialized,
91
87
* the credentials associated with the {@code Subject} are not.
92
88
* Note that the {@code java.security.Principal} class
93
- * does not implement {@code Serializable}. Therefore all concrete
89
+ * does not implement {@code Serializable}. Therefore, all concrete
94
90
* {@code Principal} implementations associated with Subjects
95
91
* must implement {@code Serializable}.
96
92
*
@@ -752,7 +748,7 @@ public <T extends Principal> Set<T> getPrincipals(Class<T> c) {
752
748
753
749
// always return an empty Set instead of null
754
750
// so LoginModules can add to the Set if necessary
755
- return new ClassSet <T >(PRINCIPAL_SET , c );
751
+ return new ClassSet <>(PRINCIPAL_SET , c );
756
752
}
757
753
758
754
/**
@@ -846,7 +842,7 @@ public <T> Set<T> getPublicCredentials(Class<T> c) {
846
842
847
843
// always return an empty Set instead of null
848
844
// so LoginModules can add to the Set if necessary
849
- return new ClassSet <T >(PUB_CREDENTIAL_SET , c );
845
+ return new ClassSet <>(PUB_CREDENTIAL_SET , c );
850
846
}
851
847
852
848
/**
@@ -890,7 +886,7 @@ public <T> Set<T> getPrivateCredentials(Class<T> c) {
890
886
891
887
// always return an empty Set instead of null
892
888
// so LoginModules can add to the Set if necessary
893
- return new ClassSet <T >(PRIV_CREDENTIAL_SET , c );
889
+ return new ClassSet <>(PRIV_CREDENTIAL_SET , c );
894
890
}
895
891
896
892
/**
@@ -923,9 +919,7 @@ public boolean equals(Object o) {
923
919
return true ;
924
920
}
925
921
926
- if (o instanceof Subject ) {
927
-
928
- final Subject that = (Subject )o ;
922
+ if (o instanceof final Subject that ) {
929
923
930
924
// check the principal and credential sets
931
925
Set <Principal > thatPrincipals ;
@@ -1180,7 +1174,7 @@ private static class SecureSet<E>
1180
1174
SecureSet (Subject subject , int which ) {
1181
1175
this .subject = subject ;
1182
1176
this .which = which ;
1183
- this .elements = new LinkedList <E >();
1177
+ this .elements = new LinkedList <>();
1184
1178
}
1185
1179
1186
1180
SecureSet (Subject subject , int which , LinkedList <E > list ) {
@@ -1195,10 +1189,12 @@ public int size() {
1195
1189
1196
1190
public Iterator <E > iterator () {
1197
1191
final LinkedList <E > list = elements ;
1198
- return new Iterator <E >() {
1199
- ListIterator <E > i = list .listIterator (0 );
1192
+ return new Iterator <>() {
1193
+ final ListIterator <E > i = list .listIterator (0 );
1200
1194
1201
- public boolean hasNext () {return i .hasNext ();}
1195
+ public boolean hasNext () {
1196
+ return i .hasNext ();
1197
+ }
1202
1198
1203
1199
public E next () {
1204
1200
if (which != Subject .PRIV_CREDENTIAL_SET ) {
@@ -1337,7 +1333,7 @@ public boolean contains(Object o) {
1337
1333
// For private credentials:
1338
1334
// If the caller does not have read permission
1339
1335
// for o.getClass(), we throw a SecurityException.
1340
- // Otherwise we check the private cred set to see whether
1336
+ // Otherwise, we check the private cred set to see whether
1341
1337
// it contains the Object
1342
1338
1343
1339
SecurityManager sm = System .getSecurityManager ();
@@ -1472,7 +1468,7 @@ public Object[] toArray() {
1472
1468
// The next() method performs a security manager check
1473
1469
// on each element in the SecureSet. If we make it all
1474
1470
// the way through we should be able to simply return
1475
- // element's toArray results. Otherwise we'll let
1471
+ // element's toArray results. Otherwise, we'll let
1476
1472
// the SecurityException pass up the call stack.
1477
1473
e .next ();
1478
1474
}
@@ -1486,7 +1482,7 @@ public <T> T[] toArray(T[] a) {
1486
1482
// The next() method performs a security manager check
1487
1483
// on each element in the SecureSet. If we make it all
1488
1484
// the way through we should be able to simply return
1489
- // element's toArray results. Otherwise we'll let
1485
+ // element's toArray results. Otherwise, we'll let
1490
1486
// the SecurityException pass up the call stack.
1491
1487
e .next ();
1492
1488
}
@@ -1586,14 +1582,14 @@ private void readObject(ObjectInputStream ois)
1586
1582
*/
1587
1583
private class ClassSet <T > extends AbstractSet <T > {
1588
1584
1589
- private int which ;
1590
- private Class <T > c ;
1591
- private Set <T > set ;
1585
+ private final int which ;
1586
+ private final Class <T > c ;
1587
+ private final Set <T > set ;
1592
1588
1593
1589
ClassSet (int which , Class <T > c ) {
1594
1590
this .which = which ;
1595
1591
this .c = c ;
1596
- set = new HashSet <T >();
1592
+ set = new HashSet <>();
1597
1593
1598
1594
switch (which ) {
1599
1595
case Subject .PRINCIPAL_SET :
0 commit comments