Skip to content

Commit 33a264a

Browse files
authored
Logging: Drop Settings from security logger get calls (#33940)
`Settings` is no longer required to get a `Logger` and we went to quite a bit of effort to pass it to the `Logger` getters. This removes the `Settings` from all of the logger fetches in security and x-pack:core.
1 parent 15515a6 commit 33a264a

File tree

33 files changed

+78
-122
lines changed

33 files changed

+78
-122
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/license/StartupSelfGeneratedLicenseTask.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.elasticsearch.license;
77

88
import org.apache.logging.log4j.Logger;
9+
import org.apache.logging.log4j.LogManager;
910
import org.apache.logging.log4j.message.ParameterizedMessage;
1011
import org.apache.logging.log4j.util.Supplier;
1112
import org.elasticsearch.Version;
@@ -14,14 +15,14 @@
1415
import org.elasticsearch.cluster.metadata.MetaData;
1516
import org.elasticsearch.cluster.service.ClusterService;
1617
import org.elasticsearch.common.Nullable;
17-
import org.elasticsearch.common.logging.Loggers;
1818
import org.elasticsearch.common.settings.Settings;
1919
import org.elasticsearch.xpack.core.XPackPlugin;
2020

2121
import java.time.Clock;
2222
import java.util.UUID;
2323

2424
public class StartupSelfGeneratedLicenseTask extends ClusterStateUpdateTask {
25+
private static final Logger logger = LogManager.getLogger(StartupSelfGeneratedLicenseTask.class);
2526

2627
/**
2728
* Max number of nodes licensed by generated trial license
@@ -31,13 +32,11 @@ public class StartupSelfGeneratedLicenseTask extends ClusterStateUpdateTask {
3132
private final Settings settings;
3233
private final Clock clock;
3334
private final ClusterService clusterService;
34-
private final Logger logger;
3535

3636
public StartupSelfGeneratedLicenseTask(Settings settings, Clock clock, ClusterService clusterService) {
3737
this.settings = settings;
3838
this.clock = clock;
3939
this.clusterService = clusterService;
40-
this.logger = Loggers.getLogger(getClass(), settings);
4140
}
4241

4342
@Override

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/SecurityContext.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
package org.elasticsearch.xpack.core.security;
77

88
import org.apache.logging.log4j.Logger;
9+
import org.apache.logging.log4j.LogManager;
910
import org.elasticsearch.Version;
10-
import org.elasticsearch.common.logging.Loggers;
1111
import org.elasticsearch.common.settings.Settings;
1212
import org.elasticsearch.common.util.concurrent.ThreadContext;
1313
import org.elasticsearch.common.util.concurrent.ThreadContext.StoredContext;
@@ -23,8 +23,8 @@
2323
* A lightweight utility that can find the current user and authentication information for the local thread.
2424
*/
2525
public class SecurityContext {
26+
private final Logger logger = LogManager.getLogger(SecurityContext.class);
2627

27-
private final Logger logger;
2828
private final ThreadContext threadContext;
2929
private final UserSettings userSettings;
3030
private final String nodeName;
@@ -35,9 +35,8 @@ public class SecurityContext {
3535
* and {@link UserSettings#getAuthentication()} will always return null.
3636
*/
3737
public SecurityContext(Settings settings, ThreadContext threadContext) {
38-
this.logger = Loggers.getLogger(getClass(), settings);
3938
this.threadContext = threadContext;
40-
this.userSettings = new UserSettings(settings, threadContext);
39+
this.userSettings = new UserSettings(threadContext);
4140
this.nodeName = Node.NODE_NAME_SETTING.get(settings);
4241
}
4342

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/UserSettings.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,22 @@
66
package org.elasticsearch.xpack.core.security;
77

88
import org.apache.logging.log4j.Logger;
9-
import org.elasticsearch.common.logging.Loggers;
10-
import org.elasticsearch.common.settings.Settings;
9+
import org.apache.logging.log4j.LogManager;
1110
import org.elasticsearch.common.util.concurrent.ThreadContext;
1211
import org.elasticsearch.xpack.core.security.authc.Authentication;
1312
import org.elasticsearch.xpack.core.security.user.User;
1413

1514
import java.io.IOException;
1615

1716
public final class UserSettings {
18-
private final Logger logger;
17+
private final Logger logger = LogManager.getLogger(UserSettings.class);
18+
1919
private final ThreadContext threadContext;
2020

21-
UserSettings(Settings settings, ThreadContext threadContext) {
22-
this.logger = Loggers.getLogger(getClass(), settings);
21+
UserSettings(ThreadContext threadContext) {
2322
this.threadContext = threadContext;
2423
}
2524

26-
2725
/**
2826
* Returns the current user information, or null if the current request has no authentication info.
2927
*/

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/Realm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.elasticsearch.xpack.core.security.authc;
77

88
import org.apache.logging.log4j.Logger;
9+
import org.apache.logging.log4j.LogManager;
910
import org.elasticsearch.action.ActionListener;
1011
import org.elasticsearch.common.util.concurrent.ThreadContext;
1112
import org.elasticsearch.license.XPackLicenseState;
@@ -25,7 +26,7 @@
2526
*/
2627
public abstract class Realm implements Comparable<Realm> {
2728

28-
protected final Logger logger;
29+
protected final Logger logger = LogManager.getLogger(getClass());
2930
protected final String type;
3031

3132
public String getType() {
@@ -37,7 +38,6 @@ public String getType() {
3738
public Realm(String type, RealmConfig config) {
3839
this.type = type;
3940
this.config = config;
40-
this.logger = config.logger(getClass());
4141
}
4242

4343
/**

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/RealmConfig.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
package org.elasticsearch.xpack.core.security.authc;
77

8-
import org.apache.logging.log4j.Logger;
9-
import org.elasticsearch.common.logging.Loggers;
108
import org.elasticsearch.common.settings.Settings;
119
import org.elasticsearch.common.util.concurrent.ThreadContext;
1210
import org.elasticsearch.env.Environment;
@@ -59,10 +57,6 @@ public Settings globalSettings() {
5957
return globalSettings;
6058
}
6159

62-
public Logger logger(Class clazz) {
63-
return Loggers.getLogger(clazz, globalSettings);
64-
}
65-
6660
public Environment env() {
6761
return env;
6862
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/SecurityIndexSearcherWrapper.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.elasticsearch.xpack.core.security.authz.accesscontrol;
77

88
import org.apache.logging.log4j.Logger;
9+
import org.apache.logging.log4j.LogManager;
910
import org.apache.lucene.index.DirectoryReader;
1011
import org.apache.lucene.index.LeafReaderContext;
1112
import org.apache.lucene.search.BooleanQuery;
@@ -30,14 +31,12 @@
3031
import org.elasticsearch.ExceptionsHelper;
3132
import org.elasticsearch.common.bytes.BytesReference;
3233
import org.elasticsearch.common.logging.LoggerMessageFormat;
33-
import org.elasticsearch.common.logging.Loggers;
3434
import org.elasticsearch.common.lucene.search.Queries;
3535
import org.elasticsearch.common.util.concurrent.ThreadContext;
3636
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
3737
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3838
import org.elasticsearch.common.xcontent.XContentFactory;
3939
import org.elasticsearch.common.xcontent.XContentParser;
40-
import org.elasticsearch.index.IndexSettings;
4140
import org.elasticsearch.index.cache.bitset.BitsetFilterCache;
4241
import org.elasticsearch.index.engine.EngineException;
4342
import org.elasticsearch.index.query.BoolQueryBuilder;
@@ -89,19 +88,18 @@
8988
* instance.
9089
*/
9190
public class SecurityIndexSearcherWrapper extends IndexSearcherWrapper {
91+
private static final Logger logger = LogManager.getLogger(SecurityIndexSearcherWrapper.class);
9292

9393
private final Function<ShardId, QueryShardContext> queryShardContextProvider;
9494
private final BitsetFilterCache bitsetFilterCache;
9595
private final XPackLicenseState licenseState;
9696
private final ThreadContext threadContext;
97-
private final Logger logger;
9897
private final ScriptService scriptService;
9998

100-
public SecurityIndexSearcherWrapper(IndexSettings indexSettings, Function<ShardId, QueryShardContext> queryShardContextProvider,
99+
public SecurityIndexSearcherWrapper(Function<ShardId, QueryShardContext> queryShardContextProvider,
101100
BitsetFilterCache bitsetFilterCache, ThreadContext threadContext, XPackLicenseState licenseState,
102101
ScriptService scriptService) {
103102
this.scriptService = scriptService;
104-
this.logger = Loggers.getLogger(getClass(), indexSettings.getSettings());
105103
this.queryShardContextProvider = queryShardContextProvider;
106104
this.bitsetFilterCache = bitsetFilterCache;
107105
this.threadContext = threadContext;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/RestrictedTrustConfig.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@
3030
public final class RestrictedTrustConfig extends TrustConfig {
3131

3232
private static final String RESTRICTIONS_KEY_SUBJECT_NAME = "trust.subject_name";
33-
private final Settings settings;
3433
private final String groupConfigPath;
3534
private final TrustConfig delegate;
3635

37-
RestrictedTrustConfig(Settings settings, String groupConfigPath, TrustConfig delegate) {
38-
this.settings = settings;
36+
RestrictedTrustConfig(String groupConfigPath, TrustConfig delegate) {
3937
this.groupConfigPath = Objects.requireNonNull(groupConfigPath);
4038
this.delegate = Objects.requireNonNull(delegate);
4139
}
@@ -45,7 +43,7 @@ RestrictedTrustManager createTrustManager(@Nullable Environment environment) {
4543
try {
4644
final X509ExtendedTrustManager delegateTrustManager = delegate.createTrustManager(environment);
4745
final CertificateTrustRestrictions trustGroupConfig = readTrustGroup(resolveGroupConfigPath(environment));
48-
return new RestrictedTrustManager(settings, delegateTrustManager, trustGroupConfig);
46+
return new RestrictedTrustManager(delegateTrustManager, trustGroupConfig);
4947
} catch (IOException e) {
5048
throw new ElasticsearchException("failed to initialize TrustManager for {}", e, toString());
5149
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/RestrictedTrustManager.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
package org.elasticsearch.xpack.core.ssl;
77

88
import org.apache.logging.log4j.Logger;
9+
import org.apache.logging.log4j.LogManager;
910
import org.apache.logging.log4j.message.ParameterizedMessage;
10-
import org.elasticsearch.common.logging.Loggers;
11-
import org.elasticsearch.common.settings.Settings;
1211

1312
import javax.net.ssl.SSLEngine;
1413
import javax.net.ssl.X509ExtendedTrustManager;
@@ -35,15 +34,14 @@
3534
* The underlying certificate validation is delegated to another TrustManager.
3635
*/
3736
public final class RestrictedTrustManager extends X509ExtendedTrustManager {
38-
37+
private static final Logger logger = LogManager.getLogger(RestrictedTrustManager.class);
3938
private static final String CN_OID = "2.5.4.3";
4039
private static final int SAN_CODE_OTHERNAME = 0;
41-
private final Logger logger;
40+
4241
private final X509ExtendedTrustManager delegate;
4342
private final CertificateTrustRestrictions trustRestrictions;
4443

45-
public RestrictedTrustManager(Settings settings, X509ExtendedTrustManager delegate, CertificateTrustRestrictions restrictions) {
46-
this.logger = Loggers.getLogger(getClass(), settings);
44+
public RestrictedTrustManager(X509ExtendedTrustManager delegate, CertificateTrustRestrictions restrictions) {
4745
this.delegate = delegate;
4846
this.trustRestrictions = restrictions;
4947
logger.debug("Configured with trust restrictions: [{}]", restrictions);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/SSLConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private static KeyConfig createKeyConfig(Settings settings, SSLConfiguration glo
206206
private static TrustConfig createTrustConfig(Settings settings, KeyConfig keyConfig, SSLConfiguration global) {
207207
final TrustConfig trustConfig = createCertChainTrustConfig(settings, keyConfig, global);
208208
return SETTINGS_PARSER.trustRestrictionsPath.get(settings)
209-
.map(path -> (TrustConfig) new RestrictedTrustConfig(settings, path, trustConfig))
209+
.map(path -> (TrustConfig) new RestrictedTrustConfig(path, trustConfig))
210210
.orElse(trustConfig);
211211
}
212212

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transform/TransformRegistry.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package org.elasticsearch.xpack.core.watcher.transform;
77

88
import org.elasticsearch.ElasticsearchParseException;
9-
import org.elasticsearch.common.settings.Settings;
109
import org.elasticsearch.common.xcontent.XContentParser;
1110
import org.elasticsearch.xpack.core.watcher.transform.chain.ChainTransform;
1211
import org.elasticsearch.xpack.core.watcher.transform.chain.ChainTransformFactory;
@@ -20,9 +19,9 @@ public class TransformRegistry {
2019

2120
private final Map<String, TransformFactory> factories;
2221

23-
public TransformRegistry(Settings settings, Map<String, TransformFactory> factories) {
22+
public TransformRegistry(Map<String, TransformFactory> factories) {
2423
Map<String, TransformFactory> map = new HashMap<>(factories);
25-
map.put(ChainTransform.TYPE, new ChainTransformFactory(settings, this));
24+
map.put(ChainTransform.TYPE, new ChainTransformFactory(this));
2625
this.factories = Collections.unmodifiableMap(map);
2726
}
2827

0 commit comments

Comments
 (0)