[FIXED] GA

parent ee037b7b
...@@ -137,7 +137,8 @@ class JWTokenApi { ...@@ -137,7 +137,8 @@ class JWTokenApi {
JSONObject json = new JSONObject(data); JSONObject json = new JSONObject(data);
try { try {
boolean onelife = json.optBoolean("onelife", false); boolean onelife = json.optBoolean("onelife", false);
String tokenized = jwtTokenUtil.tokenizeData(data, onelife ? BigInteger.valueOf(0) : BigInteger.valueOf(3600000), onelife); int ms = json.optInt("ms", 3600000);
String tokenized = jwtTokenUtil.tokenizeData(data, BigInteger.valueOf(ms), onelife);
if(onelife){ if(onelife){
tokenSingleton.addToken(tokenized); tokenSingleton.addToken(tokenized);
} }
......
...@@ -4,8 +4,10 @@ import lombok.Getter; ...@@ -4,8 +4,10 @@ import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import web.multitask.trismegistoservices.utils.JWTokenUtil;
import java.util.stream.IntStream; import java.util.stream.IntStream;
...@@ -16,6 +18,9 @@ public class TokenSingleton { ...@@ -16,6 +18,9 @@ public class TokenSingleton {
private final JSONArray tokens = new JSONArray(); private final JSONArray tokens = new JSONArray();
@Autowired
private JWTokenUtil jwtTokenUtil;
public boolean consumeToken(String token) { public boolean consumeToken(String token) {
boolean isAvailable = false; boolean isAvailable = false;
for (int i = 0; i < tokens.length(); i++) { for (int i = 0; i < tokens.length(); i++) {
...@@ -48,10 +53,10 @@ public class TokenSingleton { ...@@ -48,10 +53,10 @@ public class TokenSingleton {
@Scheduled(fixedRate = 3600000) @Scheduled(fixedRate = 3600000)
public void removeUnavailableTokens() { public void removeUnavailableTokens() {
System.out.println("Removing unavailable tokens"); System.out.println("Removing unavailable tokens");
IntStream.range(0, tokens.length()).forEach(i -> { for(int i = 0; i < tokens.length(); i++){
if (!tokens.getJSONObject(i).getBoolean("available")) { if(!tokens.getJSONObject(i).getBoolean("available") || jwtTokenUtil.isTokenExpired(tokens.getJSONObject(i).getString("token"))){
System.out.println(tokens.remove(i)); System.out.println("Token removed "+tokens.remove(i));
} }
}); }
} }
} }
...@@ -44,7 +44,7 @@ public class JWTokenUtil implements Serializable{ ...@@ -44,7 +44,7 @@ public class JWTokenUtil implements Serializable{
return Jwts.builder() return Jwts.builder()
.setSubject(data) .setSubject(data)
.setIssuedAt(new Date()) .setIssuedAt(new Date())
.setExpiration(new Date(new Date().getTime() + 36000000)) .setExpiration(new Date(new Date().getTime() + ms.longValue()))
.signWith(Keys.hmacShaKeyFor(onelife ? jwtSecret2.getBytes() : jwtSecret.getBytes())) .signWith(Keys.hmacShaKeyFor(onelife ? jwtSecret2.getBytes() : jwtSecret.getBytes()))
.compact(); .compact();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment