8290975: Minor cleanup could be done in javax.security

Reviewed-by: wetmore, mullan
This commit is contained in:
Mark Powers 2022-08-08 17:30:22 +00:00 committed by Bradford Wetmore
parent 7db5abddd1
commit 08274e6fea
16 changed files with 90 additions and 104 deletions

View File

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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -50,7 +50,7 @@ public interface Destroyable {
* @exception SecurityException if the caller does not have permission
* to destroy this {@code Object}.
*/
public default void destroy() throws DestroyFailedException {
default void destroy() throws DestroyFailedException {
throw new DestroyFailedException();
}
@ -63,7 +63,7 @@ public interface Destroyable {
* @return true if this {@code Object} has been destroyed,
* false otherwise.
*/
public default boolean isDestroyed() {
default boolean isDestroyed() {
return false;
}
}

View File

@ -127,7 +127,7 @@ public final class PrivateCredentialPermission extends Permission {
/**
* @serial
*/
private boolean testing = false;
private final boolean testing = false;
/**
* Create a new {@code PrivateCredentialPermission}
@ -269,11 +269,9 @@ public final class PrivateCredentialPermission extends Permission {
if (obj == this)
return true;
if (! (obj instanceof PrivateCredentialPermission))
if (! (obj instanceof PrivateCredentialPermission that))
return false;
PrivateCredentialPermission that = (PrivateCredentialPermission)obj;
return (this.implies(that) && that.implies(this));
}
@ -316,8 +314,8 @@ public final class PrivateCredentialPermission extends Permission {
ArrayList<CredOwner> pList = new ArrayList<>();
StringTokenizer tokenizer = new StringTokenizer(name, " ", true);
String principalClass = null;
String principalName = null;
String principalClass;
String principalName;
if (testing)
System.out.println("whole name = " + name);
@ -327,7 +325,7 @@ public final class PrivateCredentialPermission extends Permission {
if (testing)
System.out.println("Credential Class = " + credentialClass);
if (tokenizer.hasMoreTokens() == false) {
if (!tokenizer.hasMoreTokens()) {
MessageFormat form = new MessageFormat(ResourcesMgr.getString
("permission.name.name.syntax.invalid."));
Object[] source = {name};
@ -346,7 +344,7 @@ public final class PrivateCredentialPermission extends Permission {
if (testing)
System.out.println(" Principal Class = " + principalClass);
if (tokenizer.hasMoreTokens() == false) {
if (!tokenizer.hasMoreTokens()) {
MessageFormat form = new MessageFormat(ResourcesMgr.getString
("permission.name.name.syntax.invalid."));
Object[] source = {name};
@ -428,7 +426,7 @@ public final class PrivateCredentialPermission extends Permission {
if (thisC.equals("*"))
return true;
/**
/*
* XXX let's not enable this for now --
* if people want it, we'll enable it later
*/
@ -533,7 +531,7 @@ public final class PrivateCredentialPermission extends Permission {
}
}
/**
/*
* XXX no code yet to support a.b.*
*/

View File

@ -25,20 +25,16 @@
package javax.security.auth;
import java.util.*;
import java.io.*;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamField;
import java.security.*;
import java.text.MessageFormat;
import java.security.AccessController;
import java.security.AccessControlContext;
import java.security.DomainCombiner;
import java.security.Principal;
import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException;
import java.security.ProtectionDomain;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletionException;
import sun.security.action.GetBooleanAction;
import sun.security.util.ResourcesMgr;
/**
@ -90,7 +86,7 @@ import sun.security.util.ResourcesMgr;
* While the Principals associated with the {@code Subject} are serialized,
* the credentials associated with the {@code Subject} are not.
* Note that the {@code java.security.Principal} class
* does not implement {@code Serializable}. Therefore all concrete
* does not implement {@code Serializable}. Therefore, all concrete
* {@code Principal} implementations associated with Subjects
* must implement {@code Serializable}.
*
@ -752,7 +748,7 @@ public final class Subject implements java.io.Serializable {
// always return an empty Set instead of null
// so LoginModules can add to the Set if necessary
return new ClassSet<T>(PRINCIPAL_SET, c);
return new ClassSet<>(PRINCIPAL_SET, c);
}
/**
@ -846,7 +842,7 @@ public final class Subject implements java.io.Serializable {
// always return an empty Set instead of null
// so LoginModules can add to the Set if necessary
return new ClassSet<T>(PUB_CREDENTIAL_SET, c);
return new ClassSet<>(PUB_CREDENTIAL_SET, c);
}
/**
@ -890,7 +886,7 @@ public final class Subject implements java.io.Serializable {
// always return an empty Set instead of null
// so LoginModules can add to the Set if necessary
return new ClassSet<T>(PRIV_CREDENTIAL_SET, c);
return new ClassSet<>(PRIV_CREDENTIAL_SET, c);
}
/**
@ -923,9 +919,7 @@ public final class Subject implements java.io.Serializable {
return true;
}
if (o instanceof Subject) {
final Subject that = (Subject)o;
if (o instanceof final Subject that) {
// check the principal and credential sets
Set<Principal> thatPrincipals;
@ -1180,7 +1174,7 @@ public final class Subject implements java.io.Serializable {
SecureSet(Subject subject, int which) {
this.subject = subject;
this.which = which;
this.elements = new LinkedList<E>();
this.elements = new LinkedList<>();
}
SecureSet(Subject subject, int which, LinkedList<E> list) {
@ -1195,10 +1189,12 @@ public final class Subject implements java.io.Serializable {
public Iterator<E> iterator() {
final LinkedList<E> list = elements;
return new Iterator<E>() {
ListIterator<E> i = list.listIterator(0);
return new Iterator<>() {
final ListIterator<E> i = list.listIterator(0);
public boolean hasNext() {return i.hasNext();}
public boolean hasNext() {
return i.hasNext();
}
public E next() {
if (which != Subject.PRIV_CREDENTIAL_SET) {
@ -1337,7 +1333,7 @@ public final class Subject implements java.io.Serializable {
// For private credentials:
// If the caller does not have read permission
// for o.getClass(), we throw a SecurityException.
// Otherwise we check the private cred set to see whether
// Otherwise, we check the private cred set to see whether
// it contains the Object
SecurityManager sm = System.getSecurityManager();
@ -1472,7 +1468,7 @@ public final class Subject implements java.io.Serializable {
// The next() method performs a security manager check
// on each element in the SecureSet. If we make it all
// the way through we should be able to simply return
// element's toArray results. Otherwise we'll let
// element's toArray results. Otherwise, we'll let
// the SecurityException pass up the call stack.
e.next();
}
@ -1486,7 +1482,7 @@ public final class Subject implements java.io.Serializable {
// The next() method performs a security manager check
// on each element in the SecureSet. If we make it all
// the way through we should be able to simply return
// element's toArray results. Otherwise we'll let
// element's toArray results. Otherwise, we'll let
// the SecurityException pass up the call stack.
e.next();
}
@ -1586,14 +1582,14 @@ public final class Subject implements java.io.Serializable {
*/
private class ClassSet<T> extends AbstractSet<T> {
private int which;
private Class<T> c;
private Set<T> set;
private final int which;
private final Class<T> c;
private final Set<T> set;
ClassSet(int which, Class<T> c) {
this.which = which;
this.c = c;
set = new HashSet<T>();
set = new HashSet<>();
switch (which) {
case Subject.PRINCIPAL_SET:

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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 {
/**
* Construct a {@code ChoiceCallback} with a prompt,
* a list of choices, a default choice, and a boolean specifying
* whether or not multiple selections from the list of choices are allowed.
* whether multiple selections from the list of choices are allowed.
*
*
* @param prompt the prompt used to describe the list of choices.
@ -83,9 +83,8 @@ public class ChoiceCallback implements Callback, java.io.Serializable {
* is represented as an index into the
* {@code choices} array.
*
* @param multipleSelectionsAllowed boolean specifying whether or
* not multiple selections can be made from the
* list of choices.
* @param multipleSelectionsAllowed boolean specifying whether multiple
* selections can be made from the list of choices.
*
* @exception IllegalArgumentException if {@code prompt} is null,
* if {@code prompt} has a length of 0,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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 {
* @serial
* @since 1.4
*/
private String prompt;
private final String prompt;
/**
* @serial
* @since 1.4
*/
private String defaultName;
private final String defaultName;
/**
* @serial
* @since 1.4
@ -66,6 +66,7 @@ public class NameCallback implements Callback, java.io.Serializable {
if (prompt == null || prompt.isEmpty())
throw new IllegalArgumentException();
this.prompt = prompt;
this.defaultName = null;
}
/**

View File

@ -155,8 +155,6 @@ public class PasswordCallback implements Callback, java.io.Serializable {
}
private static Runnable cleanerFor(char[] password) {
return () -> {
Arrays.fill(password, ' ');
};
return () -> Arrays.fill(password, ' ');
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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 {
* @serial
* @since 1.4
*/
private String prompt;
private final String prompt;
/**
* @serial
* @since 1.4
*/
private String defaultText;
private final String defaultText;
/**
* @serial
* @since 1.4
@ -67,6 +67,7 @@ public class TextInputCallback implements Callback, java.io.Serializable {
if (prompt == null || prompt.isEmpty())
throw new IllegalArgumentException();
this.prompt = prompt;
this.defaultText = null;
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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 {
* @serial
* @since 1.4
*/
private int messageType;
private final int messageType;
/**
* @serial
* @since 1.4
*/
private String message;
private final String message;
/**
* Construct a TextOutputCallback with a message type and message

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -40,7 +40,7 @@ public class UnsupportedCallbackException extends Exception {
* @serial
*/
@SuppressWarnings("serial") // Not statically typed as Serializable
private Callback callback;
private final Callback callback;
/**
* Constructs an {@code UnsupportedCallbackException}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -44,9 +44,9 @@ import java.util.Collections;
*/
public class AppConfigurationEntry {
private String loginModuleName;
private LoginModuleControlFlag controlFlag;
private Map<String,?> options;
private final String loginModuleName;
private final LoginModuleControlFlag controlFlag;
private final Map<String,?> options;
/**
* Default constructor for this class.
@ -122,12 +122,12 @@ public class AppConfigurationEntry {
}
/**
* This class represents whether or not a {@code LoginModule}
* This class represents whether a {@code LoginModule}
* is REQUIRED, REQUISITE, SUFFICIENT or OPTIONAL.
*/
public static class LoginModuleControlFlag {
private String controlFlag;
private final String controlFlag;
/**
* Required {@code LoginModule}.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -321,7 +321,7 @@ public abstract class Configuration {
* {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by
* may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}.
*
* @param type the specified Configuration type. See the Configuration
@ -519,7 +519,7 @@ public abstract class Configuration {
*
* <p> This Configuration instance will only have a Provider if it
* was obtained via a call to {@code Configuration.getInstance}.
* Otherwise this method returns null.
* Otherwise, this method returns null.
*
* @return the Provider of this Configuration, or null.
*
@ -534,7 +534,7 @@ public abstract class Configuration {
*
* <p> This Configuration instance will only have a type if it
* was obtained via a call to {@code Configuration.getInstance}.
* Otherwise this method returns null.
* Otherwise, this method returns null.
*
* @return the type of this Configuration, or null.
*
@ -549,7 +549,7 @@ public abstract class Configuration {
*
* <p> This Configuration instance will only have parameters if it
* was obtained via a call to {@code Configuration.getInstance}.
* Otherwise this method returns null.
* Otherwise, this method returns null.
*
* @return Configuration parameters, or null.
*
@ -595,10 +595,10 @@ public abstract class Configuration {
*/
private static class ConfigDelegate extends Configuration {
private ConfigurationSpi spi;
private Provider p;
private String type;
private Configuration.Parameters params;
private final ConfigurationSpi spi;
private final Provider p;
private final String type;
private final Configuration.Parameters params;
private ConfigDelegate(ConfigurationSpi spi, Provider p,
String type, Configuration.Parameters params) {
@ -628,5 +628,5 @@ public abstract class Configuration {
*
* @since 1.6
*/
public static interface Parameters { }
public interface Parameters { }
}

View File

@ -208,7 +208,7 @@ public class LoginContext {
private boolean subjectProvided = false;
private boolean loginSucceeded = false;
private CallbackHandler callbackHandler;
private Map<String,?> state = new HashMap<String,Object>();
private final Map<String,?> state = new HashMap<>();
private Configuration config;
@SuppressWarnings("removal")
@ -658,8 +658,7 @@ public class LoginContext {
clearState();
// throw the exception
LoginException error = (originalError != null) ? originalError : le;
throw error;
throw (originalError != null) ? originalError : le;
}
/**
@ -767,7 +766,7 @@ public class LoginContext {
throw new AssertionError("Unknown method " + methodName);
}
if (status == true) {
if (status) {
// if SUFFICIENT, return if no prior REQUIRED errors
if (!methodName.equals(ABORT_METHOD) &&
@ -887,14 +886,14 @@ public class LoginContext {
}
}
// we went thru all the LoginModules.
// we went through all the LoginModules.
if (firstRequiredError != null) {
// a REQUIRED module failed -- return the error
throwException(firstRequiredError, null);
} else if (success == false && firstError != null) {
} else if (!success && firstError != null) {
// no module succeeded -- return the first error
throwException(firstError, null);
} else if (success == false) {
} else if (!success) {
// no module succeeded -- all modules were IGNORED
throwException(new LoginException
(ResourcesMgr.getString("Login.Failure.all.modules.ignored")),
@ -903,7 +902,6 @@ public class LoginContext {
// success
clearState();
return;
}
}
@ -948,7 +946,7 @@ public class LoginContext {
/**
* LoginModule information -
* incapsulates Configuration info and actual module instances
* encapsulates Configuration info and actual module instances
*/
private static class ModuleInfo {
AppConfigurationEntry entry;

View File

@ -25,10 +25,10 @@
package javax.security.auth.spi;
import javax.security.auth.Subject;
import javax.security.auth.callback.*;
import javax.security.auth.login.*;
import java.util.Map;
import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginException;
/**
* <p> Service-provider interface for authentication technology providers.
@ -39,7 +39,7 @@ import java.util.Map;
* authentication technology providers implement the
* {@code LoginModule} interface.
* A {@code Configuration} specifies the LoginModule(s)
* to be used with a particular login application. Therefore different
* to be used with a particular login application. Therefore, different
* LoginModules can be plugged in under the application without
* requiring any modifications to the application itself.
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -91,7 +91,7 @@ public final class X500Principal implements Principal, java.io.Serializable {
*
* NOTE: The constructor is package private. It is intended to be accessed
* using privileged reflection from classes in sun.security.*.
* Currently referenced from sun.security.x509.X500Name.asX500Principal().
* Currently, it is referenced from sun.security.x509.X500Name.asX500Principal().
*/
X500Principal(X500Name x500Name) {
thisX500Name = x500Name;
@ -126,7 +126,7 @@ public final class X500Principal implements Principal, java.io.Serializable {
* is improperly specified
*/
public X500Principal(String name) {
this(name, Collections.<String, String>emptyMap());
this(name, Collections.emptyMap());
}
/**
@ -288,7 +288,7 @@ public final class X500Principal implements Principal, java.io.Serializable {
/**
* Returns a string representation of the X.500 distinguished name
* using the specified format. Valid values for the format are
* "RFC1779", "RFC2253", and "CANONICAL" (case insensitive).
* "RFC1779", "RFC2253", and "CANONICAL" (case-insensitive).
*
* <p> If "RFC1779" is specified as the format,
* this method emits the attribute type keywords defined in
@ -363,7 +363,7 @@ public final class X500Principal implements Principal, java.io.Serializable {
/**
* Returns a string representation of the X.500 distinguished name
* using the specified format. Valid values for the format are
* "RFC1779" and "RFC2253" (case insensitive). "CANONICAL" is not
* "RFC1779" and "RFC2253" (case-insensitive). "CANONICAL" is not
* permitted and an {@code IllegalArgumentException} will be thrown.
*
* <p>This method returns Strings in the format as specified in
@ -461,10 +461,9 @@ public final class X500Principal implements Principal, java.io.Serializable {
if (this == o) {
return true;
}
if (o instanceof X500Principal == false) {
if (!(o instanceof X500Principal other)) {
return false;
}
X500Principal other = (X500Principal)o;
return this.thisX500Name.equals(other.thisX500Name);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,17 +27,13 @@
package javax.security.cert;
import java.io.InputStream;
import java.lang.Class;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.security.Security;
import java.math.BigInteger;
import java.security.AccessController;
import java.security.Principal;
import java.security.PrivilegedAction;
import java.security.PublicKey;
import java.util.BitSet;
import java.security.Security;
import java.util.Date;
/**