From 0783648c0183f798b9d231b1beac4bd66ab1c812 Mon Sep 17 00:00:00 2001 From: zbq2019 <49929998+zbq2019@users.noreply.github.com> Date: Thu, 23 Apr 2020 12:16:15 +0800 Subject: [PATCH] =?UTF-8?q?fix=20bug:=20=E5=BD=93=E5=89=8D=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=A6=82=E6=9E=9C=E6=B2=A1=E6=9C=89=E4=BB=BB=E4=BD=95?= =?UTF-8?q?=E6=9D=83=E9=99=90=E6=97=B6=EF=BC=8C=E5=9C=A8=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=E5=90=8E=EF=BC=8C=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E4=BC=9A=E6=8A=9BIllegalArgumentExc?= =?UTF-8?q?eption=20(#333)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dingwq --- .../modules/security/security/TokenProvider.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/security/security/TokenProvider.java b/eladmin-system/src/main/java/me/zhengjie/modules/security/security/TokenProvider.java index fb19eb962..efe587684 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/security/security/TokenProvider.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/security/security/TokenProvider.java @@ -1,5 +1,6 @@ package me.zhengjie.modules.security.security; +import cn.hutool.core.util.ObjectUtil; import io.jsonwebtoken.*; import io.jsonwebtoken.io.Decoders; import io.jsonwebtoken.security.Keys; @@ -16,6 +17,7 @@ import java.security.Key; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.stream.Collectors; @@ -63,10 +65,13 @@ Authentication getAuthentication(String token) { .parseClaimsJws(token) .getBody(); + // fix bug: 当前用户如果没有任何权限时,在输入用户名后,刷新验证码会抛IllegalArgumentException + Object authoritiesStr = claims.get(AUTHORITIES_KEY); Collection authorities = - Arrays.stream(claims.get(AUTHORITIES_KEY).toString().split(",")) + ObjectUtil.isNotEmpty(authoritiesStr) ? + Arrays.stream(authoritiesStr.toString().split(",")) .map(SimpleGrantedAuthority::new) - .collect(Collectors.toList()); + .collect(Collectors.toList()) : Collections.emptyList(); User principal = new User(claims.getSubject(), "", authorities);