-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathPersonRestController.java
More file actions
42 lines (33 loc) · 1.11 KB
/
Copy pathPersonRestController.java
File metadata and controls
42 lines (33 loc) · 1.11 KB
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
package org.zerhusen.rest;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api")
public class PersonRestController {
@GetMapping("/person")
public ResponseEntity<Person> getPerson() {
return ResponseEntity.ok(new Person("John Doe", "john.doe@test.org"));
}
@GetMapping("/person-preauthorize")
@PreAuthorize("hasAuthority('ROLE_USER')")
public ResponseEntity<Person> getPersonExample() {
return ResponseEntity.ok(new Person("John Snow", "john.snow@test.org"));
}
private static class Person {
private final String name;
private final String email;
public Person(String name, String email) {
this.name = name;
this.email = email;
}
public String getName() {
return name;
}
public String getEmail() {
return email;
}
}
}