[FIXED] GA

parent ee037b7b
......@@ -137,7 +137,8 @@ class JWTokenApi {
JSONObject json = new JSONObject(data);
try {
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){
tokenSingleton.addToken(tokenized);
}
......
......@@ -4,8 +4,10 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import web.multitask.trismegistoservices.utils.JWTokenUtil;
import java.util.stream.IntStream;
......@@ -16,6 +18,9 @@ public class TokenSingleton {
private final JSONArray tokens = new JSONArray();
@Autowired
private JWTokenUtil jwtTokenUtil;
public boolean consumeToken(String token) {
boolean isAvailable = false;
for (int i = 0; i < tokens.length(); i++) {
......@@ -48,10 +53,10 @@ public class TokenSingleton {
@Scheduled(fixedRate = 3600000)
public void removeUnavailableTokens() {
System.out.println("Removing unavailable tokens");
IntStream.range(0, tokens.length()).forEach(i -> {
if (!tokens.getJSONObject(i).getBoolean("available")) {
System.out.println(tokens.remove(i));
for(int i = 0; i < tokens.length(); i++){
if(!tokens.getJSONObject(i).getBoolean("available") || jwtTokenUtil.isTokenExpired(tokens.getJSONObject(i).getString("token"))){
System.out.println("Token removed "+tokens.remove(i));
}
}
});
}
}
......@@ -44,7 +44,7 @@ public class JWTokenUtil implements Serializable{
return Jwts.builder()
.setSubject(data)
.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()))
.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