add security

This commit is contained in:
Mohd-Arham
2025-11-26 18:01:36 +05:30
parent 985f6eecfd
commit 2991349f8b
19 changed files with 542 additions and 30 deletions
@@ -3,6 +3,7 @@ package com.billpaymentservice.bbps.serviceImpl;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,10 +32,12 @@ import com.billpaymentservice.bbps.entites.BharatConnectMaster;
import com.billpaymentservice.bbps.entites.ComplaintStatusOptionsMaster;
import com.billpaymentservice.bbps.entites.InboundTraceLog;
import com.billpaymentservice.bbps.entites.OutboundTraceLog;
import com.billpaymentservice.bbps.entites.TransactionMaster;
import com.billpaymentservice.bbps.exception.CustomException;
import com.billpaymentservice.bbps.repository.BharatConnectMasterRepository;
import com.billpaymentservice.bbps.repository.ComplainRepository;
import com.billpaymentservice.bbps.repository.ComplaintOptionsStatusMasterRepository;
import com.billpaymentservice.bbps.repository.TransactionMasterRepository;
import com.billpaymentservice.bbps.service.ComplainService;
import com.billpaymentservice.bbps.util.BBPSConstant;
import com.billpaymentservice.bbps.util.BillerMapperHelper;
@@ -61,6 +64,7 @@ public class ComplainServiceImpl implements ComplainService {
private final BillerMapperHelper mapperHelper;
private final ComplainRepository complainRepository;
private final ComplaintOptionsStatusMasterRepository complaintStatusMasterRepository;
private final TransactionMasterRepository transactionMasterRepository;
// moved to class-level
private final ObjectMapper objectMapper;
@@ -69,7 +73,8 @@ public class ComplainServiceImpl implements ComplainService {
public ComplainServiceImpl(RestClient restClient, HttpService httpService, Helper helper,
BharatConnectMasterRepository beneficiaryDetailsRepository, BillerMapperHelper mapperHelper,
ComplainRepository complainRepository,
ComplaintOptionsStatusMasterRepository complaintStatusMasterRepository) {
ComplaintOptionsStatusMasterRepository complaintStatusMasterRepository,
TransactionMasterRepository transactionMasterRepository) {
this.restClient = restClient;
this.httpService = httpService;
this.helper = helper;
@@ -77,7 +82,7 @@ public class ComplainServiceImpl implements ComplainService {
this.mapperHelper = mapperHelper;
this.complainRepository = complainRepository;
this.complaintStatusMasterRepository = complaintStatusMasterRepository;
this.transactionMasterRepository = transactionMasterRepository;
// initialize shared ObjectMapper once
this.objectMapper = new ObjectMapper();
this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
@@ -110,10 +115,20 @@ public class ComplainServiceImpl implements ComplainService {
BBPSConstant.HTTP_POST, null);
try {
Optional<TransactionMaster> dataById = transactionMasterRepository.findById(complainRequestDTO.getTxnId());
if (dataById == null || dataById.isEmpty()) {
LOGGER.warn("Master Data By Id is null");
throw new CustomException("Master Data is required", "FAILED", BBPSConstant.BADREQUEST, null);
}
TransactionMaster transData = dataById.get();
// Inject tenantId + agentId into request JSON
ObjectNode root = (ObjectNode) objectMapper.readTree(forwardJson);
root.put("tenantId", headersData.getTenantId());
root.put("agentId", headersData.getAgentId());
root.put("billerId", transData.getBillerId());
root.put("billerName", transData.getBillerName());
String finalJson = root.toString();
LOGGER.info("[{}] Final Request Sent to API | reqId={} | payload={}", apiName, requestId, finalJson);