diff --git a/README.md b/README.md index 8707766..04da88a 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,21 @@ # eJMask `{*:*}` -eJMask is a JVM-based masking library that provides an easy-to-use API for masking sensitive data in your Java applications. With eJMask, you can quickly mask sensitive information like personal information, credit card numbers, and more. eJMask library is designed to provide a simple interface to make masking sensitive data sets before logging easier and simpler without impacting performance. +eJMask is a JVM-based masking library that provides an easy-to-use API for masking sensitive data in your Java applications. With eJMask, you can quickly mask sensitive information like personal information, credit card numbers, and more. eJMask library is designed to provide a simple interface to make masking sensitive data sets before +logging easier and simpler without impacting performance. ### Features + - Easy-to-use API for integration into your Java applications - Support for multiple masking strategies, including character substitution and partial masking - Custom masking strategies can be added easily to meet your specific needs - Lightweight and efficient, with no external dependencies +### Dependencies + +| JDK Version | Spring Version | Spring Boot Version | +|-------------|----------------|---------------------| +| 8 | 5.3.31 | 2.7.18 | + ### Getting Started To get started with eJMask, you'll need to add the eJMask library to your project using your preferred build system, such as Maven or Gradle. @@ -41,7 +49,8 @@ public class EJMaskExample { `IPatternBuilder` implementations are responsible to generate the regular expression needed to replace data to be masked. Pattern builder also have additional responsibility to optimize the regex by creating one expression to mask all list of field names for better performance. -#### eg: +#### eg: + ```java public class JsonPatternBuilder implements IPatternBuilder { @@ -57,7 +66,9 @@ public class JsonPatternBuilder implements IPatternBuilder { } } ``` + #### Extensions + For many standard use cases you can make use of pattern builders defined in `ejmask-extensions` module. - HeaderFieldPatternBuilder @@ -71,6 +82,7 @@ For many standard use cases you can make use of pattern builders defined in `ejm `IFilter` defines how a field should be masked. This includes the field name, the pattern builder need to be used, number of characters need to be visible at the end or beginning, etc. eg: + ```java public class Sample implements IFilter { @@ -86,6 +98,7 @@ public class Sample implements IFilter { } } ``` + > Users can also override default values for `VisibleCharacters`,`Group`, `Order)` etc if needed. ### ContentProcessor @@ -94,6 +107,7 @@ public class Sample implements IFilter { A few use case we can use is to decode and encode the string before masking and/or to reduce the size of a large string before performing the masking operation to improve performance. #### Extensions + - ContentSlicerPreProcessor ### LogProvider @@ -107,6 +121,7 @@ LoggerUtil.register(new MyLogProvider()); ## Getting Started ### Supported Languages + eJMask is created as a Maven based Java project and can be used as a dependency in a Java based application or other JVM based languages such as Kotlin, Groovy, Scala etc. ### Manual configuration. @@ -116,7 +131,7 @@ eJMask will internally dedupe the given set of filters and generate the most opt #### Adding Filters -Invoke `EJMaskInitializer.addFilters` with list of all Filter instances. `EJMaskInitializer` Internally removes all duplicate and optimizes the MaskingPatterns by grouping similar patterns. +Invoke `EJMaskInitializer.addFilters` with list of all Filter instances. `EJMaskInitializer` Internally removes all duplicate and optimizes the MaskingPatterns by grouping similar patterns. #### Adding ContentProcessors @@ -145,6 +160,7 @@ If you are using spring application ejamsk configurations can easily be auto wir - Done !! ```java + @Component("data-filter.add-address") public class AddAddressFilter extends BaseFilter { AddAddressFilter() { @@ -165,6 +181,7 @@ public class AddAddressFilter extends BaseFilter { - ✔ Done !! ```java + @Configuration("data-filter.config.add-shareholder") public class AddShareholderRequestFilterConfiguration { @@ -189,26 +206,29 @@ eJMask is a spring native library, spring eases the process of configuring eJMas Fist add `ejmask-spring-core` to your dependency list. ```xml + - com.ebay.ejmask - ejmask-spring-autoconfig + com.ebay.ejmask + ejmask-spring-core ``` then simply add `com.ebay.ejmask.spring.core` to your spring context scanning. ```xml + ``` #### AutoConfiguration -If your application is built on spring boot you can skip the above step by simply adding `ejmask-spring-boot` into dependency list. +If your application is built on spring boot you can skip the above step by simply adding `ejmask-spring-starter` into dependency list. ```xml + - com.ebay.ejmask - ejmask-spring-boot + com.ebay.ejmask + ejmask-spring-starter ``` @@ -228,12 +248,15 @@ You can download source and binaries from our [release page](https://github.com/ Alternatively you can pull it from the central Maven repositories: ### Using in your maven project. + > Please check the release version before adding to your project. + ```xml + - com.ebay.ejmask - ejmask-bom - 1.2.1 + com.ebay.ejmask + ejmask-bom + 1.2.1 ``` @@ -252,8 +275,8 @@ compile group: 'com.ebay.ejmask', name: 'ejmask-bom', version: '1.2.1' - [ ] Users will should be able to configure data filters through `ejmask.ymal`. - [ ] Users will be able to mask any given field by annotating with `@Mask` annotation. - ## License Information + Copyright 2023 eBay Inc. Author(s): [Prasanth Kaimattil Venu](https://github.com/prasanthkv), [Manikandan Perumal](https://github.com/tbd) @@ -261,3 +284,4 @@ Author(s): [Prasanth Kaimattil Venu](https://github.com/prasanthkv), [Manikandan Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + diff --git a/ejmask-bom/pom.xml b/ejmask-bom/pom.xml index c3b9101..604cbfe 100644 --- a/ejmask-bom/pom.xml +++ b/ejmask-bom/pom.xml @@ -40,12 +40,7 @@ com.ebay.ejmask - ejmask-spring-boot - ${project.parent.version} - - - com.ebay.ejmask - ejmask-spring-autoconfig + ejmask-spring-starter ${project.parent.version} diff --git a/ejmask-core/pom.xml b/ejmask-core/pom.xml index 7a0738c..197f804 100644 --- a/ejmask-core/pom.xml +++ b/ejmask-core/pom.xml @@ -16,16 +16,6 @@ ${project.version} - - org.junit.jupiter - junit-jupiter - test - - - org.mockito - mockito-inline - test - org.apache.commons commons-lang3 diff --git a/ejmask-core/src/main/java/com/ebay/ejmask/core/BaseFilter.java b/ejmask-core/src/main/java/com/ebay/ejmask/core/BaseFilter.java index 11bd130..9ecabb0 100644 --- a/ejmask-core/src/main/java/com/ebay/ejmask/core/BaseFilter.java +++ b/ejmask-core/src/main/java/com/ebay/ejmask/core/BaseFilter.java @@ -1,5 +1,4 @@ package com.ebay.ejmask.core; - /** * Copyright (c) 2023 eBay Inc. *

