I am using the current version of Spring Data Rest and Spring Data JPA and have following entity:
public class User {
@Id
@GeneratedValue
private
No, Spring Data REST projections don't support this.
You can also do it using a RegexRequestMatcher in your Spring Security config like this:
.regexMatchers(HttpMethod.GET,"/user/.*projection=simple.*").hasRole("ROLE_ADMIN")
You can add a "virtual" value property into the projection that invoke a service method with security checks:
@Projection(name = "detailed", types = User.class)
public interface UserDetailProjection extends UserSimpleProjection{
@Value("#{@userService.checkAccess(target)? target.email : null}")
public String getEmail();
}
Where your custom UserService
component would return true
if email should be exposed or simply has @PreAuthorize
on checkAccess(..)
to throw an AccessDeniedException
whatever is better for you.
Note, the target
property in the SpEL holds the original object - provided by Spring-DATA.