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

[MOSIP-29662] changed protocol logic in datashare (#181) #183

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -19,5 +19,7 @@ public class DataShareDto {

private String typeOfShare;

private String protocol;

private String source;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package io.mosip.datashare.dto;

import java.time.LocalDateTime;
import java.util.List;


import lombok.Data;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,41 +140,41 @@ public DataShare createDataShare(String policyId, String subscriberId, Multipart
PolicyResponseDto policyDetailResponse = policyUtil.getPolicyDetail(policyId, subscriberId);


DataShareDto dataSharePolicies = policyDetailResponse.getPolicies().getDataSharePolicies();
DataShareDto dataSharePolicy = policyDetailResponse.getPolicies().getDataSharePolicies();
byte[] encryptedData = null;
if (PARTNERBASED.equalsIgnoreCase(dataSharePolicies.getEncryptionType())) {
if (PARTNERBASED.equalsIgnoreCase(dataSharePolicy.getEncryptionType())) {
LOGGER.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.POLICYID.toString(),
policyId, subscriberId + "encryptionNeeded" + dataSharePolicies.getEncryptionType());
policyId, subscriberId + "encryptionNeeded" + dataSharePolicy.getEncryptionType());
encryptedData = encryptionUtil.encryptData(fileData, subscriberId);

} else if (NONE.equalsIgnoreCase(dataSharePolicies.getEncryptionType())) {
} else if (NONE.equalsIgnoreCase(dataSharePolicy.getEncryptionType())) {

encryptedData = fileData;
LOGGER.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.POLICYID.toString(),
policyId, subscriberId + "Without encryption" + dataSharePolicies.getEncryptionType());
policyId, subscriberId + "Without encryption" + dataSharePolicy.getEncryptionType());

}

String createShareTime = DateUtils
.getUTCCurrentDateTimeString(env.getProperty(DATETIME_PATTERN));
String expiryTime = DateUtils
.toISOString(DateUtils.addMinutes(DateUtils.parseUTCToDate(createShareTime),
Integer.parseInt(dataSharePolicies.getValidForInMinutes())));
Integer.parseInt(dataSharePolicy.getValidForInMinutes())));

String jwtSignature = digitalSignatureUtil.jwtSign(fileData, file.getName(), subscriberId,
createShareTime, expiryTime);
Map<String, Object> aclMap = prepareMetaData(subscriberId, policyId, policyDetailResponse,
jwtSignature);
randomShareKey = storefile(aclMap, new ByteArrayInputStream(encryptedData), policyId, subscriberId);
String dataShareUrl = constructURL(randomShareKey, dataSharePolicies, policyId,
String dataShareUrl = constructURL(randomShareKey, dataSharePolicy, policyId,
subscriberId);


dataShare.setUrl(dataShareUrl);
dataShare.setPolicyId(policyId);
dataShare.setSubscriberId(subscriberId);
dataShare.setValidForInMinutes(Integer.parseInt(dataSharePolicies.getValidForInMinutes()));
dataShare.setTransactionsAllowed(Integer.parseInt(dataSharePolicies.getTransactionsAllowed()));
dataShare.setValidForInMinutes(Integer.parseInt(dataSharePolicy.getValidForInMinutes()));
dataShare.setTransactionsAllowed(Integer.parseInt(dataSharePolicy.getTransactionsAllowed()));
LOGGER.info(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.POLICYID.toString(), policyId,
"Datashare" + dataShare.toString());
LOGGER.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.POLICYID.toString(), policyId,
Expand Down Expand Up @@ -203,8 +203,8 @@ public DataShare createDataShare(String policyId, String subscriberId, Multipart
* @param subscriberId the subscriber id
* @return the string
*/
private String constructURL(String randomShareKey, DataShareDto dataSharePolicies, String policyId, String subscriberId) {
String protocol = (httpProtocol != null && !httpProtocol.isEmpty()) ? HTTP_PROTOCOL : HTTPS_PROTOCOL;
private String constructURL(String randomShareKey, DataShareDto dataSharePolicy, String policyId, String subscriberId) {
String protocol = (dataSharePolicy.getProtocol() != null) ? dataSharePolicy.getProtocol() :HTTP_PROTOCOL ;
String url = null;
if (isShortUrl) {
int length = DEFAULT_KEY_LENGTH;
Expand All @@ -214,19 +214,19 @@ private String constructURL(String randomShareKey, DataShareDto dataSharePolicie

String shortRandomShareKey = generateShortRandomShareKey(length);
cacheUtil.getShortUrlData(shortRandomShareKey, policyId, subscriberId, randomShareKey);
url = dataSharePolicies.getShareDomainUrlRead() != null ?
dataSharePolicies.getShareDomainUrlRead() +
url = dataSharePolicy.getShareDomainUrlRead() != null ?
dataSharePolicy.getShareDomainUrlRead() +
servletPath + DATASHARE + FORWARD_SLASH + shortRandomShareKey
:
protocol + dataSharePolicies.getShareDomain() +
protocol + dataSharePolicy.getShareDomain() +
servletPath + DATASHARE + FORWARD_SLASH + shortRandomShareKey;

} else {
url = dataSharePolicies.getShareDomainUrlRead() != null ?
dataSharePolicies.getShareDomainUrlRead() +
url = dataSharePolicy.getShareDomainUrlRead() != null ?
dataSharePolicy.getShareDomainUrlRead() +
servletPath + FORWARD_SLASH + GET + FORWARD_SLASH
+ policyId + FORWARD_SLASH + subscriberId + FORWARD_SLASH + randomShareKey
: protocol + dataSharePolicies.getShareDomain() + servletPath + FORWARD_SLASH + GET + FORWARD_SLASH
: protocol + dataSharePolicy.getShareDomain() + servletPath + FORWARD_SLASH + GET + FORWARD_SLASH
+ policyId + FORWARD_SLASH + subscriberId + FORWARD_SLASH + randomShareKey;
}
url = url.replaceAll("[\\[\\]]", "");
Expand Down