Skip to content

Commit 39ba75b

Browse files
authored
[ES-2158] Fixed bugs reported in sonar (#81) (#83)
* [ES-2158] Fixed bugs reported in sonar * [ES-2158] Update rwview comments * [ES-2158] Update rwview comments * [ES-2158] Update rwview comments * [ES-2158] Update rwview comments --------- Signed-off-by: pvsaidurga <saidurgacsea@gmail.com>
1 parent 2d6f369 commit 39ba75b

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

sunbird-rc-plugin/src/main/java/io/mosip/esignet/plugin/sunbirdrc/service/SunbirdRCAuthenticationService.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,14 @@ public KycAuthResult doKycAuth(@NotBlank String relyingPartyId, @NotBlank String
121121
log.info("Started to build kyc-auth request with transactionId : {} && clientId : {}",
122122
kycAuthDto.getTransactionId(), clientId);
123123
try {
124-
for (AuthChallenge authChallenge : kycAuthDto.getChallengeList()) {
125-
if(Objects.equals(authChallenge.getAuthFactorType(),"KBI")){
126-
return validateKnowledgeBasedAuth(kycAuthDto.getIndividualId(),authChallenge);
127-
}
128-
throw new KycAuthException("invalid_challenge_format");
124+
Optional<AuthChallenge> optionalAuthChallenge = kycAuthDto.getChallengeList().stream()
125+
.filter(authChallenge -> Objects.equals(authChallenge.getAuthFactorType(), "KBI"))
126+
.findFirst();
127+
if (optionalAuthChallenge.isPresent()) {
128+
return validateKnowledgeBasedAuth(kycAuthDto.getIndividualId(), optionalAuthChallenge.get());
129+
}
130+
else{
131+
throw new KycAuthException("invalid_challenge_type");
129132
}
130133
} catch (KycAuthException e) {
131134
throw e;
@@ -268,7 +271,7 @@ private KycAuthResult validateKnowledgeBasedAuth(String individualId, AuthChalle
268271
new ParameterizedTypeReference<List<Map<String,Object>>>() {});
269272
if (responseEntity.getStatusCode().is2xxSuccessful() && responseEntity.getBody() != null) {
270273
List<Map<String,Object>> responseList = responseEntity.getBody();
271-
if(responseList.size()==1){
274+
if(responseList != null && responseList.size()==1){
272275
//TODO This need to be removed since it can contain PII
273276
log.debug("getting response {}", responseEntity);
274277
kycAuthResult.setKycToken((String)responseList.get(0).get(entityIdField));

sunbird-rc-plugin/src/test/java/io/mosip/esignet/plugin/sunbirdrc/service/SunbirdRCAuthenticaionServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public void doKycAuthWithInValidChallengeType_thenFail() {
242242
sunbirdRCAuthenticationService.doKycAuth(relyingPartyId, clientId, kycAuthDto);
243243
Assert.fail();
244244
}catch (KycAuthException e){
245-
Assert.assertEquals(e.getErrorCode(),"invalid_challenge_format");
245+
Assert.assertEquals(e.getErrorCode(),"invalid_challenge_type");
246246
}
247247
}
248248

0 commit comments

Comments
 (0)