add security
This commit is contained in:
@@ -2,28 +2,35 @@ package com.billpaymentservice.bbps.serviceImpl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.modelmapper.convention.MatchingStrategies;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.billpaymentservice.bbps.config.JwtUtil;
|
||||
import com.billpaymentservice.bbps.dto.CustomParamDTO;
|
||||
import com.billpaymentservice.bbps.dto.CustomerParamGroupsDTO;
|
||||
import com.billpaymentservice.bbps.dto.GeneralResp;
|
||||
import com.billpaymentservice.bbps.dto.MasterApiResponse;
|
||||
import com.billpaymentservice.bbps.dto.ResponseModel;
|
||||
import com.billpaymentservice.bbps.dto.UserDetailsDTO;
|
||||
import com.billpaymentservice.bbps.dto.request.BillerDetailRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.ContactMasterRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.CustomParamRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.DispositionRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.LoginRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.MasterCategoryRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.MasterRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.PlanRequest;
|
||||
import com.billpaymentservice.bbps.dto.response.AmountOptionsResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.AuthResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.BillerDataResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.BillerResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.ChannelsListResponse;
|
||||
@@ -42,6 +49,7 @@ import com.billpaymentservice.bbps.entites.DispositionDetails;
|
||||
import com.billpaymentservice.bbps.entites.InboundTraceLog;
|
||||
import com.billpaymentservice.bbps.entites.OutboundTraceLog;
|
||||
import com.billpaymentservice.bbps.entites.PlanResponses;
|
||||
import com.billpaymentservice.bbps.entites.UsersDetails;
|
||||
import com.billpaymentservice.bbps.exception.CustomException;
|
||||
import com.billpaymentservice.bbps.repository.BharatConnectMasterRepository;
|
||||
import com.billpaymentservice.bbps.repository.BillerDataRepository;
|
||||
@@ -50,6 +58,7 @@ import com.billpaymentservice.bbps.repository.DispositionRepository;
|
||||
import com.billpaymentservice.bbps.repository.InboundTraceLogRepository;
|
||||
import com.billpaymentservice.bbps.repository.MerchantRepository;
|
||||
import com.billpaymentservice.bbps.repository.OutboundTraceLogRepository;
|
||||
import com.billpaymentservice.bbps.repository.UsersDetailsRepository;
|
||||
import com.billpaymentservice.bbps.service.MasterDataService;
|
||||
import com.billpaymentservice.bbps.util.BBPSConstant;
|
||||
import com.billpaymentservice.bbps.util.BillerMapperHelper;
|
||||
@@ -80,6 +89,11 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
private final InboundTraceLogRepository inboundTraceLogRepository;
|
||||
private final OutboundTraceLogRepository outboundTraceLogRepository;
|
||||
private final CustomParamRepository customParamReposiotory;
|
||||
@Autowired
|
||||
private UsersDetailsRepository userRepo;
|
||||
|
||||
@Autowired
|
||||
private JwtUtil jwtUtil;
|
||||
|
||||
public MasterDataServiceImpl(MerchantRepository merchantRegisterRepo, HttpService httpService,
|
||||
HttpClientApi httpClientApi, Helper helper, BillerDataRepository billerDataRespository,
|
||||
@@ -224,7 +238,7 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseModel getCustomerParamByBillerId(CustomParamRequest customerParamRequest) {
|
||||
String apiName = BBPSConstant.API_GET_CUSTOMER_PARAM_BY_BILLER_ID;
|
||||
@@ -366,7 +380,7 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
LOGGER.info("[{}] START | reqId={} | mid={} | billerName={} | category={}", apiName, requestId, mid,
|
||||
masterRequest.getBillerName(), masterRequest.getCategory());
|
||||
|
||||
String txnID = helper.generateTxnId(15);
|
||||
String txnID = helper.generateTxnId(15);
|
||||
String fullUrl = String.format("%s%s?billerName=%s&category=%s&page=%d&pagesize=%d", masterRegisterUrl,
|
||||
BBPSConstant.BILLER_URL, masterRequest.getBillerName(), masterRequest.getCategory(),
|
||||
masterRequest.getPageNo(), masterRequest.getPageSize());
|
||||
@@ -472,7 +486,7 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
if (entities != null) {
|
||||
dispositionRepository.saveAll(entities);
|
||||
} else {
|
||||
|
||||
|
||||
LOGGER.warn("No disposition found in response to save.");
|
||||
}
|
||||
|
||||
@@ -868,4 +882,40 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse authenticateUser(LoginRequest loginRequest) {
|
||||
LOGGER.info("Processing login for Request: " + loginRequest);
|
||||
|
||||
try {
|
||||
String mobileNo = loginRequest.getMobileNumber();
|
||||
|
||||
Optional<UsersDetails> byAdminEmail = userRepo.findByUserMobNo(mobileNo);
|
||||
|
||||
if (byAdminEmail.isPresent()) {
|
||||
UsersDetails user = byAdminEmail.get();
|
||||
String token = jwtUtil.generateToken(user.getUserMobNo());
|
||||
|
||||
LOGGER.info("Generated JWT token for mobileNo: " + mobileNo);
|
||||
|
||||
Object userDetailsDTO = null;
|
||||
|
||||
if (user != null) {
|
||||
userDetailsDTO = UserDetailsDTO.builder().id(user.getId()).userEmailId(user.getUserEmailId())
|
||||
.userMobNo(user.getUserMobNo()).userName(user.getUserName()).userAge(user.getUserAge())
|
||||
.build();
|
||||
}
|
||||
return new AuthResponse(token, "Success", "Login Done", 200, userDetailsDTO);
|
||||
} else {
|
||||
return new AuthResponse("", "User Not Found", "Authentication failed", 401, null);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Error occurred during login for mobile no: " + loginRequest.getMobileNumber()
|
||||
+ " Exception: " + ex.getMessage());
|
||||
|
||||
return AuthResponse.builder().status("Unauthorized").message("Authentication failed: " + ex.getMessage())
|
||||
.statusCode(401).build();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user