royclarkson / spring-rest-service-oauth

A simple OAuth protected REST service built with Spring Boot and Spring Security OAuth
Apache License 2.0
664 stars 339 forks source link

how to avoid password from serialization in User entity #29

Open sridhar1982 opened 9 years ago

sridhar1982 commented 9 years ago

This is more of a question.

I do not want the password of user available in controller. After making the following change to the controller, I see the password of the User returned.

@RestController
public class GreetingController {

    private static final String template = "Hello, %s! your password is %s";

    private final AtomicLong counter = new AtomicLong();

    @RequestMapping("/greeting")
    public Greeting greeting(@AuthenticationPrincipal User user) {
        return new Greeting(counter.incrementAndGet(), String.format(template, user.getName(),user.getPassword()));
    }

}

In order to avoid password, I add the following in the User Entity.

@Entity
public class User {

    ......

    @NotEmpty
    @JsonIgnore
    private String password;

       ......
}

I still see the password returned. Any help here will be very useful.

Thanks