diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..80bfbd5
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,68 @@
+name: Build
+
+on:
+ push:
+ branches:
+ - master
+ - dev
+ - dev-*
+
+jobs:
+ build:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-latest]
+ steps:
+ - name: Notify slack success
+ if: success()
+ id: slack # IMPORTANT: reference this step ID value in future Slack steps
+ env:
+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
+ uses: voxmedia/github-action-slack-notify-build@v1.1.1
+ with:
+ channel: github-actions
+ status: STARTING
+ color: warning
+
+ - uses: actions/checkout@v2
+ - name: Set up JDK 1.8
+ uses: actions/setup-java@v1
+ with:
+ java-version: 1.8
+
+ - name: Build
+ run: mvn -B package --file pom.xml
+
+ - name: Run Tests
+ run: mvn test
+
+ - name: Upload coverage to Codecov
+ uses: codecov/codecov-action@v1
+ with:
+ token: ${{ secrets.CODECOV_TOKEN }}
+ flags: unittests
+ name: codecov-umbrella
+ fail_ci_if_error: true
+
+ - name: Notify slack success
+ if: success()
+ env:
+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
+ uses: voxmedia/github-action-slack-notify-build@v1.1.1
+ with:
+ message_id: ${{ steps.slack.outputs.message_id }}
+ channel: github-actions
+ status: SUCCESS
+ color: good
+
+ - name: Notify slack fail
+ if: failure()
+ env:
+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
+ uses: voxmedia/github-action-slack-notify-build@v1.1.1
+ with:
+ message_id: ${{ steps.slack.outputs.message_id }}
+ channel: github-actions
+ status: FAILED
+ color: danger
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..395c068
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,60 @@
+name: CI
+
+on:
+ pull_request:
+ branches:
+ - master
+ - dev
+ - dev-*
+
+jobs:
+ ci:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-latest]
+ steps:
+ - name: Notify slack success
+ if: success()
+ id: slack # IMPORTANT: reference this step ID value in future Slack steps
+ env:
+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
+ uses: voxmedia/github-action-slack-notify-build@v1.1.1
+ with:
+ channel: github-actions
+ status: STARTING
+ color: warning
+
+ - uses: actions/checkout@v2
+ - name: Set up JDK 1.8
+ uses: actions/setup-java@v1
+ with:
+ java-version: 1.8
+
+ - name: Build
+ run: mvn -B package --file pom.xml
+
+ - name: Run Tests
+ run: mvn test
+
+ - name: Notify slack success
+ if: success()
+ env:
+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
+ uses: voxmedia/github-action-slack-notify-build@v1.1.1
+ with:
+ message_id: ${{ steps.slack.outputs.message_id }}
+ channel: github-actions
+ status: SUCCESS
+ color: good
+
+ - name: Notify slack fail
+ if: failure()
+ env:
+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
+ uses: voxmedia/github-action-slack-notify-build@v1.1.1
+ with:
+ message_id: ${{ steps.slack.outputs.message_id }}
+ channel: github-actions
+ status: FAILED
+ color: danger
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
new file mode 100644
index 0000000..cea2dba
--- /dev/null
+++ b/.github/workflows/publish.yml
@@ -0,0 +1,65 @@
+name: Publish
+
+on:
+ release:
+ types: [created]
+
+jobs:
+ release:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Notify Starting
+ if: success()
+ id: slack # IMPORTANT: reference this step ID value in future Slack steps
+ env:
+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
+ uses: voxmedia/github-action-slack-notify-build@v1.1.1
+ with:
+ channel: github-actions
+ status: STARTING
+ color: warning
+
+ - uses: actions/checkout@v2
+ - name: Set up Maven Central Repository
+ uses: actions/setup-java@v1
+ with:
+ java-version: 1.8
+ server-id: ossrh
+ server-username: MAVEN_USERNAME
+ server-password: MAVEN_PASSWORD
+
+ - name: Build
+ run: mvn -B package --file pom.xml
+
+ - name: Run Tests
+ run: mvn test
+
+ - name: Release Maven package
+ uses: samuelmeuli/action-maven-publish@v1
+ with:
+ gpg_private_key: ${{ secrets.gpg_private_key }}
+ gpg_passphrase: ${{ secrets.gpg_passphrase }}
+ nexus_username: ${{ secrets.nexus_username }}
+ nexus_password: ${{ secrets.nexus_password }}
+
+ - name: Notify slack success
+ if: success()
+ env:
+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
+ uses: voxmedia/github-action-slack-notify-build@v1.1.1
+ with:
+ message_id: ${{ steps.slack.outputs.message_id }}
+ channel: github-actions
+ status: SUCCESS
+ color: good
+
+ - name: Notify slack fail
+ if: failure()
+ env:
+ SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
+ uses: voxmedia/github-action-slack-notify-build@v1.1.1
+ with:
+ message_id: ${{ steps.slack.outputs.message_id }}
+ channel: github-actions
+ status: FAILED
+ color: danger
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 146a7f2..7cd28f6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,3 +22,11 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
+
+/target
+/.classpath
+/.project
+*.iml
+.idea
+.vscode
+.DS_Store
diff --git a/.settings/org.eclipse.jdt.apt.core.prefs b/.settings/org.eclipse.jdt.apt.core.prefs
new file mode 100644
index 0000000..d4313d4
--- /dev/null
+++ b/.settings/org.eclipse.jdt.apt.core.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.apt.aptEnabled=false
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..1b6e1ef
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,9 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
+org.eclipse.jdt.core.compiler.processAnnotations=disabled
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/LICENSE b/LICENSE
index 7f4ad0a..edac868 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2019 nevoalm
+Copyright (c) 2019 SecureNative
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index 6c3e32c..ff6e4ee 100644
--- a/README.md
+++ b/README.md
@@ -1,179 +1,310 @@
-
-# Java SDK for SecureNative
-
-
-**[SecureNative](https://www.securenative.com/) is rethinking-security-as-a-service, disrupting the cyber security space and the way enterprises consume and implement security solutions.**
-
-
-#SDK
-
-This Java sdk is very light, comes with only two dependencies (httpAsyncClient and Jackson).
-In addition, you can find two modules that can help you:
-
-[Spring](https://github.com/securenative/securenative-java/tree/master/spring) or any web application that uses javax.servlet
-
-[akka-http](https://github.com/securenative/securenative-java/tree/master/akka-http)
-
-# Quickstart
+
+
+
+
+
+ A Cloud-Native Security Monitoring and Protection for Modern Applications
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Documentation |
+ Quick Start |
+ Blog |
+ Chat with us on Slack!
+
+
+
+
+[SecureNative](https://www.securenative.com/) performs user monitoring by analyzing user interactions with your application and various factors such as network, devices, locations and access patterns to stop and prevent account takeover attacks.
+
+## Install the SDK
When using Maven, add the following dependency to your `pom.xml` file:
```xml
-
- com.securenative.java
- sdk-base
- 0.2.4
-
+
+ com.securenative.java
+ securenative-java
+ LATEST
+
```
-Gradle:
-
-compile group: 'com.securenative.java', name: 'sdk-base', version: 'LATEST'
-
+When using Gradle, add the following dependency to your `build.gradle` file:
+```gradle
+compile group: 'com.securenative.java', name: 'sdk-parent', version: '0.3.1', ext: 'pom'
+```
+When using SBT, add the following dependency to your `build.sbt` file:
+```sbt
+libraryDependencies += "com.securenative.java" % "sdk-parent" % "0.3.1" pomOnly()
+```
## Initialize the SDK
-Go to the settings page of your SecureNative account and find your **API KEY**
+To get your *API KEY*, login to your SecureNative account and go to project settings page:
-**Initialize using API KEY**
+### Option 1: Initialize via Config file
+SecureNative can automatically load your config from *securenative.properties* file or from the file that is specified in your *SECURENATIVE_CONFIG_FILE* env variable:
```java
- secureNative = new SecureNative(API_KEY,new SecureNativeOptions());
+// Options 1: Use default config file path
+try {
+ SecureNative securenative = SecureNative.init();
+} catch (SecureNativeSDKException | SecureNativeConfigException e) {
+ e.printStackTrace();
+}
+
+// Options 2: Use specific config file path
+Path path = Paths.get("/path/to/securenative.properties");
+try {
+ SecureNative.init(path);
+} catch (SecureNativeSDKException | SecureNativeConfigException e) {
+ System.err.printf("Could not initialize SecureNative sdk; %s%n", e);
+}
```
+### Option 2: Initialize via API Key
-You can pass empty SecureNativeOptions object or you can set the following:
+```java
+try {
+ SecureNative securenative = SecureNative.init("YOUR_API_KEY");
+} catch (SecureNativeSDKException | SecureNativeConfigException e) {
+ e.printStackTrace();
+}
+```
- api url - target url the events will be sent (https://api.securenative.com/collector/api/v1).
- interval - minimum interval between sending events (1000ms).
- max events - maximum events that will be sent (1000).
- timeout - (1500 ms).
+### Option 3: Initialize via ConfigurationBuilder
+```java
+try {
+ securenative = SecureNative.init(SecureNative.configBuilder()
+ .withApiKey("API_KEY")
+ .withMaxEvents(10)
+ .withLogLevel("error")
+ .build());
+} catch (SecureNativeSDKException e) {
+ e.printStackTrace();
+}
+```
- ```java
- secureNative = new SecureNative(API_KEY,new SecureNativeOptions(
- "https://other.domain.com/collector/api/v1",
- 1200,
- 5000,
- 2000
- ));
- ```
+## Getting SecureNative instance
+Once initialized, sdk will create a singleton instance which you can get:
+```java
+SecureNative securenative = null;
+try {
+ securenative = SecureNative.getInstance();
+} catch (SecureNativeSDKIllegalStateException e) {
+ System.err.printf("Could not get SecureNative instance; %s%n", e);
+}
+```
## Tracking events
-Once the SDK has been initialized, tracking requests are sent through the SDK
+Once the SDK has been initialized, tracking requests sent through the SDK
instance. Make sure you build event with the EventBuilder:
```java
-Event event = new SnEvent.EventBuilder(EventTypes.LOG_IN.getType()).
- withUser(new User("","","apple@sucks.com")).
- withIp("35.199.23.1").
- withCookieValue("eyJjaWQiOiJkYzgyYjdhZS00ODFkLTQyODItYTMyZC0xZTU1Njk2ZjNmZTQiLCJmcCI6Ijk5NGYzZjVjZTRiYWUwODQzMTRhOTFkNzgyN2I1MWYuMjQ3MDBmOWYxOTg2ODAwYWI0ZmNjODgwNTMwZGQwZWQifQ").
- withRemoteIP("35.199.23.1").
- withUserAgent("Mozilla/5.0 (Linux; U; Android 4.4.2; zh-cn; GT-I9500 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.0 QQ-URL-Manager Mobile Safari/537.36").
- build();
+@RequestMapping("/track")
+public void track() {
+ SecureNative securenative = null;
+ try {
+ securenative = SecureNative.getInstance();
+ } catch (SecureNativeSDKIllegalStateException e) {
+ System.err.printf("Could not get SecureNative instance; %s%n", e);
+ }
+
+ SecureNativeContext context = SecureNative.contextBuilder()
+ .withIp("37.86.255.94")
+ .withClientToken("SECURENATIVE_CLIENT_TOKEN")
+ .withHeaders(Maps.defaultBuilder()
+ .put("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36")
+ .build())
+ .build();
+
+ EventOptions eventOptions = null;
+ try {
+ eventOptions = EventOptionsBuilder.builder(EventTypes.LOG_IN)
+ .userId("1234")
+ .userTraits("Your Name", "name@gmail.com", "+1234567890")
+ .context(context)
+ .properties(Maps.builder()
+ .put("prop1", "CUSTOM_PARAM_VALUE")
+ .put("prop2", true)
+ .put("prop3", 3)
+ .build())
+ .timestamp(new Date())
+ .build();
+ } catch (SecureNativeInvalidOptionsException e) {
+ e.printStackTrace();
+ }
+
+ try {
+ securenative.track(eventOptions);
+ } catch (SecureNativeInvalidOptionsException e) {
+ e.printStackTrace();
+ }
+}
```
-**Example**
+You can also create request context from HttpServletRequest:
```java
- @RequestMapping("/track")
- public String track( HttpServletRequest request, HttpServletResponse response) {
- try {
- secureNative = new SecureNative(API_KEY,new SecureNativeOptions());
- Event event = new SnEvent.EventBuilder(EventTypes.LOG_IN.getType()).
- withUser(new User("","","chuck@norris.com")).
- withIp("35.199.23.1").
- withCookieValue("eyJjaWQiOiJkYzgyYjdhZS00ODFkLTQyODItYTMyZC0xZTU1Njk2ZjNmZTQiLCJmcCI6Ijk5NGYzZjVjZTRiYWUwODQzMTRhOTFkNzgyN2I1MWYuMjQ3MDBmOWYxOTg2ODAwYWI0ZmNjODgwNTMwZGQwZWQifQ").
- withRemoteIP("35.199.23.1").
- withUserAgent("Mozilla/5.0 (Linux; U; Android 4.4.2; zh-cn; GT-I9500 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.0 QQ-URL-Manager Mobile Safari/537.36").
- build();
- secureNative.track(event);
-
-
- } catch (SecureNativeSDKException e) {
- e.printStackTrace();
- return "Api key is not valid";
- }
- return "tracked";
+@RequestMapping("/track")
+public void track(HttpServletRequest request, HttpServletResponse response) {
+ SecureNative securenative = null;
+ try {
+ securenative = SecureNative.getInstance();
+ } catch (SecureNativeSDKIllegalStateException e) {
+ System.err.printf("Could not get SecureNative instance; %s%n", e);
+ }
+
+ SecureNativeContext context = securenative.fromHttpServletRequest(request).build();
+
+ EventOptions eventOptions = null;
+ try {
+ eventOptions = EventOptionsBuilder.builder(EventTypes.LOG_IN)
+ .userId("1234")
+ .userTraits("Your Name", "name@gmail.com", "+1234567890")
+ .context(context)
+ .properties(Maps.builder()
+ .put("prop1", "CUSTOM_PARAM_VALUE")
+ .put("prop2", true)
+ .put("prop3", 3)
+ .build())
+ .timestamp(new Date())
+ .build();
+ } catch (SecureNativeInvalidOptionsException e) {
+ e.printStackTrace();
}
+ try {
+ securenative.track(eventOptions);
+ } catch (SecureNativeInvalidOptionsException e) {
+ e.printStackTrace();
+ }
+}
```
-You can build an event from HttpServletRequest or from combination between event and HttpServletRequest:
+## Verify events
+**Example**
```java
- @RequestMapping("/track")
- public String track( HttpServletRequest request, HttpServletResponse response) {
- try {
- secureNative = new SecureNative(API_KEY,new SecureNativeOptions());
- Event e = new SnEvent.EventBuilder(EventTypes.LOG_IN.getType()).
- withUser(new User("","","chuck@norris.com")).
- build();
- Event event = secureNative.buildEventFromHttpServletRequest(request, e);
- secureNative.track(event);
-
-
- } catch (SecureNativeSDKException e) {
- e.printStackTrace();
- return "Api key is not valid";
- }
- return "tracked";
+@RequestMapping("/verify")
+public void verify(HttpServletRequest request, HttpServletResponse response) {
+SecureNative securenative = null;
+ try {
+ securenative = SecureNative.getInstance();
+ } catch (SecureNativeSDKIllegalStateException e) {
+ System.err.printf("Could not get SecureNative instance; %s%n", e);
}
+ SecureNativeContext context = securenative.fromHttpServletRequest(request).build();
+
+ EventOptions eventOptions = null;
+ try {
+ eventOptions = EventOptionsBuilder.builder(EventTypes.LOG_IN)
+ .userId("1234")
+ .userTraits("Your Name", "name@gmail.com", "+1234567890")
+ .context(context)
+ .properties(Maps.builder()
+ .put("prop1", "CUSTOM_PARAM_VALUE")
+ .put("prop2", true)
+ .put("prop3", 3)
+ .build())
+ .timestamp(new Date())
+ .build();
+ } catch (SecureNativeInvalidOptionsException e) {
+ e.printStackTrace();
+ }
+
+ VerifyResult verifyResult = null;
+ try {
+ verifyResult = securenative.verify(eventOptions);
+ } catch (SecureNativeInvalidOptionsException e) {
+ e.printStackTrace();
+ }
+
+ verifyResult.getRiskLevel(); // Low, Medium, High
+ verifyResult.getScore(); // Risk score: 0 -1 (0 - Very Low, 1 - Very High)
+ verifyResult.getTriggers(); // ["TOR", "New IP", "New City"]
+}
```
+## Webhook signature verification
+
+Apply our filter to verify the request is from us, example in spring:
+
+```java
+@RequestMapping("/webhook")
+public void webhookEndpoint(HttpServletRequest request, HttpServletResponse response) {
+ SecureNative securenative = null;
+ try {
+ securenative = SecureNative.getInstance();
+ } catch (SecureNativeSDKIllegalStateException e) {
+ System.err.printf("Could not get SecureNative instance; %s%n", e);
+ }
+
+ // Checks if request is verified
+ Boolean isVerified = securenative.verifyRequestPayload(request);
+}
+ ```
+## Extract proxy headers from cloud providers
+You can specify custom header keys to allow extraction of client ip from different providers.
+This example demonstrates the usage of proxy headers for ip extraction from Cloudflare.
+### Option 1: Using config file
+```properties
+SECURENATIVE_API_KEY="YOUR_API_KEY"
+SECURENATIVE_PROXY_HEADERS=["CF-Connecting-IP"]
+```
-## Verification events
+Initialize sdk as shown above.
-**Example**
+### Options 2: Using ConfigurationBuilder
```java
- @RequestMapping("/verify")
- public String verify(HttpServletRequest request, HttpServletResponse response) {
- try {
- secureNative = new SecureNative(API_KEY,new SecureNativeOptions());
- } catch (SecureNativeSDKException e) {
- e.printStackTrace();
- return "Api key is not valid";
- }
- secureNative.verify(new SnEvent.EventBuilder(EventTypes.LOG_IN.getType()).withUser(new User("1","Dan","Dan@Dan.dan")).withIp(ip).withRemoteIP(remoteIP).withUserAgent(userAgent).build());
-);
- return "verify";
- }
-
+try {
+ securenative = SecureNative.init(SecureNative.configBuilder()
+ .withApiKey("API_KEY")
+ .WithProxyHeaders(new ["CF-Connecting-IP"])
+ .build());
+} catch (SecureNativeSDKException e) {
+ e.printStackTrace();
+}
```
-## Flow events
-**Example**
+## Remove PII Data From Headers
-```java
- @RequestMapping("/flow")
- public String flow( HttpServletRequest request, HttpServletResponse response) {
- try {
- secureNative = new SecureNative(API_KEY,new SecureNativeOptions());
- } catch (SecureNativeSDKException e) {
- e.printStackTrace();
- return "Api key is not valid";
- }
- secureNative.flow(1,new SnEvent.EventBuilder(EventTypes.LOG_IN.getType()).withUser(new User("1","Dan","Dan@Dan.dan")).withIp(ip).withRemoteIP(remoteIP).withUserAgent(userAgent).build());
- return "flow";
- }
+By default, SecureNative SDK remove any known pii headers from the received request.
+We also support using custom pii headers and regex matching via configuration, for example:
+
+### Option 1: Using config file
+```properties
+SECURENATIVE_API_KEY="YOUR_API_KEY"
+SECURENATIVE_PII_HEADERS=["apiKey"]
```
-## Webhook entry filter
+Initialize sdk as shown above.
-Apply our filter to verify the request is from us, example in spring:
+### Options 2: Using ConfigurationBuilder
```java
-
- @Bean
- public FilterRegistrationBean filterWebhook() throws SecureNativeSDKException {
- FilterRegistrationBean registrationBean = new FilterRegistrationBean();
- VerifyWebHookMiddleware customURLFilter = new VerifyWebHookMiddleware("API KEY");
- registrationBean.setFilter(customURLFilter);
- return registrationBean;
- }
- ```
\ No newline at end of file
+try {
+ securenative = SecureNative.init(SecureNative.configBuilder()
+ .withApiKey("API_KEY")
+ .WithPiiRegexPattern("((?i)(http_auth_)(\\w+)?)")
+ .build());
+} catch (SecureNativeSDKException e) {
+ e.printStackTrace();
+}
+```
\ No newline at end of file
diff --git a/akka-http/README.md b/akka-http/README.md
deleted file mode 100644
index b162bf1..0000000
--- a/akka-http/README.md
+++ /dev/null
@@ -1,120 +0,0 @@
-# Akka Http for Secure Native
-This module adds Akka Http (scala) directives to Secure Native SDK in order to easily integrate with Akka Http applications.
-
-## Quickstart
-Download the latest version of the SDK to your favourite scala build system:
-
-#### Maven
-```
-
- com.securenative.java
- akka-http
- LATEST
-
-```
-
-#### Gradle
-`compile group: 'com.securenative.java', name: 'akka-http', version: 'LATEST'`
-
-#### SBT
-`libraryDependencies += "com.securenative.java" % "akka-http" % "LATEST"`
-
-### Initialize the SDK
-Create an instance (singleton) of the SecureNative object with your Api Key:
-```scala
-import com.securenative.snlogic.SecureNative
-import com.securenative.models.SecureNativeOptions
-
-object Main {
- val apiKey = "YOUR_API_KEY"
- implicit val snSdk: SecureNative = new SecureNative(apiKey, new SecureNativeOptions())
-}
-```
-
-### Tracking Events
-Secure Native let you send Async event that won't impact your regular flows, you may use our built in types (such as login, logout, etc...)
-or using your own custom events. Secure Native needs these events in order to learn the user behaviour.
-```scala
-object Main {
- val apiKey = "YOUR_API_KEY"
- implicit val snSdk: SecureNative = new SecureNative(apiKey, new SecureNativeOptions())
-
- def main(args: Array[String]): Unit = {
-
- def route = path("login") {
- post {
- // Add Secure Native event directive to automatically build your event from
- // the http request:
- SnDirectives.extractSnEvent(EventTypes.LOG_IN)(snSdk) { builder =>
-
- /* YOUR LOGIN BUSINESS LOGIC */
-
- val event = builder // You may change or add your custom fields to the builder
- .withUser(new User("jas723h2", "Jack Jefferson", "jackje@gmail.com"))
- .build() // Finally call the build method to create the event
-
- // Track the event using the SDK:
- snSdk.track(event)
- complete("SOMETHING")
- }
- }
- }
- }
-}
-```
-
-
-### Guarding Sensitive Operations
-In order to guard sensitive resources you can use the `verify` method, which will return the risk score of the current user.
-Allowing you to take a decision on how to act, for example when trying to delete project from github we can use the verify method before actually deleting the project
-when getting the risk score you can decide if you want to allow/block the deletion.
-
-```scala
-object Main {
- val apiKey = "YOUR_API_KEY"
- implicit val snSdk: SecureNative = new SecureNative(apiKey, new SecureNativeOptions())
-
- def main(args: Array[String]): Unit = {
-
- def route = path("project") {
- delete {
- SnDirectives.extractSnEvent(EventTypes.LOG_IN)(snSdk) { builder =>
- val event = builder
- .withUser(new User("jas723h2", "Jack Jefferson", "jackje@gmail.com"))
- .build() // Finally call the build method to create the event
-
- val riskScore = snSdk.verify(event)
-
- if (riskScore.riskLevel == "high") {
- /* Your blocking logic */
- } else {
- /* Your allowing logic */
- }s
- complete("SOMETHING")
- }
- }
- }
- }
-}
-```
-
-### Accepting Webhooks from Secure Native
-Secure Native can respond on real time to changes in risk score based on your sent events to get those real-time notification
-you can create a new endpoint so we can call it when something happens.
-In order to verify that the incoming request originated from Secure Native servers we have another directive that called `verifyWebhook`.
-```scala
-object Main {
- val apiKey = "YOUR_API_KEY"
- def main(args: Array[String]): Unit = {
-
- def route = path("riskscore") {
- post { // it has to be a post endpoint
- SnDirectives.verifyWebhook(apiKey) { body =>
- println(body) // the body will be passed only for Secure Native requests
- complete(body)
- }
- }
- }
- }
-}
-```
\ No newline at end of file
diff --git a/akka-http/pom.xml b/akka-http/pom.xml
deleted file mode 100644
index 9986d1f..0000000
--- a/akka-http/pom.xml
+++ /dev/null
@@ -1,102 +0,0 @@
-
-
-
- sdk-parent
- com.securenative.java
- 0.3.0
-
- 4.0.0
-
- akka
- jar
-
-
- 1.6
- 1.6
- 2.15.2
- 2.12
- 10.0.0
- 2.5.13
-
-
-
-
- org.scala-lang
- scala-library
- ${scala-library.version}.6
-
-
-
- com.securenative.java
- sdk-base
- 0.2.0
-
-
-
- com.typesafe.akka
- akka-http_${scala-library.version}
- ${akka-http.version}
- provided
-
-
-
- com.typesafe.akka
- akka-stream_${scala-library.version}
- ${akka.version}
- provided
-
-
-
-
-
-
- net.alchim31.maven
- scala-maven-plugin
- 3.2.2
-
-
-
- compile
-
-
-
- attach-javadocs
-
- doc-jar
-
-
-
- attach-sources
-
- add-source
-
-
-
-
-
- maven-assembly-plugin
-
-
-
- your.MainClass
-
-
-
- jar-with-dependencies
-
-
-
-
- make-assembly
- package
-
- single
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/akka-http/src/main/scala/com/securenative/java/akka/SnDirectives.scala b/akka-http/src/main/scala/com/securenative/java/akka/SnDirectives.scala
deleted file mode 100644
index b5809f3..0000000
--- a/akka-http/src/main/scala/com/securenative/java/akka/SnDirectives.scala
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.securenative.java.akka
-
-import akka.http.scaladsl.model.HttpRequest
-import akka.http.scaladsl.server.directives.{BasicDirectives, MarshallingDirectives}
-import akka.http.scaladsl.server.{Directive1, ValidationRejection}
-import com.securenative.models.SnEvent.EventBuilder
-import com.securenative.models.{EventTypes, SnEvent}
-import com.securenative.snlogic.{SecureNative, Utils}
-
-object SnDirectives extends BasicDirectives with MarshallingDirectives {
- private val DEFAULT_IP = "127.0.0.1"
- private val utils = new Utils()
-
- def verifyWebhook(secret: String): Directive1[String] = extractRequest.flatMap { request =>
- entity(as[String]).flatMap { body =>
- val headerSig = request.getHeader(utils.SN_HEADER)
-
- if (!headerSig.isPresent) {
- cancelRejection(ValidationRejection(s"Failed to extract ${utils.SN_HEADER} header from the request, this request cannot be validated and probably not sent from SecureNative."))
- }
-
- if (utils.isVerifiedSnRequest(body, headerSig.get().value(), secret)) {
- provide(body)
- } else {
- provide(null)
- }
- }
- }
-
- def extractSnEvent(eventType: EventTypes)(implicit sdk: SecureNative): Directive1[EventBuilder] = extractRequest.flatMap { request =>
- val builder = fromRequest(eventType, request)
- provide(builder)
- }
-
- private def fromRequest(eventName: EventTypes, httpRequest: HttpRequest)(implicit snSdk: SecureNative): SnEvent.EventBuilder = {
- val headers = Map(httpRequest.headers.map { h => h.name.toLowerCase -> h.value }: _*)
- val cookies = Map(httpRequest.cookies.map { c => c.name -> c.value }: _*)
-
- val ua = headers.getOrElse("user-agent", "")
-
- val utils = new Utils()
- val ip = utils.remoteIpFromRequest(name => headers.getOrElse(name, DEFAULT_IP))
- val remoteIp = headers.getOrElse("remote-address", DEFAULT_IP)
- val snCookie = cookies.getOrElse(snSdk.getDefaultCookieName, headers.getOrElse(utils.SN_HEADER, ""))
-
- val builder = new SnEvent.EventBuilder(eventName.getType)
- .withCookieValue(snCookie)
- .withIp(ip)
- .withRemoteIP(remoteIp)
- .withUserAgent(ua)
-
- builder
- }
-}
diff --git a/pom.xml b/pom.xml
index 4ce04af..61a01ee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,33 +1,26 @@
-
-
- 4.0.0
+
+
+ 4.0.0
com.securenative.java
- sdk-parent
- 0.3.0
+ securenative-java
+ jar
+ 0.5.7
https://github.com/securenative/securenative-java
+
+ ${project.groupId}:${project.artifactId}:${project.version}
+ SecureNative user monitoring sdk.
+
The MIT License
https://opensource.org/licenses/MIT
-
-
- Nevo Elmalem
- nevo@securenative.com
- securenative
- http://www.securenative.com
-
-
-
- scm:git:git://github.com/securenative/securenative-java.git
- scm:git:ssh://github.com:securenative/securenative-java.git
- http://github.com/securenative/securenative-java/tree/master
-
+
+
ossrh
https://oss.sonatype.org/content/repositories/snapshots
@@ -37,6 +30,161 @@
https://oss.sonatype.org/service/local/staging/deploy/maven2
+
+
+
+ SecureNative Dev Team
+ info@securenative.com
+ SecureNative
+ https://www.securenative.com
+
+
+
+
+ scm:git:git://github.com/securenative/securenative-java.git
+ scm:git:ssh://github.com:securenative/securenative-java.git
+ http://github.com/securenative/securenative-java/tree/master
+
+
+
+
+ deploy
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 2.4
+
+
+ attach-sources
+
+ jar-no-fork
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 2.10.4
+
+
+ attach-javadocs
+
+ jar
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-gpg-plugin
+ 1.6
+
+
+ sign-artifacts
+ verify
+
+ sign
+
+
+
+
+ --pinentry-mode
+ loopback
+
+
+
+
+
+
+
+
+
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.11.0
+
+
+ javax.servlet
+ javax.servlet-api
+ 4.0.1
+ provided
+
+
+ org.apache.maven
+ maven-model
+ 3.0.2
+
+
+ org.slf4j
+ slf4j-api
+ 1.7.12
+
+
+ com.squareup.okhttp3
+ okhttp
+ 3.14.8
+
+
+ org.mockito
+ mockito-core
+ 2.21.0
+ test
+
+
+ org.springframework
+ spring-test
+ 5.2.6.RELEASE
+ test
+
+
+ org.assertj
+ assertj-core
+ 3.15.0
+ test
+
+
+ com.squareup.okhttp3
+ mockwebserver
+ 3.14.8
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.7.0-M1
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.7.0-M1
+ test
+
+
+ org.junit-pioneer
+ junit-pioneer
+ 0.5.1
+ test
+
+
+ org.skyscreamer
+ jsonassert
+ 1.5.0
+ test
+
+
+
@@ -46,6 +194,20 @@
8
8
+ 3.8.1
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.4
+
+
+
+ true
+ true
+
+
+
maven-deploy-plugin
@@ -63,7 +225,7 @@
org.sonatype.plugins
nexus-staging-maven-plugin
- 1.6.7
+ 1.6.8
true
ossrh
@@ -73,80 +235,74 @@
org.apache.maven.plugins
- maven-source-plugin
- 3.0.1
+ maven-gpg-plugin
+ 1.6
- attach-sources
+ sign-artifacts
+ verify
- jar
+ sign
org.apache.maven.plugins
- maven-javadoc-plugin
+ maven-dependency-plugin
- attach-javadocs
+ copy-dependencies
+ prepare-package
- jar
+ copy-dependencies
+
+ ${project.build.directory}/lib
+ false
+ false
+ true
+
org.apache.maven.plugins
- maven-gpg-plugin
- 1.6
-
-
- sign-artifacts
- verify
-
- sign
-
-
-
-
-
- maven-assembly-plugin
+ maven-surefire-plugin
+ 3.0.0-M3
-
-
- your.MainClass
-
-
-
- jar-with-dependencies
-
+ false
+ true
+ false
-
-
- make-assembly
- package
-
- single
-
-
-
+
+ org.jacoco
+ jacoco-maven-plugin
+ 0.8.3
+
+
+
+ prepare-agent
+
+
+
+ report
+ test
+
+ report
+
+
+
+
-
- sdk-base
- spring
- akka-http
-
- pom
-
+ UTF-8
+ UTF-8
1.6
1.6
0.2.3
-
-
-
\ No newline at end of file
+
diff --git a/sdk-base/pom.xml b/sdk-base/pom.xml
deleted file mode 100644
index 57c0248..0000000
--- a/sdk-base/pom.xml
+++ /dev/null
@@ -1,194 +0,0 @@
-
-
-
- sdk-parent
- com.securenative.java
- 0.3.0
-
- sdk-base
- 4.0.0
-
- ${project.artifactId}
- Secure Native SDK in java
- https://github.com/securenative/securenative-java
-
-
- The MIT License
- https://opensource.org/licenses/MIT
-
-
-
-
- Nevo Elmalem
- nevo@securenative.com
- securenative
- http://www.securenative.com
-
-
-
- scm:git:git://github.com/securenative/securenative-java.git
- scm:git:ssh://github.com:securenative/securenative-java.git
- http://github.com/securenative/securenative-java/tree/master
-
-
-
- ossrh
- https://oss.sonatype.org/content/repositories/snapshots
-
-
- ossrh
- https://oss.sonatype.org/service/local/staging/deploy/maven2
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
- 8
- 8
-
-
-
- maven-deploy-plugin
- 2.8.2
-
-
- default-deploy
- deploy
-
- deploy
-
-
-
-
-
- org.sonatype.plugins
- nexus-staging-maven-plugin
- 1.6.7
- true
-
- ossrh
- https://oss.sonatype.org/
- true
-
-
-
- org.apache.maven.plugins
- maven-source-plugin
- 3.0.1
-
-
- attach-sources
-
- jar
-
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
-
-
- attach-javadocs
-
- jar
-
-
-
-
-
- org.apache.maven.plugins
- maven-gpg-plugin
- 1.6
-
-
- sign-artifacts
- verify
-
- sign
-
-
-
-
-
- maven-assembly-plugin
-
-
-
- your.MainClass
-
-
-
- jar-with-dependencies
-
-
-
-
- make-assembly
- package
-
- single
-
-
-
-
-
-
-
-
-
- com.fasterxml.jackson.core
- jackson-databind
- 2.9.9.2
-
-
- junit
- junit
- 4.12
- test
-
-
- org.mockito
- mockito-core
- 2.21.0
- test
-
-
- org.apache.maven
- maven-model
- 3.0.2
-
-
- org.asynchttpclient
- async-http-client
- 2.2.0
-
-
- net.bytebuddy
- byte-buddy-agent
- 1.10.1
- compile
-
-
- org.reflections
- reflections
- 0.9.11
-
-
- net.bytebuddy
- byte-buddy
- 1.9.16
-
-
- org.apache.logging.log4j
- log4j-api
- 2.11.2
-
-
-
-
\ No newline at end of file
diff --git a/sdk-base/src/main/java/com/securenative/models/ActionType.java b/sdk-base/src/main/java/com/securenative/models/ActionType.java
deleted file mode 100644
index 122f564..0000000
--- a/sdk-base/src/main/java/com/securenative/models/ActionType.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.securenative.models;
-
-public enum ActionType {
- ALLOW,
- BLOCK,
- REDIRECT,
- MFA
-}
diff --git a/sdk-base/src/main/java/com/securenative/models/Event.java b/sdk-base/src/main/java/com/securenative/models/Event.java
deleted file mode 100644
index 4bc99b8..0000000
--- a/sdk-base/src/main/java/com/securenative/models/Event.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.securenative.models;
-
-import java.util.Map;
-
-public interface Event {
- String getEventType();
- String getCid();
- String getVid();
- String getFp();
- String getIp();
- String getRemoteIP();
- String getUserAgent();
- User getUser();
- Device getDevice();
- String getCookieName();
- String getCookieValue();
- Map getParams();
-}
diff --git a/sdk-base/src/main/java/com/securenative/models/EventOptions.java b/sdk-base/src/main/java/com/securenative/models/EventOptions.java
deleted file mode 100644
index 8d98417..0000000
--- a/sdk-base/src/main/java/com/securenative/models/EventOptions.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package com.securenative.models;
-
-import java.util.AbstractMap;
-import java.util.List;
-
-public class EventOptions {
- private String ip;
- private String userAgent;
- private String remoteIP;
- private User user;
- private Device device;
- private String cookieName;
- private String cookieValue;
- private String eventType;
- private List > params;
-
- public EventOptions(String ip, String remoteIP, String userAgent, Device device, User user, String cookieName, String cookieValue, String eventType, List> params) {
- this.ip = ip;
- this.remoteIP = remoteIP;
- this.userAgent = userAgent;
- this.device = device;
- this.user = user;
- this.cookieName = cookieName;
- this.eventType = eventType;
- this.params = params;
- this.cookieValue = cookieValue;
- }
-
- public EventOptions(String ip, String userAgent,String eventType) {
- this.ip = ip;
- this.userAgent = userAgent;
- this.eventType = eventType;
- }
-
-
- public String getIp() {
- return ip;
- }
-
- public void setIp(String ip) {
- this.ip = ip;
- }
-
- public String getUserAgent() {
- return userAgent;
- }
-
- public void setUserAgent(String userAgent) {
- this.userAgent = userAgent;
- }
-
- public String getRemoteIP() {
- return remoteIP;
- }
-
- public void setRemoteIP(String remoteIP) {
- this.remoteIP = remoteIP;
- }
-
- public User getUser() {
- return user;
- }
-
- public void setUser(User user) {
- this.user = user;
- }
-
- public Device getDevice() {
- return device;
- }
-
- public void setDevice(Device device) {
- this.device = device;
- }
-
- public String getCookieName() {
- return cookieName;
- }
-
- public void setCookieName(String cookieName) {
- this.cookieName = cookieName;
- }
- public String getEventType() {
- return eventType;
- }
-
- public void setEventType(String eventType) {
- this.eventType = eventType;
- }
-
- public List> getParams() {
- return params;
- }
-
- public void setParams(List> params) {
- this.params = params;
- }
-
- public String getCookieValue() {
- return cookieValue;
- }
-
- public void setCookieValue(String cookieValue) {
- this.cookieValue = cookieValue;
- }
-
-
-
-
-
-}
diff --git a/sdk-base/src/main/java/com/securenative/models/Message.java b/sdk-base/src/main/java/com/securenative/models/Message.java
deleted file mode 100644
index c665d39..0000000
--- a/sdk-base/src/main/java/com/securenative/models/Message.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.securenative.models;
-
-public class Message {
- private Event snEvent;
- private String url;
-
- public Message(Event snEvent, String url) {
- this.snEvent = snEvent;
- this.url = url;
- }
-
- public Event getSnEvent() {
- return snEvent;
- }
-
- public void setSnEvent(Event snEvent) {
- this.snEvent = snEvent;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-}
diff --git a/sdk-base/src/main/java/com/securenative/models/RiskLevel.java b/sdk-base/src/main/java/com/securenative/models/RiskLevel.java
deleted file mode 100644
index e6199b8..0000000
--- a/sdk-base/src/main/java/com/securenative/models/RiskLevel.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.securenative.models;
-
-public enum RiskLevel {
- high,
- low,
- medium
-}
\ No newline at end of file
diff --git a/sdk-base/src/main/java/com/securenative/models/SecureNativeOptions.java b/sdk-base/src/main/java/com/securenative/models/SecureNativeOptions.java
deleted file mode 100644
index ea6485c..0000000
--- a/sdk-base/src/main/java/com/securenative/models/SecureNativeOptions.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package com.securenative.models;
-
-public class SecureNativeOptions {
- private String apiUrl;
- private int interval;
- private long maxEvents;
- private long timeout;
- private Boolean autoSend;
- private Boolean isSdkEnabled;
- private Boolean debugMode;
-
- public SecureNativeOptions(){
- this.autoSend = true;
- this.isSdkEnabled = true;
- this.debugMode = false;
- }
-
- public SecureNativeOptions(String apiUrl, int interval, long maxEvents, int timeout, boolean autoSend, boolean isSdkEnabled, boolean debugMode) {
- this.interval = interval;
- this.maxEvents = maxEvents;
- this.apiUrl = apiUrl;
- this.timeout = timeout;
- this.autoSend = autoSend;
- this.isSdkEnabled = isSdkEnabled;
- this.debugMode = debugMode;
- }
-
- public SecureNativeOptions(String apiUrl, int interval, long maxEvents, int timeout) {
- this.interval = interval;
- this.maxEvents = maxEvents;
- this.apiUrl = apiUrl;
- this.timeout = timeout;
- this.autoSend = true;
- this.isSdkEnabled = true;
- this.debugMode = false;
-
- }
-
- public String getApiUrl() {
- return apiUrl;
- }
-
- public void setApiUrl(String apiUrl) {
- this.apiUrl = apiUrl;
- }
-
- public int getInterval() {
- return interval;
- }
-
- public void setInterval(int interval) {
- this.interval = interval;
- }
-
- public long getMaxEvents() {
- return maxEvents;
- }
-
- public void setMaxEvents(long maxEvents) {
- this.maxEvents = maxEvents;
- }
-
- public long getTimeout() {
- return timeout;
- }
-
- public void setTimeout(long timeout) {
- this.timeout = timeout;
- }
-
- public Boolean isAutoSend() {
- return autoSend;
- }
-
- public void setAutoSend(Boolean autoSend) {
- this.autoSend = autoSend;
- }
-
- public Boolean getSdkEnabled() {
- return isSdkEnabled;
- }
-
- public void setSdkEnabled(Boolean sdkEnabled) {
- isSdkEnabled = sdkEnabled;
- }
-
- public Boolean getDebugMode() {
- return debugMode;
- }
-
- public void setDebugMode(Boolean debugMode) {
- this.debugMode = debugMode;
- }
-}
diff --git a/sdk-base/src/main/java/com/securenative/models/SnEvent.java b/sdk-base/src/main/java/com/securenative/models/SnEvent.java
deleted file mode 100644
index 5c53df2..0000000
--- a/sdk-base/src/main/java/com/securenative/models/SnEvent.java
+++ /dev/null
@@ -1,287 +0,0 @@
-package com.securenative.models;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.securenative.exceptions.SecureNativeSDKException;
-import com.securenative.snlogic.Utils;
-
-import java.nio.charset.Charset;
-import java.time.Instant;
-import java.util.*;
-
-public class SnEvent implements Event {
- public enum ParamsKeys {
- PARAM_1("param_1"),
- PARAM_2("param_2"),
- PARAM_3("param_3"),
- PARAM_4("param_4"),
- PARAM_5("param_5"),
- PARAM_6("param_6");
-
- private String param;
-
- ParamsKeys(String param) {
- this.param = param;
- }
- @Override
- public String toString(){
- return this.param;
- }
- }
- protected static Set paramKeys = new HashSet(Arrays.asList(ParamsKeys.PARAM_1.name(),ParamsKeys.PARAM_2.name(),ParamsKeys.PARAM_3.name(),ParamsKeys.PARAM_4.name(),ParamsKeys.PARAM_5.name(),ParamsKeys.PARAM_6.name()));
-
- private final static Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
-
- private String eventType;
- private String cid;
- private String vid;
- private String fp;
- private String ip;
- private String remoteIP;
- private String userAgent;
- private User user;
- private long ts;
- private Device device;
- private String CookieName;
- private String CookieValue;
- private Map params;
-
- public static class EventBuilder {
- private String eventType;
- private String cid;
- private String fp;
- private String ip;
- private String remoteIP;
- private String userAgent;
- private User user;
- private Device device;
- private String cookieName;
- private String cookieValue;
- private Utils utils;
- private Map params;
-
-
- public EventBuilder(String eventType) {
- this.eventType = eventType;
- this.utils = new Utils();
- }
-
-
- public EventBuilder withCid(String cid) {
- this.cid = cid;
- return this;
- }
-
- public EventBuilder withFp(String fp) {
- this.fp = fp;
- return this;
- }
-
- public EventBuilder withIp(String ip) {
- this.ip = ip;
- return this;
- }
-
- public EventBuilder withRemoteIP(String remoteIP) {
- this.remoteIP = remoteIP;
- return this;
- }
-
- public EventBuilder withUserAgent(String userAgent) {
- this.userAgent = userAgent;
- return this;
- }
-
- public EventBuilder withUser(User user) {
- this.user = user;
- return this;
- }
-
-
- public EventBuilder withDevice(Device device) {
- this.device = device;
- return this;
- }
-
- public EventBuilder withCookieValue(String cookieBase64Value) {
- if (this.utils.isNullOrEmpty(cookieBase64Value)) {
- return this;
- }
- String decodedCookie = new String(Base64.getDecoder().decode(cookieBase64Value), DEFAULT_CHARSET);
- ClientFingerPrint clientFP = this.parseClientFP(decodedCookie);
- this.cookieValue = cookieBase64Value;
- this.cid = clientFP != null ? clientFP.getCid() : "";
- this.fp = clientFP != null ? clientFP.getFp() : "";
- return this;
- }
-
- public EventBuilder withParams(Map params) throws SecureNativeSDKException{
- if (params == null){
- params = new HashMap<>();
- params.put(ParamsKeys.PARAM_1.toString(),"");
- params.put(ParamsKeys.PARAM_2.toString(),"");
- params.put(ParamsKeys.PARAM_3.toString(),"");
- params.put(ParamsKeys.PARAM_4.toString(),"");
- params.put(ParamsKeys.PARAM_5.toString(),"");
- params.put(ParamsKeys.PARAM_6.toString(),"");
- }
- else{
- Iterator i = params.keySet().iterator();
- while(i.hasNext()){
- if(!paramKeys.contains(i)){
- throw new SecureNativeSDKException("Key must be of param_1..param_6");
- }
- }
- }
- this.params = params;
- return this;
- }
-
- public Event build() {
- SnEvent event = new SnEvent();
- event.eventType = this.eventType;
- event.cid = this.cid;
- event.vid = UUID.randomUUID().toString();
- event.fp = this.fp;
- event.ip = this.ip;
- event.remoteIP = this.remoteIP;
- event.userAgent = this.userAgent;
- event.user = this.user;
- event.ts = Instant.now().getEpochSecond();
- event.device = this.device;
- event.CookieName = this.cookieName;
- event.CookieValue = this.cookieValue;
- event.params = this.params;
- return event;
- }
-
- private ClientFingerPrint parseClientFP(String json) {
- if (this.utils.isNullOrEmpty(json)) {
- return null;
- }
- ObjectMapper mapper = new ObjectMapper();
- try {
- return mapper.readValue(json, ClientFingerPrint.class);
- } catch (Exception e) {
- return null;
- }
- }
-
- public String base64decode(String encodedString) {
- if (this.utils.isNullOrEmpty(encodedString)) {
- return "";
- }
- return String.valueOf(Base64.getDecoder().decode(encodedString));
- }
- }
-
-
- private SnEvent() {
-
- }
-
- public String getEventType() {
- return eventType;
- }
-
- public void setEventType(String eventType) {
- this.eventType = eventType;
- }
-
- public String getCid() {
- return cid;
- }
-
- public void setCid(String cid) {
- this.cid = cid;
- }
-
- public String getVid() {
- return vid;
- }
-
- public void setVid(String vid) {
- this.vid = vid;
- }
-
- public String getFp() {
- return fp;
- }
-
- public void setFp(String fp) {
- this.fp = fp;
- }
-
- public String getIp() {
- return ip;
- }
-
- public void setIp(String ip) {
- this.ip = ip;
- }
-
- public String getRemoteIP() {
- return remoteIP;
- }
-
- public void setRemoteIP(String remoteIP) {
- this.remoteIP = remoteIP;
- }
-
- public String getUserAgent() {
- return userAgent;
- }
-
- public void setUserAgent(String userAgent) {
- this.userAgent = userAgent;
- }
-
- public User getUser() {
- return user;
- }
-
- public void setUser(User user) {
- this.user = user;
- }
-
- public long getTs() {
- return ts;
- }
-
- public void setTs(long ts) {
- this.ts = ts;
- }
-
- public Device getDevice() {
- return device;
- }
-
- public void setDevice(Device device) {
- this.device = device;
- }
-
-
- public String getCookieName() {
- return CookieName;
- }
-
- public void setCookieName(String cookieName) {
- CookieName = cookieName;
- }
-
- public String getCookieValue() {
- return CookieValue;
- }
-
- public void setCookieValue(String cookieValue) {
- CookieValue = cookieValue;
- }
-
-
- public Map getParams() {
- return params;
- }
-
- public void setParams(Map params) {
- this.params = params;
- }
-}
diff --git a/sdk-base/src/main/java/com/securenative/models/User.java b/sdk-base/src/main/java/com/securenative/models/User.java
deleted file mode 100644
index 686bb2b..0000000
--- a/sdk-base/src/main/java/com/securenative/models/User.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.securenative.models;
-
-public class User {
- private String id;
- private String name;
- private String email;
-
-
- public User(String id, String name, String email) {
- this.id = id;
- this.name = name;
- this.email = email;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getEmail() {
- return email;
- }
-
- public void setEmail(String email) {
- this.email = email;
- }
-}
diff --git a/sdk-base/src/main/java/com/securenative/snlogic/Agent.java b/sdk-base/src/main/java/com/securenative/snlogic/Agent.java
deleted file mode 100644
index a9cc32b..0000000
--- a/sdk-base/src/main/java/com/securenative/snlogic/Agent.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package com.securenative.snlogic;
-
-import net.bytebuddy.ByteBuddy;
-import net.bytebuddy.agent.ByteBuddyAgent;
-import net.bytebuddy.dynamic.loading.ClassReloadingStrategy;
-import net.bytebuddy.implementation.MethodDelegation;
-import org.apache.logging.log4j.util.ProcessIdUtil;
-import org.reflections.Reflections;
-import org.reflections.scanners.ResourcesScanner;
-
-
-import java.lang.reflect.Field;
-import java.util.*;
-import java.util.regex.Pattern;
-
-import static net.bytebuddy.matcher.ElementMatchers.*;
-
-public class Agent {
-
-
- public static String getPomXmlPaths() {
- Reflections reflections = new Reflections(new ResourcesScanner());
- Set resources = reflections.getResources(Pattern.compile(".*jar"));
- return resources.toString();
- }
-
- public static void changeClassMethod(Class cls, Class cls1, String methodName) {
- ByteBuddyAgent.install();
- new ByteBuddy()
- .redefine(cls)
- .method(named(methodName)
- .and(isDeclaredBy(cls)
- .and(returns(String.class))))
- .intercept(MethodDelegation.to(cls1))
- .make()
- .load(cls.getClassLoader(), ClassReloadingStrategy.fromInstalledAgent())
- .getLoaded();
- }
-
- public static Set scanAllClasses() {
- Field f;
- Set locations = new HashSet<>();
- try {
- f = ClassLoader.class.getDeclaredField("classes");
- f.setAccessible(true);
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- List classes = Collections.unmodifiableList((Vector) f.get(classLoader));
- for (Class next :classes){
- java.net.URL location = next.getResource('/' + next.getName().replace('.',
- '/') + ".class");
- if (location != null && !Utils.isNullOrEmpty(location.getPath())){
- locations.add(location.getPath());
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return locations;
-
- }
-
- public static String readVersionInfoInManifest() {
- Set locations = new HashSet<>();
- //build an object whose class is in the target jar
- ProcessIdUtil object = new ProcessIdUtil();
- //navigate from its class object to a package object
- Package objPackage = object.getClass().getPackage();
- //examine the package object
- String name = objPackage.getSpecificationTitle();
- String version = objPackage.getSpecificationVersion();
- //some jars may use 'Implementation Version' entries in the manifest instead
- return "Package name: " + name + ", Package version: " + version;
- }
-}
diff --git a/sdk-base/src/main/java/com/securenative/snlogic/EventManager.java b/sdk-base/src/main/java/com/securenative/snlogic/EventManager.java
deleted file mode 100644
index 1fcf82f..0000000
--- a/sdk-base/src/main/java/com/securenative/snlogic/EventManager.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.securenative.snlogic;
-
-
-import com.securenative.models.Event;
-import com.securenative.models.RiskResult;
-
-public interface EventManager {
- RiskResult sendSync(Event event, String requestUrl);
- void sendAsync(Event event, String url);
-
-}
diff --git a/sdk-base/src/main/java/com/securenative/snlogic/ISDK.java b/sdk-base/src/main/java/com/securenative/snlogic/ISDK.java
deleted file mode 100644
index dfa1317..0000000
--- a/sdk-base/src/main/java/com/securenative/snlogic/ISDK.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.securenative.snlogic;
-
-
-import com.securenative.models.Event;
-import com.securenative.models.RiskResult;
-
-public interface ISDK {
- void track(Event event) throws Exception;
- RiskResult verify(Event event);
- RiskResult flow(long flowId, Event event);
- String getApiKey();
- String getDefaultCookieName();
-}
diff --git a/sdk-base/src/main/java/com/securenative/snlogic/ImpotentLogger.java b/sdk-base/src/main/java/com/securenative/snlogic/ImpotentLogger.java
deleted file mode 100644
index 93781c4..0000000
--- a/sdk-base/src/main/java/com/securenative/snlogic/ImpotentLogger.java
+++ /dev/null
@@ -1,310 +0,0 @@
-package com.securenative.snlogic;
-
-import org.slf4j.Marker;
-
-public class ImpotentLogger implements org.slf4j.Logger {
- @Override
- public String getName() {
- return null;
- }
-
- @Override
- public boolean isTraceEnabled() {
- return false;
- }
-
- @Override
- public void trace(String s) {
-
- }
-
- @Override
- public void trace(String s, Object o) {
-
- }
-
- @Override
- public void trace(String s, Object o, Object o1) {
-
- }
-
- @Override
- public void trace(String s, Object... objects) {
-
- }
-
- @Override
- public void trace(String s, Throwable throwable) {
-
- }
-
- @Override
- public boolean isTraceEnabled(Marker marker) {
- return false;
- }
-
- @Override
- public void trace(Marker marker, String s) {
-
- }
-
- @Override
- public void trace(Marker marker, String s, Object o) {
-
- }
-
- @Override
- public void trace(Marker marker, String s, Object o, Object o1) {
-
- }
-
- @Override
- public void trace(Marker marker, String s, Object... objects) {
-
- }
-
- @Override
- public void trace(Marker marker, String s, Throwable throwable) {
-
- }
-
- @Override
- public boolean isDebugEnabled() {
- return false;
- }
-
- @Override
- public void debug(String s) {
-
- }
-
- @Override
- public void debug(String s, Object o) {
-
- }
-
- @Override
- public void debug(String s, Object o, Object o1) {
-
- }
-
- @Override
- public void debug(String s, Object... objects) {
-
- }
-
- @Override
- public void debug(String s, Throwable throwable) {
-
- }
-
- @Override
- public boolean isDebugEnabled(Marker marker) {
- return false;
- }
-
- @Override
- public void debug(Marker marker, String s) {
-
- }
-
- @Override
- public void debug(Marker marker, String s, Object o) {
-
- }
-
- @Override
- public void debug(Marker marker, String s, Object o, Object o1) {
-
- }
-
- @Override
- public void debug(Marker marker, String s, Object... objects) {
-
- }
-
- @Override
- public void debug(Marker marker, String s, Throwable throwable) {
-
- }
-
- @Override
- public boolean isInfoEnabled() {
- return false;
- }
-
- @Override
- public void info(String s) {
-
- }
-
- @Override
- public void info(String s, Object o) {
-
- }
-
- @Override
- public void info(String s, Object o, Object o1) {
-
- }
-
- @Override
- public void info(String s, Object... objects) {
-
- }
-
- @Override
- public void info(String s, Throwable throwable) {
-
- }
-
- @Override
- public boolean isInfoEnabled(Marker marker) {
- return false;
- }
-
- @Override
- public void info(Marker marker, String s) {
-
- }
-
- @Override
- public void info(Marker marker, String s, Object o) {
-
- }
-
- @Override
- public void info(Marker marker, String s, Object o, Object o1) {
-
- }
-
- @Override
- public void info(Marker marker, String s, Object... objects) {
-
- }
-
- @Override
- public void info(Marker marker, String s, Throwable throwable) {
-
- }
-
- @Override
- public boolean isWarnEnabled() {
- return false;
- }
-
- @Override
- public void warn(String s) {
-
- }
-
- @Override
- public void warn(String s, Object o) {
-
- }
-
- @Override
- public void warn(String s, Object... objects) {
-
- }
-
- @Override
- public void warn(String s, Object o, Object o1) {
-
- }
-
- @Override
- public void warn(String s, Throwable throwable) {
-
- }
-
- @Override
- public boolean isWarnEnabled(Marker marker) {
- return false;
- }
-
- @Override
- public void warn(Marker marker, String s) {
-
- }
-
- @Override
- public void warn(Marker marker, String s, Object o) {
-
- }
-
- @Override
- public void warn(Marker marker, String s, Object o, Object o1) {
-
- }
-
- @Override
- public void warn(Marker marker, String s, Object... objects) {
-
- }
-
- @Override
- public void warn(Marker marker, String s, Throwable throwable) {
-
- }
-
- @Override
- public boolean isErrorEnabled() {
- return false;
- }
-
- @Override
- public void error(String s) {
-
- }
-
- @Override
- public void error(String s, Object o) {
-
- }
-
- @Override
- public void error(String s, Object o, Object o1) {
-
- }
-
- @Override
- public void error(String s, Object... objects) {
-
- }
-
- @Override
- public void error(String s, Throwable throwable) {
-
- }
-
- @Override
- public boolean isErrorEnabled(Marker marker) {
- return false;
- }
-
- @Override
- public void error(Marker marker, String s) {
-
- }
-
- @Override
- public void error(Marker marker, String s, Object o) {
-
- }
-
- @Override
- public void error(Marker marker, String s, Object o, Object o1) {
-
- }
-
- @Override
- public void error(Marker marker, String s, Object... objects) {
-
- }
-
- @Override
- public void error(Marker marker, String s, Throwable throwable) {
-
- }
-}
diff --git a/sdk-base/src/main/java/com/securenative/snlogic/Logger.java b/sdk-base/src/main/java/com/securenative/snlogic/Logger.java
deleted file mode 100644
index c08f0b1..0000000
--- a/sdk-base/src/main/java/com/securenative/snlogic/Logger.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.securenative.snlogic;
-
-import org.slf4j.LoggerFactory;
-
-public class Logger{
- private static org.slf4j.Logger logger = new ImpotentLogger();
-
- public static org.slf4j.Logger getLogger() {
- return logger;
- }
-
- public static void setLoggingEnable(boolean isLoggingEnabledInput) {
- if(isLoggingEnabledInput){
- logger = LoggerFactory.getLogger(Logger.class);
- logger.info("Secure Native logger is enabled");
- return;
- }
- logger = new ImpotentLogger();
-
- }
-}
-
diff --git a/sdk-base/src/main/java/com/securenative/snlogic/SecureNative.java b/sdk-base/src/main/java/com/securenative/snlogic/SecureNative.java
deleted file mode 100644
index 04e48dd..0000000
--- a/sdk-base/src/main/java/com/securenative/snlogic/SecureNative.java
+++ /dev/null
@@ -1,119 +0,0 @@
-package com.securenative.snlogic;
-
-
-import com.securenative.exceptions.SecureNativeSDKException;
-import com.securenative.models.Event;
-import com.securenative.models.RiskResult;
-import com.securenative.models.SecureNativeOptions;
-
-public class SecureNative implements ISDK {
- private final String API_URL = "https://api.securenative.com/collector/api/v1";
- private final int INTERVAL = 1000;
- private final int MAX_EVENTS = 1000;
- private final Boolean AUTO_SEND = true;
- private final Boolean SDK_ENABLED = true;
- private final Boolean DEBUG_LOG = false;
- private final int DEFAULT_TIMEOUT = 1500;
-
- private EventManager eventManager;
- private SecureNativeOptions snOptions;
- private String apiKey;
- private Utils utils;
-
- private static ISDK secureNative = null;
-
-
- private SecureNative(String apiKey, SecureNativeOptions options) throws SecureNativeSDKException {
- this.utils = new Utils();
- if (this.utils.isNullOrEmpty(apiKey)) {
- throw new SecureNativeSDKException("You must pass your SecureNative api key");
- }
- this.apiKey = apiKey;
- this.snOptions = initializeOptions(options);
- this.eventManager = new SnEventManager(apiKey,this.snOptions);
- Logger.setLoggingEnable(this.snOptions.getDebugMode());
- }
-
-
- public static ISDK init(String apiKey, SecureNativeOptions options) throws SecureNativeSDKException {
- if (secureNative == null) {
- secureNative = new SecureNative(apiKey, options);
- if(options != null && options.getDebugMode() != null){
- Logger.setLoggingEnable(options.getDebugMode());
- }
- return secureNative;
- }
- throw new SecureNativeSDKException("This SDK was already initialized");
- }
-
- public static ISDK getInstance() throws SecureNativeSDKException {
- if (secureNative == null) {
- throw new SecureNativeSDKException("Secure Native SDK wasnt initialized yet, please call init first");
- }
- return secureNative;
- }
-
- private SecureNativeOptions initializeOptions(SecureNativeOptions options) {
- if (options == null) {
- Logger.getLogger().info("SecureNative options are empty, initializing default values");
- options = new SecureNativeOptions();
- }
- if (this.utils.isNullOrEmpty(options.getApiUrl())) {
- options.setApiUrl(API_URL);
- }
-
- if (options.getInterval() == 0) {
- options.setInterval(INTERVAL);
- }
-
- if (options.getMaxEvents() == 0) {
- options.setMaxEvents(MAX_EVENTS);
- }
- if (options.isAutoSend() == null) {
- options.setAutoSend(AUTO_SEND);
- }
- if (options.getSdkEnabled() == null){
- options.setSdkEnabled(SDK_ENABLED);
- }
- if (options.getDebugMode() == null){
- options.setSdkEnabled(DEBUG_LOG);
- }
- if(options.getTimeout() == 0){
- options.setTimeout(DEFAULT_TIMEOUT);
- }
- if(options.getDebugMode() == null){
- options.setDebugMode(false);
- }
-
- return options;
- }
-
- @Override
- public String getDefaultCookieName(){
- return this.utils.COOKIE_NAME;
- }
-
- @Override
- public void track(Event event) {
- Logger.getLogger().info("Track event call");
- this.eventManager.sendAsync(event, this.snOptions.getApiUrl() + "/track");
- }
-
- @Override
- public RiskResult verify(Event event) {
- Logger.getLogger().info("Verify event call");
- return this.eventManager.sendSync(event, this.snOptions.getApiUrl() + "/verify");
- }
-
- @Override
- public RiskResult flow(long flowId, Event event) {//FOR FUTURE PURPOSES
- Logger.getLogger().info("Flow event call");
- return this.eventManager.sendSync(event, this.snOptions.getApiUrl() + "/flow/" + flowId);
- }
-
- @Override
- public String getApiKey() {
- return apiKey;
- }
-
- }
\ No newline at end of file
diff --git a/sdk-base/src/main/java/com/securenative/snlogic/SnEventManager.java b/sdk-base/src/main/java/com/securenative/snlogic/SnEventManager.java
deleted file mode 100644
index 92ffcbc..0000000
--- a/sdk-base/src/main/java/com/securenative/snlogic/SnEventManager.java
+++ /dev/null
@@ -1,140 +0,0 @@
-package com.securenative.snlogic;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.securenative.exceptions.SecureNativeSDKException;
-import com.securenative.models.*;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.asynchttpclient.*;
-
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-
-public class SnEventManager implements EventManager {
- private final String USER_AGENT_VALUE = "com.securenative.snlogic.SecureNative-java";
- private final String SN_VERSION = "SN-Version";
- private BoundRequestBuilder asyncClient;
- private String apiKey;
- private Utils utils;
- private ExecutorService executor;
- private ConcurrentLinkedQueue events;
- private ObjectMapper mapper;
- private int HTTP_STATUS_OK = 201;
- private String AUTHORIZATION = "Authorization";
- private SecureNativeOptions options;
- RiskResult defaultRiskResult = new RiskResult(RiskLevel.low.name(), 0.0, new String[0]);
-
- public SnEventManager(String apiKey, SecureNativeOptions options) throws SecureNativeSDKException {
- this.utils = new Utils();
- this.options = options;
- events = new ConcurrentLinkedQueue<>();
- if (this.utils.isNullOrEmpty(apiKey) || options == null) {
- throw new SecureNativeSDKException("You must pass a valid api key");
- }
- this.asyncClient = initializeAsyncHttpClient(options);
- this.apiKey = apiKey;
-
- if (this.options.getSdkEnabled() != null && !this.options.getSdkEnabled()) {
- executor = Executors.newSingleThreadScheduledExecutor();
- Logger.getLogger().info(String.format("Starting thread listening to messages queue"));
- executor.execute(() -> {
- try {
- Thread.sleep((long) (Math.random() * 1000));
- Message msg = events.poll();
- if (msg != null) {
- sendSync(msg.getSnEvent(), msg.getUrl());
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- });
- }
- mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- }
-
-
- @Override
- public RiskResult sendSync(Event event, String url) {
- if (this.options.getSdkEnabled() != null && !this.options.getSdkEnabled()) {
- return defaultRiskResult;
- }
-
- this.asyncClient.setHeader(AUTHORIZATION, this.apiKey).setUrl(url);
-
- try {
- this.asyncClient.setBody(mapper.writeValueAsString(event));
- Response response = this.asyncClient.execute().get();
- if (response == null || response.getStatusCode() > HTTP_STATUS_OK) {
- Logger.getLogger().info(String.format("Secure Native http call failed to end point: %s with event type %s. adding back to queue.", url, event.getEventType()));
- events.add(new Message(event, response.getUri().toUrl()));
- }
- String responseBody = response.getResponseBody();
- if (utils.isNullOrEmpty(responseBody)) {
- Logger.getLogger().info(String.format("Secure Native http call to %s returned with empty response. returning default risk result.", url));
- return defaultRiskResult;
- }
- Logger.getLogger().info(String.format("Secure Native http call to %s was successful.", url));
- return mapper.readValue(responseBody, RiskResult.class);
- } catch (InterruptedException | ExecutionException | IOException e) {
- e.printStackTrace();
- }
- return defaultRiskResult;
-
- }
-
- @Override
- public void sendAsync(Event event, String url) {
- if (this.options.getSdkEnabled() != null && !this.options.getSdkEnabled()) {
- return;
- }
- this.asyncClient.setUrl(url).setHeader(AUTHORIZATION, this.apiKey);
- try {
- this.asyncClient.setBody(mapper.writeValueAsString(event));
- } catch (JsonProcessingException e) {
- Logger.getLogger().info(String.format("Secure Native async http call failed to end point: %s with event type %s. error: %s", url, event.getEventType(), e));
- }
-
- this.asyncClient.execute(
- new AsyncCompletionHandler