Skip to content

Commit

Permalink
Switch to log4j logger (opensearch-project#1751)
Browse files Browse the repository at this point in the history
In OpenSearch 1.3.0 we removed an explicit dependency on log4j
opensearch-project#1563 this caused the
log4j-slf4j-impl-X.XX.X.jar file no longer to be included in the plugin.
When the plugin started up the default no-op logger was used instead.
This prevented the security plugin from logging anything, yikes.

When looking at the other opensearch plugins, none of them use slf4.
Rather than continue using a seperate logging process, moving to the
standard log4j Logger/LogManager.

Tested this change on 2.0.0-alpha distribution and logging works as
expected.

Signed-off-by: Peter Nied <[email protected]>
(cherry picked from commit 54a920b)
  • Loading branch information
peternied authored and DarshitChanpura committed Apr 25, 2022
1 parent 3a873f8 commit f9c2f36
Show file tree
Hide file tree
Showing 106 changed files with 311 additions and 311 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ dependencies {
implementation 'commons-cli:commons-cli:1.3.1'
implementation 'org.bouncycastle:bcprov-jdk15on:1.67'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.6'
implementation 'org.slf4j:slf4j-api:1.7.32'
implementation 'org.ldaptive:ldaptive:1.2.3'
implementation 'org.apache.httpcomponents:httpclient-cache:4.5.13'
implementation 'io.jsonwebtoken:jjwt-api:0.10.8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import org.apache.cxf.rs.security.jose.jwt.JwtClaims;
import org.apache.cxf.rs.security.jose.jwt.JwtToken;
import org.apache.http.HttpHeaders;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.opensearch.OpenSearchSecurityException;
import org.opensearch.SpecialPermission;
import org.opensearch.common.Strings;
Expand All @@ -46,7 +48,7 @@
import org.opensearch.security.user.AuthCredentials;

public abstract class AbstractHTTPJwtAuthenticator implements HTTPAuthenticator {
private final static Logger log = LoggerFactory.getLogger(AbstractHTTPJwtAuthenticator.class);
private final static Logger log = LogManager.getLogger(AbstractHTTPJwtAuthenticator.class);

private static final String BEARER = "bearer ";
private static final Pattern BASIC = Pattern.compile("^\\s*Basic\\s.*", Pattern.CASE_INSENSITIVE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import java.util.regex.Pattern;

import org.apache.http.HttpHeaders;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.opensearch.OpenSearchSecurityException;
import org.opensearch.SpecialPermission;
import org.opensearch.common.settings.Settings;
Expand All @@ -51,7 +51,7 @@

public class HTTPJwtAuthenticator implements HTTPAuthenticator {

protected final Logger log = LoggerFactory.getLogger(this.getClass());
protected final Logger log = LogManager.getLogger(this.getClass());

private static final Pattern BASIC = Pattern.compile("^\\s*Basic\\s.*", Pattern.CASE_INSENSITIVE);
private static final String BEARER = "bearer ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class HTTPJwtKeyByOpenIdConnectAuthenticator extends AbstractHTTPJwtAuthenticator {

//private final static Logger log = LoggerFactory.getLogger(HTTPJwtKeyByOpenIdConnectAuthenticator.class);
//private final static Logger log = LogManager.getLogger(HTTPJwtKeyByOpenIdConnectAuthenticator.class);

public HTTPJwtKeyByOpenIdConnectAuthenticator(Settings settings, Path configPath) {
super(settings, configPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
import org.apache.cxf.rs.security.jose.jwt.JwtToken;
import org.apache.cxf.rs.security.jose.jwt.JwtUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

import com.google.common.base.Strings;

public class JwtVerifier {

private final static Logger log = LoggerFactory.getLogger(JwtVerifier.class);
private final static Logger log = LogManager.getLogger(JwtVerifier.class);

private final KeyProvider keyProvider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
import org.apache.http.impl.client.cache.BasicHttpCacheStorage;
import org.apache.http.impl.client.cache.CacheConfig;
import org.apache.http.impl.client.cache.CachingHttpClients;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

import com.amazon.dlic.auth.http.jwt.oidc.json.OpenIdProviderConfiguration;
import com.amazon.dlic.util.SettingsBasedSSLConfigurator.SSLConfig;


public class KeySetRetriever implements KeySetProvider {
private final static Logger log = LoggerFactory.getLogger(KeySetRetriever.class);
private final static Logger log = LogManager.getLogger(KeySetRetriever.class);
private static final long CACHE_STATUS_LOG_INTERVAL_MS = 60L * 60L * 1000L;

private String openIdConnectEndpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

import org.apache.cxf.rs.security.jose.jwk.JsonWebKey;
import org.apache.cxf.rs.security.jose.jwk.JsonWebKeys;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

import com.google.common.base.Strings;

public class SelfRefreshingKeySet implements KeyProvider {
private static final Logger log = LoggerFactory.getLogger(SelfRefreshingKeySet.class);
private static final Logger log = LogManager.getLogger(SelfRefreshingKeySet.class);

private final KeySetProvider keySetProvider;
private final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 10, 1000, TimeUnit.MILLISECONDS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import javax.security.auth.Subject;
import javax.security.auth.login.LoginException;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.opensearch.ExceptionsHelper;
import org.opensearch.SpecialPermission;
import org.opensearch.common.settings.Settings;
Expand Down Expand Up @@ -65,7 +65,7 @@ public class HTTPSpnegoAuthenticator implements HTTPAuthenticator {
private static final String EMPTY_STRING = "";
private static final Oid[] KRB_OIDS = new Oid[] {KrbConstants.SPNEGO, KrbConstants.KRB5MECH};

protected final Logger log = LoggerFactory.getLogger(this.getClass());
protected final Logger log = LogManager.getLogger(this.getClass());

private boolean stripRealmFromPrincipalName;
private Set<String> acceptorPrincipal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import org.apache.cxf.rs.security.jose.jwt.JwtClaims;
import org.apache.cxf.rs.security.jose.jwt.JwtToken;
import org.apache.cxf.rs.security.jose.jwt.JwtUtils;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.opensearch.OpenSearchSecurityException;
import org.opensearch.SpecialPermission;
import org.opensearch.common.bytes.BytesReference;
Expand All @@ -68,8 +68,8 @@
import com.onelogin.saml2.util.Util;

class AuthTokenProcessorHandler {
private static final Logger log = LoggerFactory.getLogger(AuthTokenProcessorHandler.class);
private static final Logger token_log = LoggerFactory.getLogger("com.amazon.dlic.auth.http.saml.Token");
private static final Logger log = LogManager.getLogger(AuthTokenProcessorHandler.class);
private static final Logger token_log = LogManager.getLogger("com.amazon.dlic.auth.http.saml.Token");
private static final Pattern EXPIRY_SETTINGS_PATTERN = Pattern.compile("\\s*(\\w+)\\s*(?:\\+\\s*(\\w+))?\\s*");

private Saml2SettingsProvider saml2SettingsProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import net.shibboleth.utilities.java.support.xml.BasicParserPool;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.cxf.rs.security.jose.jwk.JsonWebKey;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.opensearch.OpenSearchSecurityException;
import org.opensearch.SpecialPermission;
import org.opensearch.common.settings.Settings;
Expand Down Expand Up @@ -73,7 +73,7 @@


public class HTTPSamlAuthenticator implements HTTPAuthenticator, Destroyable {
protected final static Logger log = LoggerFactory.getLogger(HTTPSamlAuthenticator.class);
protected final static Logger log = LogManager.getLogger(HTTPSamlAuthenticator.class);

public static final String IDP_METADATA_URL = "idp.metadata_url";
public static final String IDP_METADATA_FILE = "idp.metadata_file";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import java.util.Set;
import java.util.stream.Collectors;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

import org.opensearch.SpecialPermission;
import org.opensearch.common.settings.Settings;
Expand All @@ -52,7 +52,7 @@
import net.shibboleth.utilities.java.support.resolver.ResolverException;

public class Saml2SettingsProvider {
protected final static Logger log = LoggerFactory.getLogger(Saml2SettingsProvider.class);
protected final static Logger log = LogManager.getLogger(Saml2SettingsProvider.class);

private final Settings opensearchSettings;
private final MetadataResolver metadataResolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.UUID;

import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.opensearch.OpenSearchSecurityException;
import org.opensearch.common.settings.Settings;

Expand All @@ -53,7 +53,7 @@ public class LDAPAuthenticationBackend implements AuthenticationBackend {
static final String DEFAULT_USERBASE = "";
static final String DEFAULT_USERSEARCH_PATTERN = "(sAMAccountName={0})";

protected static final Logger log = LoggerFactory.getLogger(LDAPAuthenticationBackend.class);
protected static final Logger log = LogManager.getLogger(LDAPAuthenticationBackend.class);

private final Settings settings;
private final Path configPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.opensearch.OpenSearchSecurityException;
import org.opensearch.SpecialPermission;
import org.opensearch.common.Strings;
Expand Down Expand Up @@ -99,7 +99,7 @@ public class LDAPAuthorizationBackend implements AuthorizationBackend {
static final String DEFAULT_ROLENAME = "name";
static final String DEFAULT_USERROLENAME = "memberOf";

protected static final Logger log = LoggerFactory.getLogger(LDAPAuthorizationBackend.class);
protected static final Logger log = LogManager.getLogger(LDAPAuthorizationBackend.class);
private final Settings settings;
private final WildcardMatcher skipUsersMatcher;
private final WildcardMatcher nestedRoleMatcher;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/amazon/dlic/auth/ldap/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
import java.util.Map;
import java.util.Set;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.opensearch.SpecialPermission;
import org.opensearch.common.settings.Settings;
import org.ldaptive.Connection;
import org.ldaptive.LdapAttribute;

public final class Utils {

private static final Logger log = LoggerFactory.getLogger(Utils.class);
private static final Logger log = LogManager.getLogger(Utils.class);

private Utils() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import java.util.Collections;
import java.util.UUID;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.opensearch.OpenSearchSecurityException;
import org.opensearch.SpecialPermission;
import org.opensearch.common.settings.Settings;
Expand All @@ -51,7 +51,7 @@

public class LDAPAuthenticationBackend2 implements AuthenticationBackend, Destroyable {

protected static final Logger log = LoggerFactory.getLogger(LDAPAuthenticationBackend2.class);
protected static final Logger log = LogManager.getLogger(LDAPAuthenticationBackend2.class);

private final Settings settings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.opensearch.OpenSearchSecurityException;
import org.opensearch.SpecialPermission;
import org.opensearch.common.Strings;
Expand Down Expand Up @@ -68,7 +68,7 @@ public class LDAPAuthorizationBackend2 implements AuthorizationBackend, Destroya
static final String DEFAULT_ROLENAME = "name";
static final String DEFAULT_USERROLENAME = "memberOf";

protected static final Logger log = LoggerFactory.getLogger(LDAPAuthorizationBackend2.class);
protected static final Logger log = LogManager.getLogger(LDAPAuthorizationBackend2.class);
private final Settings settings;
private final WildcardMatcher skipUsersMatcher;
private final WildcardMatcher nestedRoleMatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.opensearch.common.settings.Settings;
import org.ldaptive.ActivePassiveConnectionStrategy;
import org.ldaptive.BindConnectionInitializer;
Expand Down Expand Up @@ -67,7 +67,7 @@

public class LDAPConnectionFactoryFactory {

private static final Logger log = LoggerFactory.getLogger(LDAPConnectionFactoryFactory.class);
private static final Logger log = LogManager.getLogger(LDAPConnectionFactoryFactory.class);

private final Settings settings;
private final SettingsBasedSSLConfigurator.SSLConfig sslConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import java.util.Set;

import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.opensearch.common.settings.Settings;
import org.ldaptive.Connection;
import org.ldaptive.LdapEntry;
Expand All @@ -36,7 +36,7 @@
import com.amazon.dlic.auth.ldap.util.Utils;

public class LDAPUserSearcher {
protected static final Logger log = LoggerFactory.getLogger(LDAPUserSearcher.class);
protected static final Logger log = LogManager.getLogger(LDAPUserSearcher.class);

private static final int ZERO_PLACEHOLDER = 0;
private static final String DEFAULT_USERBASE = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@
import org.apache.http.ssl.PrivateKeyStrategy;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.SSLContexts;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.opensearch.common.settings.Settings;

import org.opensearch.security.ssl.util.SSLConfigConstants;
import org.opensearch.security.support.PemKeyReader;
import com.google.common.collect.ImmutableList;

public class SettingsBasedSSLConfigurator {
private static final Logger log = LoggerFactory.getLogger(SettingsBasedSSLConfigurator.class);
private static final Logger log = LogManager.getLogger(SettingsBasedSSLConfigurator.class);

public static final String CERT_ALIAS = "cert_alias";
public static final String CA_ALIAS = "ca_alias";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
import org.opensearch.security.setting.OpensearchDynamicSetting;
import org.opensearch.security.setting.TransportPassiveAuthSetting;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.lucene.search.QueryCachingPolicy;
import org.apache.lucene.search.Weight;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
Expand Down Expand Up @@ -180,7 +180,7 @@
public final class OpenSearchSecurityPlugin extends OpenSearchSecuritySSLPlugin implements ClusterPlugin, MapperPlugin {

private static final String KEYWORD = ".keyword";
private static final Logger actionTrace = LoggerFactory.getLogger("opendistro_security_action_trace");
private static final Logger actionTrace = LogManager.getLogger("opendistro_security_action_trace");
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(OpenSearchSecurityPlugin.class);

public static final String LEGACY_OPENDISTRO_PREFIX = "_opendistro/_security";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import java.io.IOException;
import java.util.List;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.opensearch.action.FailedNodeException;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.nodes.BaseNodeRequest;
Expand All @@ -57,7 +57,7 @@ public class TransportConfigUpdateAction
extends
TransportNodesAction<ConfigUpdateRequest, ConfigUpdateResponse, TransportConfigUpdateAction.NodeConfigUpdateRequest, ConfigUpdateNodeResponse> {

protected Logger logger = LoggerFactory.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());
private final Provider<BackendRegistry> backendRegistry;
private final ConfigurationRepository configurationRepository;
private DynamicConfigFactory dynamicConfigFactory;
Expand Down
Loading

0 comments on commit f9c2f36

Please sign in to comment.