ZhuDongming
2019-10-22 28215e381131b0919567ec5c3f236b29ebd3ad5c
src/main/java/com/moral/security/endpoint/RefreshTokenEndpoint.java
@@ -1,7 +1,7 @@
package com.moral.security.endpoint;
import com.moral.entity.Account;
import com.moral.security.auth.JwtAuthenticationToken;
import com.moral.entity.Role;
import com.moral.security.auth.login.LoginMode;
import com.moral.security.model.token.JwtTokenFactory;
import com.moral.security.auth.jwt.extractor.TokenExtractor;
@@ -14,6 +14,8 @@
import com.moral.security.model.token.RawAccessJwtToken;
import com.moral.security.model.token.RefreshToken;
import com.moral.service.AccountService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.MediaType;
@@ -69,9 +71,9 @@
        // 从refresh token里 拿到登录方式
        LoginMode mode = LoginMode.valueOf(refreshToken.getClaims().getBody().get("mode").toString());
        Account account = accountService.queryAccountByName(subject).orElseThrow(() -> new UsernameNotFoundException("User not found: " + subject));
        if (account.getRoles() == null) throw new InsufficientAuthenticationException("User has no roles assigned");
        List<GrantedAuthority> authorities = account.getRoles().stream()
        List<Role> roleList = accountService.getRolesByAccountName(account.getAccountName());
        if (CollectionUtils.isEmpty(roleList)) throw new InsufficientAuthenticationException("User has no roles assigned");
        List<GrantedAuthority> authorities = roleList.stream()
                .map(authority -> new SimpleGrantedAuthority(authority.getRoleName()))
                .collect(Collectors.toList());