Skip to content

regex support for email whitelist #2920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/main/java/fr/xephi/authme/service/ValidationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Locale;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import static fr.xephi.authme.util.StringUtils.isInsideString;

Expand Down Expand Up @@ -202,13 +203,21 @@ private boolean validateWhitelistAndBlacklist(String value, Property<List<String

private static boolean containsIgnoreCase(Collection<String> coll, String needle) {
for (String entry : coll) {
if (entry.equalsIgnoreCase(needle)) {
if (entry.startsWith("r:")) {
String pattern = entry.substring(2);
try {
if (Pattern.compile(pattern, Pattern.CASE_INSENSITIVE).matcher(needle).matches()) {
return true;
}
} catch (PatternSyntaxException e) {
//possible way to log error?
}
} else if (entry.equalsIgnoreCase(needle)) {
return true;
}
}
return false;
}

/**
* Loads the configured name restrictions into a Multimap by player name (all-lowercase).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public final class EmailSettings implements SettingsHolder {
public static final Property<List<String>> DOMAIN_BLACKLIST =
newListProperty("Email.emailBlacklisted", "10minutemail.com");

@Comment("Whitelist ONLY these domains for emails")
@Comment("Whitelist ONLY these domains for emails. Use 'r:' prefix for regex")
public static final Property<List<String>> DOMAIN_WHITELIST =
newListProperty("Email.emailWhitelisted");

Expand Down