DWN-39926 : use patterns to avoid multiple compilation

pull/1601/head
Harry Smith 2023-01-23 09:00:19 +00:00
parent 9325917ce2
commit 42b6aa57bd
2 changed files with 6 additions and 3 deletions

View File

@ -21,6 +21,7 @@
package org.mitre.oauth2.web; package org.mitre.oauth2.web;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern;
import org.mitre.oauth2.model.SystemScope; import org.mitre.oauth2.model.SystemScope;
import org.mitre.oauth2.service.SystemScopeService; import org.mitre.oauth2.service.SystemScopeService;
@ -57,7 +58,7 @@ public class ScopeAPI {
public static final String URL = RootController.API_URL + "/scopes"; public static final String URL = RootController.API_URL + "/scopes";
private static final String characterMatcher = "[a-zA-Z]+"; private static final String characterMatcher = "[a-zA-Z]+";
private static final Pattern pattern = Pattern.compile(characterMatcher);
@Autowired @Autowired
private SystemScopeService scopeService; private SystemScopeService scopeService;
@ -183,7 +184,7 @@ public class ScopeAPI {
} }
private void validateScope(SystemScope scope) throws ScopeException { private void validateScope(SystemScope scope) throws ScopeException {
if (!scope.getValue().matches(characterMatcher)) { if (!pattern.matcher(scope.getValue()).matches()) {
throw new ScopeException(scope.getValue()); throw new ScopeException(scope.getValue());
} }
} }

View File

@ -23,6 +23,7 @@ package org.mitre.openid.connect.web;
import java.security.Principal; import java.security.Principal;
import java.util.Collection; import java.util.Collection;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern;
import org.mitre.openid.connect.exception.ScopeException; import org.mitre.openid.connect.exception.ScopeException;
import org.mitre.openid.connect.model.WhitelistedSite; import org.mitre.openid.connect.model.WhitelistedSite;
@ -59,6 +60,7 @@ public class WhitelistAPI {
public static final String URL = RootController.API_URL + "/whitelist"; public static final String URL = RootController.API_URL + "/whitelist";
private static final String characterMatcher = "[a-zA-Z]+"; private static final String characterMatcher = "[a-zA-Z]+";
private static final Pattern pattern = Pattern.compile(characterMatcher);
@Autowired @Autowired
private WhitelistedSiteService whitelistService; private WhitelistedSiteService whitelistService;
@ -182,7 +184,7 @@ public class WhitelistAPI {
private void validateWhitelistScopes(Set<String> scopes) throws ScopeException { private void validateWhitelistScopes(Set<String> scopes) throws ScopeException {
for (String s : scopes) { for (String s : scopes) {
if (!s.matches(characterMatcher)) { if (!pattern.matcher(s).matches()) {
throw new ScopeException(s); throw new ScopeException(s);
} }
} }