Skip to content

Commit 08274e6

Browse files
Mark PowersBradford Wetmore
Mark Powers
authored and
Bradford Wetmore
committed
8290975: Minor cleanup could be done in javax.security
Reviewed-by: wetmore, mullan
1 parent 7db5abd commit 08274e6

16 files changed

+90
-104
lines changed

src/java.base/share/classes/javax/security/auth/AuthPermission.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,7 +31,7 @@
3131
* list; you either have the named permission or you don't.
3232
*
3333
* <p> The target name is the name of a security configuration parameter
34-
* (see below). Currently the {@code AuthPermission} object is used to
34+
* (see below). Currently, the {@code AuthPermission} object is used to
3535
* guard access to the {@link Subject},
3636
* {@link javax.security.auth.login.LoginContext}, and
3737
* {@link javax.security.auth.login.Configuration} objects.

src/java.base/share/classes/javax/security/auth/Destroyable.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -50,7 +50,7 @@ public interface Destroyable {
5050
* @exception SecurityException if the caller does not have permission
5151
* to destroy this {@code Object}.
5252
*/
53-
public default void destroy() throws DestroyFailedException {
53+
default void destroy() throws DestroyFailedException {
5454
throw new DestroyFailedException();
5555
}
5656

@@ -63,7 +63,7 @@ public default void destroy() throws DestroyFailedException {
6363
* @return true if this {@code Object} has been destroyed,
6464
* false otherwise.
6565
*/
66-
public default boolean isDestroyed() {
66+
default boolean isDestroyed() {
6767
return false;
6868
}
6969
}

src/java.base/share/classes/javax/security/auth/PrivateCredentialPermission.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public final class PrivateCredentialPermission extends Permission {
127127
/**
128128
* @serial
129129
*/
130-
private boolean testing = false;
130+
private final boolean testing = false;
131131

132132
/**
133133
* Create a new {@code PrivateCredentialPermission}
@@ -269,11 +269,9 @@ public boolean equals(Object obj) {
269269
if (obj == this)
270270
return true;
271271

272-
if (! (obj instanceof PrivateCredentialPermission))
272+
if (! (obj instanceof PrivateCredentialPermission that))
273273
return false;
274274

275-
PrivateCredentialPermission that = (PrivateCredentialPermission)obj;
276-
277275
return (this.implies(that) && that.implies(this));
278276
}
279277

@@ -316,8 +314,8 @@ private void init(String name) {
316314

317315
ArrayList<CredOwner> pList = new ArrayList<>();
318316
StringTokenizer tokenizer = new StringTokenizer(name, " ", true);
319-
String principalClass = null;
320-
String principalName = null;
317+
String principalClass;
318+
String principalName;
321319

322320
if (testing)
323321
System.out.println("whole name = " + name);
@@ -327,7 +325,7 @@ private void init(String name) {
327325
if (testing)
328326
System.out.println("Credential Class = " + credentialClass);
329327

330-
if (tokenizer.hasMoreTokens() == false) {
328+
if (!tokenizer.hasMoreTokens()) {
331329
MessageFormat form = new MessageFormat(ResourcesMgr.getString
332330
("permission.name.name.syntax.invalid."));
333331
Object[] source = {name};
@@ -346,7 +344,7 @@ private void init(String name) {
346344
if (testing)
347345
System.out.println(" Principal Class = " + principalClass);
348346

349-
if (tokenizer.hasMoreTokens() == false) {
347+
if (!tokenizer.hasMoreTokens()) {
350348
MessageFormat form = new MessageFormat(ResourcesMgr.getString
351349
("permission.name.name.syntax.invalid."));
352350
Object[] source = {name};
@@ -428,7 +426,7 @@ private boolean impliesCredentialClass(String thisC, String thatC) {
428426
if (thisC.equals("*"))
429427
return true;
430428

431-
/**
429+
/*
432430
* XXX let's not enable this for now --
433431
* if people want it, we'll enable it later
434432
*/
@@ -533,7 +531,7 @@ public boolean implies(Object obj) {
533531
}
534532
}
535533

536-
/**
534+
/*
537535
* XXX no code yet to support a.b.*
538536
*/
539537

src/java.base/share/classes/javax/security/auth/Subject.java

+24-28
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,16 @@
2525

2626
package javax.security.auth;
2727

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.*;
3033
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.*;
3835
import java.util.concurrent.Callable;
3936
import java.util.concurrent.CompletionException;
4037

41-
import sun.security.action.GetBooleanAction;
4238
import sun.security.util.ResourcesMgr;
4339

4440
/**
@@ -90,7 +86,7 @@
9086
* While the Principals associated with the {@code Subject} are serialized,
9187
* the credentials associated with the {@code Subject} are not.
9288
* 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
9490
* {@code Principal} implementations associated with Subjects
9591
* must implement {@code Serializable}.
9692
*
@@ -752,7 +748,7 @@ public <T extends Principal> Set<T> getPrincipals(Class<T> c) {
752748

753749
// always return an empty Set instead of null
754750
// so LoginModules can add to the Set if necessary
755-
return new ClassSet<T>(PRINCIPAL_SET, c);
751+
return new ClassSet<>(PRINCIPAL_SET, c);
756752
}
757753

758754
/**
@@ -846,7 +842,7 @@ public <T> Set<T> getPublicCredentials(Class<T> c) {
846842

847843
// always return an empty Set instead of null
848844
// 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);
850846
}
851847

852848
/**
@@ -890,7 +886,7 @@ public <T> Set<T> getPrivateCredentials(Class<T> c) {
890886

891887
// always return an empty Set instead of null
892888
// 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);
894890
}
895891

896892
/**
@@ -923,9 +919,7 @@ public boolean equals(Object o) {
923919
return true;
924920
}
925921

926-
if (o instanceof Subject) {
927-
928-
final Subject that = (Subject)o;
922+
if (o instanceof final Subject that) {
929923

930924
// check the principal and credential sets
931925
Set<Principal> thatPrincipals;
@@ -1180,7 +1174,7 @@ private static class SecureSet<E>
11801174
SecureSet(Subject subject, int which) {
11811175
this.subject = subject;
11821176
this.which = which;
1183-
this.elements = new LinkedList<E>();
1177+
this.elements = new LinkedList<>();
11841178
}
11851179

11861180
SecureSet(Subject subject, int which, LinkedList<E> list) {
@@ -1195,10 +1189,12 @@ public int size() {
11951189

11961190
public Iterator<E> iterator() {
11971191
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);
12001194

1201-
public boolean hasNext() {return i.hasNext();}
1195+
public boolean hasNext() {
1196+
return i.hasNext();
1197+
}
12021198

12031199
public E next() {
12041200
if (which != Subject.PRIV_CREDENTIAL_SET) {
@@ -1337,7 +1333,7 @@ public boolean contains(Object o) {
13371333
// For private credentials:
13381334
// If the caller does not have read permission
13391335
// 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
13411337
// it contains the Object
13421338

13431339
SecurityManager sm = System.getSecurityManager();
@@ -1472,7 +1468,7 @@ public Object[] toArray() {
14721468
// The next() method performs a security manager check
14731469
// on each element in the SecureSet. If we make it all
14741470
// 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
14761472
// the SecurityException pass up the call stack.
14771473
e.next();
14781474
}
@@ -1486,7 +1482,7 @@ public <T> T[] toArray(T[] a) {
14861482
// The next() method performs a security manager check
14871483
// on each element in the SecureSet. If we make it all
14881484
// 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
14901486
// the SecurityException pass up the call stack.
14911487
e.next();
14921488
}
@@ -1586,14 +1582,14 @@ private void readObject(ObjectInputStream ois)
15861582
*/
15871583
private class ClassSet<T> extends AbstractSet<T> {
15881584

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;
15921588

15931589
ClassSet(int which, Class<T> c) {
15941590
this.which = which;
15951591
this.c = c;
1596-
set = new HashSet<T>();
1592+
set = new HashSet<>();
15971593

15981594
switch (which) {
15991595
case Subject.PRINCIPAL_SET:

src/java.base/share/classes/javax/security/auth/callback/ChoiceCallback.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -70,7 +70,7 @@ public class ChoiceCallback implements Callback, java.io.Serializable {
7070
/**
7171
* Construct a {@code ChoiceCallback} with a prompt,
7272
* a list of choices, a default choice, and a boolean specifying
73-
* whether or not multiple selections from the list of choices are allowed.
73+
* whether multiple selections from the list of choices are allowed.
7474
*
7575
*
7676
* @param prompt the prompt used to describe the list of choices.
@@ -83,9 +83,8 @@ public class ChoiceCallback implements Callback, java.io.Serializable {
8383
* is represented as an index into the
8484
* {@code choices} array.
8585
*
86-
* @param multipleSelectionsAllowed boolean specifying whether or
87-
* not multiple selections can be made from the
88-
* list of choices.
86+
* @param multipleSelectionsAllowed boolean specifying whether multiple
87+
* selections can be made from the list of choices.
8988
*
9089
* @exception IllegalArgumentException if {@code prompt} is null,
9190
* if {@code prompt} has a length of 0,

src/java.base/share/classes/javax/security/auth/callback/NameCallback.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -42,12 +42,12 @@ public class NameCallback implements Callback, java.io.Serializable {
4242
* @serial
4343
* @since 1.4
4444
*/
45-
private String prompt;
45+
private final String prompt;
4646
/**
4747
* @serial
4848
* @since 1.4
4949
*/
50-
private String defaultName;
50+
private final String defaultName;
5151
/**
5252
* @serial
5353
* @since 1.4
@@ -66,6 +66,7 @@ public NameCallback(String prompt) {
6666
if (prompt == null || prompt.isEmpty())
6767
throw new IllegalArgumentException();
6868
this.prompt = prompt;
69+
this.defaultName = null;
6970
}
7071

7172
/**

src/java.base/share/classes/javax/security/auth/callback/PasswordCallback.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ public void clearPassword() {
155155
}
156156

157157
private static Runnable cleanerFor(char[] password) {
158-
return () -> {
159-
Arrays.fill(password, ' ');
160-
};
158+
return () -> Arrays.fill(password, ' ');
161159
}
162160
}

src/java.base/share/classes/javax/security/auth/callback/TextInputCallback.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -43,12 +43,12 @@ public class TextInputCallback implements Callback, java.io.Serializable {
4343
* @serial
4444
* @since 1.4
4545
*/
46-
private String prompt;
46+
private final String prompt;
4747
/**
4848
* @serial
4949
* @since 1.4
5050
*/
51-
private String defaultText;
51+
private final String defaultText;
5252
/**
5353
* @serial
5454
* @since 1.4
@@ -67,6 +67,7 @@ public TextInputCallback(String prompt) {
6767
if (prompt == null || prompt.isEmpty())
6868
throw new IllegalArgumentException();
6969
this.prompt = prompt;
70+
this.defaultText = null;
7071
}
7172

7273
/**

src/java.base/share/classes/javax/security/auth/callback/TextOutputCallback.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -50,12 +50,12 @@ public class TextOutputCallback implements Callback, java.io.Serializable {
5050
* @serial
5151
* @since 1.4
5252
*/
53-
private int messageType;
53+
private final int messageType;
5454
/**
5555
* @serial
5656
* @since 1.4
5757
*/
58-
private String message;
58+
private final String message;
5959

6060
/**
6161
* Construct a TextOutputCallback with a message type and message

src/java.base/share/classes/javax/security/auth/callback/UnsupportedCallbackException.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,7 +40,7 @@ public class UnsupportedCallbackException extends Exception {
4040
* @serial
4141
*/
4242
@SuppressWarnings("serial") // Not statically typed as Serializable
43-
private Callback callback;
43+
private final Callback callback;
4444

4545
/**
4646
* Constructs an {@code UnsupportedCallbackException}

0 commit comments

Comments
 (0)