1

I'm trying to call Java springboot webservice with my Angular 4.1 application but there is a HTTP 401 error.

My springboot webservice works fine with Firefox or rest client but not with angular. I think it's angular typescript problem.

This is the Java EE error :

Access is denied (user is anonymous); redirecting to authentication entry point org.springframework.security.access.AccessDeniedException: Access is denied

This is my angular code :

var headers = new Headers({authorization : "Basic " + btoa("j:j")});
let options = new RequestOptions({ headers: headers });
let url: string = 'http://localhost:8080/wstest';
return this._http.get(url, options)
.map((res: Response) => res.json())
.subscribe(datas => {
  console.log(datas);
});

When I use wireshark with browser webservice call, see basic autorization header :

Authorization: Basic ajpq\r\n
Credentials: j:j

But, with angular call, there is no credentials :

Access-Control-Request-Headers: authorization

How can I call my springboot webservice with Angular 4.1 in order to add Basic authorisation credentials?

Mario Petrovic
  • 7,500
  • 14
  • 42
  • 62
Jérémy
  • 391
  • 2
  • 7
  • 20

1 Answers1

0

I have find my response.

Standalone Spring OAuth2 JWT Authorization Server + CORS

Springboot server must implements specific filter in order to allow angular "OPTION" webservice request.

Jérémy
  • 391
  • 2
  • 7
  • 20