Skip to content

Commit

Permalink
Fixes Issue #151
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherRBrown committed Feb 27, 2019
1 parent a707b9e commit acecc02
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 326 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.viadee.sonarquest.controllers.PathConstants;
import com.viadee.sonarquest.security.JwtHelper;
import com.viadee.sonarquest.services.UserService;

@RestController
@RequestMapping(PathConstants.LOGIN_URL)
Expand All @@ -33,6 +34,9 @@ public class LoginController {
@Autowired
private JwtHelper jwtHelper;

@Autowired
private UserService userService;

@GetMapping
public String info() {
return "Dies ist eine Login Seite";
Expand All @@ -41,10 +45,11 @@ public String info() {
@PostMapping
public Token login(@Valid @RequestBody final UserCredentials credentials) {

String username = credentials.getUsername();
final String username = credentials.getUsername();
LOGGER.info("Log-In request received from user {}", Objects.hashCode(username));
final User authenticatedUser = authentificateUser(credentials);
final Token token = createTokenForUser(authenticatedUser);
userService.updateLastLogin(authenticatedUser.getUsername());
LOGGER.info("Log-In request successful for user {}", Objects.hashCode(username));
return token;
}
Expand All @@ -55,12 +60,12 @@ private User authentificateUser(final UserCredentials credentials) {
}

private Authentication authenticate(final UserCredentials credentials) {
String username = credentials.getUsername();
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(username,
final String username = credentials.getUsername();
final UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(username,
credentials.getPassword());
try {
return authenticationManager.authenticate(authToken);
} catch (BadCredentialsException ex) {
} catch (final BadCredentialsException ex) {
LOGGER.warn(String.format("Log-In request denied with bad credentials for user %s",
Objects.hashCode(username)));
throw ex;
Expand Down
Loading

0 comments on commit acecc02

Please sign in to comment.