| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | // 从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()); |
| | | |