类 AccessKeyUtil
java.lang.Object
cn.vorbote.simplejwt.AccessKeyUtil
JWT Token implementation, easy to use.
- 作者:
- vorbote thills@vorbote.cn
-
构造器概要
构造器构造器说明AccessKeyUtil(@NonNull JwtAlgorithm algorithm, @NonNull String secret, @NonNull String issuer) -
方法概要
修饰符和类型方法说明createToken(cn.vorbote.core.time.TimeSpan expire, String subject, String[] audience, Map<String, Object> claims) Create a new Token.createTokenWithBean(cn.vorbote.core.time.TimeSpan expire, String subject, String[] audience, Object bean) Create a new token with all data(except null data) in the bean.protected JwtAlgorithm<T> TGet the bean in the token.protected Stringprotected Stringcom.auth0.jwt.interfaces.DecodedJWTDecode the token, and you can easily get some info from this token.已过时。Renew the token.renewWithBean(String token, cn.vorbote.core.time.TimeSpan expireAfter, Class<?> requiredType) Renew this token with the data in the bean.protected voidprotected voidvoidCheck whether the token is valid.
-
构造器详细资料
-
AccessKeyUtil
public AccessKeyUtil(@NonNull @NonNull JwtAlgorithm algorithm, @NonNull @NonNull String secret, @NonNull @NonNull String issuer)
-
-
方法详细资料
-
getSecret
-
setSecret
-
getIssuer
-
setIssuer
-
getAlgorithm
-
createToken
public String createToken(cn.vorbote.core.time.TimeSpan expire, String subject, String[] audience, Map<String, Object> claims) Create a new Token. All the items in claims will be set as a String into this JSON Web Token.- 参数:
expire- Specify when will the token be expired. (Unit: Second)subject- Specify the users will be faced.audience- Specify who will receive this token.claims- Give some info need to be transformed by token, can be null when you don't need to pass any information.- 返回:
- A token string.
-
createTokenWithBean
public String createTokenWithBean(cn.vorbote.core.time.TimeSpan expire, String subject, String[] audience, Object bean) throws Exception Create a new token with all data(except null data) in the bean.- 参数:
expire- After this time span, this jwt will be expired and is not be able to use again.subject- The subject of this jwt.audience- The audience of this jwt.bean- The bean contains any possible users' data.- 返回:
- A token generated by the data of the bean.
- 抛出:
Exception- Any possible exception may occurred in runtime, please check the upriver methods.- 另请参阅:
-
Class.getDeclaredFields()Field.get(Object)Field.setAccessible(boolean)JWTCreator.Builder.withClaim(String, Boolean)JWTCreator.Builder.withClaim(String, Date)JWTCreator.Builder.withClaim(String, Double)JWTCreator.Builder.withClaim(String, Integer)JWTCreator.Builder.withClaim(String, List)JWTCreator.Builder.withClaim(String, Long)JWTCreator.Builder.withClaim(String, Map)JWTCreator.Builder.withClaim(String, String)
-
verify
Check whether the token is valid. This method will happen nothing when the token is valid, or throw some exception when token is invalid.- 参数:
token- The token.
-
info
Decode the token, and you can easily get some info from this token.- 参数:
token- The token.- 返回:
- The decoded jwt token.
- 抛出:
com.auth0.jwt.exceptions.AlgorithmMismatchException- If the algorithm stated in the token's header it's not equal to the one defined in the JWTVerifier.com.auth0.jwt.exceptions.SignatureVerificationException- If the signature is invalid.com.auth0.jwt.exceptions.TokenExpiredException- If the token has expired.com.auth0.jwt.exceptions.InvalidClaimException- If a claim contained a different value than the expected one.com.auth0.jwt.exceptions.JWTVerificationException- If any of the verification steps fail- 另请参阅:
-
JWTVerifier.verify(String)
-
renew
已过时。Renew the token.- 参数:
token- The original token.expireAfter- The time period (seconds) when the new token expired.- 返回:
- The renewed token.
-
renew
Renew the token.- 参数:
token- The original token.expireAfter- The time period (seconds) when the new token expired.- 返回:
- The renewed token.
-
renewWithBean
public String renewWithBean(String token, cn.vorbote.core.time.TimeSpan expireAfter, Class<?> requiredType) throws Exception Renew this token with the data in the bean. This method will auto distract the data needed by required type.- 参数:
token- The original token.expireAfter- Expire after this time.requiredType- The required type's class.- 返回:
- A new token.
- 抛出:
Exception- This method is using lots of methods could cause some exception, please see its upriver methods.- 另请参阅:
-
getBean
Get the bean in the token. In this method, you have to make sure that your stored info is in the format of key-value pair and which is stored in the claims. And the key must be the same with that field in the required type (such as the field name in required is declared asprivate String name;, then your key must bename). Meanwhile, the setter for this field is required either. Be advised, the field log and logger is thought as a helper field, thus, it will not be put into the token.- 类型参数:
T- The type of the bean.- 参数:
token- The user token.requiredType- The class of user.- 返回:
- The user bean.
- 抛出:
Exception- This method is using lots of methods could cause some exception, please see its upriver methods.- 另请参阅:
-
Class.getConstructor(Class...)Class.getDeclaredFields()Constructor.newInstance(Object...)Map.get(Object)MapUtil.setFieldValue(Object, String, Object)
-