Fix leaderboard compare & add config for token expiration (in minutes) & advance on parser & Add Headers
This commit is contained in:
parent
7e75c54092
commit
1eafa7e972
10 changed files with 55 additions and 11 deletions
|
@ -21,6 +21,7 @@ public class Configuration {
|
|||
private String ssl_keystorePasswd;
|
||||
|
||||
private String token_issuer;
|
||||
private int token_expiration;
|
||||
|
||||
private File _file;
|
||||
|
||||
|
@ -127,6 +128,10 @@ public class Configuration {
|
|||
return this.token_issuer;
|
||||
}
|
||||
|
||||
public int getTokenExpiration(){
|
||||
return this.token_expiration;
|
||||
}
|
||||
|
||||
public String getSslKeystorePasswd(){
|
||||
return this.ssl_keystorePasswd;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class Main {
|
|||
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
|
||||
Router router = new Router(new DatabaseRepository(config), config.getTokenIssuer());
|
||||
Router router = new Router(new DatabaseRepository(config), config.getTokenIssuer(), config.getTokenExpiration());
|
||||
|
||||
router.setDefault(new Response(){
|
||||
|
||||
|
|
|
@ -93,16 +93,17 @@ public class Player implements Comparable<Player> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Player arg0) {
|
||||
if (this == arg0)
|
||||
public int compareTo(Player other) {
|
||||
if (this == other)
|
||||
return 0;
|
||||
if (arg0 == null)
|
||||
if (other == null)
|
||||
return -1;
|
||||
int compare = Integer.compare(arg0.getTotalScore(), totalScore);
|
||||
int compare = Integer.compare(other.getTotalScore(), totalScore);
|
||||
if (compare == 0) {
|
||||
compare = Integer.compare(arg0.getTotalCompletion(), totalCompletion);
|
||||
compare = Integer.compare(other.getTotalCompletion(), totalCompletion);
|
||||
if (compare == 0) {
|
||||
compare = Integer.compare(totalTries, arg0.getTotalTries());
|
||||
compare = Integer.compare(totalTries, other.getTotalTries());
|
||||
if(compare == 0) compare = other.getPseudo().compareTo(pseudo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package be.jeffcheasey88.peeratcode.parser.java;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
|
@ -43,6 +44,7 @@ public class Class {
|
|||
content = content.substring(index);
|
||||
}else if(equals >= 0 && equals < braces){
|
||||
//variable with value
|
||||
System.out.println(content);
|
||||
System.out.println("equals < braces");
|
||||
break;
|
||||
}else{
|
||||
|
@ -64,4 +66,9 @@ public class Class {
|
|||
return this.name;
|
||||
}
|
||||
|
||||
public void show(){
|
||||
System.out.println(Modifier.toString(modifier)+" "+this.name+"{");
|
||||
for(Variable v : this.vars) v.show(1);
|
||||
System.out.println("}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,23 @@
|
|||
package be.jeffcheasey88.peeratcode.parser.java;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JavaParser {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\JavaBenjaminCompiler\\src\\be\\jeffcheasey88\\parser\\rework\\Import.java");
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
|
||||
JavaParser parser = new JavaParser(reader);
|
||||
parser.parse();
|
||||
parser.show();
|
||||
}
|
||||
|
||||
private Package pack;
|
||||
private List<Import> imports;
|
||||
private Class clazz;
|
||||
|
@ -55,6 +66,14 @@ public class JavaParser {
|
|||
return this.clazz;
|
||||
}
|
||||
|
||||
public void show(){
|
||||
System.out.println("package "+this.pack.getName()+";");
|
||||
System.out.println();
|
||||
for(Import i : this.imports) System.out.println("import "+i.getName()+";");
|
||||
System.out.println();
|
||||
this.clazz.show();
|
||||
}
|
||||
|
||||
public static int getModifier(String modifier){
|
||||
switch(modifier){
|
||||
case "public": return Modifier.PUBLIC;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package be.jeffcheasey88.peeratcode.parser.java;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -38,4 +39,10 @@ public class Variable {
|
|||
public String getType(){
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void show(int tab){
|
||||
String start = "";
|
||||
for(int i = 0; i < tab; i++) start+="\t";
|
||||
System.out.println(start+Modifier.toString(modifier)+" "+type+" "+name+";");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ public class DatabaseRepository {
|
|||
ResultSet result = playersStmt.executeQuery();
|
||||
SortedSet<Player> players = new TreeSet<Player>();
|
||||
Player tmpPlayer;
|
||||
while (result.next()) {
|
||||
while (result.next()){
|
||||
tmpPlayer = makePlayer(result);
|
||||
tmpPlayer.setTotalScore(result.getInt("playerScore"));
|
||||
tmpPlayer.setTotalCompletion(result.getInt("playerCompletions"));
|
||||
|
|
|
@ -41,6 +41,7 @@ public class Login implements Response {
|
|||
if ((id = databaseRepo.login(pseudo, password)) >= 0){
|
||||
HttpUtil.responseHeaders(writer, 200,
|
||||
"Access-Control-Allow-Origin: *",
|
||||
"Access-Control-Expose-Headers: Authorization",
|
||||
"Authorization: Bearer "+this.router.createAuthUser(id));
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,9 @@ public class Register implements Response {
|
|||
int id;
|
||||
if ((id = databaseRepo.register(pseudo, email, password, firstname, lastname, description, group,
|
||||
avatar)) >= 0) {
|
||||
HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *",
|
||||
HttpUtil.responseHeaders(writer, 200,
|
||||
"Access-Control-Allow-Origin: *",
|
||||
"Access-Control-Expose-Headers: Authorization",
|
||||
"Authorization: Bearer " + this.router.createAuthUser(id));
|
||||
createFolderToSaveSourceCode(pseudo);
|
||||
return;
|
||||
|
|
|
@ -20,10 +20,12 @@ public class Router{
|
|||
private RsaJsonWebKey rsaJsonWebKey;
|
||||
private DatabaseRepository repo;
|
||||
private String token_issuer;
|
||||
private int token_expiration;
|
||||
|
||||
public Router(DatabaseRepository repo, String token_issuer) throws Exception{
|
||||
public Router(DatabaseRepository repo, String token_issuer, int token_expiration) throws Exception{
|
||||
this.repo = repo;
|
||||
this.token_issuer = token_issuer;
|
||||
this.token_expiration = token_expiration;
|
||||
this.responses = new ArrayList<>();
|
||||
this.rsaJsonWebKey = RsaJwkGenerator.generateJwk(2048);
|
||||
}
|
||||
|
@ -64,7 +66,7 @@ public class Router{
|
|||
public String createAuthUser(int id) throws JoseException{
|
||||
JwtClaims claims = new JwtClaims();
|
||||
claims.setIssuer(token_issuer); // who creates the token and signs it
|
||||
claims.setExpirationTimeMinutesInTheFuture(10); // time when the token will expire (10 minutes from now)
|
||||
claims.setExpirationTimeMinutesInTheFuture(token_expiration);
|
||||
claims.setGeneratedJwtId(); // a unique identifier for the token
|
||||
claims.setIssuedAtToNow(); // when the token was issued/created (now)
|
||||
claims.setNotBeforeMinutesInThePast(2); // time before which the token is not yet valid (2 minutes ago)
|
||||
|
|
Loading…
Add table
Reference in a new issue