Skip to content

Commit

Permalink
fix bug: 当前用户如果没有任何权限时,在输入用户名后,刷新验证码会抛IllegalArgumentException (elune…
Browse files Browse the repository at this point in the history
…z#333)

Co-authored-by: Dingwq <[email protected]>
  • Loading branch information
cnzbq and Dingwq authored Apr 23, 2020
1 parent 95e9128 commit 0783648
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -63,10 +65,13 @@ Authentication getAuthentication(String token) {
.parseClaimsJws(token)
.getBody();

// fix bug: 当前用户如果没有任何权限时,在输入用户名后,刷新验证码会抛IllegalArgumentException
Object authoritiesStr = claims.get(AUTHORITIES_KEY);
Collection<? extends GrantedAuthority> 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);

Expand Down

0 comments on commit 0783648

Please sign in to comment.