@@ -96,3 +96,181 @@ def sn_webhook_handler(headers, body):
9696 pass
9797
9898```
99+
100+ <p align =" center " >
101+ <a href =" https://www.securenative.com " ><img src =" https://user-images.githubusercontent.com/45174009/77826512-f023ed80-7120-11ea-80e0-58aacde0a84e.png " alt =" SecureNative Logo " /></a >
102+ </p >
103+
104+ <p align =" center " >
105+ <b >A Cloud-Native Security Monitoring and Protection for Modern Applications</b >
106+ </p >
107+ <p align =" center " >
108+ <a href =" https://github.com/securenative/securenative-python " >
109+ <img alt="Github Actions" src="https://github.com/securenative/securenative-java/workflows/CI/badge.svg">
110+ </a >
111+ <a href =" https://codecov.io/gh/securenative/securenative-python " >
112+ <img src="https://codecov.io/gh/securenative/securenative-java/branch/master/graph/badge.svg" />
113+ </a >
114+ </p >
115+ <p align =" center " >
116+ <a href =" https://docs.securenative.com " >Documentation</a > |
117+ <a href =" https://docs.securenative.com/quick-start " >Quick Start</a > |
118+ <a href =" https://blog.securenative.com " >Blog</a > |
119+ <a href =" " >Chat with us on Slack!</a >
120+ </p >
121+ <hr />
122+
123+
124+ [ 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.
125+
126+ ## Install the SDK
127+
128+ When using Maven, add the following dependency to your ` pom.xml ` file:
129+ ``` xml
130+ <dependency >
131+ <groupId >com.securenative.java</groupId >
132+ <artifactId >sdk-base</artifactId >
133+ <version >LATEST</version >
134+ </dependency >
135+ ```
136+
137+ When using Gradle, add the following dependency to your ` build.gradle ` file:
138+ ``` gradle
139+ compile group: 'com.securenative.java', name: 'sdk-parent', version: '0.3.1', ext: 'pom'
140+ ```
141+
142+ When using SBT, add the following dependency to your ` build.sbt ` file:
143+ ``` sbt
144+ libraryDependencies += " com.securenative.java" % " sdk-parent" % " 0.3.1" pomOnly()
145+ ```
146+
147+ ## Initialize the SDK
148+
149+ To get your * API KEY* , login to your SecureNative account and go to project settings page:
150+
151+ ### Option 1: Initialize via Config file
152+ SecureNative can automatically load your config from * securenative.properties* file or from the file that is specified in your * SECURENATIVE_CONFIG_FILE* env variable:
153+
154+ ``` java
155+ SecureNative secureNative = SecureNative . init();
156+ ```
157+ ### Option 2: Initialize via API Key
158+
159+ ``` java
160+ SecureNative secureNative = SecureNative . init(" YOUR_API_KEY" );
161+ ```
162+
163+ ### Option 3: Initialize via ConfigurationBuilder
164+ ``` java
165+ SecureNative secureNative = SecureNative . init(SecureNative . configBuilder()
166+ .withApiKey(" API_KEY" )
167+ .withMaxEvents(10 )
168+ .withLogLevel(" error" )
169+ .build());
170+ ```
171+
172+ ## Getting SecureNative instance
173+ Once initialized, sdk will create a singleton instance which you can get:
174+ ``` java
175+ SecureNative secureNative = SecureNative . getInstance();
176+ ```
177+
178+ ## Tracking events
179+
180+ Once the SDK has been initialized, tracking requests sent through the SDK
181+ instance. Make sure you build event with the EventBuilder:
182+
183+ ``` java
184+ SecureNative secureNative = SecureNative . getInstance();
185+
186+ SecureNativeContext context = SecureNative . contextBuilder()
187+ .withIp(" 127.0.0.1" )
188+ .withClientToken(" SECURED_CLIENT_TOKEN" )
189+ .withHeaders(Maps . defaultBuilder()
190+ .put(" user-agent" , " Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405" )
191+ .build())
192+ .build();
193+
194+ EventOptions eventOptions = EventOptionsBuilder . builder(EventTypes . LOG_IN )
195+ .userId(" USER_ID" )
196+ .userTraits(" USER_NAME" , " USER_EMAIL" )
197+ .context(context)
198+ .properties(Maps . builder()
199+ .put(" prop1" , " CUSTOM_PARAM_VALUE" )
200+ .put(" prop2" , true )
201+ .put(" prop3" , 3 )
202+ .build())
203+ .timestamp(new Date ())
204+ .build();
205+
206+ secureNative. track(eventOptions);
207+ ```
208+
209+ You can also create request context from HttpServletRequest:
210+
211+ ``` java
212+ @RequestMapping (" /track" )
213+ public void track(HttpServletRequest request, HttpServletResponse response) {
214+ SecureNativeContext context = SecureNative . contextBuilder()
215+ .fromHttpServletRequest(request)
216+ .build();
217+
218+ EventOptions eventOptions = EventOptionsBuilder . builder(EventTypes . LOG_IN )
219+ .userId(" USER_ID" )
220+ .userTraits(" USER_NAME" , " USER_EMAIL" )
221+ .context(context)
222+ .properties(Maps . builder()
223+ .put(" prop1" , " CUSTOM_PARAM_VALUE" )
224+ .put(" prop2" , true )
225+ .put(" prop3" , 3 )
226+ .build())
227+ .timestamp(new Date ())
228+ .build();
229+
230+ secureNative. track(eventOptions);
231+ }
232+ ```
233+
234+ ## Verify events
235+
236+ ** Example**
237+
238+ ``` java
239+ @RequestMapping (" /track" )
240+ public void track(HttpServletRequest request, HttpServletResponse response) {
241+ SecureNativeContext context = SecureNative . contextBuilder()
242+ .fromHttpServletRequest(request)
243+ .build();
244+
245+ EventOptions eventOptions = EventOptionsBuilder . builder(EventTypes . LOG_IN )
246+ .userId(" USER_ID" )
247+ .userTraits(" USER_NAME" , " USER_EMAIL" )
248+ .context(context)
249+ .properties(Maps . builder()
250+ .put(" prop1" , " CUSTOM_PARAM_VALUE" )
251+ .put(" prop2" , true )
252+ .put(" prop3" , 3 )
253+ .build())
254+ .timestamp(new Date ())
255+ .build();
256+
257+ VerifyResult verifyResult = secureNative. verify(eventOptions);
258+ verifyResult. getRiskLevel() // Low, Medium, High
259+ verifyResult. score() // Risk score: 0 -1 (0 - Very Low, 1 - Very High)
260+ verifyResult. getTriggers() // ["TOR", "New IP", "New City"]
261+ }
262+ ```
263+
264+ ## Webhook signature verification
265+
266+ Apply our filter to verify the request is from us, example in spring:
267+
268+ ``` java
269+ @RequestMapping (" /webhook" )
270+ public void webhookEndpoint(HttpServletRequest request, HttpServletResponse response) {
271+ SecureNative secureNative = SecureNative . getInstance();
272+
273+ // Checks if request is verified
274+ Boolean isVerified = secureNative. verifyRequestPayload(request);
275+ }
276+ ```
0 commit comments