本文整理汇总了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();
}