⬆️ Upgrading dependencies. up nacos 1.3.2 https://gitee.com/log4j/pig/issues/I1Q9RG

This commit is contained in:
冷冷 committed 2020-08-24 22:04:35 +08:00
1 parent 4b27431edb
commit 86b40ec069
305 files changed
+2773 -960

No files matched your search

+25 -25
View File
@@ -13,9 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.utils;
import io.jsonwebtoken.*;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.MalformedJwtException;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.SignatureException;
import io.jsonwebtoken.UnsupportedJwtException;
import io.jsonwebtoken.security.Keys;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,7 +40,7 @@ import java.util.Date;
import java.util.List;
/**
* Jwt token tool
* Jwt token tool.
*
* @author wfnuser
*/
@@ -45,31 +52,34 @@ public class JwtTokenUtils {
private static final String AUTHORITIES_KEY = "auth";
/**
* minimum SHA_256 secretKey string length
* minimum SHA_256 secretKey string length.
*/
private static final int SHA_256_SECRET_CHAR_SIZE = 256 / 8;
/**
* default SHA_256 secretKey flag
* default SHA_256 secretKey flag.
*/
private static final String DEFAULT_SECRET_FLAG = "default";
/**
* custom SHA_256 secretKey from config property
* custom SHA_256 secretKey from config property.
*/
@Value("${nacos.security.token.secret-key:default}")
private String customSecretKeyStr;
/**
* secret key
* secret key.
*/
private SecretKey secretKey;
/**
* Token validity time(ms)
* Token validity time(ms).
*/
private long tokenValidityInMilliseconds;
/**
* Init.
*/
@PostConstruct
public void init() {
// use default secretKey for SHA-256
@@ -96,37 +106,27 @@ public class JwtTokenUtils {
}
/**
* Create token
* Create token.
* @param authentication auth info
* @return token
*/
public String createToken(Authentication authentication) {
/**
* Current time
*/
long now = (new Date()).getTime();
/**
* Validity date
*/
Date validity;
validity = new Date(now + this.tokenValidityInMilliseconds);
/**
* create token
*/
long now = System.currentTimeMillis();
Date validity = new Date(now + this.tokenValidityInMilliseconds);
return Jwts.builder().setSubject(authentication.getName()).claim(AUTHORITIES_KEY, "").setExpiration(validity)
.signWith(secretKey, SignatureAlgorithm.HS256).compact();
}
/**
* Get auth Info
* Get auth Info.
* @param token token
* @return auth info
*/
public Authentication getAuthentication(String token) {
/**
* parse the payload of token
*/
Claims claims = Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token).getBody();
List<GrantedAuthority> authorities = AuthorityUtils
@@ -137,7 +137,7 @@ public class JwtTokenUtils {
}
/**
* validate token
* validate token.
* @param token token
* @return whether valid
*/