-2

i have this code i can create a user i can get the username and password but i have an error when i want to connect

@PostMapping("/signin")

public ResponseEntity<?> authenticateUser(@Valid @RequestBody LoginRequest loginRequest) {

    System.out.println("a"+loginRequest.getUsername()+loginRequest.getPassword());
    Authentication authentication = authenticationManager.authenticate(
            new UsernamePasswordAuthenticationToken(loginRequest.getUsername(), loginRequest.getPassword()));
    System.out.println("a"+loginRequest.getUsername()+loginRequest.getPassword());
   // new RuntimeException("Error: cccccc is not found.");
    SecurityContextHolder.getContext().setAuthentication(authentication);
    String jwt = jwtUtils.generateJwtToken(authentication);
   new RuntimeException("Error: cccccc is not found."+ jwt);
    //    new RuntimeException("Error: cccccc is not found.");
    UserDetailslmpl userDetails = (UserDetailslmpl) authentication.getPrincipal();
    List<String> roles = userDetails.getAuthorities().stream()
            .map(item -> item.getAuthority())
            .collect(Collectors.toList());
   // new RuntimeException("Error: aaaa is not found.");
    return ResponseEntity.ok(new JwtResponse(jwt,
            userDetails.getId(),
            userDetails.getUsername(),
            userDetails.getEmail(),
            roles));
}

this is the error

the error on postman

  • This is just a NullPointerException, have a look here: https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it. – Marged Feb 22 '20 at 00:04

1 Answers1

0

As mentioned in the comments it is a NullPointerException within your Controller. The stack trace is telling you that in the line 56 of your controller which happens to be

String jwt = jwtUtils.generateJwtToken(authentication);

the jwtUtils object seem to be null.

pero_hero
  • 2,881
  • 3
  • 10
  • 24
  • 2
    Please don't post answers on obviously off topic/bad questions! [See: **Should one advise on off topic questions?**](//meta.stackoverflow.com/q/276572) – double-beep Feb 22 '20 at 10:43