Skip to content

Commit 9b5dd7a

Browse files
authored
Merge pull request #18 from indrasen715/master
Release Version 11.4.0
2 parents 0915336 + d66f42b commit 9b5dd7a

File tree

6 files changed

+622
-316
lines changed

6 files changed

+622
-316
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
> **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/)
22
33

4+
# Version 11.4.0
5+
Release on June 1, 2022
6+
7+
8+
## Enhancements
9+
10+
- We are introducing an additional param `getLrServerTime` in the manual SOTT generation function `getSott()`, we recomend using this method to generate SOTT manually, the old function `getSott()` will also exist but it is deprecated and will be removed in a future version of SDK.
11+
- Enhancement in `README.md` file.
12+
13+
414
# Version 11.3.1
515
Release on January 28, 2022
616

LoginRadius-JavaSDK/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.loginradius.sdk</groupId>
88
<artifactId>java-sdk</artifactId>
9-
<version>11.3.1</version>
9+
<version>11.4.0</version>
1010
<name>LoginRadius-CustomerIdentity-JavaSDK</name>
1111
<description>LoginRadius Java SDK</description>
1212
<url>https://github.com/LoginRadius/java-sdk</url>

LoginRadius-JavaSDK/src/main/java/com/loginradius/sdk/util/Sott.java

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,47 +31,102 @@
3131
import javax.crypto.spec.PBEKeySpec;
3232
import javax.crypto.spec.SecretKeySpec;
3333

34+
import com.loginradius.sdk.api.advanced.ConfigurationApi;
3435
import com.loginradius.sdk.helper.LoginRadiusValidator;
3536
import com.loginradius.sdk.models.responsemodels.otherobjects.ServiceInfoModel;
3637

3738
public class Sott {
3839

3940
private static String initVector = "tu89geji340t89u2";
40-
41+
private static String plaintext="";
4142
// <summary>
4243
// Generate SOTT Manually.
4344
// </summary>
4445
// <param name="service">ServiceInfoModel Model Class containing Definition of payload for SOTT</param>
4546
// <param name="apiKey">LoginRadius Api Key.</param>
4647
// <param name="apiSecret">LoginRadius Api Secret.</param>
48+
// <param name="getLrServerTime">If true it will call LoginRadius Get Server Time Api and fetch basic server information and server time information which is useful when generating an SOTT token..</param>
4749
// <returns>Sott data</returns>
4850

49-
public static String getSott(ServiceInfoModel service,String apiKey,String apiSecret) throws java.lang.Exception {
51+
public static String getSott(ServiceInfoModel service,String apiKey,String apiSecret,boolean getLrServerTime) throws java.lang.Exception {
5052
String secret = !LoginRadiusValidator.isNullOrWhiteSpace(apiSecret)? apiSecret:LoginRadiusSDK.getApiSecret();
5153
String key = !LoginRadiusValidator.isNullOrWhiteSpace(apiKey)? apiKey:LoginRadiusSDK.getApiKey();
5254
String token = null;
53-
55+
String timeDifference =(service!=null && !LoginRadiusValidator.isNullOrWhiteSpace(service.getSott().getTimeDifference())) ?service.getSott().getTimeDifference():"10";
56+
5457
if (service != null && !LoginRadiusValidator.isNullOrWhiteSpace(service.getSott().getStartTime()) && !LoginRadiusValidator.isNullOrWhiteSpace(service.getSott().getEndTime()) ) {
55-
String plaintext = service.getSott().getStartTime() + "#" + key + "#" + service.getSott().getEndTime();
56-
token = encrypt(plaintext, secret);
57-
} else {
58-
59-
String timeDifference =(service!=null && !LoginRadiusValidator.isNullOrWhiteSpace(service.getSott().getTimeDifference())) ?service.getSott().getTimeDifference():"10";
58+
plaintext = service.getSott().getStartTime() + "#" + key + "#" + service.getSott().getEndTime();
59+
}
60+
61+
if(getLrServerTime) {
62+
ConfigurationApi config = new ConfigurationApi();
63+
config.getServerInfo(Integer.parseInt(timeDifference), new AsyncHandler < ServiceInfoModel > () {
64+
65+
@Override
66+
public void onFailure(ErrorResponse errorResponse) {}
67+
68+
@Override
69+
public void onSuccess(ServiceInfoModel service) {
70+
71+
if(service!=null && !LoginRadiusValidator.isNullOrWhiteSpace( service.getSott().getStartTime()) && !LoginRadiusValidator.isNullOrWhiteSpace( service.getSott().getEndTime()) ) {
72+
plaintext = service.getSott().getStartTime() + "#" + key + "#" + service.getSott().getEndTime();
73+
}
74+
75+
}
76+
77+
});
78+
}
79+
80+
if(plaintext.isEmpty()) {
6081
TimeZone timeZone = TimeZone.getTimeZone("UTC");
6182
Calendar calendar = Calendar.getInstance(timeZone);
6283
DateFormat dateFormat = new SimpleDateFormat("yyyy/M/d H:m:s", Locale.US);
6384
dateFormat.setTimeZone(timeZone);
64-
String plaintext = dateFormat.format(calendar.getTime()) + "#" + key + "#";
85+
plaintext = dateFormat.format(calendar.getTime()) + "#" + key + "#";
6586
calendar.add(Calendar.MINUTE, Integer.parseInt(timeDifference));
6687
plaintext += dateFormat.format(calendar.getTime());
67-
token = encrypt(plaintext, secret);
68-
6988
}
70-
89+
token = encrypt(plaintext, secret);
90+
7191
String finalToken = token + "*" + createMd5(token);
7292
return finalToken;
7393
}
7494

95+
96+
// <summary>
97+
// Generate SOTT Manually.
98+
// </summary>
99+
// <param name="service">ServiceInfoModel Model Class containing Definition of payload for SOTT</param>
100+
// <param name="apiKey">LoginRadius Api Key.</param>
101+
// <param name="apiSecret">LoginRadius Api Secret.</param>
102+
// <returns>Sott data</returns>
103+
@Deprecated
104+
public static String getSott(ServiceInfoModel service,String apiKey,String apiSecret) throws java.lang.Exception {
105+
String secret = !LoginRadiusValidator.isNullOrWhiteSpace(apiSecret)? apiSecret:LoginRadiusSDK.getApiSecret();
106+
String key = !LoginRadiusValidator.isNullOrWhiteSpace(apiKey)? apiKey:LoginRadiusSDK.getApiKey();
107+
String token = null;
108+
109+
if (service != null && !LoginRadiusValidator.isNullOrWhiteSpace(service.getSott().getStartTime()) && !LoginRadiusValidator.isNullOrWhiteSpace(service.getSott().getEndTime()) ) {
110+
String plaintext = service.getSott().getStartTime() + "#" + key + "#" + service.getSott().getEndTime();
111+
token = encrypt(plaintext, secret);
112+
} else {
113+
114+
String timeDifference =(service!=null && !LoginRadiusValidator.isNullOrWhiteSpace(service.getSott().getTimeDifference())) ?service.getSott().getTimeDifference():"10";
115+
TimeZone timeZone = TimeZone.getTimeZone("UTC");
116+
Calendar calendar = Calendar.getInstance(timeZone);
117+
DateFormat dateFormat = new SimpleDateFormat("yyyy/M/d H:m:s", Locale.US);
118+
dateFormat.setTimeZone(timeZone);
119+
String plaintext = dateFormat.format(calendar.getTime()) + "#" + key + "#";
120+
calendar.add(Calendar.MINUTE, Integer.parseInt(timeDifference));
121+
plaintext += dateFormat.format(calendar.getTime());
122+
token = encrypt(plaintext, secret);
123+
124+
}
125+
126+
String finalToken = token + "*" + createMd5(token);
127+
return finalToken;
128+
}
129+
75130
private static String encrypt(final String plaintext, final String passPhrase) throws NoSuchAlgorithmException,
76131
InvalidKeySpecException, UnsupportedEncodingException, NoSuchPaddingException, InvalidKeyException,
77132
InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {

0 commit comments

Comments
 (0)