Skip to content

Commit f0b1b25

Browse files
committed
[MOSIP-41056] Updated review comments
Signed-off-by: pvsaidurga <[email protected]>
1 parent 8f5ad21 commit f0b1b25

File tree

8 files changed

+130
-61
lines changed

8 files changed

+130
-61
lines changed

compass-identity-plugin/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ mosip.esignet.cache.expire-in-seconds={'clientdetails' : 86400, 'preauth': 180,
3232
'consented': 120, 'vcissuance': ${mosip.esignet.access-token-expire-seconds}, 'apiRateLimit' : 180, 'blocked': 300, 'kycauth':1800, ,'challengehash': 1800}
3333
3434
mosip.esignet.cache.names=clientdetails,preauth,authenticated,authcodegenerated,userinfo,linkcodegenerated,linked,linkedcode,\
35-
linkedauth,consented,vcissuance,apiRateLimit,blocked,kycauth,challenghash
35+
linkedauth,consented,vcissuance,apiRateLimit,blocked,kycauth,challeneghash
3636
3737
## Compass identity endpoint configuration, update the API credentials based on the environment
3838
39+
mosip.esignet.send-otp.endpoint=https://api-internal.dev2.mosip.net/v1/otpmanager/otp/generate
40+
mosip.esignet.send-notification.endpoint=https://api-internal.dev2.mosip.net/v1/notifier/sms/send
41+
mosip.esignet.get-auth.endpoint=https://iam.dev2.mosip.net/auth/realms/mosip/protocol/openid-connect/token
42+
mosip.compass.user-info.endpoint= https://compass-admin.dev2.mosip.net/v1/admin/user-info
43+
mosip.esignet.client.secret=client-secret
44+
mosip.compass.client.secret=compass-client-secret
3945
4046
4147
````

compass-identity-plugin/src/main/java/io/compass/esignet/plugin/dto/NotificationRequest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
import lombok.AllArgsConstructor;
44
import lombok.Data;
5+
import org.springframework.web.multipart.MultipartFile;
56

67
@Data
78
@AllArgsConstructor
89
public class NotificationRequest {
9-
private String number;
10-
private String message;
10+
private String[] mailTo;
11+
private String[] mailCc;
12+
private String[] mailSubject;
13+
private String[] mailContent;
14+
private MultipartFile[] attachments;
1115
}
1216

compass-identity-plugin/src/main/java/io/compass/esignet/plugin/dto/UserInfo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import lombok.Data;
44

55
import java.time.LocalDate;
6+
import java.util.UUID;
67

