Skip to content

Commit

Permalink
Release Version 11.3.1
Browse files Browse the repository at this point in the history
Release Version 11.3.1
  • Loading branch information
indrasen715 committed Jan 31, 2022
1 parent eb46cda commit 1c70881
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 31 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
41 changes: 41 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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
<Blank Line>
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.
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 7 additions & 7 deletions LoginRadius-JavaSDK/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.loginradius.sdk</groupId>
<artifactId>java-sdk</artifactId>
<version>11.3.0</version>
<version>11.3.1</version>
<name>LoginRadius-CustomerIdentity-JavaSDK</name>
<description>LoginRadius Java SDK</description>
<url>https://github.com/LoginRadius/java-sdk</url>
Expand Down Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<version>2.8.9</version>
</dependency>


Expand Down Expand Up @@ -82,7 +82,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand All @@ -93,10 +93,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<version>3.9.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
<plugin>
Expand All @@ -116,7 +116,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<source>8</source>
<source>16</source>
<show>public</show>
<nohelp>true</nohelp>
<author>true</author>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
// <summary>
// Generate SOTT Manually.
// </summary>
// <param name="service">ServiceInfoModel Model Class containing Definition of payload for SOTT</param>
// <param name="apiKey">LoginRadius Api Key.</param>
// <param name="apiSecret">LoginRadius Api Secret.</param>
// <returns>Sott data</returns>

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;
}
Expand Down
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Use the following dependency in your project:
<dependency>
<groupId>com.loginradius.sdk</groupId>
<artifactId>java-sdk</artifactId>
<version>11.3.0</version>
<version>11.3.1</version>
</dependency>
```
Expand Down Expand Up @@ -7777,6 +7777,45 @@ System.out.println(error.getDescription());

<br>

### 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:
Expand Down
8 changes: 4 additions & 4 deletions demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>16</java.version>
</properties>

<dependencies>
Expand All @@ -42,7 +42,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
Expand All @@ -52,7 +52,7 @@
<dependency>
<groupId>com.loginradius.sdk</groupId>
<artifactId>java-sdk</artifactId>
<version>11.3.0</version>
<version>11.3.1</version>
</dependency>
</dependencies>

Expand Down
26 changes: 25 additions & 1 deletion demo/src/main/java/com/demo/LoginRadiusService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 "";
}
Expand Down

0 comments on commit 1c70881

Please sign in to comment.