Skip to content

Commit

Permalink
Improve assertion for ensuring that all allowed domains are ascii-pri…
Browse files Browse the repository at this point in the history
…ntable
  • Loading branch information
arteymix committed Dec 12, 2023
1 parent ac73a88 commit 61681c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* @author poirigui
*/
public class RecaptchaValidator implements Validator {

private final RestTemplate restTemplate;
private final String secret;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ubc.pavlab.rdp.validation;

import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;

import java.util.Collection;
import java.util.Collections;
Expand All @@ -19,9 +20,8 @@ public class SetBasedAllowedDomainStrategy implements AllowedDomainStrategy {

public SetBasedAllowedDomainStrategy( Collection<String> allowedDomains ) {
// ascii-only domains, case-insensitive
if ( allowedDomains.stream().anyMatch( d -> !StringUtils.isAsciiPrintable( d ) ) ) {
throw new IllegalArgumentException( "Allowed domains must only contain ASCII-printable characters." );
}
Assert.isTrue( allowedDomains.stream().allMatch( StringUtils::isAsciiPrintable ),
"Allowed domains must only contain ASCII-printable characters." );
this.allowedDomains = new TreeSet<>( String.CASE_INSENSITIVE_ORDER );
this.allowedDomains.addAll( allowedDomains );
}
Expand Down

0 comments on commit 61681c6

Please sign in to comment.