11package hawk .api .jwt ;
22
33import hawk .api .AuthenticationRequest ;
4+ import hawk .repos .UserRepo ;
45import org .springframework .beans .factory .annotation .Autowired ;
56import org .springframework .http .ResponseEntity ;
67import org .springframework .security .authentication .AuthenticationManager ;
@@ -27,12 +28,15 @@ public class JwtAuthController {
2728 private final AuthenticationManager authenticationManager ;
2829 private final JwtTokenProvider jwtTokenProvider ;
2930 private final UserDetailsService userDetailsService ;
31+ private final UserRepo userRepo ;
3032
3133 @ Autowired
32- public JwtAuthController (AuthenticationManager authenticationManager , JwtTokenProvider jwtTokenProvider , UserDetailsService userDetailsService ) {
34+ public JwtAuthController (AuthenticationManager authenticationManager , JwtTokenProvider jwtTokenProvider , UserDetailsService userDetailsService ,
35+ UserRepo userRepo ) {
3336 this .authenticationManager = authenticationManager ;
3437 this .jwtTokenProvider = jwtTokenProvider ;
3538 this .userDetailsService = userDetailsService ;
39+ this .userRepo = userRepo ;
3640 }
3741
3842 @ PostMapping ("/signin" )
@@ -44,8 +48,11 @@ public ResponseEntity signin(@RequestBody AuthenticationRequest data) {
4448 if (null == userDetails ) {
4549 throw new UsernameNotFoundException ("username" );
4650 }
51+
52+ String tenantId = this .userRepo .findByName (username ).getTenantId ();
4753 String token = jwtTokenProvider .createToken (username ,
48- userDetails .getAuthorities ().stream ().map (auth -> ((GrantedAuthority ) auth ).toString ()).collect (Collectors .toList ()));
54+ userDetails .getAuthorities ().stream ().map (auth -> ((GrantedAuthority ) auth ).toString ()).collect (Collectors .toList ()),
55+ tenantId );
4956 Map <Object , Object > model = new HashMap <>();
5057 model .put ("username" , username );
5158 model .put ("token" , token );
0 commit comments