diff --git a/CHANGELOG.md b/CHANGELOG.md index fe27310..90c7594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,20 @@ > **LoginRadius Java SDK Change Log** provides information regarding what has changed, more specifically what changes, improvements and bug fix has been made to the SDK. For more details please refer to the [LoginRadius API Documention(https://www.loginradius.com/docs/api/v2/deployment/sdk-libraries/java-library/) +# Version 11.3.1 +Release on January 28, 2022 + + +## Enhancements + +- Added a feature to add ApiKey and ApiSecret directly in LoginRadius manual SOTT generation method. +- Code optimization for better performance. +- Added Licence and Contribution Guideline files. + +## Breaking Changes + +For developers migrating from v11.3.0, there will be 1 minor breaking change in terms of SDK implementation. In this version, we have added a feature to add ApiKey & ApiSecret directly into the manual SOTT generation method `getSott()`. + # Version 11.3.0 Release on October 10, 2021 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..efe7108 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,41 @@ +# Contributing + +[Java SDK](https://github.com/LoginRadius/java-sdk) is [MIT](LICENSE) licensed and accepts contributions via GitHub pull requests. This document outlines some of the conventions on development workflow, commit message formatting, contact points, and other resources to make it easier to get your contribution accepted. + +## Getting Started + +- Fork the repository on GitHub. +- If you find any bug or Improvement in our existing code-base, please create a pull request as mentioned in Contribution Flow. + +## Contribution Flow + +This is a rough outline of what a contributor's workflow looks like: + +- Create a separate branch from the `dev` branch to base your work. +- Make commits of logical units. +- Make sure your commit messages are in the proper format (see below). +- Push your changes to a topic branch in your fork of the repository. +- Submit a pull request to the original repository. +- **Please ensure that you raise a PR on the `dev` branch instead of `master`.** + +#### Commit Messages + +Please follow the below format while writing commit messages: + +``` + title: One line description about your change + + description: An optional description of your changes. +``` + +Thanks for your contributions! + +## Code of Conduct + +### Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +### Our Responsibilities + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1614600 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2022 LoginRadius Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/LoginRadius-JavaSDK/pom.xml b/LoginRadius-JavaSDK/pom.xml index 19dc7b5..85393d0 100644 --- a/LoginRadius-JavaSDK/pom.xml +++ b/LoginRadius-JavaSDK/pom.xml @@ -6,7 +6,7 @@ com.loginradius.sdk java-sdk - 11.3.0 + 11.3.1 LoginRadius-CustomerIdentity-JavaSDK LoginRadius Java SDK https://github.com/LoginRadius/java-sdk @@ -38,7 +38,7 @@ com.google.code.gson gson - 2.2.4 + 2.8.9 @@ -82,7 +82,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.3 + 1.6.8 true ossrh @@ -93,10 +93,10 @@ org.apache.maven.plugins maven-compiler-plugin - 2.3.2 + 3.9.0 - 1.6 - 1.6 + 16 + 16 @@ -116,7 +116,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 8 + 16 public true true diff --git a/LoginRadius-JavaSDK/src/main/java/com/loginradius/sdk/util/Sott.java b/LoginRadius-JavaSDK/src/main/java/com/loginradius/sdk/util/Sott.java index ec0df70..538050a 100644 --- a/LoginRadius-JavaSDK/src/main/java/com/loginradius/sdk/util/Sott.java +++ b/LoginRadius-JavaSDK/src/main/java/com/loginradius/sdk/util/Sott.java @@ -31,41 +31,43 @@ import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.SecretKeySpec; +import com.loginradius.sdk.helper.LoginRadiusValidator; import com.loginradius.sdk.models.responsemodels.otherobjects.ServiceInfoModel; public class Sott { private static String initVector = "tu89geji340t89u2"; - public static String getSott(ServiceInfoModel service) throws java.lang.Exception { - String secret = LoginRadiusSDK.getApiSecret(); - String key = LoginRadiusSDK.getApiKey(); + // + // Generate SOTT Manually. + // + // ServiceInfoModel Model Class containing Definition of payload for SOTT + // LoginRadius Api Key. + // LoginRadius Api Secret. + // Sott data + + public static String getSott(ServiceInfoModel service,String apiKey,String apiSecret) throws java.lang.Exception { + String secret = !LoginRadiusValidator.isNullOrWhiteSpace(apiSecret)? apiSecret:LoginRadiusSDK.getApiSecret(); + String key = !LoginRadiusValidator.isNullOrWhiteSpace(apiKey)? apiKey:LoginRadiusSDK.getApiKey(); String token = null; - if (service != null && service.getSott().getStartTime() != null && service.getSott().getEndTime() != null) { + + if (service != null && !LoginRadiusValidator.isNullOrWhiteSpace(service.getSott().getStartTime()) && !LoginRadiusValidator.isNullOrWhiteSpace(service.getSott().getEndTime()) ) { String plaintext = service.getSott().getStartTime() + "#" + key + "#" + service.getSott().getEndTime(); - token = encrypt(plaintext, secret); - } else if (service != null && service.getSott().getTimeDifference() != null - && !service.getSott().getTimeDifference().equals("")) { - TimeZone timeZone = TimeZone.getTimeZone("UTC"); - Calendar calendar = Calendar.getInstance(timeZone); - DateFormat dateFormat = new SimpleDateFormat("yyyy/M/d H:m:s", Locale.US); - dateFormat.setTimeZone(timeZone); - String plaintext = dateFormat.format(calendar.getTime()) + "#" + key + "#"; - int time = Integer.parseInt(service.getSott().getTimeDifference()); - calendar.add(Calendar.MINUTE, time); - plaintext += dateFormat.format(calendar.getTime()); - token = encrypt(plaintext, secret); + token = encrypt(plaintext, secret); } else { + + String timeDifference =(service!=null && !LoginRadiusValidator.isNullOrWhiteSpace(service.getSott().getTimeDifference())) ?service.getSott().getTimeDifference():"10"; TimeZone timeZone = TimeZone.getTimeZone("UTC"); Calendar calendar = Calendar.getInstance(timeZone); DateFormat dateFormat = new SimpleDateFormat("yyyy/M/d H:m:s", Locale.US); dateFormat.setTimeZone(timeZone); String plaintext = dateFormat.format(calendar.getTime()) + "#" + key + "#"; - calendar.add(Calendar.MINUTE, 10); + calendar.add(Calendar.MINUTE, Integer.parseInt(timeDifference)); plaintext += dateFormat.format(calendar.getTime()); token = encrypt(plaintext, secret); + } - + String finalToken = token + "*" + createMd5(token); return finalToken; } diff --git a/README.md b/README.md index 215a02b..81db2c1 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Use the following dependency in your project: com.loginradius.sdk java-sdk - 11.3.0 + 11.3.1 ``` @@ -7777,6 +7777,45 @@ System.out.println(error.getDescription());
+### Generate SOTT Manually + +SOTT is a secure one-time token that can be created using the API key, API secret, and a timestamp ( start time and end time ). You can manually create a SOTT using the following util function. + +``` +ServiceSottInfo serviceSottInfo=new ServiceSottInfo(); + +// You can pass the start and end time interval and the SOTT will be valid for this time duration. + +serviceSottInfo.setStartTime("2021-01-10 07:10:42"); // Valid Start Date with Date and time + +serviceSottInfo.setEndTime("2023-01-15 07:20:42"); // Valid End Date with Date and time + +// Or you can pass the time difference in minutes for setting up the validity of SOTT, if you do not pass the time difference then the default value is 10 minutes + +serviceSottInfo.setTimeDifference("20"); // (Optional) The time difference will be used to set the expiration time of SOTT, If you do not pass time difference then the default expiration time of SOTT is 10 minutes. + + +ServiceInfoModel service=new ServiceInfoModel(); + +service.setSott(serviceSottInfo); + + +//The LoginRadius API key and primary API secret can be passed additionally, If the credentials will not be passed then this SOTT function will pick the API credentials from the SDK configuration. + +String apiKey="";//(Optional) LoginRadius Api Key. + +String apiSecret="";//(Optional) LoginRadius Api Secret (Only Primary Api Secret is used to generate the SOTT manually). + +try { + String sottResponse = Sott.getSott(service,apiKey,apiSecret); + System.out.println("sott = " + sottResponse); + +} catch (Exception e) { + e.printStackTrace(); + +} + +``` ### Demo We have a demo web application using the Java SDK, which includes the following features: diff --git a/demo/pom.xml b/demo/pom.xml index 36bb35a..b192b16 100644 --- a/demo/pom.xml +++ b/demo/pom.xml @@ -13,14 +13,14 @@ org.springframework.boot spring-boot-starter-parent - 1.5.6.RELEASE + 2.6.3 UTF-8 UTF-8 - 1.8 + 16 @@ -42,7 +42,7 @@ com.google.code.gson gson - 2.2.4 + 2.8.9 commons-codec @@ -52,7 +52,7 @@ com.loginradius.sdk java-sdk - 11.3.0 + 11.3.1 diff --git a/demo/src/main/java/com/demo/LoginRadiusService.java b/demo/src/main/java/com/demo/LoginRadiusService.java index 55809e2..5c27cae 100644 --- a/demo/src/main/java/com/demo/LoginRadiusService.java +++ b/demo/src/main/java/com/demo/LoginRadiusService.java @@ -44,6 +44,8 @@ import com.loginradius.sdk.models.responsemodels.otherobjects.DeleteResponse; import com.loginradius.sdk.models.responsemodels.otherobjects.PostResponse; import com.loginradius.sdk.models.responsemodels.otherobjects.RoleModel; +import com.loginradius.sdk.models.responsemodels.otherobjects.ServiceInfoModel; +import com.loginradius.sdk.models.responsemodels.otherobjects.ServiceSottInfo; import com.loginradius.sdk.models.responsemodels.otherobjects.UserProfilePostResponse; import com.loginradius.sdk.models.responsemodels.userprofile.Identity; import com.loginradius.sdk.util.AsyncHandler; @@ -663,8 +665,30 @@ private String decodeJWTBody(String jwtToken) return body; } private String getSott() { + ServiceSottInfo serviceSottInfo=new ServiceSottInfo(); + + // You can pass the start and end time interval and the SOTT will be valid for this time duration. + + serviceSottInfo.setStartTime(""); // Valid Start Date with Date and time + + serviceSottInfo.setEndTime(""); // Valid End Date with Date and time + + // Or you can pass the time difference in minutes for setting up the validity of SOTT, if you do not pass the time difference then the default value is 10 minutes + + serviceSottInfo.setTimeDifference("20"); // (Optional) The time difference will be used to set the expiration time of SOTT, If you do not pass time difference then the default expiration time of SOTT is 10 minutes. + + + ServiceInfoModel service=new ServiceInfoModel(); + + service.setSott(serviceSottInfo); + + + //The LoginRadius API key and primary API secret can be passed additionally, If the credentials will not be passed then this SOTT function will pick the API credentials from the SDK configuration. + String apiKey="";//(Optional) LoginRadius Api Key. + String apiSecret="";//(Optional) LoginRadius Api Secret (Only Primary Api Secret is used to generate the SOTT manually). + try { - return Sott.getSott(null); + return Sott.getSott(service,apiKey,apiSecret); } catch (Exception e) { return ""; }