|
|
|
@ -16,7 +16,6 @@ |
|
|
|
package org.thingsboard.server.service.security.model.token; |
|
|
|
|
|
|
|
import io.jsonwebtoken.Claims; |
|
|
|
import io.jsonwebtoken.ClaimsBuilder; |
|
|
|
import io.jsonwebtoken.ExpiredJwtException; |
|
|
|
import io.jsonwebtoken.Jws; |
|
|
|
import io.jsonwebtoken.JwtBuilder; |
|
|
|
@ -184,21 +183,20 @@ public class JwtTokenFactory { |
|
|
|
|
|
|
|
UserPrincipal principal = securityUser.getUserPrincipal(); |
|
|
|
|
|
|
|
ClaimsBuilder claims = Jwts.claims() |
|
|
|
.subject(principal.getValue()) |
|
|
|
.add(USER_ID, securityUser.getId().getId().toString()) |
|
|
|
.add(SCOPES, scopes); |
|
|
|
Claims claims = Jwts.claims().setSubject(principal.getValue()).build(); |
|
|
|
claims.put(USER_ID, securityUser.getId().getId().toString()); |
|
|
|
claims.put(SCOPES, scopes); |
|
|
|
if (securityUser.getSessionId() != null) { |
|
|
|
claims.add(SESSION_ID, securityUser.getSessionId()); |
|
|
|
claims.put(SESSION_ID, securityUser.getSessionId()); |
|
|
|
} |
|
|
|
|
|
|
|
ZonedDateTime currentTime = ZonedDateTime.now(); |
|
|
|
|
|
|
|
return Jwts.builder() |
|
|
|
.claims(claims.build()) |
|
|
|
.issuer(jwtSettingsService.getJwtSettings().getTokenIssuer()) |
|
|
|
.issuedAt(Date.from(currentTime.toInstant())) |
|
|
|
.expiration(Date.from(currentTime.plusSeconds(expirationTime).toInstant())) |
|
|
|
.setClaims(claims) |
|
|
|
.setIssuer(jwtSettingsService.getJwtSettings().getTokenIssuer()) |
|
|
|
.setIssuedAt(Date.from(currentTime.toInstant())) |
|
|
|
.setExpiration(Date.from(currentTime.plusSeconds(expirationTime).toInstant())) |
|
|
|
.signWith(SignatureAlgorithm.HS512, jwtSettingsService.getJwtSettings().getTokenSigningKey()); |
|
|
|
} |
|
|
|
|
|
|
|
@ -207,7 +205,7 @@ public class JwtTokenFactory { |
|
|
|
return Jwts.parser() |
|
|
|
.setSigningKey(jwtSettingsService.getJwtSettings().getTokenSigningKey()) |
|
|
|
.build() |
|
|
|
.parseSignedClaims(token); |
|
|
|
.parseClaimsJws(token); |
|
|
|
} catch (UnsupportedJwtException | MalformedJwtException | IllegalArgumentException ex) { |
|
|
|
log.debug("Invalid JWT Token", ex); |
|
|
|
throw new BadCredentialsException("Invalid JWT token: ", ex); |
|
|
|
|