Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES-541 #577

Merged
merged 8 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.mosip.esignet.core.dto;

import io.mosip.esignet.core.constants.ErrorConstants;
import io.mosip.esignet.core.validator.ClientNameLang;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -22,7 +23,7 @@
public class ClientDetailCreateRequestV2 extends ClientDetailCreateRequest {

@NotEmpty(message = ErrorConstants.INVALID_CLIENT_NAME)
private Map<@Size(message= ErrorConstants.INVALID_CLIENT_NAME_MAP_KEY, min=3, max=3) String,
private Map<@Size(message= ErrorConstants.INVALID_CLIENT_NAME_MAP_KEY, min=3, max=3) @ClientNameLang String,
ase-101 marked this conversation as resolved.
Show resolved Hide resolved
@NotBlank(message = ErrorConstants.INVALID_CLIENT_NAME_MAP_VALUE) String> clientNameLangMap;

public ClientDetailCreateRequestV2(String clientId, String clientName, Map<String, Object> publicKey, String relyingPartyId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.mosip.esignet.core.validator;

import io.mosip.esignet.core.constants.ErrorConstants;

import javax.validation.Constraint;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.TYPE_USE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Target({FIELD, TYPE_USE})
@Retention(RUNTIME)
@Constraint(validatedBy = ClientNameLangValidator.class)
@Documented
public @interface ClientNameLang {
String message() default ErrorConstants.INVALID_CLIENT_NAME_MAP_KEY;

Class<?>[] groups() default {};

Class<?>[] payload() default {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.mosip.esignet.core.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Locale;
import java.util.Set;

public class ClientNameLangValidator implements ConstraintValidator<ClientNameLang, String> {

@Override
public void initialize(ClientNameLang constraintAnnotation) {
}

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
Locale[] availableLocales = Locale.getAvailableLocales();
ase-101 marked this conversation as resolved.
Show resolved Hide resolved
boolean isValid = false;

for (Locale locale : availableLocales) {
if (value.equals(locale.getISO3Language())) {
isValid = true;
break;
}
}
return isValid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ public ClientMgmtControllerParameterizedTest(String title, ClientDetailCreateReq
Arrays.asList("mosip:idp:acr:static-code"), "https://logo-url/png",
Arrays.asList("https://logo-url/png"), Arrays.asList("authorization_code"),
Arrays.asList("private_key_jwt"),new HashMap<String,String>(){{put("eng", "clientname");}}), null, null, ErrorConstants.INVALID_CLIENT_NAME },
{ "With Invalid Language_code", new ClientDetailCreateRequestV2("client-id", "clientname", jwk,
"rp-id", Arrays.asList("given_name"),
Arrays.asList("mosip:idp:acr:static-code"), "https://logo-url/png",
Arrays.asList("https://logo-url/png"), Arrays.asList("authorization_code"),
Arrays.asList("private_key_jwt"),new HashMap<String,String>(){{put("abc", "clientname");}}), null, null, ErrorConstants.INVALID_CLIENT_NAME_MAP_KEY },
{ "With Invalid public key", new ClientDetailCreateRequestV2("client-id", "Test client", new HashMap<>(),
"rp-id", Arrays.asList("given_name"),
Arrays.asList("mosip:idp:acr:static-code"), "https://logo-url/png",
Expand Down