Remove Advised Methods from Authorization Proxy Objects
Closes gh-15561
This commit is contained in:
@@ -34,6 +34,8 @@ import java.util.TreeSet;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -336,6 +338,18 @@ public class AuthorizationAdvisorProxyFactoryTests {
|
||||
assertThat(factory.proxy(35)).isEqualTo(35);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeWhenAuthorizationProxyObjectThenOnlyIncludesProxiedProperties()
|
||||
throws JsonProcessingException {
|
||||
SecurityContextHolder.getContext().setAuthentication(this.admin);
|
||||
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory.withDefaults();
|
||||
User user = proxy(factory, this.alan);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String serialized = mapper.writeValueAsString(user);
|
||||
Map<String, Object> properties = mapper.readValue(serialized, Map.class);
|
||||
assertThat(properties).hasSize(3).containsKeys("id", "firstName", "lastName");
|
||||
}
|
||||
|
||||
private Authentication authenticated(String user, String... authorities) {
|
||||
return TestAuthentication.authenticated(TestAuthentication.withUsername(user).authorities(authorities).build());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user