@@ -41,7 +40,6 @@ public class BaseFilter implements IFilter { * @param patternBuilder new value of patternBuilder * @param fieldNames new value of fieldNames */ - @SafeVarargs public BaseFilter(Class patternBuilder, String... fieldNames) { this(patternBuilder, DEFAULT_VISIBLE_CHAR, DEFAULT_PRIORITY, fieldNames); } @@ -53,7 +51,6 @@ public BaseFilter(Class patternBuilder, String... fie * @param visibleCharacters new value of visibleCharacters * @param fieldNames new value of fieldNames */ - @SafeVarargs public BaseFilter(Class patternBuilder, int visibleCharacters, String... fieldNames) { this(patternBuilder, visibleCharacters, DEFAULT_PRIORITY, fieldNames); } @@ -67,7 +64,6 @@ public BaseFilter(Class patternBuilder, int visibleCh * @param order new value of order * @param fieldNames new value of fieldNames */ - @SafeVarargs public BaseFilter(Class patternBuilder, int visibleCharacters, int order, String... fieldNames) { if (patternBuilder == null) { throw new IllegalArgumentException("patternBuilder cannot be null."); @@ -81,7 +77,6 @@ public BaseFilter(Class patternBuilder, int visibleCh this.fieldNames = fieldNames; } - /** * Get the value of patternBuilder * @@ -121,4 +116,4 @@ public int getOrder() { public String[] getFieldNames() { return this.fieldNames; } -} +} \ No newline at end of file diff --git a/ejmask-core/src/main/java/com/ebay/ejmask/core/util/CommonUtils.java b/ejmask-core/src/main/java/com/ebay/ejmask/core/util/CommonUtils.java index 022b8ef..a33cb52 100644 --- a/ejmask-core/src/main/java/com/ebay/ejmask/core/util/CommonUtils.java +++ b/ejmask-core/src/main/java/com/ebay/ejmask/core/util/CommonUtils.java @@ -1,5 +1,4 @@ package com.ebay.ejmask.core.util; - /** * Copyright (c) 2023 eBay Inc. *

@@ -16,7 +15,6 @@ * limitations under the License. */ - import java.io.PrintWriter; import java.io.StringWriter; import java.lang.reflect.Array; @@ -89,7 +87,7 @@ public static boolean isAnEmptyArray(Object array) { * @param array the array to retrieve the length from, may be null * @return The length of the array, or {@code 0} if the array is {@code null} */ - private static int getLength(final Object array) { + private static int getLength(Object array) { return (array == null) ? 0 : Array.getLength(array); } @@ -102,7 +100,7 @@ private static int getLength(final Object array) { * @return {@code true} if the CharSequence is * not empty and not null and not whitespace only */ - public static boolean isNotBlank(final CharSequence cs) { + public static boolean isNotBlank(CharSequence cs) { return !isBlank(cs); } @@ -114,8 +112,8 @@ public static boolean isNotBlank(final CharSequence cs) { * @param cs the CharSequence to check, may be null * @return {@code true} if the CharSequence is null, empty or whitespace only */ - public static boolean isBlank(final CharSequence cs) { - final int strLen = cs == null ? 0 : cs.length(); + public static boolean isBlank(CharSequence cs) { + int strLen = cs == null ? 0 : cs.length(); if (strLen != 0) { for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(cs.charAt(i))) { diff --git a/ejmask-extensions/pom.xml b/ejmask-extensions/pom.xml index f169c27..407bd87 100644 --- a/ejmask-extensions/pom.xml +++ b/ejmask-extensions/pom.xml @@ -16,16 +16,6 @@ ${project.version} - - org.junit.jupiter - junit-jupiter - test - - - org.mockito - mockito-inline - test - org.apache.commons commons-lang3 diff --git a/ejmask-spring/ejmask-spring-autoconfig/pom.xml b/ejmask-spring/ejmask-spring-autoconfig/pom.xml deleted file mode 100644 index 411e52b..0000000 --- a/ejmask-spring/ejmask-spring-autoconfig/pom.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - 4.0.0 - - com.ebay.ejmask - ejmask-spring - ${revision}${changelist} - - - ejmask-spring-autoconfig - - - - com.ebay.ejmask - ejmask-api - ${project.version} - - - com.ebay.ejmask - ejmask-spring-core - ${project.version} - - - com.ebay.ejmask - ejmask-spring-boot - ${project.version} - - - org.springframework.boot - spring-boot-starter - - - diff --git a/ejmask-spring/ejmask-spring-boot/src/it/java/com/ebay/ejmask/spring/boot/autoconfig/EJMaskAutoConfigIT.java b/ejmask-spring/ejmask-spring-boot/src/it/java/com/ebay/ejmask/spring/boot/autoconfig/EJMaskAutoConfigIT.java deleted file mode 100644 index 06dc287..0000000 --- a/ejmask-spring/ejmask-spring-boot/src/it/java/com/ebay/ejmask/spring/boot/autoconfig/EJMaskAutoConfigIT.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.ebay.ejmask.spring.boot.autoconfig; - - -import com.ebay.ejmask.api.IContentProcessor; -import org.junit.Assert; -import org.junit.experimental.runners.Enclosed; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * Objective of this Integration test is ensure that all spring bean wiring works as expected. - * The test to verify execution SLA must pass for this test. - * - * @author prakv - */ -@RunWith(Enclosed.class) -public class EJMaskAutoConfigIT { - - @SpringBootApplication - @ContextConfiguration - @RunWith(SpringJUnit4ClassRunner.class) - @SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = EJMaskAutoConfig.class) - public static class ConfigDefaultIT { - - @Autowired(required = false) - EJMaskAutoConfig config; - - @Autowired(required = false) - IContentProcessor contentPreProcessor; - - @Test - public void testConfig() { - Assert.assertNotNull(this.config); - } - - @Test - public void testProcessor() { - Assert.assertNull(this.contentPreProcessor); - } - } - - @SpringBootApplication - @ContextConfiguration - @RunWith(SpringJUnit4ClassRunner.class) - @SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = EJMaskAutoConfig.class) - @TestPropertySource(properties = {"ejmask.autoconfig=enabled", "ejmask.processor.content-slicer=enabled" - , "ejmask.content-slicer.priority=150", "ejmask.content-slicer.max-size=100000", "ejmask.content-slicer.new-size=40000"}) - public static class ConfigEnabledIT { - - @Autowired(required = false) - EJMaskAutoConfig config; - - @Autowired(required = false) - IContentProcessor contentPreProcessor; - - @Test - public void testConfig() { - Assert.assertNotNull(this.config); - } - - @Test - public void testProcessor() { - Assert.assertNotNull(this.contentPreProcessor); - } - - @Test - public void testContentSlicerPriority() { - Assert.assertEquals(150, this.config.contentSlicerPriority); - } - - @Test - public void testContentSlicerMaxStringLimit() { - Assert.assertEquals(100000, this.config.contentSlicerMaxStringLimit); - } - - @Test - public void testContentSlicerNewSize() { - Assert.assertEquals(40000, this.config.contentSlicerNewSize); - } - } - - @SpringBootApplication - @ContextConfiguration - @RunWith(SpringJUnit4ClassRunner.class) - @SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = EJMaskAutoConfig.class) - @TestPropertySource(properties = {"ejmask.autoconfig=disabled", "ejmask.ejmask.processor.content-slicer=disabled"}) - public static class ConfigDisabledIT { - - @Autowired(required = false) - EJMaskAutoConfig config; - - @Autowired(required = false) - IContentProcessor contentPreProcessor; - - @Test - public void testConfig() { - Assert.assertNull(this.config); - } - - @Test - public void testProcessor() { - Assert.assertNull(this.contentPreProcessor); - } - } -} diff --git a/ejmask-spring/ejmask-spring-core/pom.xml b/ejmask-spring/ejmask-spring-core/pom.xml index 9224bd5..59b36f5 100644 --- a/ejmask-spring/ejmask-spring-core/pom.xml +++ b/ejmask-spring/ejmask-spring-core/pom.xml @@ -23,7 +23,6 @@ org.springframework spring-context - com.ebay.ejmask @@ -31,11 +30,6 @@ ${project.version} test - - junit - junit - test - org.springframework spring-test @@ -56,5 +50,15 @@ commons-lang3 test + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params + test + diff --git a/ejmask-spring/ejmask-spring-core/src/it/java/com/ebay/ejmask/spring/core/AbstractIT.java b/ejmask-spring/ejmask-spring-core/src/it/java/com/ebay/ejmask/spring/core/AbstractIT.java deleted file mode 100644 index 5914fed..0000000 --- a/ejmask-spring/ejmask-spring-core/src/it/java/com/ebay/ejmask/spring/core/AbstractIT.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.ebay.ejmask.spring.core; - -import org.junit.Ignore; - -/** - * Keep this cass as default visibility - * - * @author prakv - */ -@Ignore -public abstract class AbstractIT { - - -} diff --git a/ejmask-spring/ejmask-spring-core/src/it/java/com/ebay/ejmask/spring/core/EJMaskSpringCoreContextConfigurationIT.java b/ejmask-spring/ejmask-spring-core/src/it/java/com/ebay/ejmask/spring/core/EJMaskSpringCoreContextConfigurationIT.java index f99f003..dcb93bd 100644 --- a/ejmask-spring/ejmask-spring-core/src/it/java/com/ebay/ejmask/spring/core/EJMaskSpringCoreContextConfigurationIT.java +++ b/ejmask-spring/ejmask-spring-core/src/it/java/com/ebay/ejmask/spring/core/EJMaskSpringCoreContextConfigurationIT.java @@ -1,29 +1,30 @@ package com.ebay.ejmask.spring.core; - import com.ebay.ejmask.core.EJMask; import com.ebay.ejmask.core.EJMaskInitializer; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.RandomStringUtils; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestContextManager; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.support.AnnotationConfigContextLoader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.Arrays; -import java.util.Collection; +import java.util.stream.Stream; /** * Objective of this Integration test is ensure that all spring bean wiring works as expected. @@ -31,76 +32,66 @@ * * @author prakv */ -@RunWith(Parameterized.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {FilterContextConfiguration.class}, loader = AnnotationConfigContextLoader.class) -public class EJMaskSpringCoreContextConfigurationIT { - - @Parameterized.Parameter - public String testName; - - @Parameterized.Parameter(1) - public String input; +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class EJMaskSpringCoreContextConfigurationIT { - @Parameterized.Parameter(2) - public String expected; - - TestContextManager testContextManager; - - @Before + @BeforeEach public void setUp() throws Exception { - this.testContextManager = new TestContextManager(this.getClass()); - this.testContextManager.prepareTestInstance(this); - } - - @Test - public void test1VerifySetUp() { - Assert.assertFalse(EJMaskInitializer.getMaskingPatterns().isEmpty()); - Assert.assertFalse(EJMaskInitializer.getContentPreProcessors().isEmpty()); - } - - @Parameterized.Parameters(name = "{0}") - public static Collection data() throws Exception { - return Arrays.asList(new Object[]{"testEmpty", "", ""}, - testJson(), - testHTTPHeaders(), - testFlatString(), - test_big_string(), - //always last - test_largeData()); + new TestContextManager(this.getClass()).prepareTestInstance(this); } - /** - * This test validate the given string is masked as expected. - */ - @Test - public void test1_verify_the_request_is_masked_as_expected() { - String actual = EJMask.mask(this.input); - Assert.assertEquals(this.expected, actual); - Assert.assertFalse(actual.contains("sensitiveData")); + @Order(2) + @ParameterizedTest + @MethodSource("data") + @DisplayName("Verify the request is masked as expected") + public void test1_verify_the_request_is_masked_as_expected(String testName, String input, String expected) { + Assertions.assertFalse(EJMaskInitializer.getMaskingPatterns().isEmpty()); + Assertions.assertFalse(EJMaskInitializer.getContentPreProcessors().isEmpty()); + // + String actual = EJMask.mask(input); + Assertions.assertEquals(expected, actual); + Assertions.assertFalse(actual.contains("sensitiveData")); } - /** - * This test validate the given string is masked as expected. in case the string got json encoded. - */ - @Test - public void test2_verify_the_request_is_masked_as_expected_even_if_the_string_got_json_serialized() throws Exception { - String actual = EJMask.mask(new ObjectMapper().writeValueAsString(this.input)); - Assume.assumeFalse(actual, actual.contains("sensitiveData")); + @Order(3) + @ParameterizedTest + @MethodSource("data") + @DisplayName("Verify the request is masked as expected even if the string got json serialized") + public void test2_verify_the_request_is_masked_as_expected_even_if_the_string_got_json_serialized(String testName, String input, String expected) throws Exception { + Assertions.assertFalse(EJMaskInitializer.getMaskingPatterns().isEmpty()); + Assertions.assertFalse(EJMaskInitializer.getContentPreProcessors().isEmpty()); + // + String actual = EJMask.mask(new ObjectMapper().writeValueAsString(input)); + Assumptions.assumeFalse(actual.contains("sensitiveData")); } - /** - * This test will invoke mask operation 1000 times and validate the - * operation matching SLA ( sub ms ) - */ - @Test - public void test3_verify_the_masking_operation_meets_SLA() { - final long start = System.currentTimeMillis(); + @Order(4) + @ParameterizedTest + @MethodSource("data") + @DisplayName("Verify the masking operation meets SLA") + public void test3_verify_the_masking_operation_meets_SLA(String testName, String input, String expected) { + Assertions.assertFalse(EJMaskInitializer.getMaskingPatterns().isEmpty()); + Assertions.assertFalse(EJMaskInitializer.getContentPreProcessors().isEmpty()); + // + long start = System.currentTimeMillis(); for (int i = 0; i < 1000; i++) { - EJMask.mask(this.input); + EJMask.mask(input); } - final long maskTime = System.currentTimeMillis() - start; - Assume.assumeTrue("masking should be done in sub ms : (current:" + maskTime + "ms)", maskTime < 2000); + long maskTime = System.currentTimeMillis() - start; + Assumptions.assumeTrue(maskTime < 2000, "masking should be done in sub ms : (current:" + maskTime + "ms)"); + } + + static Stream data() throws Exception { + return Stream.of( + new Object[]{"testEmpty", "", ""}, + testHTTPHeaders(), + testJson(), + testFlatString(), + test_big_string(), + test_largeData() + ); } private static Object[] testHTTPHeaders() { @@ -119,6 +110,7 @@ private static Object[] testHTTPHeaders() { return new Object[]{"testHTTPHeaders", actual, expected}; } + private static Object[] testFlatString() { String actual = "insensitiv:afasdf\n" + ",Authorization=Basic 9876543210987654321&\n" @@ -388,8 +380,6 @@ private static Object[] test_largeData() throws IOException { + " \"contentEncoding\":\"BASE_64\"," + " \"documentContent\":\"w0KGgoAAAA-xxxx\"," + " \"content\":\"/9j/4AAQSk-xxxx"; - return new Object[]{"test_largeData", actual, expected}; } - -} +} \ No newline at end of file diff --git a/ejmask-spring/ejmask-spring-core/src/main/java/com/ebay/ejmask/spring/core/EJMaskSpringCoreContextConfiguration.java b/ejmask-spring/ejmask-spring-core/src/main/java/com/ebay/ejmask/spring/core/EJMaskSpringCoreContextConfiguration.java index 55ac751..60869fe 100644 --- a/ejmask-spring/ejmask-spring-core/src/main/java/com/ebay/ejmask/spring/core/EJMaskSpringCoreContextConfiguration.java +++ b/ejmask-spring/ejmask-spring-core/src/main/java/com/ebay/ejmask/spring/core/EJMaskSpringCoreContextConfiguration.java @@ -23,8 +23,8 @@ import com.ebay.ejmask.core.util.LoggerUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; +import org.springframework.beans.factory.InitializingBean; -import javax.annotation.PostConstruct; import java.util.List; /** @@ -33,8 +33,8 @@ * * @author prakv */ -@Configuration("ejMaskSpringCoreContextConfiguration") -public class EJMaskSpringCoreContextConfiguration { +@Configuration("com.ebay.ejmask.configuration") +public class EJMaskSpringCoreContextConfiguration implements InitializingBean { @Autowired(required = false) List filters; @@ -48,12 +48,12 @@ public class EJMaskSpringCoreContextConfiguration { /** * Execute post object construction */ - @PostConstruct - public void init() { + @Override + public void afterPropertiesSet() { LoggerUtil.info("ejmask-spring-core", "context-configuration", "initialization started"); - EJMaskInitializer.addFilters(this.filters); - EJMaskInitializer.addMaskingPatterns(this.maskingPatterns); - EJMaskInitializer.addContentProcessors(this.contentPreProcessors); + EJMaskInitializer.addFilters(filters); + EJMaskInitializer.addMaskingPatterns(maskingPatterns); + EJMaskInitializer.addContentProcessors(contentPreProcessors); LoggerUtil.info("ejmask-spring-core", "context-configuration", "initialization completed"); } -} +} \ No newline at end of file diff --git a/ejmask-spring/ejmask-spring-boot/pom.xml b/ejmask-spring/ejmask-spring-starter/pom.xml similarity index 79% rename from ejmask-spring/ejmask-spring-boot/pom.xml rename to ejmask-spring/ejmask-spring-starter/pom.xml index 459941d..61b8954 100644 --- a/ejmask-spring/ejmask-spring-boot/pom.xml +++ b/ejmask-spring/ejmask-spring-starter/pom.xml @@ -7,7 +7,7 @@ ${revision}${changelist} - ejmask-spring-boot + ejmask-spring-starter @@ -22,19 +22,9 @@ org.springframework.boot - spring-boot-autoconfigure + spring-boot-starter - - javax.inject - javax.inject - - - - junit - junit - test - org.springframework spring-test diff --git a/ejmask-spring/ejmask-spring-starter/src/it/java/com/ebay/ejmask/spring/boot/autoconfig/EJMaskAutoConfigIT.java b/ejmask-spring/ejmask-spring-starter/src/it/java/com/ebay/ejmask/spring/boot/autoconfig/EJMaskAutoConfigIT.java new file mode 100644 index 0000000..28f8b91 --- /dev/null +++ b/ejmask-spring/ejmask-spring-starter/src/it/java/com/ebay/ejmask/spring/boot/autoconfig/EJMaskAutoConfigIT.java @@ -0,0 +1,106 @@ +package com.ebay.ejmask.spring.boot.autoconfig; + +import com.ebay.ejmask.api.IContentProcessor; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + + +@SpringBootApplication +@ContextConfiguration +@ExtendWith(SpringExtension.class) +@SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = EJMaskAutoConfig.class) +class ConfigDefaultIT { + + @Autowired(required = false) + EJMaskAutoConfig config; + + @Autowired(required = false) + IContentProcessor contentPreProcessor; + + @Test + public void testConfig() { + Assertions.assertNotNull(this.config); + } + + @Test + public void testProcessor() { + Assertions.assertNull(this.contentPreProcessor); + } +} + +@SpringBootApplication +@ContextConfiguration +@ExtendWith(SpringExtension.class) +@SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = EJMaskAutoConfig.class) +@TestPropertySource(properties = { + "ejmask.autoconfig=enabled", + "ejmask.processor.content-slicer=enabled", + "ejmask.processor.content-slicer.priority=150", + "ejmask.processor.content-slicer.max-size=100000", + "ejmask.processor.content-slicer.new-size=40000" +}) +class ConfigEnabledIT { + + @Autowired(required = false) + EJMaskAutoConfig config; + + @Autowired(required = false) + IContentProcessor contentPreProcessor; + + @Test + public void testConfig() { + Assertions.assertNotNull(this.config); + } + + @Test + public void testProcessor() { + Assertions.assertNotNull(this.contentPreProcessor); + } + + @Test + public void testContentSlicerPriority() { + Assertions.assertEquals(150, this.config.contentSlicerPriority); + } + + @Test + public void testContentSlicerMaxStringLimit() { + Assertions.assertEquals(100000, this.config.contentSlicerMaxStringLimit); + } + + @Test + public void testContentSlicerNewSize() { + Assertions.assertEquals(40000, this.config.contentSlicerNewSize); + } +} + +@SpringBootApplication +@ContextConfiguration +@ExtendWith(SpringExtension.class) +@SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = EJMaskAutoConfig.class) +@TestPropertySource(properties = {"ejmask.autoconfig=disabled", "ejmask.ejmask.processor.content-slicer=disabled"}) +class ConfigDisabledIT { + + @Autowired(required = false) + EJMaskAutoConfig config; + + @Autowired(required = false) + IContentProcessor contentPreProcessor; + + @Test + public void testConfig() { + Assertions.assertNull(this.config); + } + + @Test + public void testProcessor() { + Assertions.assertNull(this.contentPreProcessor); + } +} diff --git a/ejmask-spring/ejmask-spring-boot/src/main/java/com/ebay/ejmask/spring/boot/autoconfig/EJMaskAutoConfig.java b/ejmask-spring/ejmask-spring-starter/src/main/java/com/ebay/ejmask/spring/boot/autoconfig/EJMaskAutoConfig.java similarity index 96% rename from ejmask-spring/ejmask-spring-boot/src/main/java/com/ebay/ejmask/spring/boot/autoconfig/EJMaskAutoConfig.java rename to ejmask-spring/ejmask-spring-starter/src/main/java/com/ebay/ejmask/spring/boot/autoconfig/EJMaskAutoConfig.java index 9b07028..2f9188b 100644 --- a/ejmask-spring/ejmask-spring-boot/src/main/java/com/ebay/ejmask/spring/boot/autoconfig/EJMaskAutoConfig.java +++ b/ejmask-spring/ejmask-spring-starter/src/main/java/com/ebay/ejmask/spring/boot/autoconfig/EJMaskAutoConfig.java @@ -24,18 +24,17 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; -import javax.inject.Named; - /** * Component scan configuration for ejmask auto configuration * * @author prakv */ @AutoConfigureOrder(105) -@Named("ejmask.autoconfig") +@Configuration("ejmask.autoconfig") @ComponentScan(basePackageClasses = EJMaskSpringCoreContextConfiguration.class) @ConditionalOnProperty(prefix = "ejmask.", name = "autoconfig", havingValue = "enabled", matchIfMissing = true) public class EJMaskAutoConfig { diff --git a/ejmask-spring/ejmask-spring-autoconfig/src/main/resources/META-INF/spring.factories b/ejmask-spring/ejmask-spring-starter/src/main/resources/META-INF/spring.factories similarity index 100% rename from ejmask-spring/ejmask-spring-autoconfig/src/main/resources/META-INF/spring.factories rename to ejmask-spring/ejmask-spring-starter/src/main/resources/META-INF/spring.factories diff --git a/ejmask-spring/pom.xml b/ejmask-spring/pom.xml index 580c4e5..89708ea 100644 --- a/ejmask-spring/pom.xml +++ b/ejmask-spring/pom.xml @@ -12,7 +12,18 @@ ejmask-spring-core - ejmask-spring-boot - ejmask-spring-autoconfig + ejmask-spring-starter + + + + + org.springframework.boot + spring-boot-dependencies + 2.7.18 + pom + import + + + diff --git a/pom.xml b/pom.xml index 26c9088..ad0cd14 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - + + 4.0.0 com.ebay.ejmask @@ -26,7 +27,7 @@ UTF-8 1.8 1.8 - 1.2.1 + 1.3.0 @@ -63,39 +64,14 @@ + - com.google.code.findbugs jsr305 3.0.2 - - javax.inject - javax.inject - 1 - - - org.springframework.boot - spring-boot-dependencies - 2.7.18 - pom - import - - - - org.junit - junit-bom - 5.11.3 - pom - - - org.mockito - mockito-bom - 5.14.2 - pom - org.apache.commons @@ -112,12 +88,27 @@ com.fasterxml.jackson.core jackson-databind - 2.13.4.2 + 2.13.5 test + + + org.junit.jupiter + junit-jupiter + 5.11.3 + test + + + org.mockito + mockito-inline + 4.11.0 + test + + + diff --git a/spotbugs-exclusions.xml b/spotbugs-exclusions.xml index 6ad7814..8c82f26 100644 --- a/spotbugs-exclusions.xml +++ b/spotbugs-exclusions.xml @@ -13,4 +13,22 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file