Skip to content

Commit

Permalink
Adding authToken validation in bulkUpload (#500)
Browse files Browse the repository at this point in the history
* Adding authToken validation in bulkUpload

* Adding pr review comment
  • Loading branch information
Sahil-tarento authored Mar 13, 2024
1 parent 79e7906 commit ba004ce
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ public ResponseEntity<?> userSignup(@RequestBody Map<String, Object> request) {
public ResponseEntity<?> bulkUpload(@RequestParam(value = "file", required = true) MultipartFile multipartFile,
@RequestHeader(Constants.X_AUTH_USER_ORG_ID) String rootOrgId,
@RequestHeader(Constants.X_AUTH_USER_CHANNEL) String channel,
@RequestHeader(Constants.X_AUTH_USER_ID) String userId) throws UnsupportedEncodingException {
@RequestHeader(Constants.X_AUTH_USER_ID) String userId,
@RequestHeader(Constants.X_AUTH_TOKEN) String userAuthToken) throws UnsupportedEncodingException {
log.info(String.format("bulkupload channel name:%s,OrgId:%s",
URLDecoder.decode(channel, "UTF-8"), rootOrgId));
SBApiResponse uploadResponse = profileService.bulkUpload(multipartFile, rootOrgId, URLDecoder.decode(channel, "UTF-8"), userId);
SBApiResponse uploadResponse = profileService.bulkUpload(multipartFile, rootOrgId, URLDecoder.decode(channel, "UTF-8"), userId, userAuthToken);
return new ResponseEntity<>(uploadResponse, uploadResponse.getResponseCode());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface ProfileService {

SBApiResponse userSignup(Map<String, Object> request);

SBApiResponse bulkUpload(MultipartFile mFile, String orgId, String orgName, String userId);
SBApiResponse bulkUpload(MultipartFile mFile, String orgId, String orgName, String userId, String userAuthToken);

SBApiResponse getBulkUploadDetails(String orgId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ public SBApiResponse userSignup(Map<String, Object> request) {
}

@Override
public SBApiResponse bulkUpload(MultipartFile mFile, String orgId, String channel, String userId) {
public SBApiResponse bulkUpload(MultipartFile mFile, String orgId, String channel, String userId, String userAuthToken) {
SBApiResponse response = ProjectUtil.createDefaultResponse(Constants.API_USER_BULK_UPLOAD);
try {
SBApiResponse uploadResponse = storageService.uploadFile(mFile, serverConfig.getBulkUploadContainerName());
Expand Down Expand Up @@ -770,6 +770,7 @@ public SBApiResponse bulkUpload(MultipartFile mFile, String orgId, String channe
response.setResponseCode(HttpStatus.OK);
response.getResult().putAll(uploadedFile);
uploadedFile.put(Constants.ORG_NAME, channel);
uploadedFile.put(Constants.X_AUTH_TOKEN, userAuthToken);
kafkaProducer.push(serverConfig.getUserBulkUploadTopic(), uploadedFile);
sendBulkUploadNotification(orgId, channel, (String) uploadResponse.getResult().get(Constants.URL));
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ private void processBulkUpload(HashMap<String, String> inputDataMap) throws IOEx
} else {
invalidErrList.addAll(validateEmailContactAndDomain(userRegistration));
if (invalidErrList.isEmpty()) {
userRegistration.setUserAuthToken(inputDataMap.get(Constants.X_AUTH_TOKEN));
String responseCode = userUtilityService.createBulkUploadUser(userRegistration);
if (!responseCode.equalsIgnoreCase(Constants.OK)) {
failedRecordsCount++;
Expand Down Expand Up @@ -354,6 +355,9 @@ private List<String> validateReceivedKafkaMessage(HashMap<String, String> inputD
if (StringUtils.isEmpty(inputDataMap.get(Constants.ORG_NAME))) {
errList.add("Orgname is not present");
}
if (StringUtils.isEmpty(inputDataMap.get(Constants.X_AUTH_TOKEN))) {
errList.add("User Token is not present");
}
if (!errList.isEmpty()) {
str.append("Failed to Validate User Details. Error Details - [").append(errList.toString()).append("]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class UserRegistration extends UserRegistrationInfo {
private String userId;
private String userName;
private String proposedDeptName;
private String userAuthToken;

public String getWfId() {
return wfId;
Expand Down Expand Up @@ -101,6 +102,14 @@ public void setProposedDeptName(String proposedDeptName) {
this.proposedDeptName = proposedDeptName;
}

public String getUserAuthToken() {
return userAuthToken;
}

public void setUserAuthToken(String userAuthToken) {
this.userAuthToken = userAuthToken;
}

public String toMininumString() {
StringBuilder strBuilder = new StringBuilder("[ UserRegistrationCode : ");
strBuilder.append(this.getRegistrationCode()).append(", UserId : ").append(this.getUserId()).append("]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,13 @@ public String createBulkUploadUser(UserRegistration userRegistration) {
requestBody.put(Constants.PHONE_VERIFIED, true);
requestBody.put(Constants.ROLES, Arrays.asList(Constants.PUBLIC));
request.put(Constants.REQUEST, requestBody);
Map<String, String> headerValues = ProjectUtil.getDefaultHeaders();
if (StringUtils.isNotEmpty(userRegistration.getUserAuthToken())) {
headerValues.put(Constants.X_AUTH_TOKEN, userRegistration.getUserAuthToken());
}
try {
Map<String, Object> readData = (Map<String, Object>) outboundRequestHandlerService.fetchResultUsingPost(
props.getSbUrl() + props.getLmsUserCreatePath(), request, ProjectUtil.getDefaultHeaders());
props.getSbUrl() + props.getLmsUserCreatePath(), request, headerValues);
if (readData != null && !Constants.OK.equalsIgnoreCase((String) readData.get(Constants.RESPONSE_CODE))) {
Map<String, Object> params = (Map<String, Object>) readData.get(Constants.PARAMS);
if (!MapUtils.isEmpty(params)) {
Expand Down

0 comments on commit ba004ce

Please sign in to comment.