mirror of
				https://github.com/open-metadata/OpenMetadata.git
				synced 2025-11-04 04:29:13 +00:00 
			
		
		
		
	Remove unnecessary singletons (#11713)
This commit is contained in:
		
							parent
							
								
									6509a3670a
								
							
						
					
					
						commit
						ac8498ab80
					
				@ -18,7 +18,6 @@ import lombok.Getter;
 | 
			
		||||
import org.openmetadata.schema.security.SecurityConfiguration;
 | 
			
		||||
 | 
			
		||||
public class EntityMaskerFactory {
 | 
			
		||||
 | 
			
		||||
  @Getter private static EntityMasker entityMasker;
 | 
			
		||||
 | 
			
		||||
  private EntityMaskerFactory() {}
 | 
			
		||||
@ -28,11 +27,8 @@ public class EntityMaskerFactory {
 | 
			
		||||
    if (entityMasker != null) {
 | 
			
		||||
      return entityMasker;
 | 
			
		||||
    }
 | 
			
		||||
    if (Boolean.TRUE.equals(config.getMaskPasswordsAPI())) {
 | 
			
		||||
      entityMasker = PasswordEntityMasker.getInstance();
 | 
			
		||||
    } else {
 | 
			
		||||
      entityMasker = NoopEntityMasker.getInstance();
 | 
			
		||||
    }
 | 
			
		||||
    entityMasker =
 | 
			
		||||
        Boolean.TRUE.equals(config.getMaskPasswordsAPI()) ? new PasswordEntityMasker() : new NoopEntityMasker();
 | 
			
		||||
    return entityMasker;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -19,17 +19,7 @@ import org.openmetadata.schema.entity.services.ingestionPipelines.IngestionPipel
 | 
			
		||||
import org.openmetadata.schema.entity.teams.AuthenticationMechanism;
 | 
			
		||||
 | 
			
		||||
public class NoopEntityMasker extends EntityMasker {
 | 
			
		||||
 | 
			
		||||
  private static NoopEntityMasker INSTANCE;
 | 
			
		||||
 | 
			
		||||
  private NoopEntityMasker() {}
 | 
			
		||||
 | 
			
		||||
  public static NoopEntityMasker getInstance() {
 | 
			
		||||
    if (INSTANCE == null) {
 | 
			
		||||
      INSTANCE = new NoopEntityMasker();
 | 
			
		||||
    }
 | 
			
		||||
    return INSTANCE;
 | 
			
		||||
  }
 | 
			
		||||
  protected NoopEntityMasker() {}
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public Object maskServiceConnectionConfig(Object connectionConfig, String connectionType, ServiceType serviceType) {
 | 
			
		||||
 | 
			
		||||
@ -31,21 +31,10 @@ import org.openmetadata.service.util.IngestionPipelineBuilder;
 | 
			
		||||
import org.openmetadata.service.util.ReflectionUtil;
 | 
			
		||||
 | 
			
		||||
public class PasswordEntityMasker extends EntityMasker {
 | 
			
		||||
 | 
			
		||||
  private static PasswordEntityMasker INSTANCE;
 | 
			
		||||
 | 
			
		||||
  protected static final String PASSWORD_MASK = "*********";
 | 
			
		||||
 | 
			
		||||
  private static final String NEW_KEY = "";
 | 
			
		||||
 | 
			
		||||
  private PasswordEntityMasker() {}
 | 
			
		||||
 | 
			
		||||
  public static PasswordEntityMasker getInstance() {
 | 
			
		||||
    if (INSTANCE == null) {
 | 
			
		||||
      INSTANCE = new PasswordEntityMasker();
 | 
			
		||||
    }
 | 
			
		||||
    return INSTANCE;
 | 
			
		||||
  }
 | 
			
		||||
  protected PasswordEntityMasker() {}
 | 
			
		||||
 | 
			
		||||
  public Object maskServiceConnectionConfig(Object connectionConfig, String connectionType, ServiceType serviceType) {
 | 
			
		||||
    if (connectionConfig != null) {
 | 
			
		||||
@ -252,9 +241,6 @@ public class PasswordEntityMasker extends EntityMasker {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private String createKey(String previousKey, String key) {
 | 
			
		||||
    if (NEW_KEY.equals(previousKey)) {
 | 
			
		||||
      return key;
 | 
			
		||||
    }
 | 
			
		||||
    return previousKey + "." + key;
 | 
			
		||||
    return NEW_KEY.equals(previousKey) ? key : previousKey + "." + key;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -8,12 +8,10 @@ import org.junit.jupiter.api.Test;
 | 
			
		||||
import org.openmetadata.schema.security.SecurityConfiguration;
 | 
			
		||||
 | 
			
		||||
public class EntityMaskerFactoryTest {
 | 
			
		||||
 | 
			
		||||
  SecurityConfiguration config;
 | 
			
		||||
  private static final SecurityConfiguration CONFIG = new SecurityConfiguration();
 | 
			
		||||
 | 
			
		||||
  @BeforeEach
 | 
			
		||||
  void setUp() {
 | 
			
		||||
    config = new SecurityConfiguration();
 | 
			
		||||
    EntityMaskerFactory.setEntityMasker(null);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -24,12 +22,13 @@ public class EntityMaskerFactoryTest {
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  void testInitWithNoopEntityMasker() {
 | 
			
		||||
    assertTrue(EntityMaskerFactory.createEntityMasker(config) instanceof NoopEntityMasker);
 | 
			
		||||
    CONFIG.setMaskPasswordsAPI(false);
 | 
			
		||||
    assertTrue(EntityMaskerFactory.createEntityMasker(CONFIG) instanceof NoopEntityMasker);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  void testInitWithPasswordEntityMasker() {
 | 
			
		||||
    config.setMaskPasswordsAPI(true);
 | 
			
		||||
    assertTrue(EntityMaskerFactory.createEntityMasker(config) instanceof PasswordEntityMasker);
 | 
			
		||||
    CONFIG.setMaskPasswordsAPI(true);
 | 
			
		||||
    assertTrue(EntityMaskerFactory.createEntityMasker(CONFIG) instanceof PasswordEntityMasker);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user