1010import java .util .ArrayList ;
1111import java .util .List ;
1212import java .util .Map ;
13- import java .util .regex .Pattern ;
1413
1514/**
1615 * Utility class for validating parameters.
1716 */
1817public final class ValidationUtil {
19- private static final Pattern TENANT_IDENTIFIER_CHAR_PATTERN = Pattern .compile ("^(?:[A-Z]|[0-9]|[a-z]|-|.)+$" );
20-
2118 public static void validate (String className , Map <String , Object > parameters , ClientLogger logger ) {
2219 List <String > missing = new ArrayList <>();
2320 for (Map .Entry <String , Object > entry : parameters .entrySet ()) {
@@ -46,11 +43,13 @@ public static void validateAuthHost(String authHost, ClientLogger logger) {
4643
4744 public static void validateTenantIdCharacterRange (String id , ClientLogger logger ) {
4845 if (id != null ) {
49- if (!TENANT_IDENTIFIER_CHAR_PATTERN .matcher (id ).matches ()) {
50- throw logger .logExceptionAsError (
51- new IllegalArgumentException (
52- "Invalid tenant id provided. You can locate your tenant id by following the instructions"
53- + " listed here: https://docs.microsoft.com/partner-center/find-ids-and-domain-names" ));
46+ for (int i = 0 ; i < id .length (); i ++) {
47+ if (!isValidTenantCharacter (id .charAt (i ))) {
48+ throw logger .logExceptionAsError (
49+ new IllegalArgumentException (
50+ "Invalid tenant id provided. You can locate your tenant id by following the instructions"
51+ + " listed here: https://docs.microsoft.com/partner-center/find-ids-and-domain-names" ));
52+ }
5453 }
5554 }
5655 }
@@ -64,4 +63,8 @@ public static void validateInteractiveBrowserRedirectUrlSetup(Integer port, Stri
6463 + " the redirect URL on the builder." ));
6564 }
6665 }
66+
67+ private static boolean isValidTenantCharacter (char c ) {
68+ return (c >= 'a' && c <= 'z' ) || (c >= 'A' && c <= 'Z' ) || (c >= '0' && c <= '9' ) || (c == '.' ) || (c == '-' );
69+ }
6770}
0 commit comments