@Test public void testLoginUser() { registerUser("alice", "passw0rd", "alice@example.com"); UserApiData alice = service().users().search().findUserForLogin("alice").getData().stream().findFirst().get(); ResponseEntity loginResult = alice.getResource().loggedIn(); assertThat(loginResult.getStatusCode(), is(HttpStatus.OK)); UserApiData loggedInAlice = service().users().search().findByUsername("alice").getData().stream().findFirst().get(); assertThat(loggedInAlice.getLastLogin(), is(notNullValue())); }
@RequestMapping(value = "{userId}", method = RequestMethod.POST) public ResponseEntity loginUser(@PathVariable Long userId) { User user = userService.findById(userId); if (user == null || !user.isEnabled() || !user.isAccountNonExpired() || !user.isAccountNonLocked() || !user.isCredentialsNonExpired()) { return new ResponseEntity(HttpStatus.NOT_FOUND); } user.setLastLogin(LocalDateTime.now()); userService.save(user); return new ResponseEntity(HttpStatus.OK); }
UserLoginRestController { @RequestMapping(value = "{userId}", method = RequestMethod.POST) public ResponseEntity loginUser(@PathVariable Long userId) { User user = userService.findById(userId); if (user == null || !user.isEnabled() || !user.isAccountNonExpired() || !user.isAccountNonLocked() || !user.isCredentialsNonExpired()) { return new ResponseEntity(HttpStatus.NOT_FOUND); } user.setLastLogin(LocalDateTime.now()); userService.save(user); return new ResponseEntity(HttpStatus.OK); } }
UserLoginRestController { @RequestMapping(value = "{userId}", method = RequestMethod.POST) public ResponseEntity loginUser(@PathVariable Long userId) { User user = userService.findById(userId); if (user == null || !user.isEnabled() || !user.isAccountNonExpired() || !user.isAccountNonLocked() || !user.isCredentialsNonExpired()) { return new ResponseEntity(HttpStatus.NOT_FOUND); } user.setLastLogin(LocalDateTime.now()); userService.save(user); return new ResponseEntity(HttpStatus.OK); }  }
UserLoginRestController { @RequestMapping(value = "{userId}", method = RequestMethod.POST) public ResponseEntity loginUser(@PathVariable Long userId) { User user = userService.findById(userId); if (user == null || !user.isEnabled() || !user.isAccountNonExpired() || !user.isAccountNonLocked() || !user.isCredentialsNonExpired()) { return new ResponseEntity(HttpStatus.NOT_FOUND); } user.setLastLogin(LocalDateTime.now()); userService.save(user); return new ResponseEntity(HttpStatus.OK); }  @RequestMapping(value = "{userId}", method = RequestMethod.POST) ResponseEntity loginUser(@PathVariable Long userId); }
UserLoginRestController { @RequestMapping(value = "{userId}", method = RequestMethod.POST) public ResponseEntity loginUser(@PathVariable Long userId) { User user = userService.findById(userId); if (user == null || !user.isEnabled() || !user.isAccountNonExpired() || !user.isAccountNonLocked() || !user.isCredentialsNonExpired()) { return new ResponseEntity(HttpStatus.NOT_FOUND); } user.setLastLogin(LocalDateTime.now()); userService.save(user); return new ResponseEntity(HttpStatus.OK); }  @RequestMapping(value = "{userId}", method = RequestMethod.POST) ResponseEntity loginUser(@PathVariable Long userId);  }