Skip to content

Commit 4a92a89

Browse files
committed
code clean-up
1 parent d3d1ec0 commit 4a92a89

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

src/main/java/com/javachinna/controller/JwtAuthenticationController.java

+1-13
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import org.springframework.context.annotation.Profile;
44
import org.springframework.http.ResponseEntity;
55
import org.springframework.security.authentication.AuthenticationManager;
6-
import org.springframework.security.authentication.BadCredentialsException;
7-
import org.springframework.security.authentication.DisabledException;
86
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
97
import org.springframework.security.core.Authentication;
108
import org.springframework.security.core.userdetails.UserDetails;
@@ -30,19 +28,9 @@ public class JwtAuthenticationController {
3028

3129
@PostMapping("/authenticate")
3230
public ResponseEntity<?> createAuthenticationToken(@RequestBody JwtRequest authenticationRequest) throws Exception {
33-
Authentication authentication = authenticate(authenticationRequest.getUsername(), authenticationRequest.getPassword());
31+
Authentication authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(authenticationRequest.getUsername(), authenticationRequest.getPassword()));
3432
final UserDetails userDetails = (UserDetails) authentication.getPrincipal();
3533
final String token = jwtTokenUtil.generateToken(userDetails);
3634
return ResponseEntity.ok(new JwtResponse(token));
3735
}
38-
39-
private Authentication authenticate(String username, String password) throws Exception {
40-
try {
41-
return authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
42-
} catch (DisabledException e) {
43-
throw new Exception("USER_DISABLED", e);
44-
} catch (BadCredentialsException e) {
45-
throw new Exception("INVALID_CREDENTIALS", e);
46-
}
47-
}
4836
}

0 commit comments

Comments
 (0)