|
|
@ -46,31 +46,22 @@ public class TokenAuthenticationFilter extends GenericFilterBean { |
|
|
|
if (null != accessToken) { |
|
|
|
// get and check whether token is valid ( from DB or file wherever you are |
|
|
|
// storing the token) |
|
|
|
Token token = tokenService.verifyToken(accessToken); |
|
|
|
|
|
|
|
if (token == null) { |
|
|
|
throw new UsernameNotFoundException("Token not issued by us"); |
|
|
|
} |
|
|
|
UserToken userToken = tokenRepository.findByToken(accessToken); |
|
|
|
|
|
|
|
if (userToken == null) { |
|
|
|
throw new UsernameNotFoundException("Token not associated with any user"); |
|
|
|
} |
|
|
|
Token token = tokenService.verifyToken(userToken.getTokenContent()); |
|
|
|
|
|
|
|
if (token == null) { |
|
|
|
throw new UsernameNotFoundException("Token not issued by us"); |
|
|
|
} |
|
|
|
|
|
|
|
String userName = userToken.getUserName(); |
|
|
|
if (userName == null) { |
|
|
|
throw new UsernameNotFoundException("User not found"); |
|
|
|
} |
|
|
|
|
|
|
|
// List<UserRole> userRoles = userRoleRepository.findByUser(chatUser.getUserName()); |
|
|
|
// // Populate SecurityContextHolder by fetching relevant information using token |
|
|
|
// final UserDetails userPrincipal = User.withUsername(chatUser.getUserName()).password(chatUser.getPassword()) |
|
|
|
// .roles(userRoles.stream().map(userRole -> { |
|
|
|
//// System.out.println("role = " + userRole.getRole().getName()); |
|
|
|
// return userRole.getRole().getName(); |
|
|
|
// }).toArray(size -> new String[size])).build(); |
|
|
|
// final UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( |
|
|
|
// userPrincipal, null, userPrincipal.getAuthorities()); |
|
|
|
SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority(userToken.getRole()); |
|
|
|
List<SimpleGrantedAuthority> updatedAuthorities = new ArrayList<SimpleGrantedAuthority>(); |
|
|
|
updatedAuthorities.add(simpleGrantedAuthority); |
|
|
|