This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 35534b1776a4e94f58b0dabe0fddef81910bcd29 Author: Mark Thomas <ma...@apache.org> AuthorDate: Tue Sep 26 19:03:04 2023 +0100 Code clean-up - no functional change --- java/org/apache/catalina/realm/CombinedRealm.java | 11 ++--- .../org/apache/catalina/realm/DataSourceRealm.java | 6 +-- .../realm/DigestCredentialHandlerBase.java | 4 +- .../apache/catalina/realm/GenericPrincipal.java | 8 ++-- .../catalina/realm/JAASMemoryLoginModule.java | 10 ++--- java/org/apache/catalina/realm/JAASRealm.java | 4 +- java/org/apache/catalina/realm/JNDIRealm.java | 49 +++++++++++---------- java/org/apache/catalina/realm/LockOutRealm.java | 8 ++-- java/org/apache/catalina/realm/MemoryRealm.java | 4 +- java/org/apache/catalina/realm/RealmBase.java | 50 ++++++++++------------ 10 files changed, 74 insertions(+), 80 deletions(-) diff --git a/java/org/apache/catalina/realm/CombinedRealm.java b/java/org/apache/catalina/realm/CombinedRealm.java index 69f50ab8ba..ffb3ff22cd 100644 --- a/java/org/apache/catalina/realm/CombinedRealm.java +++ b/java/org/apache/catalina/realm/CombinedRealm.java @@ -97,7 +97,8 @@ public class CombinedRealm extends RealmBase { log.debug(sm.getString("combinedRealm.authStart", username, realm.getClass().getName())); } - authenticatedUser = realm.authenticate(username, clientDigest, nonce, nc, cnonce, qop, realmName, digestA2, algorithm); + authenticatedUser = + realm.authenticate(username, clientDigest, nonce, nc, cnonce, qop, realmName, digestA2, algorithm); if (authenticatedUser == null) { if (log.isDebugEnabled()) { @@ -355,8 +356,8 @@ public class CombinedRealm extends RealmBase { protected String getPassword(String username) { // This method should never be called // Stack trace will show where this was called from - UnsupportedOperationException uoe = new UnsupportedOperationException( - sm.getString("combinedRealm.getPassword")); + UnsupportedOperationException uoe = + new UnsupportedOperationException(sm.getString("combinedRealm.getPassword")); log.error(sm.getString("combinedRealm.unexpectedMethod"), uoe); throw uoe; } @@ -365,8 +366,8 @@ public class CombinedRealm extends RealmBase { protected Principal getPrincipal(String username) { // This method should never be called // Stack trace will show where this was called from - UnsupportedOperationException uoe = new UnsupportedOperationException( - sm.getString("combinedRealm.getPrincipal")); + UnsupportedOperationException uoe = + new UnsupportedOperationException(sm.getString("combinedRealm.getPrincipal")); log.error(sm.getString("combinedRealm.unexpectedMethod"), uoe); throw uoe; } diff --git a/java/org/apache/catalina/realm/DataSourceRealm.java b/java/org/apache/catalina/realm/DataSourceRealm.java index d97ae3b126..ef982807ae 100644 --- a/java/org/apache/catalina/realm/DataSourceRealm.java +++ b/java/org/apache/catalina/realm/DataSourceRealm.java @@ -227,9 +227,9 @@ public class DataSourceRealm extends RealmBase { /** * {@inheritDoc} * <p> - * If there are any errors with the JDBC connection, executing the query or anything this method returns - * null (doesn't authenticate). This event is also logged, and the connection will be closed so that a subsequent - * request will automatically re-open it. + * If there are any errors with the JDBC connection, executing the query or anything this method returns null + * (doesn't authenticate). This event is also logged, and the connection will be closed so that a subsequent request + * will automatically re-open it. */ @Override public Principal authenticate(String username, String credentials) { diff --git a/java/org/apache/catalina/realm/DigestCredentialHandlerBase.java b/java/org/apache/catalina/realm/DigestCredentialHandlerBase.java index 2743184df0..03db3b5bb2 100644 --- a/java/org/apache/catalina/realm/DigestCredentialHandlerBase.java +++ b/java/org/apache/catalina/realm/DigestCredentialHandlerBase.java @@ -190,8 +190,8 @@ public abstract class DigestCredentialHandlerBase implements CredentialHandler { return false; } - String inputHexEncoded = mutate(inputCredentials, salt, iterations, - HexUtils.fromHexString(storedHexEncoded).length * Byte.SIZE); + String inputHexEncoded = + mutate(inputCredentials, salt, iterations, HexUtils.fromHexString(storedHexEncoded).length * Byte.SIZE); if (inputHexEncoded == null) { // Failed to mutate user credentials. Automatic fail. // Root cause should be logged by mutate() diff --git a/java/org/apache/catalina/realm/GenericPrincipal.java b/java/org/apache/catalina/realm/GenericPrincipal.java index 0832203cfd..5d2ca675cb 100644 --- a/java/org/apache/catalina/realm/GenericPrincipal.java +++ b/java/org/apache/catalina/realm/GenericPrincipal.java @@ -153,7 +153,7 @@ public class GenericPrincipal implements TomcatPrincipal, Serializable { * @param attributes - If provided, additional attributes associated with this Principal */ public GenericPrincipal(String name, List<String> roles, Principal userPrincipal, LoginContext loginContext, - GSSCredential gssCredential, Map<String, Object> attributes) { + GSSCredential gssCredential, Map<String,Object> attributes) { super(); this.name = name; this.userPrincipal = userPrincipal; @@ -252,7 +252,7 @@ public class GenericPrincipal implements TomcatPrincipal, Serializable { /** * The additional attributes associated with this Principal. */ - protected final Map<String, Object> attributes; + protected final Map<String,Object> attributes; // ---------------------------------------------------------- Public Methods @@ -332,9 +332,9 @@ public class GenericPrincipal implements TomcatPrincipal, Serializable { private final String name; private final String[] roles; private final Principal principal; - private final Map<String, Object> attributes; + private final Map<String,Object> attributes; - SerializablePrincipal(String name, String[] roles, Principal principal, Map<String, Object> attributes) { + SerializablePrincipal(String name, String[] roles, Principal principal, Map<String,Object> attributes) { this.name = name; this.roles = roles; if (principal instanceof Serializable) { diff --git a/java/org/apache/catalina/realm/JAASMemoryLoginModule.java b/java/org/apache/catalina/realm/JAASMemoryLoginModule.java index 54ac7c3451..d4e3b0959b 100644 --- a/java/org/apache/catalina/realm/JAASMemoryLoginModule.java +++ b/java/org/apache/catalina/realm/JAASMemoryLoginModule.java @@ -92,7 +92,7 @@ public class JAASMemoryLoginModule extends MemoryRealm implements LoginModule { /** * The configuration information for this <code>LoginModule</code>. */ - protected Map<String, ?> options = null; + protected Map<String,?> options = null; /** @@ -110,7 +110,7 @@ public class JAASMemoryLoginModule extends MemoryRealm implements LoginModule { /** * The state information that is shared with other configured <code>LoginModule</code> instances. */ - protected Map<String, ?> sharedState = null; + protected Map<String,?> sharedState = null; /** @@ -181,8 +181,8 @@ public class JAASMemoryLoginModule extends MemoryRealm implements LoginModule { @Override - public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, - Map<String, ?> options) { + public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String,?> sharedState, + Map<String,?> options) { if (log.isDebugEnabled()) { log.debug("Init"); } @@ -213,7 +213,7 @@ public class JAASMemoryLoginModule extends MemoryRealm implements LoginModule { credentialHandler = new MessageDigestCredentialHandler(); } - for (Entry<String, ?> entry : options.entrySet()) { + for (Entry<String,?> entry : options.entrySet()) { if ("pathname".equals(entry.getKey())) { continue; } diff --git a/java/org/apache/catalina/realm/JAASRealm.java b/java/org/apache/catalina/realm/JAASRealm.java index 9b80c44cbf..cac685c00d 100644 --- a/java/org/apache/catalina/realm/JAASRealm.java +++ b/java/org/apache/catalina/realm/JAASRealm.java @@ -598,8 +598,8 @@ public class JAASRealm extends RealmBase { URL resource = Thread.currentThread().getContextClassLoader().getResource(configFile); URI uri = resource.toURI(); @SuppressWarnings("unchecked") - Class<Configuration> sunConfigFile = (Class<Configuration>) Class - .forName("com.sun.security.auth.login.ConfigFile"); + Class<Configuration> sunConfigFile = + (Class<Configuration>) Class.forName("com.sun.security.auth.login.ConfigFile"); Constructor<Configuration> constructor = sunConfigFile.getConstructor(URI.class); Configuration config = constructor.newInstance(uri); this.jaasConfiguration = config; diff --git a/java/org/apache/catalina/realm/JNDIRealm.java b/java/org/apache/catalina/realm/JNDIRealm.java index 1a9c2a6f52..75869d3662 100644 --- a/java/org/apache/catalina/realm/JNDIRealm.java +++ b/java/org/apache/catalina/realm/JNDIRealm.java @@ -1120,9 +1120,9 @@ public class JNDIRealm extends RealmBase { /** * {@inheritDoc} * <p> - * If there are any errors with the JNDI connection, executing the query or anything we return - * null (don't authenticate). This event is also logged, and the connection will be closed so that a subsequent - * request will automatically re-open it. + * If there are any errors with the JNDI connection, executing the query or anything we return null (don't + * authenticate). This event is also logged, and the connection will be closed so that a subsequent request will + * automatically re-open it. */ @Override public Principal authenticate(String username, String credentials) { @@ -1232,7 +1232,7 @@ public class JNDIRealm extends RealmBase { } ClassLoader ocl = null; - Thread currentThread= null; + Thread currentThread = null; try { // https://bz.apache.org/bugzilla/show_bug.cgi?id=65553 // This can move back to open() once it is known that Tomcat must be @@ -1977,14 +1977,14 @@ public class JNDIRealm extends RealmBase { } // Perform the configured search and process the results - NamingEnumeration<SearchResult> results = searchAsUser(connection.context, user, base, filter, controls, - isRoleSearchAsUser()); + NamingEnumeration<SearchResult> results = + searchAsUser(connection.context, user, base, filter, controls, isRoleSearchAsUser()); if (results == null) { return list; // Should never happen, but just in case ... } - Map<String, String> groupMap = new HashMap<>(); + Map<String,String> groupMap = new HashMap<>(); try { while (results.hasMore()) { SearchResult result = results.next(); @@ -2007,9 +2007,9 @@ public class JNDIRealm extends RealmBase { } if (containerLog.isTraceEnabled()) { - Set<Entry<String, String>> entries = groupMap.entrySet(); + Set<Entry<String,String>> entries = groupMap.entrySet(); containerLog.trace(" Found " + entries.size() + " direct roles"); - for (Entry<String, String> entry : entries) { + for (Entry<String,String> entry : entries) { containerLog.trace(" Found direct role " + entry.getKey() + " -> " + entry.getValue()); } } @@ -2021,11 +2021,11 @@ public class JNDIRealm extends RealmBase { // Directory Groups". It avoids group slurping and handles cyclic group memberships as well. // See http://middleware.internet2.edu/dir/ for details - Map<String, String> newGroups = new HashMap<>(groupMap); + Map<String,String> newGroups = new HashMap<>(groupMap); while (!newGroups.isEmpty()) { - Map<String, String> newThisRound = new HashMap<>(); // Stores the groups we find in this iteration + Map<String,String> newThisRound = new HashMap<>(); // Stores the groups we find in this iteration - for (Entry<String, String> group : newGroups.entrySet()) { + for (Entry<String,String> group : newGroups.entrySet()) { // Group key is already value escaped if required // Group value is not value escaped // Everything needs to be filter escaped @@ -2354,11 +2354,10 @@ public class JNDIRealm extends RealmBase { principal = getPrincipal(connection, username, gssCredential); } catch (NamingException e) { - /* While we would like to catch specialized exceptions like - * CommunicationException and ServiceUnavailableException, - * some network communication problems are reported as - * this general exception. This is fixed in Java 18 by - * https://bugs.openjdk.org/browse/JDK-8273402 + /* + * While we would like to catch specialized exceptions like CommunicationException and + * ServiceUnavailableException, some network communication problems are reported as this general + * exception. This is fixed in Java 18 by https://bugs.openjdk.org/browse/JDK-8273402 */ // log the exception so we know it's there. containerLog.info(sm.getString("jndiRealm.exception.retry"), e); @@ -2410,7 +2409,7 @@ public class JNDIRealm extends RealmBase { User user = null; List<String> roles = null; - Hashtable<?, ?> preservedEnvironment = null; + Hashtable<?,?> preservedEnvironment = null; DirContext context = connection.context; try { @@ -2445,7 +2444,7 @@ public class JNDIRealm extends RealmBase { private void restoreEnvironmentParameter(DirContext context, String parameterName, - Hashtable<?, ?> preservedEnvironment) { + Hashtable<?,?> preservedEnvironment) { try { context.removeFromEnvironment(parameterName); if (preservedEnvironment != null && preservedEnvironment.containsKey(parameterName)) { @@ -2551,7 +2550,7 @@ public class JNDIRealm extends RealmBase { } - private DirContext createDirContext(Hashtable<String, String> env) throws NamingException { + private DirContext createDirContext(Hashtable<String,String> env) throws NamingException { if (useStartTls) { return createTlsDirContext(env); } else { @@ -2616,8 +2615,8 @@ public class JNDIRealm extends RealmBase { * * @throws NamingException when something goes wrong while negotiating the connection */ - private DirContext createTlsDirContext(Hashtable<String, String> env) throws NamingException { - Map<String, Object> savedEnv = new HashMap<>(); + private DirContext createTlsDirContext(Hashtable<String,String> env) throws NamingException { + Map<String,Object> savedEnv = new HashMap<>(); for (String key : Arrays.asList(Context.SECURITY_AUTHENTICATION, Context.SECURITY_CREDENTIALS, Context.SECURITY_PRINCIPAL, Context.SECURITY_PROTOCOL)) { Object entry = env.remove(key); @@ -2643,7 +2642,7 @@ public class JNDIRealm extends RealmBase { } } finally { if (result != null) { - for (Map.Entry<String, Object> savedEntry : savedEnv.entrySet()) { + for (Map.Entry<String,Object> savedEntry : savedEnv.entrySet()) { result.addToEnvironment(savedEntry.getKey(), savedEntry.getValue()); } } @@ -2657,9 +2656,9 @@ public class JNDIRealm extends RealmBase { * * @return java.util.Hashtable the configuration for the directory context. */ - protected Hashtable<String, String> getDirectoryContextEnvironment() { + protected Hashtable<String,String> getDirectoryContextEnvironment() { - Hashtable<String, String> env = new Hashtable<>(); + Hashtable<String,String> env = new Hashtable<>(); // Configure our directory context environment. if (containerLog.isDebugEnabled() && connectionAttempt == 0) { diff --git a/java/org/apache/catalina/realm/LockOutRealm.java b/java/org/apache/catalina/realm/LockOutRealm.java index 45ce3736f0..dba91ccd22 100644 --- a/java/org/apache/catalina/realm/LockOutRealm.java +++ b/java/org/apache/catalina/realm/LockOutRealm.java @@ -69,7 +69,7 @@ public class LockOutRealm extends CombinedRealm { * Users whose last authentication attempt failed. Entries will be ordered in access order from least recent to most * recent. */ - protected Map<String, LockRecord> failedUsers = null; + protected Map<String,LockRecord> failedUsers = null; @Override @@ -83,7 +83,7 @@ public class LockOutRealm extends CombinedRealm { private static final long serialVersionUID = 1L; @Override - protected boolean removeEldestEntry(Map.Entry<String, LockRecord> eldest) { + protected boolean removeEldestEntry(Map.Entry<String,LockRecord> eldest) { if (size() > cacheSize) { // Check to see if this element has been removed too quickly long timeInCache = (System.currentTimeMillis() - eldest.getValue().getLastFailureTime()) / 1000; @@ -106,8 +106,8 @@ public class LockOutRealm extends CombinedRealm { public Principal authenticate(String username, String clientDigest, String nonce, String nc, String cnonce, String qop, String realmName, String digestA2, String algorithm) { - Principal authenticatedUser = super.authenticate(username, clientDigest, nonce, nc, cnonce, qop, realmName, - digestA2, algorithm); + Principal authenticatedUser = + super.authenticate(username, clientDigest, nonce, nc, cnonce, qop, realmName, digestA2, algorithm); return filterLockedAccounts(username, authenticatedUser); } diff --git a/java/org/apache/catalina/realm/MemoryRealm.java b/java/org/apache/catalina/realm/MemoryRealm.java index 2de6ab75dc..317af24712 100644 --- a/java/org/apache/catalina/realm/MemoryRealm.java +++ b/java/org/apache/catalina/realm/MemoryRealm.java @@ -65,13 +65,13 @@ public class MemoryRealm extends RealmBase { /** * The set of valid Principals for this Realm, keyed by user name. */ - private final Map<String, GenericPrincipal> principals = new HashMap<>(); + private final Map<String,GenericPrincipal> principals = new HashMap<>(); /** * The set of credentials for this Realm, keyed by user name. */ - private final Map<String, String> credentials = new HashMap<>(); + private final Map<String,String> credentials = new HashMap<>(); // ------------------------------------------------------------- Properties diff --git a/java/org/apache/catalina/realm/RealmBase.java b/java/org/apache/catalina/realm/RealmBase.java index 548380653d..d4721dc185 100644 --- a/java/org/apache/catalina/realm/RealmBase.java +++ b/java/org/apache/catalina/realm/RealmBase.java @@ -81,14 +81,15 @@ public abstract class RealmBase extends LifecycleMBeanBase implements Realm { protected static final String USER_ATTRIBUTES_DELIMITER = ","; /** - * The character used as wildcard in user attribute lists. Using it means - * <i>query all available user attributes</i>. + * The character used as wildcard in user attribute lists. Using it means <i>query all available user + * attributes</i>. * <p> * Applies to some of the Realm implementations only. */ protected static final String USER_ATTRIBUTES_WILDCARD = "*"; - private static final List<Class<? extends DigestCredentialHandlerBase>> credentialHandlerClasses = new ArrayList<>(); + private static final List<Class<? extends DigestCredentialHandlerBase>> credentialHandlerClasses = + new ArrayList<>(); static { // Order is important since it determines the search order for a @@ -160,17 +161,15 @@ public abstract class RealmBase extends LifecycleMBeanBase implements Realm { /** - * The comma separated names of user attributes to additionally query from the - * realm. These will be provided to the user through the created - * Principal's <i>attributes</i> map. Support for this feature is optional. + * The comma separated names of user attributes to additionally query from the realm. These will be provided to the + * user through the created Principal's <i>attributes</i> map. Support for this feature is optional. */ protected String userAttributes = null; /** - * The list of user attributes to additionally query from the - * realm. These will be provided to the user through the created - * Principal's <i>attributes</i> map. Support for this feature is optional. + * The list of user attributes to additionally query from the realm. These will be provided to the user through the + * created Principal's <i>attributes</i> map. Support for this feature is optional. */ protected List<String> userAttributesList = null; @@ -304,18 +303,14 @@ public abstract class RealmBase extends LifecycleMBeanBase implements Realm { } /** - * Set the comma separated names of user attributes to additionally query from - * the realm. These will be provided to the user through the created - * Principal's <i>attributes</i> map. In this map, each field value is bound to - * the field's name, that is, the name of the field serves as the key of the - * mapping. + * Set the comma separated names of user attributes to additionally query from the realm. These will be provided to + * the user through the created Principal's <i>attributes</i> map. In this map, each field value is bound to the + * field's name, that is, the name of the field serves as the key of the mapping. * <p> - * If set to the wildcard character, or, if the wildcard character is part of - * the comma separated list, all available attributes - except the - * <i>password</i> attribute (as specified by <code>userCredCol</code>) - are - * queried. The wildcard character is defined by constant - * {@link RealmBase#USER_ATTRIBUTES_WILDCARD}. It defaults to the asterisk (*) - * character. + * If set to the wildcard character, or, if the wildcard character is part of the comma separated list, all + * available attributes - except the <i>password</i> attribute (as specified by <code>userCredCol</code>) - are + * queried. The wildcard character is defined by constant {@link RealmBase#USER_ATTRIBUTES_WILDCARD}. It defaults to + * the asterisk (*) character. * * @param userAttributes the comma separated names of user attributes */ @@ -916,15 +911,14 @@ public abstract class RealmBase extends LifecycleMBeanBase implements Realm { /** - * Parse the specified delimiter separated attribute names and return a list of - * that names or <code>null</code>, if no attributes have been specified. + * Parse the specified delimiter separated attribute names and return a list of that names or <code>null</code>, if + * no attributes have been specified. * <p> - * If a wildcard character is found, return a list consisting of a single - * wildcard character only. + * If a wildcard character is found, return a list consisting of a single wildcard character only. * * @param userAttributes comma separated names of attributes to parse - * @return a list containing the parsed attribute names or <code>null</code>, if - * no attributes have been specified + * + * @return a list containing the parsed attribute names or <code>null</code>, if no attributes have been specified */ protected List<String> parseUserAttributes(String userAttributes) { if (userAttributes == null) { @@ -1526,8 +1520,8 @@ public abstract class RealmBase extends LifecycleMBeanBase implements Realm { try { @SuppressWarnings("unchecked") - Class<? extends X509UsernameRetriever> clazz = (Class<? extends X509UsernameRetriever>) Class - .forName(className); + Class<? extends X509UsernameRetriever> clazz = + (Class<? extends X509UsernameRetriever>) Class.forName(className); return clazz.getConstructor().newInstance(); } catch (ReflectiveOperationException e) { throw new LifecycleException(sm.getString("realmBase.createUsernameRetriever.newInstance", className), e); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org