Merge branch 'feature/GEPAFINBE-3' of https://github.com/Kitzanos/GEPAFIN-BE into feature/GEPAFINBE-8
This commit is contained in:
@@ -5,6 +5,8 @@ import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -39,7 +41,7 @@ public class TokenProvider {
|
||||
log.info("JWT Secret Key initialized.");
|
||||
}
|
||||
|
||||
public String createToken(Authentication authentication, Boolean rememberMe) {
|
||||
public String createToken(Authentication authentication, Boolean rememberMe, UserEntity user) {
|
||||
String authorities = authentication.getAuthorities().stream()
|
||||
.map(GrantedAuthority::getAuthority)
|
||||
.collect(Collectors.joining(","));
|
||||
@@ -55,9 +57,14 @@ public class TokenProvider {
|
||||
validity = new Date(now + (this.tokenValidityInSeconds * 1000));
|
||||
log.info("Creating token with standard validity of {} seconds.", this.tokenValidityInSeconds);
|
||||
}
|
||||
|
||||
String payload = authentication.getName();
|
||||
if(user != null) {
|
||||
payload += ":"+user.getId();
|
||||
}
|
||||
|
||||
String token = Jwts.builder()
|
||||
.setSubject(authentication.getName())
|
||||
.setSubject(payload)
|
||||
.claim("auth", authorities)
|
||||
.signWith(key, SignatureAlgorithm.HS512)
|
||||
.setExpiration(validity)
|
||||
|
||||
Reference in New Issue
Block a user