保护REST中管理字段的最佳实践

时间:2017-03-06 21:24:12

标签: angularjs spring mongodb spring-mvc

让我说MCV Rest Controller在mongo db中更新我的帐户文档。

Account.class

public class Account extends Credentials {

private static final long serialVersionUID = 1L;
private String email;
private String password;
private Boolean admin;
private String street;
private String postalcode;
private String city;
private String country;
private String phone;
private String birthday;
private String image;
}

电子邮件,密码是仅在注册过程中可写的字段。 admin是一个只能由管理员写入的字段。

其他字段可以通过"编辑帐户更新" html UI。

提供这样的RESTfull方法将使所有普通用户都能访问所有字段:

@RequestMapping(value = "upsert", method = RequestMethod.POST)
    public ResponseEntity<Account> upsert(@RequestBody Account acc) throws Exception {
        Provider entity = providerRepository.save(acc);
        return new ResponseEntity<Account>(entity, HttpStatus.OK);
    }

如果我标记&#34;特殊&#34;只有@JsonProperty的字段才能进行读取访问,然后上面的更新将在保存操作期间将它们从数据库中删除。

分离&#34;特殊&#34;的最佳方法是什么?来自&#34; normal&#34;的字段字段?

0 个答案:

没有答案