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
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:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user