From 8593a99a37ac64f8976bf82a8f50125c955c2273 Mon Sep 17 00:00:00 2001 From: Jayendra Date: Fri, 26 Jul 2019 18:27:42 +0530 Subject: [PATCH] Added app token in request header of exchangeRefreshToken grpc endpoint --- .../airdrop/CassandraStartupScripts.java | 2 +- src/main/java/biz/nynja/airdrop/Config.java | 6 +- .../nynja/airdrop/constants/Constants.java | 6 + .../airdrop/controller/AirdropController.java | 254 ++++++++++++++++-- .../nynja/airdrop/grpc/AuthServiceClient.java | 53 +++- .../nynja/airdrop/kafka/KafkaConsumer.java | 15 +- .../airdrop/security/CustomTokenEnhancer.java | 6 + .../biz/nynja/airdrop/util/HttpConstants.java | 4 +- .../nynja/airdrop/util/RestTemplateUtil.java | 6 +- src/main/resources/application.yml | 1 + src/main/resources/token/token.json | 5 +- 11 files changed, 332 insertions(+), 26 deletions(-) diff --git a/src/main/java/biz/nynja/airdrop/CassandraStartupScripts.java b/src/main/java/biz/nynja/airdrop/CassandraStartupScripts.java index 88de0dc..7760aae 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 test2 WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1};"; + String createKeyspace = "CREATE KEYSPACE IF NOT EXISTS " + KEYSPACE + " 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/Config.java b/src/main/java/biz/nynja/airdrop/Config.java index 6ade37f..34bad91 100644 --- a/src/main/java/biz/nynja/airdrop/Config.java +++ b/src/main/java/biz/nynja/airdrop/Config.java @@ -238,7 +238,7 @@ public class Config implements WebMvcConfigurer { // ====== GRPC CONFIGURATION ===== - // NOTE : Since, GRPC header is not updated So, its configuration will be done in GRPC Account Service call function. + // NOTE : Since, GRPC header is not updated So, its configuration will be done in GRPC Account and Auth Service call function. /* @Bean(name = "accountServiceManagedChannel") public ManagedChannel accountServiceManagedChannel() { @@ -248,13 +248,13 @@ public class Config implements WebMvcConfigurer { return managedChannel; }*/ - @Bean(name = "authServiceManagedChannel") +/* @Bean(name = "authServiceManagedChannel") public ManagedChannel authServiceManagedChannel() { // ManagedChannel managedChannel = ManagedChannelBuilder.forAddress(GRPC_AUTH_SERVICE_HOST, GRPC_AUTH_SERVICE_PORT).usePlaintext().build(); ManagedChannel managedChannel = NettyChannelBuilder.forAddress(GRPC_AUTH_SERVICE_HOST, GRPC_AUTH_SERVICE_PORT).usePlaintext().build(); logger.info("Auth Service grpc channel is established"); return managedChannel; - } + }*/ @Bean public RestTemplate restTemplate() { diff --git a/src/main/java/biz/nynja/airdrop/constants/Constants.java b/src/main/java/biz/nynja/airdrop/constants/Constants.java index df4c592..5e89ee1 100644 --- a/src/main/java/biz/nynja/airdrop/constants/Constants.java +++ b/src/main/java/biz/nynja/airdrop/constants/Constants.java @@ -54,4 +54,10 @@ public interface Constants { String LONG = "long"; } } + + interface message { + String OTP_MESSAGE = "Your verification OTP is "; + } + + // "accessToken": "eyJraWQiOiIyMDE5MDcxNSIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2In0.eyJzdWIiOiJZVGM1TWpkalpHVXRNamhrWmkwMFpqWmlMVGxoWmpBdE4yRmlZV0l3TkdFeVpEUmwiLCJhdWQiOiJNVEl6OjEyMzoxMjMiLCJzY29wZSI6ImFjY2VzcyIsInJvbGVzIjpbIlVTRVIiXSwiaXNzIjoiaHR0cHM6Ly9hdXRoLm55bmphLmJpei8iLCJleHAiOjE1NjM5NzE2NDUsImlhdCI6MTU2MzM2Njg0NX0.ZY92lChPm37AsjmWpdWx-k307cADwY9-HghrsUAuRnih9l565RTw-0P3UVDZI9-VEjTtg-L4rx70QizDONv7NQ", } diff --git a/src/main/java/biz/nynja/airdrop/controller/AirdropController.java b/src/main/java/biz/nynja/airdrop/controller/AirdropController.java index 6f2d168..23578b2 100644 --- a/src/main/java/biz/nynja/airdrop/controller/AirdropController.java +++ b/src/main/java/biz/nynja/airdrop/controller/AirdropController.java @@ -38,6 +38,7 @@ import javax.servlet.http.HttpServletRequest; import static biz.nynja.airdrop.util.HttpConstants.statusCode.*; import static biz.nynja.airdrop.util.HttpConstants.MessageTags.*; +import java.io.File; import java.io.IOException; import java.util.*; @@ -114,6 +115,7 @@ public class AirdropController { private RestTemplate restTemplate; // https://airdrop.staging.nynja.net + @GetMapping("/") public String index() { @@ -181,14 +183,41 @@ public class AirdropController { } + @GetMapping("/test/kafka/send/{accId}/{event}") + public String testKafkaProducer(@PathVariable("accId") String accId, + @PathVariable("event") String event) { + + System.out.println(""); + System.out.println("------------------"); + System.out.println(""); + System.out.println("KAFKA-PRODUCER SEND MESSAGE"); + System.out.println(""); + System.out.println("accId : " + accId); + System.out.println("event : " + event); + System.out.println(""); + System.out.println("------------------"); + System.out.println(""); + + KafkaMessageTemplate messageTemplate = new KafkaMessageTemplate(); + messageTemplate.setAccount_id(accId); + messageTemplate.setEvent_type(event); + + kafkaProducer.sendKafkaMessage(messageTemplate); + + System.out.println(""); + System.out.println("Kafka Message is sent"); + System.out.println(""); + + return "Kafka Message is Produced"; + + } + @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 : "); @@ -225,7 +254,7 @@ public class AirdropController { @GetMapping("/test/rest/qoinpro/{accountId}/{username}") public String restQoinPro(@PathVariable("accountId") String accountId, @PathVariable("username") String username - ) { + ) { System.out.println(""); System.out.println("Sending QoinPro Notification"); @@ -233,16 +262,16 @@ public class AirdropController { System.out.println("accountId : " + accountId); System.out.println("username : " + username); System.out.println(""); + String response = restTemplateUtil.qoinProChannelEngagementAPI(accountId, username, "join", ""); + System.out.println(""); System.out.println(""); - return response; } - @GetMapping("/test/1") public String testEndpoint1() { @@ -275,10 +304,97 @@ public class AirdropController { return response.toString(); } + @PostMapping("/tokenDetails/update") + public String updateTokens(@RequestParam(value = "refreshToken", required = false) String refreshToken, + @RequestParam(value = "appToken", required = false) String appToken, + @RequestParam(value = "accessToken", required = false) String accessToken + ) throws IOException { + + + System.out.println(""); + System.out.println("------------------"); + System.out.println(""); + System.out.println("Update Token Details"); + System.out.println(""); + System.out.println("refreshToken : " + refreshToken); + System.out.println("accessToken : " + accessToken); + System.out.println("appToken : " + appToken); + System.out.println(""); + System.out.println("------------------"); + System.out.println(""); + + File outputDirectory = new File(AirdropController.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/token/token.json"); + + Map newTokenDetails = new HashMap<>(2); + + if (accessToken != null && !accessToken.equals("")) { + System.out.println(""); + System.out.println("Updating New Access Token in Tokens File"); + System.out.println(""); + + newTokenDetails.put("accessToken", accessToken); + + } else { + + System.out.println(""); + System.out.println("Access Token would not update in Tokens File"); + System.out.println(""); + + newTokenDetails.put("accessToken", authServiceClient.tokens.get("accessToken")); + } + + if (refreshToken != null && !refreshToken.equals("")) { + System.out.println(""); + System.out.println("Updating New Refresh Token in Tokens File"); + System.out.println(""); + + newTokenDetails.put("refreshToken", refreshToken); + + } else { + System.out.println(""); + System.out.println("Refresh Token would not update in Tokens File"); + System.out.println(""); + + newTokenDetails.put("refreshToken", authServiceClient.tokens.get("refreshToken")); + } + + + if (appToken != null && !appToken.equals("")) { + System.out.println(""); + System.out.println("Updating New App Token in Tokens File"); + System.out.println(""); + + newTokenDetails.put("appToken", appToken); + + } else { + System.out.println(""); + System.out.println("App Token would not update in Tokens File"); + System.out.println(""); + + newTokenDetails.put("appToken", authServiceClient.tokens.get("appToken")); + } + + System.out.println(""); + System.out.println("newTokenDetails (After Updation would be):"); + System.out.println(newTokenDetails); + System.out.println(""); + + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.writeValue(outputDirectory, newTokenDetails); + + System.out.println(""); + System.out.println("Token File is updated"); + System.out.println(""); + + authServiceClient.tokens = objectMapper.readValue(AuthServiceClient.class.getClassLoader().getResourceAsStream("token/token.json"), Map.class); + + return "Token Values are updated"; + } + @GetMapping("/test/verifyAccount/{username}") public String test1(@PathVariable("username") String username, - @RequestHeader(value = "Authorization", required = false) String token) { + @RequestHeader(value = "Authorization", required = false) String token) throws IOException { System.out.println(""); System.out.println("--------------"); @@ -304,7 +420,32 @@ public class AirdropController { System.out.println("Using File Token"); System.out.println(""); - searchResponse = accountServiceClient.accountEndpointTest(username, authServiceClient.tokens.get("accessToken")); + try { + searchResponse = accountServiceClient.accountEndpointTest(username, authServiceClient.tokens.get("accessToken")); + } catch (io.grpc.StatusRuntimeException exception) { + + System.out.println(""); + System.out.println("Exception Occured"); + System.out.println(""); + System.out.println("Message : " + exception.getMessage()); + System.out.println(""); + logger.warn("Exception in verifying user, Message: {}, Cause: {}", exception.getMessage(), exception.getCause()); + exception.getStackTrace(); + + System.out.println(""); + System.out.println("Refreshing Token"); + System.out.println(""); + + boolean tokenRefreshed = authServiceClient.exchangeRefreshToken(); + + System.out.println(""); + System.out.println("TokenRefreshed : " + tokenRefreshed); + System.out.println(""); + System.out.println("Calling searchByUsername Endpoint Again"); + System.out.println(""); + + searchResponse = accountServiceClient.accountEndpointTest(username, authServiceClient.tokens.get("accessToken")); + } } else { @@ -312,7 +453,32 @@ public class AirdropController { System.out.println("Using Provided Token"); System.out.println(""); - searchResponse = accountServiceClient.accountEndpointTest(username, token); + try { + searchResponse = accountServiceClient.accountEndpointTest(username, authServiceClient.tokens.get("accessToken")); + } catch (io.grpc.StatusRuntimeException exception) { + + System.out.println(""); + System.out.println("Exception Occured"); + System.out.println(""); + System.out.println("Message : " + exception.getMessage()); + System.out.println(""); + logger.warn("Exception in verifying user, Message: {}, Cause: {}", exception.getMessage(), exception.getCause()); + exception.getStackTrace(); + + System.out.println(""); + System.out.println("Refreshing Token"); + System.out.println(""); + + boolean tokenRefreshed = authServiceClient.exchangeRefreshToken(); + + System.out.println(""); + System.out.println("TokenRefreshed : " + tokenRefreshed); + System.out.println(""); + System.out.println("Calling searchByUsername Endpoint Again"); + System.out.println(""); + + searchResponse = accountServiceClient.accountEndpointTest(username, authServiceClient.tokens.get("accessToken")); + } } System.out.println(""); @@ -425,7 +591,7 @@ public class AirdropController { " \"status\": 200\n" + "}" )})*/ - public Map verifyUser(@RequestParam("username") String username) { + public Map verifyUser(@RequestParam("username") String username) throws IOException { logger.info("verifyUser API is called"); logger.info("Parameters:-"); @@ -467,10 +633,40 @@ public class AirdropController { System.out.println(""); System.out.println("AccessToken : " + authServiceClient.tokens.get("accessToken")); System.out.println(""); - UUID accountId = accountServiceClient.verifyAccount(username, authServiceClient.tokens.get("accessToken")); + + UUID accountId = null; + + try { + + accountId = accountServiceClient.verifyAccount(username, authServiceClient.tokens.get("accessToken")); + } catch (io.grpc.StatusRuntimeException exception) { + + System.out.println(""); + System.out.println("Exception Occured"); + System.out.println(""); + System.out.println("Message : " + exception.getMessage()); + System.out.println(""); + logger.warn("Exception in verifying user, Message: {}, Cause: {}", exception.getMessage(), exception.getCause()); + exception.getStackTrace(); + + System.out.println(""); + System.out.println("Refreshing Token"); + System.out.println(""); + + boolean tokenRefreshed = authServiceClient.exchangeRefreshToken(); + + System.out.println(""); + System.out.println("TokenRefreshed : " + tokenRefreshed); + System.out.println(""); + System.out.println("Calling searchByUsername Endpoint Again"); + System.out.println(""); + + accountId = accountServiceClient.verifyAccount(username, authServiceClient.tokens.get("accessToken")); + } logger.info("accountId:"); logger.debug("{}", accountId); + System.out.println(""); System.out.println("accountId : " + accountId); System.out.println(""); @@ -485,7 +681,6 @@ public class AirdropController { return HttpResponse.getResponse(BAD_REQUEST_STATUS_CODE, null, HttpConstants.MessageTags.AIRDROP_PROFILE_NOT_EXISTS); - } // NOTE :- This code commented and will be removed in future because accoundID will be given by NynjaAccountService @@ -634,7 +829,7 @@ public class AirdropController { @RequestParam("username") String username, @RequestParam("otp") String otpString, @RequestParam("session_id") UUID sessionId // OTP SESSION-ID - ) { + ) throws IOException { System.out.println(""); System.out.println("-------------------"); @@ -696,8 +891,36 @@ public class AirdropController { System.out.println("AccessToken : " + authServiceClient.tokens.get("accessToken")); System.out.println(""); - // This code is Dummy - UUID accountId = accountServiceClient.verifyAccount(username, authServiceClient.tokens.get("accessToken")); + UUID accountId = null; + + try { + + accountId = accountServiceClient.verifyAccount(username, authServiceClient.tokens.get("accessToken")); + + } catch (io.grpc.StatusRuntimeException exception) { + + System.out.println(""); + System.out.println("Exception Occured"); + System.out.println(""); + System.out.println("Message : " + exception.getMessage()); + System.out.println(""); + logger.warn("Exception in verifying user, Message: {}, Cause: {}", exception.getMessage(), exception.getCause()); + exception.getStackTrace(); + + System.out.println(""); + System.out.println("Refreshing Token"); + System.out.println(""); + + boolean tokenRefreshed = authServiceClient.exchangeRefreshToken(); + + System.out.println(""); + System.out.println("TokenRefreshed : " + tokenRefreshed); + System.out.println(""); + System.out.println("Calling searchByUsername Endpoint Again"); + System.out.println(""); + + accountId = accountServiceClient.verifyAccount(username, authServiceClient.tokens.get("accessToken")); + } if (accountId == null) { @@ -950,7 +1173,7 @@ public class AirdropController { } - Map responseData = new HashMap(1); + Map responseData = new HashMap(2); // If OTP session is expired // if (otpSessions.getExpired_ts() < AirdropUtil.generateCurrentEpochTimeStamp()) { @@ -983,6 +1206,7 @@ public class AirdropController { logger.info("New Otp Session Created"); + responseData.put("is_verified", Constants.VerificationStatus.NOT_VERIFIED); responseData.put("otp_session_id", newOtpSessionId); responseData.put("expiry_duration", OTP_EXPIRE_TIME); /*} else { diff --git a/src/main/java/biz/nynja/airdrop/grpc/AuthServiceClient.java b/src/main/java/biz/nynja/airdrop/grpc/AuthServiceClient.java index 6723ee6..2970cef 100644 --- a/src/main/java/biz/nynja/airdrop/grpc/AuthServiceClient.java +++ b/src/main/java/biz/nynja/airdrop/grpc/AuthServiceClient.java @@ -3,8 +3,12 @@ package biz.nynja.airdrop.grpc; import biz.nynja.authentication.grpc.*; import com.fasterxml.jackson.databind.ObjectMapper; import io.grpc.ManagedChannel; +import io.grpc.Metadata; +import io.grpc.netty.NettyChannelBuilder; +import io.grpc.stub.MetadataUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @@ -17,10 +21,18 @@ import java.util.Map; @Component public class AuthServiceClient extends AuthenticationServiceGrpc.AuthenticationServiceImplBase { + //======= GRPC PROPERTIES =========== + @Value("${grpc.authService.host}") + private String GRPC_AUTH_SERVICE_HOST; + @Value("${grpc.authService.port}") + private int GRPC_AUTH_SERVICE_PORT; + +/* @Autowired @Qualifier("authServiceManagedChannel") private ManagedChannel managedChannel; private AuthenticationServiceGrpc.AuthenticationServiceBlockingStub authenticationServiceStub; +*/ private ObjectMapper objectMapper; public Map tokens; @@ -28,7 +40,7 @@ public class AuthServiceClient extends AuthenticationServiceGrpc.AuthenticationS @PostConstruct public void init() throws URISyntaxException { - authenticationServiceStub = AuthenticationServiceGrpc.newBlockingStub(managedChannel); +// authenticationServiceStub = AuthenticationServiceGrpc.newBlockingStub(managedChannel); objectMapper = new ObjectMapper(); try { @@ -60,9 +72,21 @@ public class AuthServiceClient extends AuthenticationServiceGrpc.AuthenticationS System.out.println(""); System.out.println("Refresh-Token : " + refreshToken); System.out.println(""); + System.out.println("GRPC_AUTH_SERVICE_HOST : " + GRPC_AUTH_SERVICE_HOST); + System.out.println("GRPC_AUTH_SERVICE_PORT : " + GRPC_AUTH_SERVICE_PORT); + System.out.println(""); System.out.println("---------------"); System.out.println(""); + ManagedChannel managedChannel = NettyChannelBuilder.forAddress(GRPC_AUTH_SERVICE_HOST, GRPC_AUTH_SERVICE_PORT).usePlaintext().build(); + AuthenticationServiceGrpc.AuthenticationServiceBlockingStub authenticationServiceStub = AuthenticationServiceGrpc.newBlockingStub(managedChannel); + + Metadata header = new Metadata(); + Metadata.Key key = + Metadata.Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER); + header.put(key, "Bearer " + tokens.get("appToken")); + + ExchangeRefreshTokenRequest request = ExchangeRefreshTokenRequest.newBuilder().setRefreshToken(refreshToken).build(); GenerateTokenResponse generateTokenResponse = authenticationServiceStub.exchangeRefreshToken(request); @@ -98,9 +122,27 @@ public class AuthServiceClient extends AuthenticationServiceGrpc.AuthenticationS System.out.println(""); System.out.println("Refresh-Token : " + tokens.get("refreshToken")); System.out.println(""); + System.out.println("App-Token : " + tokens.get("appToken")); + System.out.println(""); + System.out.println("GRPC_AUTH_SERVICE_HOST : " + GRPC_AUTH_SERVICE_HOST); + System.out.println("GRPC_AUTH_SERVICE_PORT : " + GRPC_AUTH_SERVICE_PORT); + System.out.println(""); System.out.println("---------------"); System.out.println(""); + ManagedChannel managedChannel = NettyChannelBuilder.forAddress(GRPC_AUTH_SERVICE_HOST, GRPC_AUTH_SERVICE_PORT).usePlaintext().build(); + AuthenticationServiceGrpc.AuthenticationServiceBlockingStub authenticationServiceStub = AuthenticationServiceGrpc.newBlockingStub(managedChannel); + + Metadata header = new Metadata(); + Metadata.Key key = + Metadata.Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER); + header.put(key, "Bearer " + tokens.get("appToken")); + + + authenticationServiceStub = MetadataUtils.attachHeaders(authenticationServiceStub, header); + + + ExchangeRefreshTokenRequest request = ExchangeRefreshTokenRequest.newBuilder().setRefreshToken(tokens.get("refreshToken")).build(); GenerateTokenResponse generateTokenResponse = authenticationServiceStub.exchangeRefreshToken(request); @@ -187,12 +229,21 @@ public class AuthServiceClient extends AuthenticationServiceGrpc.AuthenticationS newTokenDetails.put("refreshToken", tokens.get("refreshToken")); } + newTokenDetails.put("appToken", tokens.get("appToken")); + + System.out.println(""); + System.out.println("newTokenDetails (After Updation would be):"); + System.out.println(newTokenDetails); + System.out.println(""); + objectMapper.writeValue(outputDirectory, newTokenDetails); System.out.println(""); System.out.println("Token File is updated"); System.out.println(""); + tokens = objectMapper.readValue(AuthServiceClient.class.getClassLoader().getResourceAsStream("token/token.json"), Map.class); + } return true; diff --git a/src/main/java/biz/nynja/airdrop/kafka/KafkaConsumer.java b/src/main/java/biz/nynja/airdrop/kafka/KafkaConsumer.java index 55e5658..ca8d0ca 100644 --- a/src/main/java/biz/nynja/airdrop/kafka/KafkaConsumer.java +++ b/src/main/java/biz/nynja/airdrop/kafka/KafkaConsumer.java @@ -97,6 +97,9 @@ public class KafkaConsumer { if (airdropActionsList != null && !airdropActionsList.isEmpty() && airdropActionsList.get(0).getAction_type().equals(Constants.KafkaActionType.JOIN)) { logger.info("" + Constants.KafkaActionType.JOIN + " Action is already consumed. So, It won't be notified to QuionPro again"); + System.out.println(""); + System.out.println("" + Constants.KafkaActionType.JOIN + " Action is already consumed. So, It won't be notified to QuionPro again"); + System.out.println(""); } else { @@ -124,8 +127,15 @@ public class KafkaConsumer { notifiedQoinPro = true;*/ } + if (notifiedQoinPro == null) { + System.out.println(""); + System.out.println("QoinPro API is not called (notifiedQoinPro is NULL)"); + System.out.println(""); + logger.info("QoinPro API is not called"); + } + // If qoinPro response message is "Success" than data will be added in AirdropActions Table - if (notifiedQoinPro == true) { + else if (notifiedQoinPro == true) { if (airdropActionsList == null || airdropActionsList.isEmpty()) { @@ -184,6 +194,9 @@ public class KafkaConsumer { actionsFailedService.addActionsFailed(actionsFailed); } else { + System.out.println(""); + System.out.println("QoinPro API is not called (notifiedQoinPro is NULL)"); + System.out.println(""); logger.info("QoinPro API is not called"); } diff --git a/src/main/java/biz/nynja/airdrop/security/CustomTokenEnhancer.java b/src/main/java/biz/nynja/airdrop/security/CustomTokenEnhancer.java index 8d6d2b5..7e0cb33 100644 --- a/src/main/java/biz/nynja/airdrop/security/CustomTokenEnhancer.java +++ b/src/main/java/biz/nynja/airdrop/security/CustomTokenEnhancer.java @@ -17,8 +17,14 @@ public class CustomTokenEnhancer implements org.springframework.security.oauth2. // additionalInfo.put("customInfo", "some_stuff_here"); // ((DefaultOAuth2AccessToken) oAuth2AccessToken).setAdditionalInformation(additionalInfo); + ((DefaultOAuth2AccessToken) oAuth2AccessToken).setRefreshToken(null); + System.out.println(""); + System.out.println("OAUTH Token : "); + System.out.println(oAuth2AccessToken.getValue()); + System.out.println(""); + return oAuth2AccessToken; } } diff --git a/src/main/java/biz/nynja/airdrop/util/HttpConstants.java b/src/main/java/biz/nynja/airdrop/util/HttpConstants.java index 4b19fc8..0e7fea9 100644 --- a/src/main/java/biz/nynja/airdrop/util/HttpConstants.java +++ b/src/main/java/biz/nynja/airdrop/util/HttpConstants.java @@ -49,9 +49,9 @@ public class HttpConstants { messages.put(MessageTags.USERNAME_IS_BLANK, "Username is Blank."); messages.put(MessageTags.INVALID_KAFKA_ACTION_TYPE, "Action Type is not valid."); messages.put(MessageTags.NO_ACTION_EVENT_FOUND, "No actions found."); - messages.put(MessageTags.OTP_IS_NOT_VALID, "OTP is not valid."); + messages.put(MessageTags.OTP_IS_NOT_VALID, "Otp is not valid."); messages.put(MessageTags.AIRDROP_PROFILE_VERIFIED, "Profile is verified."); - messages.put(MessageTags.INVALID_OTP_SESSION, "OTP Session is not correct."); + messages.put(MessageTags.INVALID_OTP_SESSION, "Otp Session is not correct."); messages.put(MessageTags.FAILED_ACTIONS_NOTIFIED_SUCCESSFULLY, "Actions are successfully notified to QoinPro."); messages.put(MessageTags.NO_ACTION_TO_NOTIFY, "No action exists to notify."); messages.put(MessageTags.AIRDROP_PROFILE_ALREADY_VERIFIED, "Profile is already verified."); diff --git a/src/main/java/biz/nynja/airdrop/util/RestTemplateUtil.java b/src/main/java/biz/nynja/airdrop/util/RestTemplateUtil.java index b6e6ad8..24df50a 100644 --- a/src/main/java/biz/nynja/airdrop/util/RestTemplateUtil.java +++ b/src/main/java/biz/nynja/airdrop/util/RestTemplateUtil.java @@ -1,5 +1,6 @@ package biz.nynja.airdrop.util; +import biz.nynja.airdrop.constants.Constants; import biz.nynja.airdrop.constants.ServiceAPIs; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -112,6 +113,8 @@ public class RestTemplateUtil { System.out.println("nynjaP2PUserName : " + nynjaP2PUserName); System.out.println("nynjaP2PPassword : " + nynjaP2PPassword); System.out.println(""); + System.out.println("accountId : " + accountId); + System.out.println(""); System.out.println("pushNotification : "); System.out.println(pushNotification); System.out.println(""); @@ -127,7 +130,8 @@ public class RestTemplateUtil { HttpEntity request = new HttpEntity<>(httpHeaders); // http://35.198.110.223:8888/chat/3dd830d4-ffa3-4327-9866-9f8d8efbb23c/message?sender=6065b9bf-a69c-4837-99bd-489065f106f1&text=Hello, This is a message for test - ResponseEntity response = restTemplate.exchange(pushNotification + "/" + accountId + "/message?sender_type=sys&sender=" + nynjaP2PSenderAccountId + "&text=Your verification OTP is " + otp + "", HttpMethod.GET, request, String.class); + + ResponseEntity response = restTemplate.exchange(pushNotification + "/" + accountId + "/message?sender_type=sys&sender=" + nynjaP2PSenderAccountId + "&text=" + Constants.message.OTP_MESSAGE + "" + otp + "", HttpMethod.GET, request, String.class); System.out.println(""); System.out.println("Response : "); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 254c445..a1d75a5 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -82,6 +82,7 @@ authentication: password: nynjaTS senderAccountId: 6065b9bf-a69c-4837-99bd-489065f106f1 # This will be send in request parameters. + # QOIN-PRO TOKEN AUTHENTICATION DETAILS # localhost:8080/airdrop/oauth/token -> Use this url to get access Token. for calling Airdrop APIs users: diff --git a/src/main/resources/token/token.json b/src/main/resources/token/token.json index 970cf9d..36535e1 100644 --- a/src/main/resources/token/token.json +++ b/src/main/resources/token/token.json @@ -1,4 +1,5 @@ { - "accessToken": "eyJraWQiOiIyMDE5MDcxNSIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2In0.eyJzdWIiOiJZVGM1TWpkalpHVXRNamhrWmkwMFpqWmlMVGxoWmpBdE4yRmlZV0l3TkdFeVpEUmwiLCJhdWQiOiJNVEl6OjEyMzoxMjMiLCJzY29wZSI6ImFjY2VzcyIsInJvbGVzIjpbIlVTRVIiXSwiaXNzIjoiaHR0cHM6Ly9hdXRoLm55bmphLmJpei8iLCJleHAiOjE1NjM5NzE2NDUsImlhdCI6MTU2MzM2Njg0NX0.ZY92lChPm37AsjmWpdWx-k307cADwY9-HghrsUAuRnih9l565RTw-0P3UVDZI9-VEjTtg-L4rx70QizDONv7NQ", - "refreshToken": "cGVtdklVZDRaZHI3Unc1QkVMenNDazl2NklYNUt4YnZRVkY1ZlMzajdPUDB3Q0cycnB1VmFXejlNUlc4QWF4S3RJRGdJS2V4a0l5MFVrSTFmL3NnTDhSWWUrWG9zMHhKZjlzOE5CS1hHUkt3SURoSm9jKzNKUXlpMGh6ZzlkUHcvQTZFQlN3WHUwcEhjSFVJZnd2RzA4dWhwZExyVHlVN0Z4L3dvL0VBUlJFc0FyQXlqbEY5SlNuOWJHeGFJQXV5dnFzemFJbUpYVEx2UTNPRWFZWHJmNDhSaDF1dnRrQ0Y1Z1pITllNUjJTbUNOZG9sa1BUczgzQ0E6YnhKSEZLaDhhY3ZHekVWVXVwU282UT09" + "accessToken": "eyJraWQiOiIyMDE5MDcyMiIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2In0.eyJzdWIiOiJZVGM1TWpkalpHVXRNamhrWmkwMFpqWmlMVGxoWmpBdE4yRmlZV0l3TkdFeVpEUmwiLCJhdWQiOiJNVEl6OjEyMzoxMjMiLCJzY29wZSI6ImFjY2VzcyIsInJvbGVzIjpbIlVTRVIiXSwiaXNzIjoiaHR0cHM6Ly9hdXRoLm55bmphLmJpei8iLCJleHAiOjE1NjQxNDU2MDEsImlhdCI6MTU2NDE0NTMwMX0.GGGeHA1OWlnrqrdT77QjwuXs3Tr2vgpkmMh_yhUuZDvcxm-LrrPEhnQQniN6Mgprnf4cxs2a-ODzJoTJyFNvHg", + "refreshToken": "cGVtdklVZDRaZHI3Unc1QkVMenNDazl2NklYNUt4YnZRVkY1ZlMzajdPUDB3Q0cycnB1VmFXejlNUlc4QWF4S3RJRGdJS2V4a0l5MFVrSTFmL3NnTDhSWWUrWG9zMHhKZjlzOE5CS1hHUkt3SURoSm9jKzNKUXlpMGh6ZzlkUHcvQTZFQlN3WHUwcEhjSFVJZnd2RzA4dWhwZExyVHlVN0Z4L3dvL0VBUlJFc0FyQXlqbEY5SlNuOWJHeGFJQXV5dnFzemFJbUpYVEx2UTNPRWFZWHJmNDhSaDF1dnRrQ0Y1Z1pITllNUjJTbUNOZG9sa1BUczgzQ0E6YnhKSEZLaDhhY3ZHekVWVXVwU282UT09", + "appToken": "eyJraWQiOiJUbmx1YW1GWFpXST0iLCJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJzdWIiOiJUbmx1YW1GWFpXST0iLCJhdWQiOiJOeW5qYSIsInNjb3BlIjoiYXV0aCIsImlzcyI6Imh0dHBzOi8vYXV0aC5ueW5qYS5iaXovIiwiZXhwIjoxNjU4NDc3MDAyLCJpYXQiOjE1NjM4MDYxODJ9.77x21i0soQiOGHETwniE1LUaNQVAj8jxebVr_kR38NKvHJ6U--xE7OSfbfbPVCnPDGreM3hPvhEJYvKv_3HBkQ" } \ No newline at end of file -- GitLab