本文整理匯總了Java中io.jsonwebtoken.Claims.getAudience方法的典型用法代碼示例。如果您正苦於以下問題:Java Claims.getAudience方法的具體用法?Java Claims.getAudience怎麽用?Java Claims.getAudience使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.jsonwebtoken.Claims
的用法示例。
在下文中一共展示了Claims.getAudience方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: executeSignOut
import io.jsonwebtoken.Claims; //導入方法依賴的package包/類
@Override
public JsonResult executeSignOut(HttpServletRequest request, HttpServletResponse response) {
JsonResult result = new JsonResult();
Cookie tokenCookie = CookieUtil.getCookieByName(request, AppConstants.ACCESS_TOKEN);
if (tokenCookie != null) {
Claims requestClaims = JwtTokenUtil.getClaims(tokenCookie.getValue(), appProperties.getJwtSecretKey());
// 清除緩存
String cacheKey = AppConstants.CACHE_ACCESS_TOKEN + requestClaims.getAudience();
byteRedisClient.del(cacheKey);
}
// 清除Cookie
CookieUtil.removeCookie(AppConstants.ACCESS_TOKEN, "lovexq.net", response);
CookieUtil.removeCookie(AppConstants.USER_NAME, "lovexq.net", response);
return result;
}
示例2: exposureSecKillUrl
import io.jsonwebtoken.Claims; //導入方法依賴的package包/類
@Override
@Transactional(readOnly = true)
public JsonResult exposureSecKillUrl(Long id, Claims claims) throws Exception {
String account = claims.getAudience();
SpecialStockDTO specialStock = getOne(id);
LocalDateTime startTime = specialStock.getStartTime(); // 秒殺開始時間
LocalDateTime endTime = specialStock.getEndTime(); // 秒殺結束時間
LocalDateTime nowTime = TimeUtil.nowDateTime(); //係統當前時間
//若是秒殺未開始
if (startTime.isAfter(nowTime)) {
return new JsonResult(406, "秒殺活動未開始!");
//秒殺已經結束
} else if (endTime.isBefore(nowTime) || specialStock.getNumber() < 1) {
return new JsonResult(406, "秒殺活動已經結束!");
//秒殺處於開啟窗口
} else {
// 檢查是否秒殺過
SpecialOrderModel order = specialOrderRepository.findByStockIdAndAccount(id, account);
if (order != null) {
return new JsonResult(403, "已秒殺成功,請勿重複秒殺!");
}
return new JsonResult(getMd5Url(id));
}
}
示例3: executeSecKill
import io.jsonwebtoken.Claims; //導入方法依賴的package包/類
@Override
public JsonResult executeSecKill(Long id, String key, String captcha, Claims claims) throws Exception {
JsonResult result = new JsonResult();
String account = claims.getAudience();
// 先檢查驗證碼 FIXME 測試需要,暫時屏蔽
/*String cacheKey = AppConstants.CACHE_CAPTCHA + account;
String cacheCaptcha = byteRedisClient.getByteObj(cacheKey, String.class);
if (StringUtils.isBlank(cacheCaptcha)) {
return new JsonResult(401, "驗證碼已過期,請刷新重試!");
}
if (!captcha.equals(cacheCaptcha)) {
return new JsonResult(401, "請輸入正確的驗證碼!");
}*/
if (key == null || !key.equals(getMd5Url(id))) {
return new JsonResult(401, "秒殺請求無效!");
}
SpecialOrderModel specialOrderModel = new SpecialOrderModel(id, account, "下單");
// 加到緩存隊列
Boolean isAdd = byteRedisClient.zadd(AppConstants.CACHE_ZSET_SPECIAL_ORDER + id, specialOrderModel, Instant.now().toEpochMilli());
if (isAdd) {
// 成功加入才減庫存
Long stock = stringRedisClient.increment(AppConstants.CACHE_SPECIAL_STOCK_COUNT + id, -1L);
if (stock < 0) {
return new JsonResult(410, "房源已售罄!");
}
} else {
return new JsonResult(403, "已秒殺成功,請勿重複秒殺!");
}
return result;
}
示例4: saveCaptcha
import io.jsonwebtoken.Claims; //導入方法依賴的package包/類
@Override
@Transactional(readOnly = true)
public void saveCaptcha(Claims claims, String captcha) {
String cacheKey = AppConstants.CACHE_CAPTCHA + claims.getAudience();
byteRedisClient.setByteObj(cacheKey, captcha, 120);
}
示例5: getAudience
import io.jsonwebtoken.Claims; //導入方法依賴的package包/類
/**
* 從Token獲取受眾
*
* @param claims
* @return
*/
public static String getAudience(Claims claims) throws JwtException {
return claims.getAudience();
}