Skip to content

Commit

Permalink
feature: isCommonlyUsed password check not hardcoded #4018
Browse files Browse the repository at this point in the history
Signed-off-by: WillardHu <wei.hu@daocloud.io>
  • Loading branch information
WillardHu committed Jan 13, 2022
1 parent d15331b commit fcd0674
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Apollo 2.0.0
* [The release history of namespaces that are not properties will also show comments and release times](https://github.com/apolloconfig/apollo/pull/4198)
* [Add unit tests for Utils](https://github.com/apolloconfig/apollo/pull/4193)
* [Change Copy Right year to 2022](https://github.com/apolloconfig/apollo/pull/4202)
* [Make password check not hardcoded](https://github.com/apolloconfig/apollo/pull/4207)

------------------
All issues and pull requests are [here](https://github.com/ctripcorp/apollo/milestone/8?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -273,4 +275,12 @@ public String[] webHookUrls() {
public boolean supportSearchByItem() {
return getBooleanProperty("searchByItem.switch", true);
}

public List<String> listOFCodeFragment() {
String[] value = getArrayProperty("auth.userPasswordChecker.listOFCodeFragment", null);
if (value == null || value.length == 0) {
return Collections.emptyList();
}
return Arrays.asList(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.ctrip.framework.apollo.portal.util.checker;

import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import com.google.common.base.Strings;
import java.util.Arrays;
import java.util.List;
Expand All @@ -28,7 +29,7 @@ public class AuthUserPasswordChecker implements UserPasswordChecker {
private static final Pattern PWD_PATTERN = Pattern
.compile("^(?=.*[0-9].*)(?=.*[a-zA-Z].*).{8,20}$");

private static final List<String> LIST_OF_CODE_FRAGMENT = Arrays.asList(
private static final List<String> DEFAULT_LIST_OF_CODE_FRAGMENT = Arrays.asList(
"111", "222", "333", "444", "555", "666", "777", "888", "999", "000",
"001122", "112233", "223344", "334455", "445566", "556677", "667788", "778899", "889900",
"009988", "998877", "887766", "776655", "665544", "554433", "443322", "332211", "221100",
Expand All @@ -37,6 +38,12 @@ public class AuthUserPasswordChecker implements UserPasswordChecker {
"1q2w", "2w3e", "3e4r", "5t6y", "abcd", "qwer", "asdf", "zxcv"
);

private final PortalConfig portalConfig;

public AuthUserPasswordChecker(final PortalConfig portalConfig) {
this.portalConfig = portalConfig;
}

@Override
public CheckResult checkWeakPassword(String password) {
if (!PWD_PATTERN.matcher(password).matches()) {
Expand All @@ -58,7 +65,13 @@ private boolean isCommonlyUsed(String password) {
if (Strings.isNullOrEmpty(password)) {
return true;
}
for (String s : LIST_OF_CODE_FRAGMENT) {
List<String> listOfCodeFragment;
if (portalConfig != null && !portalConfig.listOFCodeFragment().isEmpty()) {
listOfCodeFragment = portalConfig.listOFCodeFragment();
} else {
listOfCodeFragment = DEFAULT_LIST_OF_CODE_FRAGMENT;
}
for (String s : listOfCodeFragment) {
if (password.toLowerCase().contains(s)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AuthUserPasswordCheckerTest {

@Before
public void setup() {
checker = new AuthUserPasswordChecker();
checker = new AuthUserPasswordChecker(null);
}

@Test
Expand Down

0 comments on commit fcd0674

Please sign in to comment.