我正在使用React和Spring开发一个基本的CRUD Web应用程序。 由于前端尚未准备好,我正在使用Postman进行测试。 我有这个方法,但我刚刚发现任何人都可以发送HTTP请求并获取所有数据,只要他们知道id。
@PostMapping("/utente")
public ResponseEntity<Object> getDatiProfiloUtente(@RequestBody final Long idUtente){
HashMap<String, Object> map = new HashMap<>();
Paziente paziente = service.findPazienteById(idUtente);
map.put("nome", paziente.getNome());
map.put("cognome", paziente.getCognome());
map.put("email", paziente.getEmail());
map.put("nTelefono", paziente.getNumeroTelefono());
map.put("emailCaregiver", paziente.getEmailCaregiver());
map.put("nomeCaregiver", paziente.getNomeCaregiver());
map.put("cognomeCaregiver", paziente.getCognomeCaregiver());
return new ResponseEntity<>(map, HttpStatus.OK);
}
我该如何提供安全性?我希望只有登录的用户可以查看自己的数据。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您想要使用由Spring Security提供的
@Secured注解,这篇baeldung的文章是一个很好的资源,可以详细解释如何设置您所需的方法安全性。