diff --git a/src/be/jeffcheasey88/peeratcode/Configuration.java b/src/be/jeffcheasey88/peeratcode/Configuration.java index 1915ed1..13eb173 100644 --- a/src/be/jeffcheasey88/peeratcode/Configuration.java +++ b/src/be/jeffcheasey88/peeratcode/Configuration.java @@ -7,7 +7,7 @@ import java.io.FileReader; import java.io.FileWriter; import java.lang.reflect.Field; -public class Configuration { +public class Configuration{ private String db_host; private int db_port; @@ -29,33 +29,33 @@ public class Configuration { private int groupJoinMinutes; private String groupQuitMinutes; + + private String git_token; - private File file; + private File _file; - public Configuration(String path) { - this.file = new File(path); - System.out.println("Config on " + file.getAbsolutePath()); + public Configuration(String path){ + this._file = new File(path); + System.out.println("Config on " + _file.getAbsolutePath()); } - public void load() throws Exception { - if (!this.file.exists()) - return; - BufferedReader reader = new BufferedReader(new FileReader(this.file)); + public void load() throws Exception{ + if(!this._file.exists()) return; + BufferedReader reader = new BufferedReader(new FileReader(this._file)); String line; - while ((line = reader.readLine()) != null) { + while((line = reader.readLine()) != null){ String[] split = line.split("="); Field field = getClass().getDeclaredField(split[0]); - if (field == null) - continue; + if(field == null) continue; field.setAccessible(true); injectValue(field, split[1]); } reader.close(); } - private void injectValue(Field field, String value) throws IllegalAccessException { - if (field.getType().isPrimitive()) { - switch (field.getType().getName()) { + private void injectValue(Field field, String value) throws IllegalAccessException{ + if(field.getType().isPrimitive()){ + switch(field.getType().getName()){ case "boolean": field.setBoolean(this, Boolean.parseBoolean(value)); break; @@ -85,26 +85,24 @@ public class Configuration { } return; } - if (field.getType().equals(String.class)) { + if(field.getType().equals(String.class)){ field.set(this, value); return; } throw new IllegalArgumentException(value); } - public void save() throws Exception { - if (!file.exists()) { - File parent = file.getParentFile(); - if (!parent.exists()) - parent.mkdirs(); - file.createNewFile(); + public void save() throws Exception{ + if(!_file.exists()){ + File parent = _file.getParentFile(); + if(!parent.exists()) parent.mkdirs(); + _file.createNewFile(); } Field[] fields = getClass().getDeclaredFields(); - BufferedWriter writer = new BufferedWriter(new FileWriter(file)); - for (Field field : fields) { + BufferedWriter writer = new BufferedWriter(new FileWriter(_file)); + for(Field field : fields){ field.setAccessible(true); - if (field.getName().startsWith("_")) - continue; + if(field.getName().startsWith("_")) continue; Object value = field.get(this); writer.write(field.getName() + "=" + value); } @@ -112,53 +110,52 @@ public class Configuration { writer.close(); } - public String getDbHost() { + public String getDbHost(){ return this.db_host; } - public int getDbPort() { + public int getDbPort(){ return this.db_port; } - public String getDbUser() { + public String getDbUser(){ return this.db_user; } - public String getDbDatabase() { + public String getDbDatabase(){ return this.db_database; } - public String getDbPassword() { + public String getDbPassword(){ return this.db_password; } - public String getSslKeystore() { + public String getSslKeystore(){ return this.ssl_keystore; } - public String getTokenIssuer() { + public String getTokenIssuer(){ return this.token_issuer; } - public int getTokenExpiration() { + public int getTokenExpiration(){ return this.token_expiration; } - public String getSslKeystorePasswd() { + public String getSslKeystorePasswd(){ return this.ssl_keystorePasswd; } - public int getTcpPort() { + public int getTcpPort(){ return this.tcp_port; } - public boolean useSsl() { + public boolean useSsl(){ return this.use_ssl; } - public String getUsersFiles() { - if (users_files == null || users_files.trim().isEmpty()) - users_files = "/tmp/users_files"; + public String getUsersFiles(){ + if(users_files == null || users_files.trim().isEmpty()) users_files = "/tmp/users_files"; return users_files; } @@ -173,4 +170,8 @@ public class Configuration { public String getGroupQuitMinutes(){ return this.groupQuitMinutes; } + + public String getGitToken(){ + return this.git_token; + } } \ No newline at end of file diff --git a/src/be/jeffcheasey88/peeratcode/Main.java b/src/be/jeffcheasey88/peeratcode/Main.java index eaebc82..22e098e 100644 --- a/src/be/jeffcheasey88/peeratcode/Main.java +++ b/src/be/jeffcheasey88/peeratcode/Main.java @@ -76,7 +76,7 @@ public class Main{ private static void initRoutes(Router router, Configuration config){ DatabaseRepository repo = router.getDataBase(); - router.register(new Register(repo, router, config.getUsersFiles())); + router.register(new Register(repo, router, config.getUsersFiles(), config.getGitToken())); router.register(new Login(repo, router)); router.register(new ProfileSettings(repo)); router.register(new ChangePassword(repo)); diff --git a/src/be/jeffcheasey88/peeratcode/routes/users/Register.java b/src/be/jeffcheasey88/peeratcode/routes/users/Register.java index 38cbbe7..b3492ad 100644 --- a/src/be/jeffcheasey88/peeratcode/routes/users/Register.java +++ b/src/be/jeffcheasey88/peeratcode/routes/users/Register.java @@ -36,11 +36,13 @@ public class Register extends FormResponse { private String usersFilesPath; private KeyPairGenerator generator; private Encoder encoder; + private String gitToken; - public Register(DatabaseRepository databaseRepo, Router router, String initUsersFilesPath) { + public Register(DatabaseRepository databaseRepo, Router router, String initUsersFilesPath, String gitToken){ this.databaseRepo = databaseRepo; this.router = router; - usersFilesPath = initUsersFilesPath; + this.usersFilesPath = initUsersFilesPath; + this.gitToken = gitToken; try { generator = KeyPairGenerator.getInstance("RSA"); generator.initialize(2048); //a changer ? @@ -120,6 +122,7 @@ public class Register extends FormResponse { HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type","application/json"); + connection.setRequestProperty("Authorization","Bearer "+this.gitToken); connection.setDoInput(true); connection.setDoOutput(true);