-
Notifications
You must be signed in to change notification settings - Fork 1
/
LoginAttemptsController.java
55 lines (48 loc) · 1.89 KB
/
LoginAttemptsController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.izettle.authmanagement.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.izettle.authmanagement.access.Permission;
import com.izettle.authmanagement.access.PermissionRequired;
import com.izettle.authmanagement.dto.login.LoggedInUserDetails;
import com.izettle.authmanagement.dto.login.LoginAttempt;
import com.izettle.authmanagement.service.LoginAttemptService;
/**
* The entry point for all the /loginAttempts requests.
*
* @author Thiyagu
* @version 1.0
*
*/
@RestController
@RequestMapping("/loginAttempts")
public class LoginAttemptsController {
/**
* The loginAttempt service bean.
*/
@Autowired
private LoginAttemptService loginAttemptService;
/**
* Method to return all the top 5 recent successful login attempts.
*
* @return list Of loginAttempt
*/
@PermissionRequired(value=Permission.READ,country="US")
@GetMapping("/success")
public ResponseEntity<List<LoginAttempt>> getSuccessfulLoggedInHistory() {
Pageable request = PageRequest.of(0, 5, Direction.DESC, "loggedInAt");
String loggedInUserId = ((LoggedInUserDetails) SecurityContextHolder.getContext().getAuthentication()
.getPrincipal()).getUserId();
List<LoginAttempt> loginAttempts = loginAttemptService.getSuccessfulLoginAttempts(loggedInUserId,
request);
return new ResponseEntity<List<LoginAttempt>>(loginAttempts, HttpStatus.OK);
}
}