正在查看: Mint v5.7.3 应用的 DefaultClaims.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Mint v5.7.3 应用的 DefaultClaims.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package io.jsonwebtoken.impl;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.RequiredTypeException;
import java.util.Date;
import java.util.Map;
public class DefaultClaims extends JwtMap implements Claims {
private static final String CONVERSION_ERROR_MSG = "Cannot convert existing claim value of type '%s' to desired type '%s'. JJWT only converts simple String, Date, Long, Integer, Short and Byte types automatically. Anything more complex is expected to be already converted to your desired type by the JSON Deserializer implementation. You may specify a custom Deserializer for a JwtParser with the desired conversion configuration via the JwtParserBuilder.deserializeJsonWith() method. See https://github.com/jwtk/jjwt#custom-json-processor for more information. If using Jackson, you can specify custom claim POJO types as described in https://github.com/jwtk/jjwt#json-jackson-custom-types";
public DefaultClaims() {
}
public DefaultClaims(Map<String, ?> map) {
super(map);
}
private <T> T castClaimValue(Object obj, Class<T> cls) {
if (obj instanceof Integer) {
int intValue = ((Integer) obj).intValue();
if (cls == Long.class) {
obj = Long.valueOf(intValue);
} else if (cls == Short.class && -32768 <= intValue && intValue <= 32767) {
obj = Short.valueOf((short) intValue);
} else if (cls == Byte.class && -128 <= intValue && intValue <= 127) {
obj = Byte.valueOf((byte) intValue);
}
}
if (cls.isInstance(obj)) {
return cls.cast(obj);
}
throw new RequiredTypeException(String.format(CONVERSION_ERROR_MSG, obj.getClass(), cls));
}
private static boolean isSpecDate(String str) {
return "exp".equals(str) || "iat".equals(str) || "nbf".equals(str);
}
public <T> T get(String str, Class<T> cls) {
Object obj = get(str);
if (obj == null) {
return null;
}
if (Date.class.equals(cls)) {
obj = isSpecDate(str) ? JwtMap.toSpecDate(obj, str) : JwtMap.toDate(obj, str);
}
return (T) castClaimValue(obj, cls);
}
public String getAudience() {
return getString("aud");
}
public Date getExpiration() {
return (Date) get("exp", Date.class);
}
public String getId() {
return getString("jti");
}
public Date getIssuedAt() {
return (Date) get("iat", Date.class);
}
public String getIssuer() {
return getString("iss");
}
public Date getNotBefore() {
return (Date) get("nbf", Date.class);
}
public String getSubject() {
return getString("sub");
}
@Override
public Object put(String str, Object obj) {
return ((obj instanceof Date) && isSpecDate(str)) ? setDateAsSeconds(str, (Date) obj) : super.put(str, obj);
}
public Claims m111setAudience(String str) {
setValue("aud", str);
return this;
}
public Claims m112setExpiration(Date date) {
setDateAsSeconds("exp", date);
return this;
}
public Claims m113setId(String str) {
setValue("jti", str);
return this;
}
public Claims m114setIssuedAt(Date date) {
setDateAsSeconds("iat", date);
return this;
}
public Claims m115setIssuer(String str) {
setValue("iss", str);
return this;
}
public Claims m116setNotBefore(Date date) {
setDateAsSeconds("nbf", date);
return this;
}
public Claims m117setSubject(String str) {
setValue("sub", str);
return this;
}
}