Fixes failure due to extra spaces in authorization url in OAuth2 datasource (#4818)
* Trimmed authorization url * Using validation instead * Update app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/helpers/DatasourceValidator.java Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com> * Update app/server/appsmith-plugins/restApiPlugin/src/main/java/com/external/helpers/DatasourceValidator.java Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com> Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
This commit is contained in:
parent
ae28731947
commit
f9a4b0e0dc
|
|
@ -6,9 +6,17 @@ import org.springframework.util.StringUtils;
|
|||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class DatasourceValidator {
|
||||
|
||||
private static final String URL_REGEX =
|
||||
"^https?://" +
|
||||
"(%[0-9A-Fa-f]{2}|[-()_.!~*';/?:@&=+$,A-Za-z0-9])+$";
|
||||
|
||||
private static final Pattern URL_PATTERN = Pattern.compile(URL_REGEX);
|
||||
|
||||
public static Set<String> validateAuthentication(AuthenticationDTO authenticationDTO) {
|
||||
|
||||
if (authenticationDTO instanceof OAuth2) {
|
||||
|
|
@ -44,8 +52,15 @@ public class DatasourceValidator {
|
|||
|
||||
if (StringUtils.isEmpty(authenticationDTO.getAuthorizationUrl())) {
|
||||
invalids.add("Missing Authorization URL");
|
||||
} else if (!isValidUrl(authenticationDTO.getAuthorizationUrl())) {
|
||||
invalids.add("Invalid Authorization URL");
|
||||
}
|
||||
|
||||
return invalids;
|
||||
}
|
||||
|
||||
private static boolean isValidUrl(String url) {
|
||||
Matcher matcher = URL_PATTERN.matcher(url);
|
||||
return matcher.matches();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user