diff --git a/pom.xml b/pom.xml
index d6e13ffc03dbbe2e706ba7488bd02c0581d2baf9..450d13c4a1e66a3fb402fe0667ceb3b6894a7732 100644
--- a/pom.xml
+++ b/pom.xml
@@ -209,6 +209,6 @@
8
-
+
\ No newline at end of file
diff --git a/releases/dev/airdrop-service.yaml b/releases/dev/airdrop-service.yaml
index 84cce598d72103d5a5dd909e5cb6640cc093d5cb..dfa22539b6dad7dac1c6c2bec030496d3c790b5f 100644
--- a/releases/dev/airdrop-service.yaml
+++ b/releases/dev/airdrop-service.yaml
@@ -55,11 +55,11 @@ spec:
# GRPC PROPERTIES
grpc:
accountService:
- host: account.dev-eu.nynja.net
+ host: account-service.account.svc.cluster.local
port: 6565
authService:
- host: auth.dev-eu.nynja.net
- port: 6565
+ host: auth-service.auth.svc.cluster.local
+ port: 6566
# REST PROPERTIES
rest:
pushService:
diff --git a/releases/staging/airdrop-service.yaml b/releases/staging/airdrop-service.yaml
index 493d90b617478e4c5b686db34dde8dc4be683738..3a0c753a2218aa0a4c171fd21fa6b33826504b64 100644
--- a/releases/staging/airdrop-service.yaml
+++ b/releases/staging/airdrop-service.yaml
@@ -55,11 +55,11 @@ spec:
# GRPC PROPERTIES
grpc:
accountService:
- host: account.staging.nynja.net
+ host: account-service.account.svc.cluster.local
port: 6565
authService:
- host: auth.staging.nynja.net
- port: 6565
+ host: auth-service.auth.svc.cluster.local
+ port: 6566
# REST PROPERTIES
rest:
pushService:
diff --git a/src/main/java/biz/nynja/airdrop/CassandraStartupScripts.java b/src/main/java/biz/nynja/airdrop/CassandraStartupScripts.java
index 7760aae5df5f555b1d4c092c07f6b12d00597d70..88de0dcc01c6de83c94001e9243ead7b0f9e91e4 100644
--- a/src/main/java/biz/nynja/airdrop/CassandraStartupScripts.java
+++ b/src/main/java/biz/nynja/airdrop/CassandraStartupScripts.java
@@ -29,7 +29,7 @@ public class CassandraStartupScripts {
List cassandraScripts = new ArrayList(6);
- String createKeyspace = "CREATE KEYSPACE IF NOT EXISTS " + KEYSPACE + " WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1};";
+ String createKeyspace = "CREATE KEYSPACE IF NOT EXISTS test2 WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1};";
String createTableAirdropProfile = "CREATE TABLE IF NOT EXISTS " + KEYSPACE + "." + cassandraTemplate.getTableName(AirdropProfiles.class).toString() + " (id uuid, account_id uuid, username text, referrer_code text, created_ts bigint, modified_ts bigint, is_verified tinyint ,verified_ts bigint,PRIMARY KEY(account_id,id));";
String createTableAirdropActions = "CREATE TABLE IF NOT EXISTS " + KEYSPACE + "." + cassandraTemplate.getTableName(AirdropActions.class).toString() + " (id uuid, account_id uuid, action_type text, last_action_ts bigint, count int, PRIMARY KEY(account_id,action_type,id));";
String createTableOtpSessions = "CREATE TABLE IF NOT EXISTS " + KEYSPACE + "." + cassandraTemplate.getTableName(OtpSessions.class).toString() + " (id uuid, created_ts bigint, otp int, is_verified tinyint, verified_ts bigint, account_id uuid, expired_ts bigint, PRIMARY KEY(id));";
diff --git a/src/main/java/biz/nynja/airdrop/constants/QoinProEndpoints.java b/src/main/java/biz/nynja/airdrop/constants/QoinProEndpoints.java
index 130b053a2e7894c3e6f959315dee80efa15a54d8..687e38a75782cf0959451e5d8d8e40c46fca91a0 100644
--- a/src/main/java/biz/nynja/airdrop/constants/QoinProEndpoints.java
+++ b/src/main/java/biz/nynja/airdrop/constants/QoinProEndpoints.java
@@ -2,5 +2,5 @@ package biz.nynja.airdrop.constants;
public interface QoinProEndpoints {
- String qoinProEndPoints [] = {"/test11", "/v1/verifyUser", "/v1/verifyOtp", "/v1/resendOtp", "/v1/eventData", "/v1/failedEventData"};
+ String qoinProEndPoints [] = {"/test/1", "/v1/verifyUser", "/v1/verifyOtp", "/v1/resendOtp", "/v1/eventData", "/v1/failedEventData"};
}
diff --git a/src/main/java/biz/nynja/airdrop/controller/AirdropController.java b/src/main/java/biz/nynja/airdrop/controller/AirdropController.java
index ec6fc29c2fd0e20057497c341950a79d34f99246..8b1ad154c434564a0fda722bf0021245ce507120 100644
--- a/src/main/java/biz/nynja/airdrop/controller/AirdropController.java
+++ b/src/main/java/biz/nynja/airdrop/controller/AirdropController.java
@@ -24,7 +24,17 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.util.UriComponentsBuilder;
+
+import javax.servlet.http.HttpServletRequest;
import static biz.nynja.airdrop.util.HttpConstants.statusCode.*;
import static biz.nynja.airdrop.util.HttpConstants.MessageTags.*;
@@ -99,34 +109,106 @@ public class AirdropController {
@Value("${grpc.authService.port}")
private int GRPC_AUTH_SERVICE_PORT;
-
private static final Logger logger = LoggerFactory.getLogger(AirdropController.class);
- @GetMapping("/")
- public String index() {
+ @Autowired
+ private RestTemplate restTemplate;
- return "Airdrop Service";
- }
+ // AccountId -> 6065b9bf-a69c-4837-99bd-489065f106f1
- @GetMapping("/rest/exchangeRefreshToken")
- public String restExchangeRefreshToken(@RequestHeader(value = "Authorization") String token) {
+ @GetMapping("/test/pushNotification/{username}/{password}")
+ public String testPushNotification(@PathVariable("username") String username,
+ @PathVariable("password") String password
+ ) {
System.out.println("");
- System.out.println("-----------");
- System.out.println("Rest Exchange Refresh Token");
- System.out.println("-----------");
+ System.out.println("----------------");
+ System.out.println("");
+ System.out.println("Test Push Notification : ");
+ System.out.println("");
+ System.out.println("username : " + username);
+ System.out.println("password : " + password);
+ System.out.println("");
+ System.out.println("----------------");
System.out.println("");
- Object response = restTemplateUtil.exchangeRefreshToken(token);
+ // UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://35.198.110.223:8888/chat/6065b9bf-a69c-4837-99bd-489065f106f1/qoinpro?sender=qoin_pro&message='This is a test Message'");
+ // UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://35.198.110.223:8888/chat/3dd830d4-ffa3-4327-9866-9f8d8efbb23c/qoinpro");
+
+ String authCredentials = username + ":" + password;
+ byte[] authCredentialsBytes = authCredentials.getBytes();
+ byte[] base64Credentials = Base64.getEncoder().encode(authCredentialsBytes);
+
+ MultiValueMap adminTokenParams = new LinkedMultiValueMap<>(1);
+ adminTokenParams.add("message", "This is a test message.");
+
+ HttpHeaders httpHeaders = new HttpHeaders();
+ httpHeaders.add("Authorization", "Basic " + new String(base64Credentials));
- System.out.println("Response : ");
+ HttpEntity> request = new HttpEntity<>( httpHeaders);
+
+
+ ResponseEntity response = restTemplate.exchange("http://35.198.110.223:8888/chat/3dd830d4-ffa3-4327-9866-9f8d8efbb23c/qoinpro?sender=qoin_pro&message=This is a test demo message", HttpMethod.GET, request, String.class);
+
+ System.out.println("");
+ System.out.println("================");
+ System.out.println("");
+ System.out.println("Test Response : ");
System.out.println(response);
+ System.out.println("");
+ System.out.println("");
+ System.out.println("Response Body : ");
+ System.out.println(response.getBody());
+ System.out.println("");
+ System.out.println("================");
System.out.println("");
- return response.toString();
+
+ return response.getBody();
+
}
+
+ @GetMapping("/test/basicAuth")
+ public String testBasicAuth(HttpServletRequest request) {
+
+ System.out.println("");
+ System.out.println("---------------");
+ System.out.println("");
+ System.out.println("");
+ System.out.println("");
+ System.out.println("PUSH NOTIFICATION TEST");
+ System.out.println("");
+ System.out.println("Request : ");
+ System.out.println("");
+ System.out.println("Authorization : ");
+ System.out.println(request.getHeader("authorization"));
+ System.out.println("");
+ System.out.println("---------------");
+ System.out.println("");
+
+ String basic = new String(Base64.getDecoder().decode(request.getHeader("authorization").split(" ")[1]));
+
+ System.out.println("");
+ System.out.println("basic : ");
+ System.out.println(basic);
+ System.out.println("");
+
+ return "Push Notification Test done : " + basic;
+ }
+
+
+ @GetMapping("/")
+ public String index() {
+
+ restTemplateUtil.sendPushNotification("3dd830d4-ffa3-4327-9866-9f8d8efbb23c", 0000);
+
+ return "Airdrop Service";
+ }
+
+
+
@GetMapping("/test/1")
public String testEndpoint1() {
@@ -471,17 +553,11 @@ public class AirdropController {
responseData.put("otp_session_id", otpSessionId);
responseData.put("expiry_duration", OTP_EXPIRE_TIME);
- /*
-
- // HERE, NYNJA PUSH SERVICE WILL BE CALLED TO SEND NOTIFICATION TO USER
-
- */
-
System.out.println("");
System.out.println("SEND PUSH NOTIFICATION API CALLED HERE");
System.out.println("");
- // restTemplateUtil.sendPushNotification(accountId.toString(), otp);
+ restTemplateUtil.sendPushNotification(accountId.toString(), otp);
return HttpResponse.getResponse(SUCCESS_STATUS_CODE, responseData, null);
}
@@ -886,16 +962,11 @@ public class AirdropController {
otpSessionsService.addOtpSessions(otpSessionsObj);
- /*
-
- // HERE, NYNJA PUSH SERVICE WILL BE CALLED TO SEND NOTIFICATION TO USER
-
- */
System.out.println("");
System.out.println("SEND PUSH NOTIFICATION API CALLED HERE");
System.out.println("");
- // restTemplateUtil.sendPushNotification(otpSessions.getAccount_id().toString(), otp);
+ restTemplateUtil.sendPushNotification(otpSessions.getAccount_id().toString(), otp);
return HttpResponse.getResponse(SUCCESS_STATUS_CODE, responseData, null);
}
diff --git a/src/main/java/biz/nynja/airdrop/grpc/AccountServiceClient.java b/src/main/java/biz/nynja/airdrop/grpc/AccountServiceClient.java
index e1ac039f2e265df6f3888a7101d9552e522df21c..e460f9449b9662a4aea4a8d89379bbb4b95bceb4 100644
--- a/src/main/java/biz/nynja/airdrop/grpc/AccountServiceClient.java
+++ b/src/main/java/biz/nynja/airdrop/grpc/AccountServiceClient.java
@@ -126,9 +126,8 @@ public class AccountServiceClient {
Metadata.Key key =
Metadata.Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER);
header.put(key, "Bearer " + token);
-
-
- accountServiceStub = MetadataUtils.attachHeaders(accountServiceStub, header);*/
+ accountServiceStub = MetadataUtils.attachHeaders(accountServiceStub, header);
+ */
ManagedChannel managedChannel = ManagedChannelBuilder.forAddress(GRPC_ACCOUNT_SERVICE_HOST, GRPC_ACCOUNT_SERVICE_PORT)
.usePlaintext().build();
@@ -174,6 +173,24 @@ public class AccountServiceClient {
return null;
}
+ if (searchResultDetails.getAccountId() == null) {
+
+ System.out.println("");
+ System.out.println("SearchResultDetails getAccountId is Null");
+ System.out.println("");
+
+ return null;
+ }
+
+ if (searchResultDetails.getAccountId().equals("")) {
+
+ System.out.println("");
+ System.out.println("SearchResultDetails getAccountId is Blank");
+ System.out.println("");
+
+ return null;
+ }
+
return UUID.fromString(searchResultDetails.getAccountId());
}
diff --git a/src/main/java/biz/nynja/airdrop/kafka/KafkaConsumer.java b/src/main/java/biz/nynja/airdrop/kafka/KafkaConsumer.java
index fa88cf7ac4a07ab64b8fbadd0da6f74535d15ed7..a44e8717212fde3f91252a7dcb1cf64ddf4ee24e 100644
--- a/src/main/java/biz/nynja/airdrop/kafka/KafkaConsumer.java
+++ b/src/main/java/biz/nynja/airdrop/kafka/KafkaConsumer.java
@@ -108,14 +108,20 @@ public class KafkaConsumer {
// UNCOMMENT IT LATER
- // String response = restTemplateUtil.qoinProChannelEngagementAPI(airdropProfilesList.get(0).getAccount_id().toString(), airdropProfilesList.get(0).getUsername(), kafkaMessageTemplate.getAction_type(), actionsSummary.getAction_description());
- // notifiedQoinPro = (response.equals("Success")) ? true : false;
+ String response = restTemplateUtil.qoinProChannelEngagementAPI(airdropProfilesList.get(0).getAccount_id().toString(), airdropProfilesList.get(0).getUsername(), kafkaMessageTemplate.getAction_type(), actionsSummary.getAction_description());
System.out.println("");
+ System.out.println("QOIN-PRO Channel Engagement API Response");
+ System.out.println(response);
+ System.out.println("");
+
+ notifiedQoinPro = (response.equals("Success")) ? true : false;
+
+ /*System.out.println("");
System.out.println("QOIN-PRO API Response is : SUCCESS");
System.out.println("");
- notifiedQoinPro = true;
+ notifiedQoinPro = true;*/
}
// If qoinPro response message is "Success" than data will be added in AirdropActions Table
@@ -152,9 +158,9 @@ public class KafkaConsumer {
airdropActionsService.updateAirdropActions(accountId, airdropActionsList.get(0).getId(), kafkaMessageTemplate.getAction_type(), updateMap);
} else {
- System.out.println("");
- System.out.println("" + Constants.KafkaActionType.JOIN + " Action is already consumed. So, It won't be consumed again");
- System.out.println("");
+ System.out.println("");
+ System.out.println("" + Constants.KafkaActionType.JOIN + " Action is already consumed. So, It won't be consumed again");
+ System.out.println("");
logger.info("" + Constants.KafkaActionType.JOIN + " Action is already consumed. So, It won't be consumed again");
@@ -187,7 +193,6 @@ public class KafkaConsumer {
}
-
acknowledgment.acknowledge();
}
}
diff --git a/src/main/java/biz/nynja/airdrop/security/AuthorizationServerConfiguration.java b/src/main/java/biz/nynja/airdrop/security/AuthorizationServerConfiguration.java
index f7e7d738f6c1c652e65bdd90cf47df6c10b75cc1..b3fc36a25cfeb7c802e054af0a3b176762e367ab 100644
--- a/src/main/java/biz/nynja/airdrop/security/AuthorizationServerConfiguration.java
+++ b/src/main/java/biz/nynja/airdrop/security/AuthorizationServerConfiguration.java
@@ -52,6 +52,8 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu
.tokenStore(tokenStore).tokenEnhancer(customTokenEnhancer);
}
+ // localhost:8080/airdrop/oauth/token?grant_type=password&password=test&username=qoinPro
+
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
diff --git a/src/main/java/biz/nynja/airdrop/security/CustomTokenEnhancer.java b/src/main/java/biz/nynja/airdrop/security/CustomTokenEnhancer.java
index ec13ed7d9203c227508ac798c73b8898c5b8ba23..8d6d2b53df440c27dac2d259c4790c4aff5da414 100644
--- a/src/main/java/biz/nynja/airdrop/security/CustomTokenEnhancer.java
+++ b/src/main/java/biz/nynja/airdrop/security/CustomTokenEnhancer.java
@@ -8,6 +8,8 @@ import org.springframework.stereotype.Component;
@Component
public class CustomTokenEnhancer implements org.springframework.security.oauth2.provider.token.TokenEnhancer {
+
+ // Here, Response of OAuth Token is updated and RefreshToken is removed.
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken oAuth2AccessToken, OAuth2Authentication oAuth2Authentication) {
diff --git a/src/main/java/biz/nynja/airdrop/util/RestTemplateUtil.java b/src/main/java/biz/nynja/airdrop/util/RestTemplateUtil.java
index 4f0f3879dee78759ff0db5a956d7d5f5fa9cb265..7dec8318a6e7dd8df6ea4dec1eab84eb285beb8c 100644
--- a/src/main/java/biz/nynja/airdrop/util/RestTemplateUtil.java
+++ b/src/main/java/biz/nynja/airdrop/util/RestTemplateUtil.java
@@ -8,12 +8,15 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
+import java.util.Base64;
+
@Component
public class RestTemplateUtil {
@@ -29,13 +32,21 @@ public class RestTemplateUtil {
@Value("${authentication.qoinPro.header.value}")
private String quionProAuthenticationHeaderValue;
-
private static final Logger logger = LoggerFactory.getLogger(RestTemplateUtil.class);
@Autowired
private RestTemplate restTemplate;
+ @Value("${authentication.nynjaP2PMessaging.username}")
+ private String nynjaP2PUserName;
+
+ @Value("${authentication.nynjaP2PMessaging.password}")
+ private String nynjaP2PPassword;
+ @Value("${authentication.nynjaP2PMessaging.sender}")
+ private String nynjaP2PSender;
+
+/*
public Object exchangeRefreshToken(String refreshToken) {
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8085/tokens/refresh")
@@ -54,6 +65,7 @@ public class RestTemplateUtil {
return response;
}
+*/
public String qoinProChannelEngagementAPI(String userId, String username, String actionType, String actionDescription) {
@@ -89,6 +101,44 @@ public class RestTemplateUtil {
public void sendPushNotification(String accountId, int otp) {
+ System.out.println("");
+ System.out.println("Send OTP Message Function");
+ System.out.println("");
+ System.out.println("nynjaP2PSender : " + nynjaP2PSender);
+ System.out.println("");
+ System.out.println("nynjaP2PUserName : " + nynjaP2PUserName);
+ System.out.println("nynjaP2PPassword : " + nynjaP2PPassword);
+ System.out.println("");
+
+ String authCredentials = nynjaP2PUserName + ":" + nynjaP2PPassword;
+ byte[] authCredentialsBytes = authCredentials.getBytes();
+ byte[] base64Credentials = Base64.getEncoder().encode(authCredentialsBytes);
+
+
+ HttpHeaders httpHeaders = new HttpHeaders();
+ httpHeaders.add("Authorization", "Basic " + new String(base64Credentials));
+
+ HttpEntity> request = new HttpEntity<>(httpHeaders);
+
+
+ ResponseEntity response = restTemplate.exchange("http://35.198.110.223:8888/chat/" + accountId + "/qoinpro?sender=" + nynjaP2PSender + "&message=Your verification OTP is " + otp +"", HttpMethod.GET, request, String.class);
+
+
+ System.out.println("");
+ System.out.println("Response : ");
+ System.out.println(response);
+ System.out.println("");
+ System.out.println("-----------");
+ System.out.println("");
+ System.out.println("Response Body : ");
+ System.out.println(response.getBody());
+ System.out.println("");
+
+ }
+
+/*
+ public void sendPushNotification(String accountId, int otp) {
+*//*
MultiValueMap pushNotificationParams = new LinkedMultiValueMap(2);
pushNotificationParams.add("account_id", accountId);
pushNotificationParams.add("otp", otp);
@@ -97,13 +147,39 @@ public class RestTemplateUtil {
boolean response = restTemplate.postForObject(pushNotification, httpEntity, Boolean.class);
- logger.info("Send Push Notification API Response: {}", response);
+ logger.info("Send Push Notification API Response: {}", response);*//*
- /* System.out.println("");
- System.out.println("SendPushNotificationResponse : " + response);
- System.out.println("");*/
+ String authCredentials = nynjaP2PUserName + ":" + nynjaP2PPassword;
+ byte[] authCredentialsBytes = authCredentials.getBytes();
+ byte[] base64Credentials = Base64.getEncoder().encode(authCredentialsBytes);
- }
+ HttpHeaders httpHeaders = new HttpHeaders();
+ httpHeaders.add("Authorization", "Basic " + new String(base64Credentials));
+
+ HttpEntity> request = new HttpEntity<>(httpHeaders);
+
+
+ ResponseEntity response = restTemplate.exchange("http://35.198.110.223:8888/chat/" + accountId +
+ "/qoinpro?sender=qoin_pro&message=This is a test demo message", HttpMethod.GET, request, String.class);
+
+ System.out.println("");
+ System.out.println("================");
+ System.out.println("");
+ System.out.println("Test Response : ");
+ System.out.println(response);
+ System.out.println("");
+ System.out.println("");
+ System.out.println("Response Body : ");
+ System.out.println(response.getBody());
+ System.out.println("");
+ System.out.println("================");
+ System.out.println("");
+
+
+ // return response.getBody();
+
+
+ }*/
}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index b76075314ae93745611b6e94a08a05501c991b3d..8a3b4dd8808459903c9fc789c01ec0446b83ba3d 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -77,7 +77,10 @@ authentication:
header:
name: 'x-api-key'
value: 'NEzzAZLl0Ma1Jos1bqqfk2TFHTywQ0Qo9IAFaO0y'
-
+ nynjaP2PMessaging: # This service will be called to send OTP message on P2P chat connection.
+ username: nynja
+ password: nynjaTS
+ sender: qoin_pro # This will be send in request parameters.
# QOIN-PRO TOKEN AUTHENTICATION DETAILS
users: