Skip to content
Open
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 @@ -59,6 +59,9 @@ private void publishResponseData(String retStr, MessageContext messageContext) {

messageContext.setProperty(DataPublisherConstants.MSISDN,
messageContext.getProperty(MSISDNConstants.USER_MSISDN));
if(Boolean.valueOf((String)messageContext.getProperty("USER_ANONYMIZATION")).booleanValue()) {
messageContext.setProperty(DataPublisherConstants.MSISDN, messageContext.getProperty(MSISDNConstants.MASKED_MSISDN));
}

boolean isPaymentReq = false;
String paymentType=null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,36 @@ public final class MSISDNConstants {

/** The Constant MSISDN. */
public static final String MSISDN = "MSISDN";


/** The Constant MSISDN_LIST. */
public static final String MSISDN_LIST = "MSISDN_LIST";

public static final String MSISDN_SUFFIX_LIST = "MSISDN_SUFFIX_LIST";

/** The Constant ADDRESSES. */
public static final String ADDRESSES = "ADDRESSES";

/** The Constant to Actual MSISDN when request user PCR MSISDN */
public static final String MASKED_MSISDN = "MASKED_MSISDN";

/** The Constant MASKED_MSISDN_SUFFIX. */
public static final String MASKED_MSISDN_SUFFIX = "MASKED_MSISDN_SUFFIX";

/** The Constant USER_MASKING_SECRET_KEY. */
public static final String USER_MASKING_SECRET_KEY = "USER_MASKING_SECRET_KEY";

/** The Constant to Actual MSISDNlist when request multiple user PCR MSISDN */
public static final String MASKED_MSISDN_LIST = "MASKED_MSISDN_LIST";

/** The Constant to Actual MASKED_MSISDN_SUFFIX_LIST when request multiple user PCR MSISDN */
public static final String MASKED_MSISDN_SUFFIX_LIST = "MASKED_MSISDN_SUFFIX_LIST";

/** The Constant to Actual MASKED_MSISDN_MAP when request multiple user PCR MSISDN */
public static final String MASKED_MSISDN_MAP = "MASKED_MSISDN_MAP";

/** The Constant to Actual MASKED_MSISDN_SUFFIX_MAP when request multiple user PCR MSISDN */
public static final String MASKED_MSISDN_SUFFIX_MAP = "MASKED_MSISDN_SUFFIX_MAP";

/** The Constant AGGRIGATOR_ROLE. */
public static final String AGGRIGATOR_ROLE = "aggregator";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public abstract class RequestExecutor {
// <TO-DO>
private String strErr;

/** userAnonymization request header */
private boolean userAnonymization;

/**
* Gets the str err.
*
Expand Down Expand Up @@ -204,6 +207,23 @@ public void setApiContext(String apiContext) {
this.apiContext = apiContext;
}

/**
* Get the request uses User Anonymization
* @return
*/
public boolean isUserAnonymization() {
return userAnonymization;
}

/**
* Set the request uses User Anonymization
* @param userAnonymization
*/
public void setUserAnonymization(boolean userAnonymization) {
this.userAnonymization = userAnonymization;
}


/**
* Gets the validoperators.
*
Expand Down Expand Up @@ -308,7 +328,9 @@ public boolean initialize(MessageContext context) throws Exception {
subResourcePath = (String) context.getProperty("REST_SUB_REQUEST_PATH");
resourceUrl = (String) context.getProperty("REST_FULL_REQUEST_PATH");
httpMethod = (String) context.getProperty("HTTP_METHOD");

if(context.getProperty("USER_ANONYMIZATION") != null) {
this.userAnonymization = Boolean.valueOf((String)context.getProperty("USER_ANONYMIZATION"));
}

/*String jsonPayloadToString = JsonUtil
.jsonPayloadToString(((Axis2MessageContext) context).getAxis2MessageContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.wso2telco.dep.oneapivalidation.service.IServiceValidate;
import com.wso2telco.dep.oneapivalidation.service.impl.payment.ValidatePaymentCharge;
import com.wso2telco.dep.subscriptionvalidator.util.ValidatorUtils;
import com.wso2telco.dep.user.masking.UserMaskHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
Expand All @@ -41,6 +42,8 @@
import org.wso2.carbon.utils.CarbonUtils;

import java.io.File;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -80,7 +83,7 @@ public boolean handle(MessageContext context) throws Exception {
HashMap<String, String> jwtDetails = apiUtils.getJwtTokenDetails(context);
OperatorEndpoint endpoint = null;
String clientCorrelator = null;
String sending_add = null;
String sendingAddress = null;

String requestResourceURL = executor.getResourceUrl();

Expand All @@ -101,12 +104,25 @@ public boolean handle(MessageContext context) throws Exception {
if (log.isDebugEnabled()) {
log.debug("Subscriber Name : " + subscriber);
}
JSONObject jsonBody = executor.getJsonBody();
try {

JSONObject jsonBody = executor.getJsonBody();
try {

String endUserId = jsonBody.getJSONObject("amountTransaction").getString("endUserId");
String endUserId = jsonBody.getJSONObject("amountTransaction").getString("endUserId");
String msisdn = endUserId.substring(5);

if(executor.isUserAnonymization()) {
context.setProperty(MSISDNConstants.MASKED_MSISDN, endUserId);
endUserId = UserMaskHandler.maskUserId(endUserId, false,
(String)context.getProperty(MSISDNConstants.USER_MASKING_SECRET_KEY) );
String endUserIdSuffix = HandlerUtils.getMSISDNSuffix(endUserId);
context.setProperty("MSISDN_SUFFIX", endUserIdSuffix);
String maskedEndUserIdSuffix = UserMaskHandler.maskUserId(endUserIdSuffix, true,
(String) context.getProperty(MSISDNConstants.USER_MASKING_SECRET_KEY));
context.setProperty(MSISDNConstants.MASKED_MSISDN_SUFFIX, maskedEndUserIdSuffix);
context.setProperty("MASKED_RESOURCE", context.getProperty("RESOURCE"));
}


//Double chargeamount = Double.parseDouble(jsonBody.getJSONObject("amountTransaction").getJSONObject("paymentAmount").getJSONObject("chargingInformation").getString("amount"));

context.setProperty(MSISDNConstants.USER_MSISDN, msisdn);
Expand All @@ -125,10 +141,16 @@ public boolean handle(MessageContext context) throws Exception {

}

sending_add = endpoint.getEndpointref().getAddress();
if (log.isDebugEnabled()) {
log.info("sending endpoint found: " + sending_add + " Request ID: " + UID.getRequestID(context));
}
sendingAddress = endpoint.getEndpointref().getAddress();
log.info("sending endpoint found: " + sendingAddress + " Request ID: " + UID.getRequestID(context));
if(executor.isUserAnonymization()) {
String maskedMsisdnSuffix = ValidationUtils.getMsisdnNumber(
URLDecoder.decode(((String)context.getProperty(MSISDNConstants.MASKED_MSISDN))
.replaceAll("\\+", "%2b"), "UTF-8"));
String msisdnSuffix = ValidationUtils.getMsisdnNumber(
URLDecoder.decode(endUserId.replaceAll("\\+", "%2b"), "UTF-8"));
sendingAddress = sendingAddress.replace(URLEncoder.encode(maskedMsisdnSuffix, "UTF-8"), msisdnSuffix);
}

JSONObject objAmountTransaction = jsonBody.getJSONObject("amountTransaction");

Expand Down Expand Up @@ -191,7 +213,7 @@ public boolean handle(MessageContext context) throws Exception {

// set information to the message context, to be used in the sequence
HandlerUtils.setHandlerProperty(context, this.getClass().getSimpleName());
HandlerUtils.setEndpointProperty(context, sending_add);
HandlerUtils.setEndpointProperty(context, sendingAddress);
HandlerUtils.setGatewayHost(context);
HandlerUtils.setAuthorizationHeader(context, executor, endpoint);
context.setProperty("operator", endpoint.getOperator());
Expand All @@ -207,7 +229,6 @@ public boolean handle(MessageContext context) throws Exception {

@Override
public boolean validate(String httpMethod, String requestPath, JSONObject jsonBody, MessageContext context) throws Exception {
IServiceValidate validator;
String validatorClass = (String) context.getProperty("validatorClass");

if (!httpMethod.equalsIgnoreCase("POST")) {
Expand All @@ -216,16 +237,10 @@ public boolean validate(String httpMethod, String requestPath, JSONObject jsonBo
throw new Exception("Method not allowed");
}

if(validatorClass != null){
Class clazz = Class.forName(validatorClass);
validator = (IServiceValidate) clazz.newInstance();
}else{
validator = new ValidatePaymentCharge();
}

IServiceValidate validator = new ValidatePaymentCharge(executor.isUserAnonymization(), (String)context.getProperty("USER_MASKING_SECRET_KEY"));
validator.validateUrl(requestPath);
validator.validate(jsonBody.toString());
ValidationUtils.compareMsisdn(executor.getSubResourcePath(), executor.getJsonBody());
ValidationUtils.compareMsisdn(executor.getSubResourcePath(), executor.getJsonBody(), executor.isUserAnonymization(), context);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public boolean validate(String httpMethod, String requestPath,
IServiceValidate validator = new ValidateRefund();
validator.validateUrl(requestPath);
validator.validate(jsonBody.toString());
ValidationUtils.compareMsisdn(executor.getSubResourcePath(), executor.getJsonBody());
ValidationUtils.compareMsisdn(executor.getSubResourcePath(), executor.getJsonBody(), executor.isUserAnonymization(), context);

return true;
}

Expand Down Expand Up @@ -253,4 +254,4 @@ public static String nullOrTrimmed(String s) {
return rv;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@
*/
package com.wso2telco.dep.mediator.impl.smsmessaging;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.axis2.AxisFault;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.json.JSONArray;
import org.json.JSONObject;

import com.google.common.base.CharMatcher;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand All @@ -50,21 +34,21 @@
import com.wso2telco.dep.mediator.service.SMSMessagingService;
import com.wso2telco.dep.mediator.util.DataPublisherConstants;
import com.wso2telco.dep.mediator.util.HandlerUtils;
import com.wso2telco.dep.mediator.util.ValidationUtils;
import com.wso2telco.dep.oneapivalidation.exceptions.CustomException;
import com.wso2telco.dep.oneapivalidation.service.IServiceValidate;
import com.wso2telco.dep.oneapivalidation.service.impl.smsmessaging.ValidateSendSms;
import com.wso2telco.dep.operatorservice.model.OperatorApplicationDTO;
import com.wso2telco.dep.subscriptionvalidator.exceptions.ValidatorException;
import com.wso2telco.dep.subscriptionvalidator.util.ValidatorUtils;
import com.wso2telco.dep.user.masking.UserMaskHandler;
import org.apache.axis2.AxisFault;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.json.JSONArray;
import org.json.JSONObject;
import org.wso2.carbon.utils.CarbonUtils;
import java.io.File;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
Expand Down Expand Up @@ -155,6 +139,9 @@ public boolean handle(MessageContext context) throws CustomException, AxisFault,
JSONArray addressArray = jsonBody.getJSONObject("outboundSMSMessageRequest").getJSONArray("address");

String firstAddress = addressArray.getString(0);
if (executor.isUserAnonymization() && UserMaskHandler.isMaskedUserId(firstAddress)) {
firstAddress = UserMaskHandler.maskUserId(firstAddress, false, (String)context.getProperty("USER_MASKING_SECRET_KEY"));
}

if(firstAddress.contains("tel:+")){

Expand All @@ -172,6 +159,9 @@ public boolean handle(MessageContext context) throws CustomException, AxisFault,
for (int a = 0; a < addressArray.length(); a++) {

String address = addressArray.getString(a);
if (executor.isUserAnonymization() && UserMaskHandler.isMaskedUserId(address)) {
address = UserMaskHandler.maskUserId(address, false, (String)context.getProperty("USER_MASKING_SECRET_KEY"));
}

if(address.contains("tel:+")){

Expand All @@ -193,9 +183,16 @@ public boolean handle(MessageContext context) throws CustomException, AxisFault,
}
}

// taking the operator endpoint with first address, since this is for same operator
OperatorEndpoint operatorEndpoint = getEndpoint(jsonBody.getJSONObject
("outboundSMSMessageRequest").getJSONArray("address").getString(0), context, API_TYPE);
// Get first address to find operator endpoint
String firstAddress = jsonBody.getJSONObject("outboundSMSMessageRequest").getJSONArray("address").getString(0);
// Get resolved MSISDN if request used User Anonymization
if (executor.isUserAnonymization() && UserMaskHandler.isMaskedUserId(firstAddress)) {
context.setProperty(MSISDNConstants.MASKED_MSISDN_SUFFIX, HandlerUtils.getMSISDNSuffix(firstAddress));
firstAddress = UserMaskHandler.maskUserId(firstAddress, false, (String)context.getProperty("USER_MASKING_SECRET_KEY"));
}

// taking the operator endpoint with first address, since this is for same o,perator
OperatorEndpoint operatorEndpoint = getEndpoint(firstAddress, context, API_TYPE);

String sending_add = operatorEndpoint.getEndpointref().getAddress();
log.info("sending endpoint found: " + sending_add + " Request ID: " + UID.getRequestID(context));
Expand Down Expand Up @@ -244,14 +241,48 @@ public boolean handle(MessageContext context) throws CustomException, AxisFault,
JSONArray addressElement = jsonBody.getJSONObject("outboundSMSMessageRequest").getJSONArray("address");
String[] addresses = new String[addressElement.length()];
String addressList = "";
String addressSuffixList = "";
String maskedAddressList = "";
String maskedAddressSuffixList = "";
Map<String, String> maskedMsisdnMap = new HashMap<>();
Map<String, String> maskedMsisdnSuffixMap = new HashMap<>();

for (int i = 0 ; i < addressElement.length() ; i ++) {
addresses[i] = addressElement.getString(i);
String resolvedAddress = addressElement.getString(i);
String resolvedAddressSuffix = HandlerUtils.getMSISDNSuffix(resolvedAddress);
if (executor.isUserAnonymization()) {
maskedAddressList += (addresses[i] + ",");
// Address List may contains unmasked user Ids too for build address list
if (UserMaskHandler.isMaskedUserId(addressElement.getString(i))) {
resolvedAddress = UserMaskHandler.maskUserId(addressElement.getString(i), false,
(String)context.getProperty(MSISDNConstants.USER_MASKING_SECRET_KEY));
resolvedAddressSuffix = HandlerUtils.getMSISDNSuffix(resolvedAddress);
}
String maskedAddressSuffix = HandlerUtils.getMSISDNSuffix(addresses[i]);
maskedAddressSuffixList += maskedAddressSuffix + ",";
// Update map<masked-msisdn, actual msisdn>
maskedMsisdnMap.put(addresses[i], resolvedAddress);
maskedMsisdnSuffixMap.put(maskedAddressSuffix, resolvedAddressSuffix);
addresses[i] = resolvedAddress;
}
addressList += (addresses[i] + ",");
addressSuffixList += resolvedAddressSuffix + ",";
}
context.setProperty(MSISDNConstants.ADDRESSES, addresses);
context.setProperty(MSISDNConstants.MSISDN_LIST, addressList.substring(0, addressList.length() - 1));
context.setProperty(MSISDNConstants.MSISDN_SUFFIX_LIST, addressSuffixList.substring(0, addressSuffixList.length() - 1));

context.setProperty(MSISDNConstants.MSISDN_LIST, addressList.substring(0, addressList.length() - 1));
if (executor.isUserAnonymization()) {
context.setProperty(MSISDNConstants.MASKED_MSISDN_LIST, maskedAddressList.substring(0, maskedAddressList.length() - 1));
context.setProperty(MSISDNConstants.MASKED_MSISDN_MAP, maskedMsisdnMap);

context.setProperty(MSISDNConstants.MASKED_MSISDN_SUFFIX_LIST, maskedAddressSuffixList.substring(0, maskedAddressSuffixList.length() - 1));
context.setProperty(MSISDNConstants.MASKED_MSISDN_SUFFIX_MAP, maskedMsisdnSuffixMap);
}
context.setProperty("ADDRESSES", addresses);
context.setProperty("MSISDN_LIST", addressList.substring(0, addressList.length() - 1));

context.setProperty("RESPONSE_DELIVERY_INFO_RESOURCE_URL", getProperty("hubGateway")+ executor.getApiContext()+ "/" + executor.getApiVersion() + executor.getSubResourcePath()+ "/" +requestid + "/deliveryInfos");
context.setProperty("RESPONSE_DELIVERY_INFO_RESOURCE_URL", getProperty("hubGateway")+executor.getResourceUrl() + "/" +requestid + "/deliveryInfos");

context.setProperty("OPERATOR_NAME", operatorEndpoint.getOperator());
context.setProperty("OPERATOR_ID", operatorEndpoint.getOperatorId());
Expand Down Expand Up @@ -303,10 +334,10 @@ public boolean validate(String httpMethod, String requestPath, JSONObject jsonBo

context.setProperty(DataPublisherConstants.OPERATION_TYPE, 200);

IServiceValidate validator = new ValidateSendSms();
IServiceValidate validator = new ValidateSendSms(executor.isUserAnonymization(), (String)context.getProperty("USER_MASKING_SECRET_KEY"));
validator.validateUrl(requestPath);
validator.validate(jsonBody.toString());

ValidationUtils.compareSenderId(executor.getSubResourcePath(), executor.getJsonBody(), context);
String senderName = jsonBody.getJSONObject("outboundSMSMessageRequest").optString("senderName");

if (senderName.equals("") || senderName == null || senderName.length() < 10) {
Expand Down
Loading