I recently started learning the sping-boot framework and I'm trying to build a controller to handle users. I created a rest controller as follow:
@RestController
@RequestMapping("/users")
public class UserController {
@Autowired
UserRepository userRepository;
@Autowired
BCryptPasswordEncoder bCryptPasswordEncoder;
@PostMapping("/sign-up")
public void signUp(@RequestBody User user) {
user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
userRepository.save(user);
}
}
and this is the model:
@Entity
@Table(name = "req_user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String username;
@JsonIgnore
private String password;
private String email;
public User() { }
public User(String username, String password, String email) {
this.id = null;
this.username = username;
this.password = password;
this.email = email;
}
...
@JsonIgnore
public String getPassword() {
return password;
}
@JsonProperty
public void setPassword(String password) {
this.password = password;
}
...
}
end this is the repository:
@Repository
public interface UserRepository extends CrudRepository<User, Long> {
User findByUsername(String username);
}
Now that works fine, but I want to disable some actions that are provided by RestController by default. In particular, I want to inhibit the possibility to view the list of all users and to delete one of them. What is the recommended way to do that?