Refractor jwt values

This commit is contained in:
jeffcheasey88 2023-02-26 20:01:18 +01:00
parent 0f9fc996f1
commit 434e0ddea6
3 changed files with 11 additions and 4 deletions

View file

@ -20,6 +20,8 @@ public class Configuration {
private String ssl_keystore; private String ssl_keystore;
private String ssl_keystorePasswd; private String ssl_keystorePasswd;
private String token_issuer;
private File _file; private File _file;
public Configuration(String path){ public Configuration(String path){
@ -121,6 +123,10 @@ public class Configuration {
return this.ssl_keystore; return this.ssl_keystore;
} }
public String getTokenIssuer(){
return this.token_issuer;
}
public String getSslKeystorePasswd(){ public String getSslKeystorePasswd(){
return this.ssl_keystorePasswd; return this.ssl_keystorePasswd;
} }

View file

@ -49,7 +49,7 @@ public class Main {
Class.forName("com.mysql.cj.jdbc.Driver"); Class.forName("com.mysql.cj.jdbc.Driver");
Router router = new Router(new DatabaseRepository(config)); Router router = new Router(new DatabaseRepository(config), config.getTokenIssuer());
router.setDefault(new Response(){ router.setDefault(new Response(){

View file

@ -19,9 +19,11 @@ public class Router{
private Response noFileFound; private Response noFileFound;
private RsaJsonWebKey rsaJsonWebKey; private RsaJsonWebKey rsaJsonWebKey;
private DatabaseRepository repo; private DatabaseRepository repo;
private String token_issuer;
public Router(DatabaseRepository repo) throws Exception{ public Router(DatabaseRepository repo, String token_issuer) throws Exception{
this.repo = repo; this.repo = repo;
this.token_issuer = token_issuer;
this.responses = new ArrayList<>(); this.responses = new ArrayList<>();
this.rsaJsonWebKey = RsaJwkGenerator.generateJwk(2048); this.rsaJsonWebKey = RsaJwkGenerator.generateJwk(2048);
} }
@ -57,8 +59,7 @@ public class Router{
public String createAuthUser(int id) throws JoseException{ public String createAuthUser(int id) throws JoseException{
JwtClaims claims = new JwtClaims(); JwtClaims claims = new JwtClaims();
claims.setIssuer("Issuer"); // who creates the token and signs it claims.setIssuer(token_issuer); // who creates the token and signs it
claims.setAudience("Audience"); // to whom the token is intended to be sent
claims.setExpirationTimeMinutesInTheFuture(10); // time when the token will expire (10 minutes from now) claims.setExpirationTimeMinutesInTheFuture(10); // time when the token will expire (10 minutes from now)
claims.setGeneratedJwtId(); // a unique identifier for the token claims.setGeneratedJwtId(); // a unique identifier for the token
claims.setIssuedAtToNow(); // when the token was issued/created (now) claims.setIssuedAtToNow(); // when the token was issued/created (now)