|
@@ -1,8 +1,11 @@ |
|
|
package com.ffii.fpsms.config.security.jwt.web; |
|
|
package com.ffii.fpsms.config.security.jwt.web; |
|
|
|
|
|
|
|
|
import java.time.Instant; |
|
|
import java.time.Instant; |
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.HashSet; |
|
|
import java.util.HashSet; |
|
|
|
|
|
import java.util.List; |
|
|
import java.util.Set; |
|
|
import java.util.Set; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils; |
|
|
import org.apache.commons.lang3.exception.ExceptionUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
@@ -11,6 +14,7 @@ import org.springframework.http.HttpStatus; |
|
|
import org.springframework.http.ResponseEntity; |
|
|
import org.springframework.http.ResponseEntity; |
|
|
import org.springframework.security.authentication.AuthenticationManager; |
|
|
import org.springframework.security.authentication.AuthenticationManager; |
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
|
|
|
|
|
import org.springframework.security.core.authority.SimpleGrantedAuthority; |
|
|
import org.springframework.security.core.userdetails.UserDetails; |
|
|
import org.springframework.security.core.userdetails.UserDetails; |
|
|
import org.springframework.web.bind.annotation.CrossOrigin; |
|
|
import org.springframework.web.bind.annotation.CrossOrigin; |
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
@@ -115,9 +119,12 @@ public class JwtAuthenticationController { |
|
|
|
|
|
|
|
|
User user = userRepository.findByName(authenticationRequest.getUsername()).get(0); |
|
|
User user = userRepository.findByName(authenticationRequest.getUsername()).get(0); |
|
|
|
|
|
|
|
|
Set<AbilityModel> abilities = new HashSet<>(); |
|
|
|
|
|
userAuthorityService.getUserAuthority(user).forEach(auth -> abilities.add(new AbilityModel(auth.getAuthority()))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> abilities = new ArrayList<>(); |
|
|
|
|
|
final Set<SimpleGrantedAuthority> userAuthority = userAuthorityService.getUserAuthority(user); |
|
|
|
|
|
if (!userAuthority.isEmpty()) { |
|
|
|
|
|
abilities = userAuthority.stream() |
|
|
|
|
|
.map(auth -> auth.getAuthority()).toList(); |
|
|
|
|
|
} |
|
|
return ResponseEntity.ok(new JwtResponse(accessToken, refreshToken, null, user, abilities)); |
|
|
return ResponseEntity.ok(new JwtResponse(accessToken, refreshToken, null, user, abilities)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|