Export & Import jwt privte key in config
This commit is contained in:
parent
19b3f6391b
commit
634bcbadf4
4 changed files with 44 additions and 9 deletions
Binary file not shown.
|
@ -42,6 +42,8 @@ public class Configuration {
|
||||||
|
|
||||||
private String git_token;
|
private String git_token;
|
||||||
|
|
||||||
|
private String jwt_key;
|
||||||
|
|
||||||
private File _file;
|
private File _file;
|
||||||
|
|
||||||
public Configuration(String path) {
|
public Configuration(String path) {
|
||||||
|
@ -207,4 +209,12 @@ public class Configuration {
|
||||||
public String getGitToken(){
|
public String getGitToken(){
|
||||||
return this.git_token;
|
return this.git_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getJwtKey(){
|
||||||
|
return this.jwt_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJwtKey(String key){
|
||||||
|
this.jwt_key = key;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@ import static dev.peerat.framework.RequestType.OPTIONS;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
import dev.peerat.backend.bonus.extract.RouteExtracter;
|
import dev.peerat.backend.bonus.extract.RouteExtracter;
|
||||||
|
@ -58,6 +59,8 @@ import dev.peerat.framework.Response;
|
||||||
import dev.peerat.framework.Route;
|
import dev.peerat.framework.Route;
|
||||||
import dev.peerat.framework.RouteInterceptor;
|
import dev.peerat.framework.RouteInterceptor;
|
||||||
import dev.peerat.framework.Router;
|
import dev.peerat.framework.Router;
|
||||||
|
import dev.peerat.framework.utils.json.JsonMap;
|
||||||
|
import dev.peerat.framework.utils.json.JsonParser;
|
||||||
|
|
||||||
public class Main{
|
public class Main{
|
||||||
|
|
||||||
|
@ -72,13 +75,6 @@ public class Main{
|
||||||
|
|
||||||
DatabaseRepository repo = new DatabaseRepository(config);
|
DatabaseRepository repo = new DatabaseRepository(config);
|
||||||
Router<PeerAtUser> router = new Router<PeerAtUser>()
|
Router<PeerAtUser> router = new Router<PeerAtUser>()
|
||||||
.configureJwt(
|
|
||||||
(builder) -> builder.setExpectedIssuer(config.getTokenIssuer()),
|
|
||||||
(claims) -> {
|
|
||||||
claims.setIssuer(config.getTokenIssuer()); // who creates the token and signs it
|
|
||||||
claims.setExpirationTimeMinutesInTheFuture(config.getTokenExpiration());
|
|
||||||
},
|
|
||||||
(claims) -> new PeerAtUser(claims))
|
|
||||||
.activeReOrdering().
|
.activeReOrdering().
|
||||||
addDefaultHeaders(RequestType.GET, "Access-Control-Allow-Origin: *").
|
addDefaultHeaders(RequestType.GET, "Access-Control-Allow-Origin: *").
|
||||||
addDefaultHeaders(RequestType.POST, "Access-Control-Allow-Origin: *").
|
addDefaultHeaders(RequestType.POST, "Access-Control-Allow-Origin: *").
|
||||||
|
@ -88,6 +84,35 @@ public class Main{
|
||||||
"Access-Control-Allow-Headers: *");
|
"Access-Control-Allow-Headers: *");
|
||||||
ACCESS_ROUTER = router;
|
ACCESS_ROUTER = router;
|
||||||
|
|
||||||
|
if(config.getJwtKey() != null){
|
||||||
|
JsonParser parser = new JsonParser();
|
||||||
|
JsonMap json = parser.parse(config.getJwtKey());
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
for(Entry<String, Object> entry : json.entries()) params.put(entry.getKey(), entry.getValue());
|
||||||
|
router.configureJwt(
|
||||||
|
(builder) -> builder.setExpectedIssuer(config.getTokenIssuer()),
|
||||||
|
(claims) -> {
|
||||||
|
claims.setIssuer(config.getTokenIssuer());
|
||||||
|
claims.setExpirationTimeMinutesInTheFuture(config.getTokenExpiration());
|
||||||
|
},
|
||||||
|
(claims) -> new PeerAtUser(claims),
|
||||||
|
params);
|
||||||
|
}else{
|
||||||
|
router.configureJwt(
|
||||||
|
(builder) -> builder.setExpectedIssuer(config.getTokenIssuer()),
|
||||||
|
(claims) -> {
|
||||||
|
claims.setIssuer(config.getTokenIssuer());
|
||||||
|
claims.setExpirationTimeMinutesInTheFuture(config.getTokenExpiration());
|
||||||
|
},
|
||||||
|
(claims) -> new PeerAtUser(claims));
|
||||||
|
JsonMap json = new JsonMap();
|
||||||
|
for(Entry<String, Object> entry : router.exportJwtKey().entrySet()){
|
||||||
|
json.set(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
config.setJwtKey(json.toString());
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
router.setDefault((matcher, context, reader, writer) -> {
|
router.setDefault((matcher, context, reader, writer) -> {
|
||||||
context.response(404);
|
context.response(404);
|
||||||
writer.write("404 not Found.\n");
|
writer.write("404 not Found.\n");
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class Leaderboard implements Response {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
leaderboardJSON.set("groups", groupsJSON);
|
leaderboardJSON.set("groups", groupsJSON);
|
||||||
writer.write(leaderboardJSON.toString().replace("\\", ""));
|
writer.write(leaderboardJSON.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void playersLeaderboard(HttpWriter writer) throws IOException {
|
public final void playersLeaderboard(HttpWriter writer) throws IOException {
|
||||||
|
@ -86,6 +86,6 @@ public class Leaderboard implements Response {
|
||||||
playersJSON.add(playerJSON);
|
playersJSON.add(playerJSON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writer.write(playersJSON.toString().replace("\\", ""));
|
writer.write(playersJSON.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue