fix: 未登录会员是否登录判断错误问题修复

This commit is contained in:
haoxr 2022-11-11 01:08:38 +08:00
parent 7d20277b59
commit cb9dff16f4
3 changed files with 12 additions and 7 deletions

View File

@ -44,7 +44,7 @@ public class SpuController {
}
@ApiOperation(value = "获取秒杀商品列表")
@GetMapping("/seckilling_list")
@GetMapping("/seckillList")
public Result<List<SeckillingSpuVO>> listSeckillingSpu() {
List<SeckillingSpuVO> list = spuService.listSeckillingSpu();
return Result.success(list);

View File

@ -162,8 +162,8 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
}
// 添加用户浏览历史记录
Long loginUserId = SecurityUtils.getMemberId();
if (loginUserId != null) {
Long memberId = SecurityUtils.getMemberId();
if (memberId != null) {
ProductHistoryVO vo = new ProductHistoryVO();
vo.setId(goodsInfo.getId());
vo.setName(goodsInfo.getName());

View File

@ -70,7 +70,7 @@ public class SecurityUtils {
*/
public static Set<String> getRoles() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication!=null && CollectionUtil.isNotEmpty(authentication.getAuthorities())) {
if (authentication != null && CollectionUtil.isNotEmpty(authentication.getAuthorities())) {
Set<String> roles = authentication.getAuthorities()
.stream()
.map(item -> StrUtil.removePrefix(item.getAuthority(), "ROLE_"))
@ -111,8 +111,13 @@ public class SecurityUtils {
public static Map<String, Object> getTokenAttributes() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
JwtAuthenticationToken jwtAuthenticationToken = (JwtAuthenticationToken) authentication;
Map<String, Object> tokenAttributes = jwtAuthenticationToken.getTokenAttributes();
return tokenAttributes;
if (authentication != null) {
if (authentication instanceof JwtAuthenticationToken) {
JwtAuthenticationToken jwtAuthenticationToken = (JwtAuthenticationToken) authentication;
Map<String, Object> tokenAttributes = jwtAuthenticationToken.getTokenAttributes();
return tokenAttributes;
}
}
return Collections.EMPTY_MAP;
}
}