-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(deployment): add datetime output for ob-odc-web.std.log (#1420)
* feat(deployment): add datetime output for ob-odc-web.std.log * refine startup log output * refine startup log output
- Loading branch information
Showing
5 changed files
with
141 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
server/odc-common/src/main/java/com/oceanbase/odc/common/security/SensitiveDataUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2023 OceanBase. | ||
* | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
package com.oceanbase.odc.common.security; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import com.oceanbase.odc.common.util.StringUtils; | ||
|
||
public class SensitiveDataUtils { | ||
|
||
private static final Pattern SENSITIVE_PATTERN = | ||
Pattern.compile("(secret|key|password|pswd|email|-p)([=|:|\\\"\\s]*)([^&,\\n\\t\\\"]+)", | ||
Pattern.CASE_INSENSITIVE); | ||
private static final String MASKED_VALUE = "***"; | ||
|
||
public static String mask(String message) { | ||
if (message == null || message.isEmpty()) { | ||
return message; | ||
} | ||
try { | ||
Matcher matcher = SENSITIVE_PATTERN.matcher(message); | ||
if (matcher.find()) { | ||
StringBuffer sb = new StringBuffer(); | ||
do { | ||
matcher.appendReplacement(sb, matcher.group(1) + matcher.group(2) + MASKED_VALUE); | ||
} while (matcher.find()); | ||
matcher.appendTail(sb); | ||
return sb.toString(); | ||
} | ||
return message; | ||
} catch (Exception ex) { | ||
return "MESSAGE_MASK_FAILED, origin message start with " + StringUtils.substring(message, 0, 10); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...er/odc-common/src/test/java/com/oceanbase/odc/common/security/SensitiveDataUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2023 OceanBase. | ||
* | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
package com.oceanbase.odc.common.security; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameter; | ||
import org.junit.runners.Parameterized.Parameters; | ||
|
||
@RunWith(Parameterized.class) | ||
public class SensitiveDataUtilsTest { | ||
@Parameter(0) | ||
public String message; | ||
@Parameter(1) | ||
public String expectedMasked; | ||
|
||
@Parameters(name = "{index}: masked value for {0} expected {1}") | ||
public static Collection<Object[]> data() { | ||
return Arrays.asList(new Object[][] { | ||
{"nomask", "nomask"}, | ||
{"password=123456", "password=***"}, | ||
{"-p 123456", "-p ***"}, | ||
{"-p123456", "-p***"}, | ||
{"somepassword=123456", "somepassword=***"}, | ||
{"PASSWORD=123456", "PASSWORD=***"}, | ||
{"password = 123456", "password = ***"}, | ||
{"password=123456,secret=654321", "password=***,secret=***"}, | ||
{"\"password\"=\"123456\"", "\"password\"=\"***\""}, | ||
{"\"password\" : \"123456\"", "\"password\" : \"***\""}, | ||
{"hello:{\"password\"=\"123456\",\"secret\"=\"654321\"}", | ||
"hello:{\"password\"=\"***\",\"secret\"=\"***\"}"} | ||
}); | ||
} | ||
|
||
@Test | ||
public void mask() { | ||
String masked = SensitiveDataUtils.mask(message); | ||
Assert.assertEquals(expectedMasked, masked); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters