|
31 | 31 | import javax.crypto.spec.PBEKeySpec;
|
32 | 32 | import javax.crypto.spec.SecretKeySpec;
|
33 | 33 |
|
| 34 | +import com.loginradius.sdk.helper.LoginRadiusValidator; |
34 | 35 | import com.loginradius.sdk.models.responsemodels.otherobjects.ServiceInfoModel;
|
35 | 36 |
|
36 | 37 | public class Sott {
|
37 | 38 |
|
38 | 39 | private static String initVector = "tu89geji340t89u2";
|
39 | 40 |
|
40 |
| - public static String getSott(ServiceInfoModel service) throws java.lang.Exception { |
41 |
| - String secret = LoginRadiusSDK.getApiSecret(); |
42 |
| - String key = LoginRadiusSDK.getApiKey(); |
| 41 | + // <summary> |
| 42 | + // Generate SOTT Manually. |
| 43 | + // </summary> |
| 44 | + // <param name="service">ServiceInfoModel Model Class containing Definition of payload for SOTT</param> |
| 45 | + // <param name="apiKey">LoginRadius Api Key.</param> |
| 46 | + // <param name="apiSecret">LoginRadius Api Secret.</param> |
| 47 | + // <returns>Sott data</returns> |
| 48 | + |
| 49 | + public static String getSott(ServiceInfoModel service,String apiKey,String apiSecret) throws java.lang.Exception { |
| 50 | + String secret = !LoginRadiusValidator.isNullOrWhiteSpace(apiSecret)? apiSecret:LoginRadiusSDK.getApiSecret(); |
| 51 | + String key = !LoginRadiusValidator.isNullOrWhiteSpace(apiKey)? apiKey:LoginRadiusSDK.getApiKey(); |
43 | 52 | String token = null;
|
44 |
| - if (service != null && service.getSott().getStartTime() != null && service.getSott().getEndTime() != null) { |
| 53 | + |
| 54 | + if (service != null && !LoginRadiusValidator.isNullOrWhiteSpace(service.getSott().getStartTime()) && !LoginRadiusValidator.isNullOrWhiteSpace(service.getSott().getEndTime()) ) { |
45 | 55 | String plaintext = service.getSott().getStartTime() + "#" + key + "#" + service.getSott().getEndTime();
|
46 |
| - token = encrypt(plaintext, secret); |
47 |
| - } else if (service != null && service.getSott().getTimeDifference() != null |
48 |
| - && !service.getSott().getTimeDifference().equals("")) { |
49 |
| - TimeZone timeZone = TimeZone.getTimeZone("UTC"); |
50 |
| - Calendar calendar = Calendar.getInstance(timeZone); |
51 |
| - DateFormat dateFormat = new SimpleDateFormat("yyyy/M/d H:m:s", Locale.US); |
52 |
| - dateFormat.setTimeZone(timeZone); |
53 |
| - String plaintext = dateFormat.format(calendar.getTime()) + "#" + key + "#"; |
54 |
| - int time = Integer.parseInt(service.getSott().getTimeDifference()); |
55 |
| - calendar.add(Calendar.MINUTE, time); |
56 |
| - plaintext += dateFormat.format(calendar.getTime()); |
57 |
| - token = encrypt(plaintext, secret); |
| 56 | + token = encrypt(plaintext, secret); |
58 | 57 | } else {
|
| 58 | + |
| 59 | + String timeDifference =(service!=null && !LoginRadiusValidator.isNullOrWhiteSpace(service.getSott().getTimeDifference())) ?service.getSott().getTimeDifference():"10"; |
59 | 60 | TimeZone timeZone = TimeZone.getTimeZone("UTC");
|
60 | 61 | Calendar calendar = Calendar.getInstance(timeZone);
|
61 | 62 | DateFormat dateFormat = new SimpleDateFormat("yyyy/M/d H:m:s", Locale.US);
|
62 | 63 | dateFormat.setTimeZone(timeZone);
|
63 | 64 | String plaintext = dateFormat.format(calendar.getTime()) + "#" + key + "#";
|
64 |
| - calendar.add(Calendar.MINUTE, 10); |
| 65 | + calendar.add(Calendar.MINUTE, Integer.parseInt(timeDifference)); |
65 | 66 | plaintext += dateFormat.format(calendar.getTime());
|
66 | 67 | token = encrypt(plaintext, secret);
|
| 68 | + |
67 | 69 | }
|
68 |
| - |
| 70 | + |
69 | 71 | String finalToken = token + "*" + createMd5(token);
|
70 | 72 | return finalToken;
|
71 | 73 | }
|
|
0 commit comments