generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RDCC-5489 - Staff : configure domain as list (#579)
* RDCC-5489 - Staff : configure domain as list * RDCC-5489 - Staff : configure domain as list - functional test cases * RDCC-5489 - Staff : configure domain as list - suppress cve fix * RDCC-5489 - Staff : configure domain as list - build fixes * RDCC-5489 - Staff : configure domain as list - sonar build fixes * RDCC-5489 - Staff : configure domain as list - sonar build fixes * RDCC-5489 - Staff : configure domain as list - sonar build fixes * RDCC-5489 - Staff : configure domain as list - sonar build fixes * RDCC-5489 - Staff : configure domain as list - sonar build fixes * RDCC-5489 - Staff : configure domain as list - flux changes * RDCC-5489 - Staff : configure domain as list - functional test * RDCC-5489 - Staff : configure domain as list - removed unwanted functional test and logs * RDCC-5489 - Staff : configure domain as list - removed unwanted functional test * RDCC-5489 - Staff : configure domain as list - build issues and test cases * RDCC-5489 - Staff : configure domain as list -parameterized test cases solved
- Loading branch information
1 parent
4e5aed6
commit d5f828f
Showing
14 changed files
with
244 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/uk/gov/hmcts/reform/cwrdapi/config/EmailDomainPropertyInitiator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package uk.gov.hmcts.reform.cwrdapi.config; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.Locale; | ||
import javax.annotation.PostConstruct; | ||
|
||
@Slf4j | ||
@NoArgsConstructor | ||
@Setter | ||
@Getter | ||
@Configuration | ||
public class EmailDomainPropertyInitiator { | ||
public static String emailDomains; | ||
@Value("${email.domainList}") | ||
private String tempEmailDomains; | ||
|
||
private static void setStaticEmailList(String emailDomains) { | ||
EmailDomainPropertyInitiator.emailDomains = emailDomains.toLowerCase(Locale.ENGLISH); | ||
} | ||
|
||
@Bean | ||
@PostConstruct | ||
public void getPropertySupportBean() { | ||
if (ObjectUtils.isNotEmpty(this.tempEmailDomains)) { | ||
setStaticEmailList(this.tempEmailDomains.toLowerCase()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/uk/gov/hmcts/reform/cwrdapi/util/EmailValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package uk.gov.hmcts.reform.cwrdapi.util; | ||
|
||
import lombok.NoArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
import uk.gov.hmcts.reform.cwrdapi.config.EmailDomainPropertyInitiator; | ||
|
||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
|
||
@Slf4j | ||
@NoArgsConstructor | ||
/* | ||
EmailValidator IS EMAIL VALIDATION. THIS ALSO ALLOWED ONLY DOMAINS MENTIONED IN APPLICATION.YAML FILE | ||
@copyrights : hmcts | ||
*/ | ||
public class EmailValidator implements ConstraintValidator<ValidateEmail, String> { | ||
|
||
private String emailDomainList; | ||
|
||
@Override | ||
public void initialize(ValidateEmail validateEmail) { | ||
this.emailDomainList = EmailDomainPropertyInitiator.emailDomains; | ||
} | ||
|
||
@Override | ||
public boolean isValid(String emailAddress, ConstraintValidatorContext constraintValidatorContext) { | ||
if (ObjectUtils.isEmpty(emailAddress) || ObjectUtils.isEmpty(this.emailDomainList)) { | ||
return false; | ||
} | ||
return this.emailPatternMatches(emailAddress.toLowerCase()); | ||
} | ||
|
||
private boolean emailPatternMatches(String emailAddress) { | ||
String emailDomainName = this.getDomainName(emailAddress); | ||
if (ObjectUtils.isNotEmpty(emailDomainName) && this.isDomainValid(emailDomainName)) { | ||
String regexPattern = CaseWorkerConstants.USER_NAME_PATTERN + "@" | ||
+ emailDomainName; | ||
return Pattern.compile(regexPattern, Pattern.CASE_INSENSITIVE) | ||
.matcher(emailAddress) | ||
.matches(); | ||
} | ||
return false; | ||
} | ||
|
||
private boolean isDomainValid(String emailDomainName) { | ||
List<String> domainList = List.of(this.emailDomainList.split(",")); | ||
return domainList.contains(emailDomainName); | ||
} | ||
|
||
private String getDomainName(String emailAddress) { | ||
String[] split = emailAddress.split("@"); | ||
final Integer two = 2; | ||
if (ObjectUtils.isNotEmpty(split) && split.length == two) { | ||
return split[1]; | ||
} | ||
return null; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/uk/gov/hmcts/reform/cwrdapi/util/ValidateEmail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package uk.gov.hmcts.reform.cwrdapi.util; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
|
||
import static java.lang.annotation.ElementType.ANNOTATION_TYPE; | ||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE_USE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
@Target({FIELD, PARAMETER, ANNOTATION_TYPE, TYPE_USE, METHOD}) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@Constraint(validatedBy = EmailValidator.class) | ||
public @interface ValidateEmail { | ||
String message() default ""; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.