fixed some issue for the token authorization (#87)
All checks were successful
Build and test backend / Build-backend (push) Successful in 2m11s
Build and test backend / Test-backend (push) Successful in 1m20s
deploy to production / deploy-frontend (push) Successful in 25s
deploy to production / deploy-backend (push) Successful in 2m21s
Build and test FrontEnd / Build-frontend (push) Successful in 23s

Reviewed-on: #87
Reviewed-by: Debucquoy Anthony <d.tonitch@gmail.com>
Co-authored-by: Bartha Maxime <231026@umons.ac.be>
Co-committed-by: Bartha Maxime <231026@umons.ac.be>
This commit is contained in:
2024-03-10 23:28:13 +01:00
committed by Maxime
parent b7c97ead2b
commit ce2efb61c8
6 changed files with 45 additions and 13 deletions

View File

@ -20,12 +20,19 @@ public class TokenService {
this.tokenRepo = tokenRepo;
}
public Iterable<Token> getAllTokens() {
return tokenRepo.findAll();
}
public String generateNewToken(){
byte[] bytes = new byte[64];
new SecureRandom().nextBytes(bytes);
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) (((bytes[i]+256)%256 %95+ 32));
while ((char)bytes[i] == ';'){
bytes[i] = new SecureRandom().generateSeed(1)[0];
}
}
// will never end up in the catch because of the way that SecureRandom.nextBytes is implemented
try {
@ -35,8 +42,10 @@ public class TokenService {
}
}
public User getUserFromToken(String token){
return tokenRepo.getByToken(token).getUser();
public User getUserFromToken(String token) {
Token tokenRep = tokenRepo.getByToken(token);
if (tokenRep == null) return null;
return tokenRep.getUser();
}
public void saveToken(String token, User user, Date expirationDate){// todo faire qlq chose de l'expDate