IE_JwtToken.java 文件源码

java
阅读 36 收藏 0 点赞 0 评论 0

项目:Customerly-Android-SDK 作者:
IE_JwtToken(@org.intellij.lang.annotations.Pattern(TOKEN_VALIDATOR_MATCHER) @Size(min = 5) @NonNull String pEncodedToken) throws IllegalArgumentException {
    super();
    this._EncodedToken = pEncodedToken;

    if(! this._EncodedToken.matches(TOKEN_VALIDATOR_MATCHER)) {
        throw new IllegalArgumentException(String.format("Wrong token format. Token: %s does not match the regex %s", pEncodedToken, TOKEN_VALIDATOR_MATCHER));
    }
    JSONObject payloadJSON = null;
    try {
        Matcher matcher = TOKEN_PAYLOAD_MATCHER.matcher(pEncodedToken);
        if (matcher.find()) {
            payloadJSON = new JSONObject(
                    new String(Base64.decode(matcher.group(1), Base64.DEFAULT), "UTF-8"));
        }
    } catch (Exception ignored) { }

    if(payloadJSON != null) {
        long tmpUserID = payloadJSON.optLong("id", -1L);
        this._UserID = tmpUserID == -1L ? null : tmpUserID;
        //noinspection WrongConstant
        this._UserType = payloadJSON.optInt("type", USER_TYPE__ANONYMOUS);
    } else {
        this._UserID = null;
        this._UserType = USER_TYPE__ANONYMOUS;
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号