78
@Data
89
public class UserInfo {
10+
private UUID userInfoId;
911
private String birthCountry;
1012
private Long cardAccessNumber;
1113
private LocalDate dateOfBirth;
@@ -17,4 +19,5 @@ public class UserInfo {
1719
private String nationalUid;
1820
private String nationality;
1921
private String compassId;
22+
private LocalDate issuanceDate;
2023
}

compass-identity-plugin/src/main/java/io/compass/esignet/plugin/service/CacheService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class CacheService {
1111

1212
public static final String KYC_AUTH_CACHE="kycauth";
1313

14-
public static final String CHALLENGE_HASH="challengehash";
14+
public static final String CHALLENGE_HASH_CACHE="challengehash";
1515

1616
@Autowired
1717
CacheManager cacheManager;
@@ -25,11 +25,11 @@ public KycAuth getKycAuth(String kycToken) {
2525
}
2626

2727
public void setChallengeHash(String challengeHash, String transactionId) {
28-
cacheManager.getCache(CHALLENGE_HASH).put(transactionId, challengeHash);
28+
cacheManager.getCache(CHALLENGE_HASH_CACHE).put(transactionId, challengeHash);
2929
}
3030

3131
public String getChallengeHash(String transactionId) {
32-
Cache.ValueWrapper valueWrapper = cacheManager.getCache(CHALLENGE_HASH).get(transactionId);
32+
Cache.ValueWrapper valueWrapper = cacheManager.getCache(CHALLENGE_HASH_CACHE).get(transactionId);
3333
return valueWrapper != null ? (String) valueWrapper.get() : null;
3434
}
3535

compass-identity-plugin/src/main/java/io/compass/esignet/plugin/service/CompassAuthenticationService.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package io.compass.esignet.plugin.service;
77

8+
import io.compass.esignet.plugin.dto.UserInfo;
89
import io.compass.esignet.plugin.util.IdentityAPIClient;
910
import io.mosip.esignet.api.dto.*;
1011
import io.mosip.esignet.api.exception.KycAuthException;
@@ -112,10 +113,15 @@ public SendOtpResult sendOtp(String relyingPartyId, String clientId, SendOtpDto
112113
String challenge = identityAPIClient.generateOTPChallenge(transactionId);
113114
String challengeHash = IdentityProviderUtil.generateB64EncodedHash(IdentityProviderUtil.ALGO_SHA3_256, challenge);
114115
cacheService.setChallengeHash(challengeHash,transactionId);
115-
HashMap<String, String> hashMap = new LinkedHashMap<>();
116-
hashMap.put("{challenge}", challenge);
117-
identityAPIClient.sendSMSNotification(sendOtpDto.getIndividualId(), "en",
118-
SEND_OTP_SMS_NOTIFICATION_TEMPLATE_KEY, hashMap);
116+
UserInfo userInfo=identityAPIClient.getUserInfoByNationalUid(sendOtpDto.getIndividualId());
117+
String email=userInfo.getEmail();
118+
identityAPIClient.sendSMSNotification(
119+
new String[]{email},
120+
null,
121+
new String[]{"subject"},
122+
new String[]{"message"},
123+
null
124+
);
119125
SendOtpResult sendOtpResult=new SendOtpResult();
120126
sendOtpResult.setTransactionId(transactionId);
121127
return sendOtpResult;

compass-identity-plugin/src/main/java/io/compass/esignet/plugin/service/CompassKeyBindingWrapperService.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.compass.esignet.plugin.service;
77

88
import com.nimbusds.jose.jwk.RSAKey;
9+
import io.compass.esignet.plugin.dto.UserInfo;
910
import io.compass.esignet.plugin.util.IdentityAPIClient;
1011
import io.mosip.esignet.api.dto.AuthChallenge;
1112
import io.mosip.esignet.api.dto.KeyBindingResult;
@@ -81,8 +82,15 @@ public SendOtpResult sendBindingOtp(String individualId, List<String> otpChannel
8182
cacheService.setChallengeHash(challengeHash,transactionId);
8283
HashMap<String, String> hashMap = new LinkedHashMap<>();
8384
hashMap.put("{challenge}", challenge);
84-
identityAPIClient.sendSMSNotification(individualId, "eng",
85-
SEND_OTP_SMS_NOTIFICATION_TEMPLATE_KEY, hashMap);
85+
UserInfo userInfo=identityAPIClient.getUserInfoByNationalUid(individualId);
86+
String email=userInfo.getEmail();
87+
identityAPIClient.sendSMSNotification(
88+
new String[]{email},
89+
null,
90+
new String[]{"subject"},
91+
new String[]{"message"},
92+
null
93+
);
8694
SendOtpResult sendOtpResult=new SendOtpResult();
8795
sendOtpResult.setTransactionId(transactionId);
8896
return sendOtpResult;

compass-identity-plugin/src/main/java/io/compass/esignet/plugin/service/HelperService.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import org.springframework.beans.factory.annotation.Value;
2020
import org.springframework.stereotype.Component;
2121

22-
import java.lang.reflect.InvocationTargetException;
23-
import java.lang.reflect.Method;
2422
import java.nio.charset.StandardCharsets;
2523
import java.security.MessageDigest;
2624
import java.security.NoSuchAlgorithmException;
@@ -35,8 +33,6 @@ public class HelperService {
3533

3634
public static final String ALGO_SHA3_256 = "SHA3-256";
3735

38-
private final String FIELD_ID_KEY="id";
39-
4036
private static final Base64.Encoder urlSafeEncoder = Base64.getUrlEncoder().withoutPadding();
4137

4238
public static final String APPLICATION_ID = "OIDC_SERVICE";
@@ -138,6 +134,11 @@ public Map<String, Object> buildKycDataBasedOnPolicy(List<String> claims, UserIn
138134
Map<String, Object> kyc = new HashMap<>();
139135
for (String claim : claims) {
140136
switch (claim) {
137+
case "userInfoId":
138+
if (userInfo.getUserInfoId() != null) {
139+
kyc.put("userInfoId", userInfo.getFirstNamePrimary());
140+
}
141+
break;
141142
case "name":
142143
if (userInfo.getFirstNamePrimary() != null) {
143144
kyc.put("name", userInfo.getFirstNamePrimary());
@@ -193,6 +194,11 @@ public Map<String, Object> buildKycDataBasedOnPolicy(List<String> claims, UserIn
193194
kyc.put("compassId", userInfo.getCompassId());
194195
}
195196
break;
197+
case "issuanceDate":
198+
if (userInfo.getIssuanceDate() != null) {
199+
kyc.put("issuanceDate", userInfo.getCompassId());
200+
}
201+
break;
196202
}
197203
}
198204
return kyc;

compass-identity-plugin/src/main/java/io/compass/esignet/plugin/util/IdentityAPIClient.java

Lines changed: 81 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,19 @@
88
import io.mosip.esignet.core.util.IdentityProviderUtil;
99
import lombok.extern.slf4j.Slf4j;
1010
import org.springframework.beans.factory.annotation.Autowired;
11-
import org.springframework.beans.factory.annotation.Qualifier;
1211
import org.springframework.beans.factory.annotation.Value;
1312
import org.springframework.core.ParameterizedTypeReference;
14-
import org.springframework.core.env.Environment;
15-
import org.springframework.http.HttpEntity;
16-
import org.springframework.http.HttpMethod;
17-
import org.springframework.http.ResponseEntity;
18-
import org.springframework.scheduling.annotation.Async;
13+
import org.springframework.http.*;
1914
import org.springframework.stereotype.Component;
2015
import org.springframework.util.CollectionUtils;
16+
import org.springframework.util.LinkedMultiValueMap;
17+
import org.springframework.util.MultiValueMap;
2118
import org.springframework.util.StringUtils;
2219
import org.springframework.web.client.RestClientException;
2320
import org.springframework.web.client.RestTemplate;
21+
import org.springframework.web.multipart.MultipartFile;
22+
2423

25-
import java.util.Base64;
26-
import java.util.List;
2724
import java.util.Map;
2825

2926
@Component
@@ -37,35 +34,66 @@ public class IdentityAPIClient {
3734
private String userInfoUrl;
3835

3936
@Autowired
40-
@Qualifier("selfTokenRestTemplate")
41-
private RestTemplate selfTokenRestTemplate;
42-
43-
@Autowired
44-
private Environment environment;
37+
private RestTemplate restTemplate;
4538

4639
@Value("${mosip.esignet.send-notification.endpoint}")
4740
private String sendNotificationEndpoint;
4841

49-
@Value("{${mosip.esignet.default-language}")
50-
private String defaultLanguage;
42+
@Value("${mosip.esignet.client.secret}")
43+
private String clientSecret ;
44+
45+
@Value("${mosip.compass.client.secret}")
46+
private String compassClientSecret ;
5147

52-
@Value("#{${mosip.esignet.sms-notification-template.encoded-langcodes}}")
53-
private List<String> encodedLangCodes;
48+
@Value("${mosip.esignet.get-auth.endpoint}")
49+
private String getAuthTokenEndpoint;
5450

55-
@Value("${mosip.signup.identifier.prefix:}")
56-
private String identifierPrefix;
51+
public String getAuthToken(String client_id,String client_secret,String grant_type)
52+
{
53+
HttpHeaders headers = new HttpHeaders();
54+
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
55+
MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
56+
body.add("client_id", client_id);
57+
body.add("client_secret", client_secret);
58+
body.add("grant_type", grant_type);
59+
60+
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers);
61+
62+
try {
63+
ResponseEntity<Map> response = restTemplate.postForEntity(getAuthTokenEndpoint, requestEntity, Map.class);
64+
if (response.getStatusCode().is2xxSuccessful()) {
65+
Map<String, Object> responseBody = response.getBody();
66+
if (responseBody != null && responseBody.containsKey("access_token")) {
67+
return responseBody.get("access_token").toString();
68+
}
69+
}
70+
} catch (Exception e) {
71+
throw new EsignetException(e.getMessage());
72+
}
73+
throw new EsignetException("Error fetching auth token");
74+
}
5775

5876
public String generateOTPChallenge(String challengeTransactionId) throws SendOtpException {
5977
OtpRequest otpRequest = new OtpRequest();
6078
otpRequest.setKey(challengeTransactionId);
6179
RequestWrapper<OtpRequest> restRequestWrapper = new RequestWrapper<>();
6280
restRequestWrapper.setRequestTime(IdentityProviderUtil.getUTCDateTime());
6381
restRequestWrapper.setRequest(otpRequest);
82+
String token = getAuthToken("mosip-signup-client", clientSecret, "client_credentials");
83+
if (token == null || token.isEmpty()) {
84+
throw new SendOtpException("Token retrieval failed");
85+
}
86+
87+
HttpHeaders headers = new HttpHeaders();
88+
headers.setContentType(MediaType.APPLICATION_JSON);
89+
headers.set("Cookie", "Authorization="+token);
90+
91+
HttpEntity<RequestWrapper<OtpRequest>> entity = new HttpEntity<>(restRequestWrapper, headers);
6492

6593
try {
66-
ResponseWrapper<OtpResponse> responseWrapper = selfTokenRestTemplate
94+
ResponseWrapper<OtpResponse> responseWrapper = restTemplate
6795
.exchange(generateChallengeUrl, HttpMethod.POST,
68-
new HttpEntity<>(restRequestWrapper),
96+
entity,
6997
new ParameterizedTypeReference<ResponseWrapper<OtpResponse>>() {
7098
})
7199
.getBody();
@@ -86,48 +114,56 @@ public String generateOTPChallenge(String challengeTransactionId) throws SendOtp
86114
}
87115

88116

89-
public void sendSMSNotification
90-
(String number, String locale, String templateKey, Map<String, String> params) throws SendOtpException {
91-
92-
locale = locale != null ? locale : defaultLanguage;
117+
public void sendSMSNotification(String[] mailTo,
118+
String[] mailCc,
119+
String[] mailSubject,
120+
String[] mailContent,
121+
MultipartFile[] attachments) throws SendOtpException {
93122

94-
String message = encodedLangCodes.contains(locale)?
95-
new String(Base64.getDecoder().decode(environment.getProperty(templateKey + "." + locale))):
96-
environment.getProperty(templateKey + "." + locale);
97-
98-
if (params != null && message != null) {
99-
for (Map.Entry<String, String> entry : params.entrySet()) {
100-
message = message.replace(entry.getKey(), entry.getValue());
101-
}
102-
}
103-
104-
NotificationRequest notificationRequest = new NotificationRequest(number.substring(identifierPrefix.length()), message);
123+
NotificationRequest notificationRequest = new NotificationRequest(mailTo, mailCc, mailSubject, mailContent, attachments);
105124

106125
RequestWrapper<NotificationRequest> restRequestWrapper = new RequestWrapper<>();
107126
restRequestWrapper.setRequestTime(IdentityProviderUtil.getUTCDateTime());
108127
restRequestWrapper.setRequest(notificationRequest);
128+
String token = getAuthToken("mosip-signup-client", clientSecret, "client_credentials");
129+
if (token == null || token.isEmpty()) {
130+
throw new SendOtpException("Token retrieval failed");
131+
}
132+
133+
HttpHeaders headers = new HttpHeaders();
134+
headers.setContentType(MediaType.APPLICATION_JSON);
135+
headers.set("Cookie", "Authorization="+token);
136+
137+
HttpEntity<RequestWrapper<NotificationRequest>> entity = new HttpEntity<>(restRequestWrapper, headers);
109138

110139
try {
111-
ResponseWrapper<NotificationResponse> responseWrapper = selfTokenRestTemplate.exchange(sendNotificationEndpoint,
140+
ResponseWrapper<NotificationResponse> responseWrapper = restTemplate.exchange(sendNotificationEndpoint,
112141
HttpMethod.POST,
113-
new HttpEntity<>(restRequestWrapper),
142+
entity,
114143
new ParameterizedTypeReference<ResponseWrapper<NotificationResponse>>(){}).getBody();
115144
log.debug("Notification response -> {}", responseWrapper);
116145
} catch (RestClientException e){
117146
throw new SendOtpException("otp_notification_failed");
118147
}
119148
}
120149

121-
@Async
122-
public void sendSMSNotificationAsync
123-
(String number, String locale, String templateKey, Map<String, String> params) throws SendOtpException {
124-
sendSMSNotification(number, locale, templateKey, params);
125-
}
126-
127150
public UserInfo getUserInfoByNationalUid(String nationalUid) {
128151
try {
129-
ResponseEntity<UserInfo> responseEntity = selfTokenRestTemplate.getForEntity(
152+
String token = getAuthToken("compass-admin", compassClientSecret, "client_credentials");
153+
if (token == null || token.isEmpty()) {
154+
throw new SendOtpException("Token retrieval failed");
155+
}
156+
157+
HttpHeaders headers = new HttpHeaders();
158+
headers.setContentType(MediaType.APPLICATION_JSON);
159+
headers.set("Authorization","Bearer "+token);
160+
161+
HttpEntity<String> entity = new HttpEntity<>(headers);
162+
163+
ResponseEntity<UserInfo> responseEntity = restTemplate.exchange(
130164
userInfoUrl + "/{nationalUid}",
165+
HttpMethod.GET,
166+
entity,
131167
UserInfo.class,
132168
nationalUid
133169
);

0 commit comments

Comments
 (0)