diff --git a/src/be/jeffcheasey88/peeratcode/Configuration.java b/src/be/jeffcheasey88/peeratcode/Configuration.java index 8a3523f..2e7a691 100644 --- a/src/be/jeffcheasey88/peeratcode/Configuration.java +++ b/src/be/jeffcheasey88/peeratcode/Configuration.java @@ -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; } diff --git a/src/be/jeffcheasey88/peeratcode/Main.java b/src/be/jeffcheasey88/peeratcode/Main.java index c00c796..574a025 100644 --- a/src/be/jeffcheasey88/peeratcode/Main.java +++ b/src/be/jeffcheasey88/peeratcode/Main.java @@ -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(){ diff --git a/src/be/jeffcheasey88/peeratcode/model/Player.java b/src/be/jeffcheasey88/peeratcode/model/Player.java index fe63524..070f271 100644 --- a/src/be/jeffcheasey88/peeratcode/model/Player.java +++ b/src/be/jeffcheasey88/peeratcode/model/Player.java @@ -93,16 +93,17 @@ public class Player implements Comparable { } @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); } } diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Class.java b/src/be/jeffcheasey88/peeratcode/parser/java/Class.java index 3b58325..f85cf50 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Class.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Class.java @@ -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("}"); + } } diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java index c241e29..e181d5e 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java @@ -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 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; diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java b/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java index 63646b6..037ff16 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java @@ -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+";"); + } } diff --git a/src/be/jeffcheasey88/peeratcode/repository/DatabaseRepository.java b/src/be/jeffcheasey88/peeratcode/repository/DatabaseRepository.java index 6f291a4..390d2c1 100644 --- a/src/be/jeffcheasey88/peeratcode/repository/DatabaseRepository.java +++ b/src/be/jeffcheasey88/peeratcode/repository/DatabaseRepository.java @@ -158,7 +158,7 @@ public class DatabaseRepository { ResultSet result = playersStmt.executeQuery(); SortedSet players = new TreeSet(); Player tmpPlayer; - while (result.next()) { + while (result.next()){ tmpPlayer = makePlayer(result); tmpPlayer.setTotalScore(result.getInt("playerScore")); tmpPlayer.setTotalCompletion(result.getInt("playerCompletions")); diff --git a/src/be/jeffcheasey88/peeratcode/routes/Login.java b/src/be/jeffcheasey88/peeratcode/routes/Login.java index 7f43e5e..3faf511 100644 --- a/src/be/jeffcheasey88/peeratcode/routes/Login.java +++ b/src/be/jeffcheasey88/peeratcode/routes/Login.java @@ -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; } diff --git a/src/be/jeffcheasey88/peeratcode/routes/Register.java b/src/be/jeffcheasey88/peeratcode/routes/Register.java index c984b54..5c45562 100644 --- a/src/be/jeffcheasey88/peeratcode/routes/Register.java +++ b/src/be/jeffcheasey88/peeratcode/routes/Register.java @@ -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; diff --git a/src/be/jeffcheasey88/peeratcode/webserver/Router.java b/src/be/jeffcheasey88/peeratcode/webserver/Router.java index f166ffe..3a9490f 100644 --- a/src/be/jeffcheasey88/peeratcode/webserver/Router.java +++ b/src/be/jeffcheasey88/peeratcode/webserver/Router.java @@ -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)