@@ -15,21 +15,21 @@
|
||||
*/
|
||||
package example.springdata.mongodb.security;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.PersistenceConstructor;
|
||||
|
||||
/**
|
||||
* An entity to represent a {@link Person}.
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
@Data
|
||||
@RequiredArgsConstructor
|
||||
public class Person {
|
||||
public record Person(@Id String id, String firstname, String lastname) {
|
||||
|
||||
private @Id String id;
|
||||
private final String firstname;
|
||||
private final String lastname;
|
||||
@PersistenceConstructor
|
||||
public Person {
|
||||
}
|
||||
|
||||
public Person(String firstname, String lastname) {
|
||||
this(null, firstname, lastname);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class PersonRepositoryIntegrationTest {
|
||||
|
||||
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(dave, "x"));
|
||||
|
||||
List<Person> persons = repository.findAllForCurrentUserById();
|
||||
var persons = repository.findAllForCurrentUserById();
|
||||
|
||||
assertThat(persons, hasSize(1));
|
||||
assertThat(persons, contains(dave));
|
||||
@@ -70,11 +70,11 @@ public class PersonRepositoryIntegrationTest {
|
||||
@Test
|
||||
public void adminCallingShouldReturnAllUsers() throws Exception {
|
||||
|
||||
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(admin, "x",
|
||||
var auth = new UsernamePasswordAuthenticationToken(admin, "x",
|
||||
Collections.singleton(new SimpleGrantedAuthority("ROLE_ADMIN")));
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
|
||||
List<Person> persons = repository.findAllForCurrentUserById();
|
||||
var persons = repository.findAllForCurrentUserById();
|
||||
|
||||
assertThat(persons, hasSize(4));
|
||||
assertThat(persons, containsInAnyOrder(admin, dave, carter, oliver));
|
||||
|
||||
Reference in New Issue
Block a user