I am new to angular and spring-security. I am having problem with updating my data from angular but i can update it using insomnia when i test my api (i pass the token in the header).
Im passing the token to the put method but i get access denied 403
this is my function in angular service
private headers = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': this.authService.jwt
});
updateUserById(id: String): Observable<any> {
console.log(this.headers);
return this.http.put(this.host_3 + '/' + id, {headers: this.headers});
}
this is my function in component controller
onSubmit(){
this.updateCustomer();
}
updateCustomer(){
console.log("inside update"+this.userr);
this.coordservice.updateUserById(this.userr).
subscribe(data => console.log("data"+data), error => console.log(error));
}
this is my backend function in spring controller
@PutMapping(value = "/customersList/updateCustomer/{idCustomer}")
public ResponseEntity<Customer> update(@PathVariable(name = "idCustomer") String idCustomer, @RequestBody Customer customer){
this.customerService.updateCustomer(idCustomer,customer);
return new ResponseEntity<Customer>(customer, HttpStatus.NO_CONTENT);
}
Security configuration
rotected void doFilterInternal(HttpServletRequest request,HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, authorization");
response.addHeader("Access-Control-Expose-Headers", "Access-Control-Allow-Origin, Access-Control-Allow-Credentials, authorization");
response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH");
Note: i can get data using http.get() but for method put i get access denied