Search code examples
springspring-bootspring-securityspring-data-restprojection

Spring data rest select Projection from user role


I have two projection

@Projection(name = "default",types = { People.class }) 
public interface DefaultPeople {
    String getFirstName();
    String getLastName();
}

and

@Projection(name = "privacy",types = { People.class }) 
public interface DefaultPeople {
    @Value("#{target.firstName.charAt(0)}")
    String getFirstName();
    @Value("#{target.lastName.charAt(0)}")
    String getLastName();
}

privacy projection print only first charater of firstname and lastname

i want : ROLE_ADMIN access to projection default and ROLE_USER access to only projection pryvacy

is possible?


Solution

  • Impossible. You need to implement the Controller to return different projection yourself.

    Spring Data REST is not a silver bullet to solve all HTTP API problem. Just don't use it if it doesn't meet your requirement.