-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ES-313] Fixed blank attribute issue & language not available issue.
- Loading branch information
1 parent
1d42341
commit 83d24c1
Showing
6 changed files
with
131 additions
and
74 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
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
90 changes: 90 additions & 0 deletions
90
...ce/src/main/java/io/mosip/authentication/service/kyc/util/ExchangeDataAttributesUtil.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,90 @@ | ||
package io.mosip.authentication.service.kyc.util; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
import io.mosip.authentication.common.service.entity.OIDCClientData; | ||
import io.mosip.authentication.common.service.helper.IdInfoHelper; | ||
import io.mosip.authentication.common.service.repository.OIDCClientDataRepository; | ||
import io.mosip.authentication.common.service.util.EnvUtil; | ||
import io.mosip.authentication.common.service.util.IdaRequestResponsConsumerUtil; | ||
import io.mosip.authentication.core.constant.IdAuthCommonConstants; | ||
import io.mosip.authentication.core.exception.IdAuthenticationBusinessException; | ||
import io.mosip.authentication.core.indauth.dto.BaseRequestDTO; | ||
import io.mosip.authentication.core.logger.IdaLogger; | ||
import io.mosip.kernel.core.logger.spi.Logger; | ||
|
||
/** | ||
* Utility class to filter the consented attribute and policy allowed attributes. | ||
* | ||
* @author Mahammed Taheer | ||
*/ | ||
|
||
@Component | ||
public class ExchangeDataAttributesUtil { | ||
|
||
/** The mosip logger. */ | ||
private static Logger mosipLogger = IdaLogger.getLogger(ExchangeDataAttributesUtil.class); | ||
|
||
@Value("${ida.idp.consented.individual_id.attribute.name:individual_id}") | ||
private String consentedIndividualIdAttributeName; | ||
|
||
@Autowired | ||
private IdInfoHelper idInfoHelper; | ||
|
||
@Autowired | ||
private OIDCClientDataRepository oidcClientDataRepo; | ||
|
||
public void mapConsentedAttributesToIdSchemaAttributes(List<String> consentAttributes, Set<String> filterAttributes, | ||
List<String> policyAllowedKycAttribs) throws IdAuthenticationBusinessException { | ||
|
||
if(consentAttributes != null && !consentAttributes.isEmpty()) { | ||
for (String attrib : consentAttributes) { | ||
Collection<? extends String> idSchemaAttribute = idInfoHelper.getIdentityAttributesForIdName(attrib); | ||
filterAttributes.addAll(idSchemaAttribute); | ||
} | ||
// removing individual id from consent if the claim is not allowed in policy. | ||
if (!policyAllowedKycAttribs.contains(consentedIndividualIdAttributeName)) { | ||
consentAttributes.remove(consentedIndividualIdAttributeName); | ||
} | ||
} | ||
} | ||
|
||
public Set<String> filterByPolicyAllowedAttributes(Set<String> filterAttributes, List<String> policyAllowedKycAttribs) { | ||
return policyAllowedKycAttribs.stream() | ||
.filter(attribute -> filterAttributes.contains(attribute)) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
public String getKycExchangeResponseTime(BaseRequestDTO authRequestDTO) { | ||
String dateTimePattern = EnvUtil.getDateTimePattern(); | ||
return IdaRequestResponsConsumerUtil.getResponseTime(authRequestDTO.getRequestTime(), dateTimePattern); | ||
} | ||
|
||
public List<String> filterAllowedUserClaims(String oidcClientId, List<String> consentAttributes) { | ||
mosipLogger.info(IdAuthCommonConstants.IDA, this.getClass().getSimpleName(), "filterAllowedUserClaims", | ||
"Checking for OIDC client allowed userclaims"); | ||
Optional<OIDCClientData> oidcClientData = oidcClientDataRepo.findByClientId(oidcClientId); | ||
|
||
List<String> oidcClientAllowedUserClaims = List.of(oidcClientData.get().getUserClaims()) | ||
.stream() | ||
.map(String::toLowerCase) | ||
.collect(Collectors.toList()); | ||
if (consentAttributes.isEmpty()) { | ||
return oidcClientAllowedUserClaims; | ||
} | ||
|
||
return consentAttributes.stream() | ||
.filter(claim -> oidcClientAllowedUserClaims.contains(claim.toLowerCase())) | ||
.collect(Collectors.toList()); | ||
|
||
} | ||
|
||
} |