mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -52,7 +52,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
*
|
||||
* @return JWT
|
||||
*/
|
||||
public static JWT create() {
|
||||
public static JWT of() {
|
||||
return new JWT();
|
||||
}
|
||||
|
||||
|
@@ -29,7 +29,7 @@ public class JWTUtil {
|
||||
* @return JWT Token
|
||||
*/
|
||||
public static String createToken(final Map<String, Object> headers, final Map<String, Object> payload, final byte[] key) {
|
||||
return JWT.create()
|
||||
return JWT.of()
|
||||
.addHeaders(headers)
|
||||
.addPayloads(payload)
|
||||
.setKey(key)
|
||||
@@ -56,7 +56,7 @@ public class JWTUtil {
|
||||
* @return JWT Token
|
||||
*/
|
||||
public static String createToken(final Map<String, Object> headers, final Map<String, Object> payload, final JWTSigner signer) {
|
||||
return JWT.create()
|
||||
return JWT.of()
|
||||
.addHeaders(headers)
|
||||
.addPayloads(payload)
|
||||
.setSigner(signer)
|
||||
|
@@ -117,7 +117,7 @@ public class JWTSignerTest {
|
||||
}
|
||||
|
||||
private static void signAndVerify(final JWTSigner signer){
|
||||
final JWT jwt = JWT.create()
|
||||
final JWT jwt = JWT.of()
|
||||
.setPayload("sub", "1234567890")
|
||||
.setPayload("name", "looly")
|
||||
.setPayload("admin", true)
|
||||
|
@@ -19,7 +19,7 @@ public class JWTTest {
|
||||
@Test
|
||||
public void createHs256Test(){
|
||||
final byte[] key = "1234567890".getBytes();
|
||||
final JWT jwt = JWT.create()
|
||||
final JWT jwt = JWT.of()
|
||||
.setPayload("sub", "1234567890")
|
||||
.setPayload("name", "looly")
|
||||
.setPayload("admin", true)
|
||||
@@ -59,7 +59,7 @@ public class JWTTest {
|
||||
|
||||
@Test
|
||||
public void createNoneTest(){
|
||||
final JWT jwt = JWT.create()
|
||||
final JWT jwt = JWT.of()
|
||||
.setPayload("sub", "1234567890")
|
||||
.setPayload("name", "looly")
|
||||
.setPayload("admin", true)
|
||||
@@ -79,7 +79,7 @@ public class JWTTest {
|
||||
*/
|
||||
@Test(expected = JWTException.class)
|
||||
public void needSignerTest(){
|
||||
final JWT jwt = JWT.create()
|
||||
final JWT jwt = JWT.of()
|
||||
.setPayload("sub", "1234567890")
|
||||
.setPayload("name", "looly")
|
||||
.setPayload("admin", true);
|
||||
@@ -150,7 +150,7 @@ public class JWTTest {
|
||||
|
||||
@Test()
|
||||
public void getDateTest(){
|
||||
final String token = JWT.create()
|
||||
final String token = JWT.of()
|
||||
.setIssuedAt(DateUtil.parse("2022-02-02"))
|
||||
.setKey("123456".getBytes())
|
||||
.sign();
|
||||
|
@@ -18,7 +18,7 @@ public class JWTValidatorTest {
|
||||
|
||||
@Test(expected = ValidateException.class)
|
||||
public void issueAtTest(){
|
||||
final String token = JWT.create()
|
||||
final String token = JWT.of()
|
||||
.setIssuedAt(DateUtil.date())
|
||||
.setKey("123456".getBytes())
|
||||
.sign();
|
||||
@@ -29,7 +29,7 @@ public class JWTValidatorTest {
|
||||
|
||||
@Test
|
||||
public void issueAtPassTest(){
|
||||
final String token = JWT.create()
|
||||
final String token = JWT.of()
|
||||
.setIssuedAt(DateUtil.date())
|
||||
.setKey("123456".getBytes())
|
||||
.sign();
|
||||
@@ -40,7 +40,7 @@ public class JWTValidatorTest {
|
||||
|
||||
@Test(expected = ValidateException.class)
|
||||
public void notBeforeTest(){
|
||||
final JWT jwt = JWT.create()
|
||||
final JWT jwt = JWT.of()
|
||||
.setNotBefore(DateUtil.date());
|
||||
|
||||
JWTValidator.of(jwt).validateDate(DateUtil.yesterday());
|
||||
@@ -48,14 +48,14 @@ public class JWTValidatorTest {
|
||||
|
||||
@Test
|
||||
public void notBeforePassTest(){
|
||||
final JWT jwt = JWT.create()
|
||||
final JWT jwt = JWT.of()
|
||||
.setNotBefore(DateUtil.date());
|
||||
JWTValidator.of(jwt).validateDate(DateUtil.date());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateAlgorithmTest(){
|
||||
final String token = JWT.create()
|
||||
final String token = JWT.of()
|
||||
.setNotBefore(DateUtil.date())
|
||||
.setKey("123456".getBytes())
|
||||
.sign();
|
||||
@@ -74,7 +74,7 @@ public class JWTValidatorTest {
|
||||
|
||||
@Test(expected = ValidateException.class)
|
||||
public void validateDateTest(){
|
||||
final JWT jwt = JWT.create()
|
||||
final JWT jwt = JWT.of()
|
||||
.setPayload("id", 123)
|
||||
.setPayload("username", "hutool")
|
||||
.setExpiresAt(DateUtil.parse("2021-10-13 09:59:00"));
|
||||
@@ -90,7 +90,7 @@ public class JWTValidatorTest {
|
||||
final Date expiredTime = new Date(now + expired);
|
||||
|
||||
// 使用这种方式生成token
|
||||
final String token = JWT.create().setPayload("sub", "blue-light").setIssuedAt(nowTime).setNotBefore(expiredTime)
|
||||
final String token = JWT.of().setPayload("sub", "blue-light").setIssuedAt(nowTime).setNotBefore(expiredTime)
|
||||
.setExpiresAt(expiredTime).setKey("123456".getBytes()).sign();
|
||||
|
||||
// 使用这种方式验证token
|
||||
|
Reference in New Issue
Block a user